Skip to content

Commit

Permalink
xdma: add kernel 6.x support
Browse files Browse the repository at this point in the history
  • Loading branch information
karenx-xilinx committed Oct 4, 2023
1 parent d79b205 commit 9cdc9e3
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 6 deletions.
8 changes: 6 additions & 2 deletions XDMA/linux-kernel/xdma/cdev_sgdma.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ static void async_io_handler(unsigned long cb_hndl, int err)
if (caio->cmpl_cnt == caio->req_cnt) {
res = caio->res;
res2 = caio->res2;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 16, 0)
caio->iocb->ki_complete(caio->iocb, caio->err_cnt ? res2 : res);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0)
caio->iocb->ki_complete(caio->iocb, res, res2);
#else
aio_complete(caio->iocb, res, res2);
Expand All @@ -119,7 +121,9 @@ static void async_io_handler(unsigned long cb_hndl, int err)
return;

skip_dev_lock:
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 16, 0)
caio->iocb->ki_complete(caio->iocb, -EBUSY);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0)
caio->iocb->ki_complete(caio->iocb, numbytes, -EBUSY);
#else
aio_complete(caio->iocb, numbytes, -EBUSY);
Expand Down
63 changes: 59 additions & 4 deletions XDMA/linux-kernel/xdma/libxdma.c
Original file line number Diff line number Diff line change
Expand Up @@ -2908,8 +2908,13 @@ static void transfer_destroy(struct xdma_dev *xdev, struct xdma_transfer *xfer)
struct sg_table *sgt = xfer->sgt;

if (sgt->nents) {
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0)
pci_unmap_sg(xdev->pdev, sgt->sgl, sgt->nents,
xfer->dir);
#else
dma_unmap_sg(&xdev->pdev->dev, sgt->sgl, sgt->nents,
xfer->dir);
#endif
sgt->nents = 0;
}
}
Expand Down Expand Up @@ -3192,8 +3197,13 @@ ssize_t xdma_xfer_aperture(struct xdma_engine *engine, bool write, u64 ep_addr,
}

if (!dma_mapped) {
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0)
sgt->nents = pci_map_sg(xdev->pdev, sgt->sgl, sgt->orig_nents,
dir);
#else
sgt->nents = dma_map_sg(&xdev->pdev->dev, sgt->sgl,
sgt->orig_nents, dir);
#endif
if (!sgt->nents) {
pr_info("map sgl failed, sgt 0x%p.\n", sgt);
return -EIO;
Expand Down Expand Up @@ -3434,7 +3444,11 @@ ssize_t xdma_xfer_aperture(struct xdma_engine *engine, bool write, u64 ep_addr,

unmap_sgl:
if (!dma_mapped && sgt->nents) {
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0)
pci_unmap_sg(xdev->pdev, sgt->sgl, sgt->orig_nents, dir);
#else
dma_unmap_sg(&xdev->pdev->dev, sgt->sgl, sgt->orig_nents, dir);
#endif
sgt->nents = 0;
}

Expand Down Expand Up @@ -3504,7 +3518,12 @@ ssize_t xdma_xfer_submit(void *dev_hndl, int channel, bool write, u64 ep_addr,
}

if (!dma_mapped) {
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0)
nents = pci_map_sg(xdev->pdev, sg, sgt->orig_nents, dir);
#else
nents = dma_map_sg(&xdev->pdev->dev, sg, sgt->orig_nents, dir);
#endif

if (!nents) {
pr_info("map sgl failed, sgt 0x%p.\n", sgt);
return -EIO;
Expand Down Expand Up @@ -3660,7 +3679,11 @@ ssize_t xdma_xfer_submit(void *dev_hndl, int channel, bool write, u64 ep_addr,

unmap_sgl:
if (!dma_mapped && sgt->nents) {
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0)
pci_unmap_sg(xdev->pdev, sgt->sgl, sgt->orig_nents, dir);
#else
dma_unmap_sg(&xdev->pdev->dev, sgt->sgl, sgt->orig_nents, dir);
#endif
sgt->nents = 0;
}

Expand Down Expand Up @@ -3781,7 +3804,11 @@ ssize_t xdma_xfer_completion(void *cb_hndl, void *dev_hndl, int channel,

unmap_sgl:
if (!dma_mapped && sgt->nents) {
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0)
pci_unmap_sg(xdev->pdev, sgt->sgl, sgt->orig_nents, dir);
#else
dma_unmap_sg(&xdev->pdev->dev, sgt->sgl, sgt->orig_nents, dir);
#endif
sgt->nents = 0;
}

Expand Down Expand Up @@ -3855,7 +3882,11 @@ ssize_t xdma_xfer_submit_nowait(void *cb_hndl, void *dev_hndl, int channel,
}

if (!dma_mapped) {
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0)
nents = pci_map_sg(xdev->pdev, sg, sgt->orig_nents, dir);
#else
nents = dma_map_sg(&xdev->pdev->dev, sg, sgt->orig_nents, dir);
#endif
if (!nents) {
pr_info("map sgl failed, sgt 0x%p.\n", sgt);
return -EIO;
Expand Down Expand Up @@ -3895,8 +3926,13 @@ ssize_t xdma_xfer_submit_nowait(void *cb_hndl, void *dev_hndl, int channel,
pr_info("transfer_init failed\n");

if (!dma_mapped && sgt->nents) {
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0)
pci_unmap_sg(xdev->pdev, sgt->sgl,
sgt->orig_nents, dir);
#else
dma_unmap_sg(&xdev->pdev->dev, sgt->sgl,
sgt->orig_nents, dir);
#endif
sgt->nents = 0;
}

Expand Down Expand Up @@ -3943,7 +3979,11 @@ ssize_t xdma_xfer_submit_nowait(void *cb_hndl, void *dev_hndl, int channel,

unmap_sgl:
if (!dma_mapped && sgt->nents) {
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0)
pci_unmap_sg(xdev->pdev, sgt->sgl, sgt->orig_nents, dir);
#else
dma_unmap_sg(&xdev->pdev->dev, sgt->sgl, sgt->orig_nents, dir);
#endif
sgt->nents = 0;
}

Expand Down Expand Up @@ -4191,16 +4231,31 @@ static int set_dma_mask(struct pci_dev *pdev)

dbg_init("sizeof(dma_addr_t) == %ld\n", sizeof(dma_addr_t));
/* 64-bit addressing capability for XDMA? */
if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0)
if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)))
#else
if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)))
#endif
{
/* query for DMA transfer */
/* @see Documentation/DMA-mapping.txt */
dbg_init("pci_set_dma_mask()\n");
dbg_init("set_dma_mask(64)\n");
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0)
pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
#endif
/* use 64-bit DMA */
dbg_init("Using a 64-bit DMA mask.\n");
pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
} else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
} else
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0)
if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)))
#else
if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)))
#endif
{
dbg_init("Could not set 64-bit DMA mask.\n");
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0)
pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
#endif
/* use 32-bit DMA */
dbg_init("Using a 32-bit DMA mask.\n");
} else {
Expand Down

0 comments on commit 9cdc9e3

Please sign in to comment.