{"id":2221952,"url":"http://patchwork.ozlabs.org/api/patches/2221952/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-pci/patch/20260410-sdxi-base-v1-22-1d184cb5c60a@amd.com/","project":{"id":28,"url":"http://patchwork.ozlabs.org/api/projects/28/?format=json","name":"Linux PCI development","link_name":"linux-pci","list_id":"linux-pci.vger.kernel.org","list_email":"linux-pci@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260410-sdxi-base-v1-22-1d184cb5c60a@amd.com>","list_archive_url":null,"date":"2026-04-10T13:07:32","name":"[22/23] dmaengine: sdxi: MSI/MSI-X vector allocation and mapping","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"5b5de8dfa200bd21bd113559d4858f2eefcb1978","submitter":{"id":91626,"url":"http://patchwork.ozlabs.org/api/people/91626/?format=json","name":"Nathan Lynch via B4 Relay","email":"devnull+nathan.lynch.amd.com@kernel.org"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-pci/patch/20260410-sdxi-base-v1-22-1d184cb5c60a@amd.com/mbox/","series":[{"id":499458,"url":"http://patchwork.ozlabs.org/api/series/499458/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-pci/list/?series=499458","date":"2026-04-10T13:07:10","name":"dmaengine: Smart Data Accelerator Interface (SDXI) basic support","version":1,"mbox":"http://patchwork.ozlabs.org/series/499458/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2221952/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2221952/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <linux-pci+bounces-52334-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-pci@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=kBtF9eLu;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c0a:e001:db::12fc:5321; helo=sea.lore.kernel.org;\n envelope-from=linux-pci+bounces-52334-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org\n header.b=\"kBtF9eLu\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=10.30.226.201"],"Received":["from sea.lore.kernel.org (sea.lore.kernel.org\n [IPv6:2600:3c0a:e001:db::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fscfQ1xxJz1yGS\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 10 Apr 2026 23:12:30 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sea.lore.kernel.org (Postfix) with ESMTP id DB65F309C677\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 10 Apr 2026 13:08:06 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 81DE13C345A;\n\tFri, 10 Apr 2026 13:07:51 +0000 (UTC)","from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org\n [10.30.226.201])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 15AE93BF67A;\n\tFri, 10 Apr 2026 13:07:51 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPS id F0465C2BCAF;\n\tFri, 10 Apr 2026 13:07:50 +0000 (UTC)","from aws-us-west-2-korg-lkml-1.web.codeaurora.org\n (localhost.localdomain [127.0.0.1])\n\tby smtp.lore.kernel.org (Postfix) with ESMTP id E9B42F44860;\n\tFri, 10 Apr 2026 13:07:50 +0000 (UTC)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1775826471; cv=none;\n b=uUHJA2KVKc+v+NHDWIisiLlOYWcO0EBByBoGABgfI7Th6wR786goK06AUJ7FxvxLu9scY264p6Xa5J7dh1dil+0UER80e0t2PcIBraAZzR4Yxy0uWVepVVjur2tDtwyrp0lEsKtIF7GHLXCXKyF/SECmEvr0uiKSyPO3Dy+BFik=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1775826471; c=relaxed/simple;\n\tbh=G2huuPtM8dkZc7ys3YvCtddLjlcJRsje8S+Ue6LmqbM=;\n\th=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:\n\t In-Reply-To:To:Cc;\n b=htgw1IC2PYxvY1lphIMjmqgl38lgf0Py7EFktpC+WlMDi1rAiifyC+9tikXR0AEYwHR5tkLknff1+LL/XnZerOhCuL00wX/jCbMGCCHMThrqWlc43smwipFJX8fmpwQGHBBCfKSkRwEDSQgshXX3s71DnTOIQ6DN6vwYX0Ne5YU=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org\n header.b=kBtF9eLu; arc=none smtp.client-ip=10.30.226.201","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;\n\ts=k20201202; t=1775826471;\n\tbh=G2huuPtM8dkZc7ys3YvCtddLjlcJRsje8S+Ue6LmqbM=;\n\th=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From;\n\tb=kBtF9eLuCD+pBYJqjlEY3TzIftzPCZffmAqfpSKPWMt1Vc/DwAL7IHKct4/a85WJD\n\t 0OAkdWGglJuYnopM2lDK0txfXejmx9KhgOqH6F3G1UBO+wnnxfQP4qzwoPmPYZJDLr\n\t GZVKjbxce6ctMb+HgXAAX0UJSQfYW2aCOtACyyoGH8MMkvXBop76KiZDO1tbtN/bRn\n\t jRyWsM60zlN31RUVsMtYSA7iSzdoGS6FrZZsKwYcZTYauVeSL2uFBqqxqIepyxdhLj\n\t IP4usiJzH4Oh+1D3RyXXV3M6xOPxGwun5IlPRWn4dH1fAZ40Nn083TCJt/d5LNVbH9\n\t 6mq6g6jCVh6WA==","From":"Nathan Lynch via B4 Relay <devnull+nathan.lynch.amd.com@kernel.org>","Date":"Fri, 10 Apr 2026 08:07:32 -0500","Subject":"[PATCH 22/23] dmaengine: sdxi: MSI/MSI-X vector allocation and\n mapping","Precedence":"bulk","X-Mailing-List":"linux-pci@vger.kernel.org","List-Id":"<linux-pci.vger.kernel.org>","List-Subscribe":"<mailto:linux-pci+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-pci+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"7bit","Message-Id":"<20260410-sdxi-base-v1-22-1d184cb5c60a@amd.com>","References":"<20260410-sdxi-base-v1-0-1d184cb5c60a@amd.com>","In-Reply-To":"<20260410-sdxi-base-v1-0-1d184cb5c60a@amd.com>","To":"Vinod Koul <vkoul@kernel.org>","Cc":"Wei Huang <wei.huang2@amd.com>,\n Mario Limonciello <mario.limonciello@amd.com>,\n Bjorn Helgaas <bhelgaas@google.com>,\n Jonathan Cameron <jonathan.cameron@huawei.com>,\n Stephen Bates <Stephen.Bates@amd.com>, PradeepVineshReddy.Kodamati@amd.com,\n John.Kariuki@amd.com, linux-pci@vger.kernel.org,\n linux-kernel@vger.kernel.org, dmaengine@vger.kernel.org,\n Nathan Lynch <nathan.lynch@amd.com>","X-Mailer":"b4 0.15.2","X-Developer-Signature":"v=1; a=ed25519-sha256; t=1775826467; l=6787;\n i=nathan.lynch@amd.com; s=20260410; h=from:subject:message-id;\n bh=+70bvPsXLZ6JtPOvD5LtOSlAhOg3eN58vo6yDBNKJ0s=;\n b=gNZi96Bgh+vS0dBam9zeGmkSaV4mScK2225z7j07aiU5mBGt3DVyCo+TfF8XaM2eeVgWVSM+B\n HwfUKkollP0Bl/f+3MeMuQPwo6ZQeFLagjMRwVaEuCSeylMKU7fXm5o","X-Developer-Key":"i=nathan.lynch@amd.com; a=ed25519;\n pk=PK4ozhq+/z9/2Jl5rgDmvHa9raVomv79qM8p1RAFpEw=","X-Endpoint-Received":"by B4 Relay for nathan.lynch@amd.com/20260410 with\n auth_id=728","X-Original-From":"Nathan Lynch <nathan.lynch@amd.com>","Reply-To":"nathan.lynch@amd.com"},"content":"From: Nathan Lynch <nathan.lynch@amd.com>\n\nDuring PCI probe, allocate a vector per context supported by the\nfunction as reported by the capability register, plus one for the\nerror log interrupt, which is always vector 0. The rest of the vector\nrange is available for use with interrupt-generating descriptors.\n\nIntroduce sdxi_alloc_vector() and sdxi_free_vector() which are thin\nwrappers around the IDA that tracks the allocated vector range.\n\nIntroduce sdxi_vector_to_irq() which invokes a new get_irq() bus op to\ntranslate the device-relative index to the Linux IRQ number for use\nwith request_irq() etc. For PCI this dispatches to pci_irq_vector().\n\nCode such as the DMA engine provider that intends to submit interrupt\ndescriptors should prepare by using sdxi_alloc_vector() and\nsdxi_vector_to_irq(), and clean up by using sdxi_free_vector().\n\nCo-developed-by: Wei Huang <wei.huang2@amd.com>\nSigned-off-by: Wei Huang <wei.huang2@amd.com>\nSigned-off-by: Nathan Lynch <nathan.lynch@amd.com>\n---\n drivers/dma/sdxi/device.c |  4 ++++\n drivers/dma/sdxi/pci.c    | 29 +++++++++++++++++++++++-\n drivers/dma/sdxi/sdxi.h   | 57 +++++++++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 89 insertions(+), 1 deletion(-)","diff":"diff --git a/drivers/dma/sdxi/device.c b/drivers/dma/sdxi/device.c\nindex aaff6b15325a..8b11197c5781 100644\n--- a/drivers/dma/sdxi/device.c\n+++ b/drivers/dma/sdxi/device.c\n@@ -10,6 +10,7 @@\n #include <linux/device.h>\n #include <linux/dma-mapping.h>\n #include <linux/dmapool.h>\n+#include <linux/idr.h>\n #include <linux/log2.h>\n #include <linux/slab.h>\n #include <linux/xarray.h>\n@@ -303,6 +304,7 @@ int sdxi_register(struct device *dev, const struct sdxi_bus_ops *ops)\n \n \tsdxi->dev = dev;\n \tsdxi->bus_ops = ops;\n+\tida_init(&sdxi->vectors);\n \txa_init_flags(&sdxi->client_cxts, XA_FLAGS_ALLOC1);\n \tdev_set_drvdata(dev, sdxi);\n \n@@ -323,5 +325,7 @@ void sdxi_unregister(struct device *dev)\n \t\tsdxi_cxt_exit(cxt);\n \txa_destroy(&sdxi->client_cxts);\n \n+\tida_destroy(&sdxi->vectors);\n+\n \tsdxi_dev_stop(sdxi);\n }\ndiff --git a/drivers/dma/sdxi/pci.c b/drivers/dma/sdxi/pci.c\nindex 8e4dfde078ff..99430eaa583d 100644\n--- a/drivers/dma/sdxi/pci.c\n+++ b/drivers/dma/sdxi/pci.c\n@@ -5,6 +5,7 @@\n  * Copyright Advanced Micro Devices, Inc.\n  */\n \n+#include <linux/bitfield.h>\n #include <linux/dev_printk.h>\n #include <linux/dma-mapping.h>\n #include <linux/err.h>\n@@ -13,6 +14,7 @@\n #include <linux/module.h>\n #include <linux/pci.h>\n \n+#include \"mmio.h\"\n #include \"sdxi.h\"\n \n enum sdxi_mmio_bars {\n@@ -29,7 +31,8 @@ static int sdxi_pci_init(struct sdxi_dev *sdxi)\n {\n \tstruct pci_dev *pdev = sdxi_to_pci_dev(sdxi);\n \tstruct device *dev = &pdev->dev;\n-\tint ret;\n+\tunsigned int cap1_max_cxt;\n+\tint vecs, ret;\n \n \tret = pcim_enable_device(pdev);\n \tif (ret)\n@@ -53,12 +56,36 @@ static int sdxi_pci_init(struct sdxi_dev *sdxi)\n \t\t\t\t     \"failed to map doorbell region\\n\");\n \t}\n \n+\t/*\n+\t * Allocate the minimum required set of vectors plus one for\n+\t * each client context supported by the function.\n+\t */\n+\tcap1_max_cxt = FIELD_GET(SDXI_MMIO_CAP1_MAX_CXT,\n+\t\t\t\t sdxi_read64(sdxi, SDXI_MMIO_CAP1));\n+\tvecs = pci_alloc_irq_vectors(pdev, SDXI_MIN_VECTORS,\n+\t\t\t\t     SDXI_MIN_VECTORS + cap1_max_cxt,\n+\t\t\t\t     PCI_IRQ_MSI | PCI_IRQ_MSIX);\n+\tif (vecs < 0) {\n+\t\treturn dev_err_probe(dev, vecs,\n+\t\t\t\t     \"failed to allocate MSIs (max_cxt=%u)\\n\",\n+\t\t\t\t     cap1_max_cxt);\n+\t}\n+\n+\tsdxi->nr_vectors = vecs;\n+\tsdxi_dbg(sdxi, \"allocated %u vectors\\n\", sdxi->nr_vectors);\n+\n \tpci_set_master(pdev);\n \treturn 0;\n }\n \n+static int sdxi_pci_get_irq(struct sdxi_dev *sdxi, unsigned int nr)\n+{\n+\treturn pci_irq_vector(sdxi_to_pci_dev(sdxi), nr);\n+}\n+\n static const struct sdxi_bus_ops sdxi_pci_ops = {\n \t.init = sdxi_pci_init,\n+\t.get_irq = sdxi_pci_get_irq,\n };\n \n static int sdxi_pci_probe(struct pci_dev *pdev,\ndiff --git a/drivers/dma/sdxi/sdxi.h b/drivers/dma/sdxi/sdxi.h\nindex da33719735ab..d4e1236a775e 100644\n--- a/drivers/dma/sdxi/sdxi.h\n+++ b/drivers/dma/sdxi/sdxi.h\n@@ -8,8 +8,10 @@\n #ifndef DMA_SDXI_H\n #define DMA_SDXI_H\n \n+#include <linux/bug.h>\n #include <linux/compiler_types.h>\n #include <linux/dev_printk.h>\n+#include <linux/idr.h>\n #include <linux/io-64-nonatomic-lo-hi.h>\n #include <linux/types.h>\n #include <linux/xarray.h>\n@@ -27,6 +29,21 @@\n #define L1_CXT_CTRL_PTR_SHIFT\t\t6\n #define L1_CXT_AKEY_PTR_SHIFT\t\t12\n \n+enum {\n+\t/*\n+\t * Per SDXI 1.0 3.4 Error Log, the error log interrupt is\n+\t * always vector 0.\n+\t */\n+\tSDXI_ERROR_VECTOR = 0,\n+\n+\t/*\n+\t * Request at least one vector to account for the error log\n+\t * interrupt. Increment this if the driver gains more\n+\t * dedicated interrupts (e.g. one for the admin context).\n+\t */\n+\tSDXI_MIN_VECTORS = 1,\n+};\n+\n struct sdxi_dev;\n \n /**\n@@ -39,6 +56,10 @@ struct sdxi_bus_ops {\n \t *        function initialization.\n \t */\n \tint (*init)(struct sdxi_dev *sdxi);\n+\t/**\n+\t * @get_irq: Map device interrupt index to Linux IRQ number.\n+\t */\n+\tint (*get_irq)(struct sdxi_dev *sdxi, unsigned int index);\n };\n \n struct sdxi_dev {\n@@ -61,6 +82,9 @@ struct sdxi_dev {\n \tstruct dma_pool *cxt_ctl_pool;\n \tstruct dma_pool *cst_blk_pool;\n \n+\tunsigned int nr_vectors;\n+\tstruct ida vectors;\n+\n \tstruct sdxi_cxt *admin_cxt;\n \tstruct xarray client_cxts; /* context id -> (struct sdxi_cxt *) */\n \n@@ -76,6 +100,39 @@ static inline struct device *sdxi_to_dev(const struct sdxi_dev *sdxi)\n #define sdxi_info(s, fmt, ...) dev_info(sdxi_to_dev(s), fmt, ## __VA_ARGS__)\n #define sdxi_err(s, fmt, ...) dev_err(sdxi_to_dev(s), fmt, ## __VA_ARGS__)\n \n+/**\n+ * sdxi_alloc_vector() - Allocate an interrupt vector.\n+ *\n+ * A vector that will have the same lifetime as the device does not\n+ * need to be released explicitly. Otherwise the vector must be\n+ * released with sdxi_free_vector().\n+ */\n+static inline int sdxi_alloc_vector(struct sdxi_dev *sdxi)\n+{\n+\treturn ida_alloc_max(&sdxi->vectors, sdxi->nr_vectors - 1,\n+\t\t\t     GFP_KERNEL);\n+}\n+\n+/**\n+ * sdxi_free_vector() - Release a previously allocated index.\n+ */\n+static inline void sdxi_free_vector(struct sdxi_dev *sdxi, unsigned int nr)\n+{\n+\tida_free(&sdxi->vectors, nr);\n+}\n+\n+/**\n+ * sdxi_vector_to_irq() - Translate an allocated interrupt vector to\n+ *                        Linux IRQ number suitable for passing to\n+ *                        request_irq() et al.\n+ */\n+static inline int sdxi_vector_to_irq(struct sdxi_dev *sdxi, unsigned int nr)\n+{\n+\t/* Moan if the index isn't currently allocated. */\n+\tWARN_ON_ONCE(!ida_exists(&sdxi->vectors, nr));\n+\treturn sdxi->bus_ops->get_irq(sdxi, nr);\n+}\n+\n int sdxi_register(struct device *dev, const struct sdxi_bus_ops *ops);\n void sdxi_unregister(struct device *dev);\n \n","prefixes":["22/23"]}