get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/50414/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 50414,
    "url": "https://patches.dpdk.org/api/patches/50414/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/c7fa33e494b9fb56658c134c44962bb3fd6f5679.1550760031.git.shahafs@mellanox.com/",
    "project": {
        "id": 1,
        "url": "https://patches.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<c7fa33e494b9fb56658c134c44962bb3fd6f5679.1550760031.git.shahafs@mellanox.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/c7fa33e494b9fb56658c134c44962bb3fd6f5679.1550760031.git.shahafs@mellanox.com",
    "date": "2019-02-21T14:50:46",
    "name": "[v2,3/6] bus: introduce device level DMA memory mapping",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "e7e749e3bbc69cb3a2b88e9740609f93a6e5f0bd",
    "submitter": {
        "id": 634,
        "url": "https://patches.dpdk.org/api/people/634/?format=api",
        "name": "Shahaf Shuler",
        "email": "shahafs@mellanox.com"
    },
    "delegate": null,
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/c7fa33e494b9fb56658c134c44962bb3fd6f5679.1550760031.git.shahafs@mellanox.com/mbox/",
    "series": [
        {
            "id": 3501,
            "url": "https://patches.dpdk.org/api/series/3501/?format=api",
            "web_url": "https://patches.dpdk.org/project/dpdk/list/?series=3501",
            "date": "2019-02-21T14:50:46",
            "name": "introduce DMA memory mapping for external memory",
            "version": 2,
            "mbox": "https://patches.dpdk.org/series/3501/mbox/"
        }
    ],
    "comments": "https://patches.dpdk.org/api/patches/50414/comments/",
    "check": "fail",
    "checks": "https://patches.dpdk.org/api/patches/50414/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@dpdk.org",
        "Delivered-To": "patchwork@dpdk.org",
        "Received": [
            "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id 4CB4D2BAB;\n\tThu, 21 Feb 2019 15:51:08 +0100 (CET)",
            "from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129])\n\tby dpdk.org (Postfix) with ESMTP id 73FA62B9E\n\tfor <dev@dpdk.org>; Thu, 21 Feb 2019 15:51:06 +0100 (CET)",
            "from Internal Mail-Server by MTLPINE1 (envelope-from\n\tshahafs@mellanox.com)\n\twith ESMTPS (AES256-SHA encrypted); 21 Feb 2019 16:51:02 +0200",
            "from unicorn01.mtl.labs.mlnx. (unicorn01.mtl.labs.mlnx\n\t[10.7.12.62])\n\tby labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x1LEp2lq022817;\n\tThu, 21 Feb 2019 16:51:02 +0200"
        ],
        "From": "Shahaf Shuler <shahafs@mellanox.com>",
        "To": "anatoly.burakov@intel.com, yskoh@mellanox.com, thomas@monjalon.net,\n\tferruh.yigit@intel.com, nhorman@tuxdriver.com, gaetan.rivet@6wind.com",
        "Cc": "dev@dpdk.org",
        "Date": "Thu, 21 Feb 2019 16:50:46 +0200",
        "Message-Id": "<c7fa33e494b9fb56658c134c44962bb3fd6f5679.1550760031.git.shahafs@mellanox.com>",
        "X-Mailer": "git-send-email 2.12.0",
        "In-Reply-To": [
            "<cover.1550760026.git.shahafs@mellanox.com>",
            "<cover.1550760026.git.shahafs@mellanox.com>"
        ],
        "References": [
            "<cover.1550760026.git.shahafs@mellanox.com>",
            "<cover.1550048187.git.shahafs@mellanox.com>\n\t<cover.1550760026.git.shahafs@mellanox.com>"
        ],
        "Subject": "[dpdk-dev] [PATCH v2 3/6] bus: introduce device level DMA memory\n\tmapping",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "The DPDK APIs expose 3 different modes to work with memory used for DMA:\n\n1. Use the DPDK owned memory (backed by the DPDK provided hugepages).\nThis memory is allocated by the DPDK libraries, included in the DPDK\nmemory system (memseg lists) and automatically DMA mapped by the DPDK\nlayers.\n\n2. Use memory allocated by the user and register to the DPDK memory\nsystems. Upon registration of memory, the DPDK layers will DMA map it\nto all needed devices. After registration, allocation of this memory\nwill be done with rte_*malloc APIs.\n\n3. Use memory allocated by the user and not registered to the DPDK memory\nsystem. This is for users who wants to have tight control on this\nmemory (e.g. avoid the rte_malloc header).\nThe user should create a memory, register it through rte_extmem_register\nAPI, and call DMA map function in order to register such memory to\nthe different devices.\n\nThe scope of the patch focus on #3 above.\n\nCurrently the only way to map external memory is through VFIO\n(rte_vfio_dma_map). While VFIO is common, there are other vendors\nwhich use different ways to map memory (e.g. Mellanox and NXP).\n\nThe work in this patch moves the DMA mapping to vendor agnostic APIs.\nDevice level DMA map and unmap APIs were added. Implementation of those\nAPIs was done currently only for PCI devices.\n\nFor PCI bus devices, the pci driver can expose its own map and unmap\nfunctions to be used for the mapping. In case the driver doesn't provide\nany, the memory will be mapped, if possible, to IOMMU through VFIO APIs.\n\nApplication usage with those APIs is quite simple:\n* allocate memory\n* call rte_extmem_register on the memory chunk.\n* take a device, and query its rte_device.\n* call the device specific mapping function for this device.\n\nFuture work will deprecate the rte_vfio_dma_map and rte_vfio_dma_unmap\nAPIs, leaving the rte device APIs as the preferred option for the user.\n\nSigned-off-by: Shahaf Shuler <shahafs@mellanox.com>\n---\n drivers/bus/pci/pci_common.c            | 48 ++++++++++++++++++++++++++++\n drivers/bus/pci/rte_bus_pci.h           | 40 +++++++++++++++++++++++\n lib/librte_eal/common/eal_common_dev.c  | 29 +++++++++++++++++\n lib/librte_eal/common/include/rte_bus.h | 44 +++++++++++++++++++++++++\n lib/librte_eal/common/include/rte_dev.h | 43 +++++++++++++++++++++++++\n lib/librte_eal/rte_eal_version.map      |  2 ++\n 6 files changed, 206 insertions(+)",
    "diff": "diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c\nindex 6276e5d695..7013c53a7b 100644\n--- a/drivers/bus/pci/pci_common.c\n+++ b/drivers/bus/pci/pci_common.c\n@@ -528,6 +528,52 @@ pci_unplug(struct rte_device *dev)\n \treturn ret;\n }\n \n+static int\n+pci_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len)\n+{\n+\tstruct rte_pci_device *pdev = RTE_DEV_TO_PCI(dev);\n+\n+\tif (!pdev || !pdev->driver) {\n+\t\trte_errno = EINVAL;\n+\t\treturn -rte_errno;\n+\t}\n+\tif (pdev->driver->dma_map)\n+\t\treturn pdev->driver->dma_map(pdev, addr, iova, len);\n+\t/**\n+\t *  In case driver don't provides any specific mapping\n+\t *  try fallback to VFIO.\n+\t */\n+\tif (pdev->kdrv == RTE_KDRV_VFIO)\n+\t\treturn rte_vfio_container_dma_map\n+\t\t\t\t(RTE_VFIO_DEFAULT_CONTAINER_FD, (uintptr_t)addr,\n+\t\t\t\t iova, len);\n+\trte_errno = ENOTSUP;\n+\treturn -rte_errno;\n+}\n+\n+static int\n+pci_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova, size_t len)\n+{\n+\tstruct rte_pci_device *pdev = RTE_DEV_TO_PCI(dev);\n+\n+\tif (!pdev || !pdev->driver) {\n+\t\trte_errno = EINVAL;\n+\t\treturn -rte_errno;\n+\t}\n+\tif (pdev->driver->dma_unmap)\n+\t\treturn pdev->driver->dma_unmap(pdev, addr, iova, len);\n+\t/**\n+\t *  In case driver don't provides any specific mapping\n+\t *  try fallback to VFIO.\n+\t */\n+\tif (pdev->kdrv == RTE_KDRV_VFIO)\n+\t\treturn rte_vfio_container_dma_unmap\n+\t\t\t\t(RTE_VFIO_DEFAULT_CONTAINER_FD, (uintptr_t)addr,\n+\t\t\t\t iova, len);\n+\trte_errno = ENOTSUP;\n+\treturn -rte_errno;\n+}\n+\n struct rte_pci_bus rte_pci_bus = {\n \t.bus = {\n \t\t.scan = rte_pci_scan,\n@@ -536,6 +582,8 @@ struct rte_pci_bus rte_pci_bus = {\n \t\t.plug = pci_plug,\n \t\t.unplug = pci_unplug,\n \t\t.parse = pci_parse,\n+\t\t.dma_map = pci_dma_map,\n+\t\t.dma_unmap = pci_dma_unmap,\n \t\t.get_iommu_class = rte_pci_get_iommu_class,\n \t\t.dev_iterate = rte_pci_dev_iterate,\n \t\t.hot_unplug_handler = pci_hot_unplug_handler,\ndiff --git a/drivers/bus/pci/rte_bus_pci.h b/drivers/bus/pci/rte_bus_pci.h\nindex f0d6d81c00..06e004cd3f 100644\n--- a/drivers/bus/pci/rte_bus_pci.h\n+++ b/drivers/bus/pci/rte_bus_pci.h\n@@ -114,6 +114,44 @@ typedef int (pci_probe_t)(struct rte_pci_driver *, struct rte_pci_device *);\n typedef int (pci_remove_t)(struct rte_pci_device *);\n \n /**\n+ * Driver-specific DMA mapping. After a successful call the device\n+ * will be able to read/write from/to this segment.\n+ *\n+ * @param dev\n+ *   Pointer to the PCI device.\n+ * @param addr\n+ *   Starting virtual address of memory to be mapped.\n+ * @param iova\n+ *   Starting IOVA address of memory to be mapped.\n+ * @param len\n+ *   Length of memory segment being mapped.\n+ * @return\n+ *   - 0 On success.\n+ *   - Negative value and rte_errno is set otherwise.\n+ */\n+typedef int (pci_dma_map_t)(struct rte_pci_device *dev, void *addr,\n+\t\t\t    uint64_t iova, size_t len);\n+\n+/**\n+ * Driver-specific DMA un-mapping. After a successful call the device\n+ * will not be able to read/write from/to this segment.\n+ *\n+ * @param dev\n+ *   Pointer to the PCI device.\n+ * @param addr\n+ *   Starting virtual address of memory to be unmapped.\n+ * @param iova\n+ *   Starting IOVA address of memory to be unmapped.\n+ * @param len\n+ *   Length of memory segment being unmapped.\n+ * @return\n+ *   - 0 On success.\n+ *   - Negative value and rte_errno is set otherwise.\n+ */\n+typedef int (pci_dma_unmap_t)(struct rte_pci_device *dev, void *addr,\n+\t\t\t      uint64_t iova, size_t len);\n+\n+/**\n  * A structure describing a PCI driver.\n  */\n struct rte_pci_driver {\n@@ -122,6 +160,8 @@ struct rte_pci_driver {\n \tstruct rte_pci_bus *bus;           /**< PCI bus reference. */\n \tpci_probe_t *probe;                /**< Device Probe function. */\n \tpci_remove_t *remove;              /**< Device Remove function. */\n+\tpci_dma_map_t *dma_map;\t\t   /**< device dma map function. */\n+\tpci_dma_unmap_t *dma_unmap;\t   /**< device dma unmap function. */\n \tconst struct rte_pci_id *id_table; /**< ID table, NULL terminated. */\n \tuint32_t drv_flags;                /**< Flags RTE_PCI_DRV_*. */\n };\ndiff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c\nindex fd7f5ca7d5..ab4dbc9499 100644\n--- a/lib/librte_eal/common/eal_common_dev.c\n+++ b/lib/librte_eal/common/eal_common_dev.c\n@@ -756,3 +756,32 @@ rte_dev_iterator_next(struct rte_dev_iterator *it)\n \tfree(cls_str);\n \treturn it->device;\n }\n+\n+int\n+rte_dev_dma_map(struct rte_device *dev, void *addr, uint64_t iova,\n+\t\tsize_t len)\n+{\n+\tif (dev->bus->dma_map == NULL || len == 0) {\n+\t\trte_errno = EINVAL;\n+\t\treturn -rte_errno;\n+\t}\n+\t/* Memory must be registered through rte_extmem_* APIs */\n+\tif (rte_mem_virt2memseg(addr, NULL) == NULL) {\n+\t\trte_errno = EINVAL;\n+\t\treturn -rte_errno;\n+\t}\n+\n+\treturn dev->bus->dma_map(dev, addr, iova, len);\n+}\n+\n+int\n+rte_dev_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova,\n+\t\t  size_t len)\n+{\n+\tif (dev->bus->dma_unmap == NULL || len == 0) {\n+\t\trte_errno = EINVAL;\n+\t\treturn -rte_errno;\n+\t}\n+\n+\treturn dev->bus->dma_unmap(dev, addr, iova, len);\n+}\ndiff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h\nindex 6be4b5cabe..4faf2d20a0 100644\n--- a/lib/librte_eal/common/include/rte_bus.h\n+++ b/lib/librte_eal/common/include/rte_bus.h\n@@ -168,6 +168,48 @@ typedef int (*rte_bus_unplug_t)(struct rte_device *dev);\n typedef int (*rte_bus_parse_t)(const char *name, void *addr);\n \n /**\n+ * Device level DMA map function.\n+ * After a successful call, the memory segment will be mapped to the\n+ * given device.\n+ *\n+ * @param dev\n+ *\tDevice pointer.\n+ * @param addr\n+ *\tVirtual address to map.\n+ * @param iova\n+ *\tIOVA address to map.\n+ * @param len\n+ *\tLength of the memory segment being mapped.\n+ *\n+ * @return\n+ *\t0 if mapping was successful.\n+ *\tNegative value and rte_errno is set otherwise.\n+ */\n+typedef int (*rte_dev_dma_map_t)(struct rte_device *dev, void *addr,\n+\t\t\t\t  uint64_t iova, size_t len);\n+\n+/**\n+ * Device level DMA unmap function.\n+ * After a successful call, the memory segment will no longer be\n+ * accessible by the given device.\n+ *\n+ * @param dev\n+ *\tDevice pointer.\n+ * @param addr\n+ *\tVirtual address to unmap.\n+ * @param iova\n+ *\tIOVA address to unmap.\n+ * @param len\n+ *\tLength of the memory segment being mapped.\n+ *\n+ * @return\n+ *\t0 if un-mapping was successful.\n+ *\tNegative value and rte_errno is set otherwise.\n+ */\n+typedef int (*rte_dev_dma_unmap_t)(struct rte_device *dev, void *addr,\n+\t\t\t\t   uint64_t iova, size_t len);\n+\n+/**\n  * Implement a specific hot-unplug handler, which is responsible for\n  * handle the failure when device be hot-unplugged. When the event of\n  * hot-unplug be detected, it could call this function to handle\n@@ -238,6 +280,8 @@ struct rte_bus {\n \trte_bus_plug_t plug;         /**< Probe single device for drivers */\n \trte_bus_unplug_t unplug;     /**< Remove single device from driver */\n \trte_bus_parse_t parse;       /**< Parse a device name */\n+\trte_dev_dma_map_t dma_map;   /**< DMA map for device in the bus */\n+\trte_dev_dma_unmap_t dma_unmap; /**< DMA unmap for device in the bus */\n \tstruct rte_bus_conf conf;    /**< Bus configuration */\n \trte_bus_get_iommu_class_t get_iommu_class; /**< Get iommu class */\n \trte_dev_iterate_t dev_iterate; /**< Device iterator. */\ndiff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h\nindex a9724dc918..fd39c5fd86 100644\n--- a/lib/librte_eal/common/include/rte_dev.h\n+++ b/lib/librte_eal/common/include/rte_dev.h\n@@ -515,4 +515,47 @@ rte_dev_hotplug_handle_enable(void);\n int __rte_experimental\n rte_dev_hotplug_handle_disable(void);\n \n+/**\n+ * Device level DMA map function.\n+ * After a successful call, the memory segment will be mapped to the\n+ * given device.\n+ *\n+ * @param dev\n+ *\tDevice pointer.\n+ * @param addr\n+ *\tVirtual address to map.\n+ * @param iova\n+ *\tIOVA address to map.\n+ * @param len\n+ *\tLength of the memory segment being mapped.\n+ *\n+ * @return\n+ *\t0 if mapping was successful.\n+ *\tNegative value and rte_errno is set otherwise.\n+ */\n+int __rte_experimental\n+rte_dev_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len);\n+\n+/**\n+ * Device level DMA unmap function.\n+ * After a successful call, the memory segment will no longer be\n+ * accessible by the given device.\n+ *\n+ * @param dev\n+ *\tDevice pointer.\n+ * @param addr\n+ *\tVirtual address to unmap.\n+ * @param iova\n+ *\tIOVA address to unmap.\n+ * @param len\n+ *\tLength of the memory segment being mapped.\n+ *\n+ * @return\n+ *\t0 if un-mapping was successful.\n+ *\tNegative value and rte_errno is set otherwise.\n+ */\n+int __rte_experimental\n+rte_dev_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova,\n+\t\t  size_t len);\n+\n #endif /* _RTE_DEV_H_ */\ndiff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map\nindex eb5f7b9cbd..264aa050fa 100644\n--- a/lib/librte_eal/rte_eal_version.map\n+++ b/lib/librte_eal/rte_eal_version.map\n@@ -277,6 +277,8 @@ EXPERIMENTAL {\n \trte_class_unregister;\n \trte_ctrl_thread_create;\n \trte_delay_us_sleep;\n+\trte_dev_dma_map;\n+\trte_dev_dma_unmap;\n \trte_dev_event_callback_process;\n \trte_dev_event_callback_register;\n \trte_dev_event_callback_unregister;\n",
    "prefixes": [
        "v2",
        "3/6"
    ]
}