]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
RDMA/umem: Add support for creating pinned DMABUF umem with a given dma device
authorYishai Hadas <yishaih@nvidia.com>
Thu, 1 Aug 2024 12:05:13 +0000 (15:05 +0300)
committerLeon Romanovsky <leon@kernel.org>
Sun, 11 Aug 2024 08:12:49 +0000 (11:12 +0300)
Add support for creating pinned DMABUF umem with a specified DMA device
instead of the DMA device of the given IB device.

This API will be utilized in the upcoming patches of the series when
multiple path DMAs are implemented.

Signed-off-by: Yishai Hadas <yishaih@nvidia.com>
Link: https://patch.msgid.link/038aad36a43797e5591b20ba81051fc5758124f9.1722512548.git.leon@kernel.org
Signed-off-by: Leon Romanovsky <leon@kernel.org>
drivers/infiniband/core/umem_dmabuf.c
include/rdma/ib_umem.h

index 39357dc2d229f0c9866fe6b3803b5394f494fee3..726a097865470830de20b2812a1a9b824c7d9f1e 100644 (file)
@@ -110,10 +110,12 @@ void ib_umem_dmabuf_unmap_pages(struct ib_umem_dmabuf *umem_dmabuf)
 }
 EXPORT_SYMBOL(ib_umem_dmabuf_unmap_pages);
 
-struct ib_umem_dmabuf *ib_umem_dmabuf_get(struct ib_device *device,
-                                         unsigned long offset, size_t size,
-                                         int fd, int access,
-                                         const struct dma_buf_attach_ops *ops)
+static struct ib_umem_dmabuf *
+ib_umem_dmabuf_get_with_dma_device(struct ib_device *device,
+                                  struct device *dma_device,
+                                  unsigned long offset, size_t size,
+                                  int fd, int access,
+                                  const struct dma_buf_attach_ops *ops)
 {
        struct dma_buf *dmabuf;
        struct ib_umem_dmabuf *umem_dmabuf;
@@ -152,7 +154,7 @@ struct ib_umem_dmabuf *ib_umem_dmabuf_get(struct ib_device *device,
 
        umem_dmabuf->attach = dma_buf_dynamic_attach(
                                        dmabuf,
-                                       device->dma_device,
+                                       dma_device,
                                        ops,
                                        umem_dmabuf);
        if (IS_ERR(umem_dmabuf->attach)) {
@@ -168,6 +170,15 @@ out_release_dmabuf:
        dma_buf_put(dmabuf);
        return ret;
 }
+
+struct ib_umem_dmabuf *ib_umem_dmabuf_get(struct ib_device *device,
+                                         unsigned long offset, size_t size,
+                                         int fd, int access,
+                                         const struct dma_buf_attach_ops *ops)
+{
+       return ib_umem_dmabuf_get_with_dma_device(device, device->dma_device,
+                                                 offset, size, fd, access, ops);
+}
 EXPORT_SYMBOL(ib_umem_dmabuf_get);
 
 static void
@@ -184,16 +195,18 @@ static struct dma_buf_attach_ops ib_umem_dmabuf_attach_pinned_ops = {
        .move_notify = ib_umem_dmabuf_unsupported_move_notify,
 };
 
-struct ib_umem_dmabuf *ib_umem_dmabuf_get_pinned(struct ib_device *device,
-                                                unsigned long offset,
-                                                size_t size, int fd,
-                                                int access)
+struct ib_umem_dmabuf *
+ib_umem_dmabuf_get_pinned_with_dma_device(struct ib_device *device,
+                                         struct device *dma_device,
+                                         unsigned long offset, size_t size,
+                                         int fd, int access)
 {
        struct ib_umem_dmabuf *umem_dmabuf;
        int err;
 
-       umem_dmabuf = ib_umem_dmabuf_get(device, offset, size, fd, access,
-                                        &ib_umem_dmabuf_attach_pinned_ops);
+       umem_dmabuf = ib_umem_dmabuf_get_with_dma_device(device, dma_device, offset,
+                                                        size, fd, access,
+                                                        &ib_umem_dmabuf_attach_pinned_ops);
        if (IS_ERR(umem_dmabuf))
                return umem_dmabuf;
 
@@ -217,6 +230,16 @@ err_release:
        ib_umem_release(&umem_dmabuf->umem);
        return ERR_PTR(err);
 }
+EXPORT_SYMBOL(ib_umem_dmabuf_get_pinned_with_dma_device);
+
+struct ib_umem_dmabuf *ib_umem_dmabuf_get_pinned(struct ib_device *device,
+                                                unsigned long offset,
+                                                size_t size, int fd,
+                                                int access)
+{
+       return ib_umem_dmabuf_get_pinned_with_dma_device(device, device->dma_device,
+                                                        offset, size, fd, access);
+}
 EXPORT_SYMBOL(ib_umem_dmabuf_get_pinned);
 
 void ib_umem_dmabuf_release(struct ib_umem_dmabuf *umem_dmabuf)
index 565a850445414d4de6fae1de3d0c96ea80b8f3ab..de05268ed6320f08d82451ffa5d9dc8dd7e8210a 100644 (file)
@@ -150,6 +150,11 @@ struct ib_umem_dmabuf *ib_umem_dmabuf_get_pinned(struct ib_device *device,
                                                 unsigned long offset,
                                                 size_t size, int fd,
                                                 int access);
+struct ib_umem_dmabuf *
+ib_umem_dmabuf_get_pinned_with_dma_device(struct ib_device *device,
+                                         struct device *dma_device,
+                                         unsigned long offset, size_t size,
+                                         int fd, int access);
 int ib_umem_dmabuf_map_pages(struct ib_umem_dmabuf *umem_dmabuf);
 void ib_umem_dmabuf_unmap_pages(struct ib_umem_dmabuf *umem_dmabuf);
 void ib_umem_dmabuf_release(struct ib_umem_dmabuf *umem_dmabuf);
@@ -196,6 +201,16 @@ ib_umem_dmabuf_get_pinned(struct ib_device *device, unsigned long offset,
 {
        return ERR_PTR(-EOPNOTSUPP);
 }
+
+static inline struct ib_umem_dmabuf *
+ib_umem_dmabuf_get_pinned_with_dma_device(struct ib_device *device,
+                                         struct device *dma_device,
+                                         unsigned long offset, size_t size,
+                                         int fd, int access)
+{
+       return ERR_PTR(-EOPNOTSUPP);
+}
+
 static inline int ib_umem_dmabuf_map_pages(struct ib_umem_dmabuf *umem_dmabuf)
 {
        return -EOPNOTSUPP;