* [PATCH] net: ethernet: mellanox: correct page conversion
@ 2015-02-26 18:59 timur-sgV2jX0FEOL9JmXXK+q4OQ
[not found] ` <1424977168-19523-1-git-send-email-timur-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
0 siblings, 1 reply; 2+ messages in thread
From: timur-sgV2jX0FEOL9JmXXK+q4OQ @ 2015-02-26 18:59 UTC (permalink / raw)
To: Roland Dreier, linux-rdma-u79uwXL29TY76Z2rM5mHXA, Eli Cohen; +Cc: Sinan Kaya
From: Sinan Kaya <okaya-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
Current code is assuming that the addresses returned
by dma_alloc_coherent is a logical address. This is
not true on ARM/ARM64 systems. This patch uses
dma_to_phys API to reach to the actual physical address
and then convert to the page pointer.
Signed-off-by: Sinan Kaya <okaya-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
---
drivers/net/ethernet/mellanox/mlx4/alloc.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx4/alloc.c b/drivers/net/ethernet/mellanox/mlx4/alloc.c
index 963dd7e..8eca66a 100644
--- a/drivers/net/ethernet/mellanox/mlx4/alloc.c
+++ b/drivers/net/ethernet/mellanox/mlx4/alloc.c
@@ -634,8 +634,13 @@ int mlx4_buf_alloc(struct mlx4_dev *dev, int size, int max_direct,
pages = kmalloc(sizeof *pages * buf->nbufs, gfp);
if (!pages)
goto err_free;
- for (i = 0; i < buf->nbufs; ++i)
- pages[i] = virt_to_page(buf->page_list[i].buf);
+ for (i = 0; i < buf->nbufs; ++i) {
+ phys_addr_t phys;
+
+ phys = dma_to_phys(&dev->pdev->dev,
+ buf->page_list[i].map);
+ pages[i] = phys_to_page(phys);
+ }
buf->direct.buf = vmap(pages, buf->nbufs, VM_MAP, PAGE_KERNEL);
kfree(pages);
if (!buf->direct.buf)
--
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] net: ethernet: mellanox: correct page conversion
[not found] ` <1424977168-19523-1-git-send-email-timur-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
@ 2015-03-15 10:05 ` Amir Vadai
0 siblings, 0 replies; 2+ messages in thread
From: Amir Vadai @ 2015-03-15 10:05 UTC (permalink / raw)
To: timur-sgV2jX0FEOL9JmXXK+q4OQ
Cc: Roland Dreier, linux-rdma-u79uwXL29TY76Z2rM5mHXA, Eli Cohen, Sinan Kaya
On Thu, Feb 26, 2015 at 8:59 PM, <timur-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org> wrote:
> From: Sinan Kaya <okaya-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
>
> Current code is assuming that the addresses returned
> by dma_alloc_coherent is a logical address. This is
> not true on ARM/ARM64 systems. This patch uses
> dma_to_phys API to reach to the actual physical address
> and then convert to the page pointer.
>
> Signed-off-by: Sinan Kaya <okaya-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
> ---
> drivers/net/ethernet/mellanox/mlx4/alloc.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/mellanox/mlx4/alloc.c b/drivers/net/ethernet/mellanox/mlx4/alloc.c
> index 963dd7e..8eca66a 100644
> --- a/drivers/net/ethernet/mellanox/mlx4/alloc.c
> +++ b/drivers/net/ethernet/mellanox/mlx4/alloc.c
> @@ -634,8 +634,13 @@ int mlx4_buf_alloc(struct mlx4_dev *dev, int size, int max_direct,
> pages = kmalloc(sizeof *pages * buf->nbufs, gfp);
> if (!pages)
> goto err_free;
> - for (i = 0; i < buf->nbufs; ++i)
> - pages[i] = virt_to_page(buf->page_list[i].buf);
> + for (i = 0; i < buf->nbufs; ++i) {
> + phys_addr_t phys;
> +
> + phys = dma_to_phys(&dev->pdev->dev,
> + buf->page_list[i].map);
> + pages[i] = phys_to_page(phys);
> + }
> buf->direct.buf = vmap(pages, buf->nbufs, VM_MAP, PAGE_KERNEL);
> kfree(pages);
> if (!buf->direct.buf)
> --
> Qualcomm Innovation Center, Inc.
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project.
>
This will not compile on non ARM arch. For example x86:
drivers/net/ethernet/mellanox/mlx4/alloc.c: In function ‘mlx4_buf_alloc’:
drivers/net/ethernet/mellanox/mlx4/alloc.c:642:5: error: implicit
declaration of function ‘phys_to_page’
[-Werror=implicit-function-declaration]
pages[i] = phys_to_page(phys);
Amir
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-03-15 10:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-26 18:59 [PATCH] net: ethernet: mellanox: correct page conversion timur-sgV2jX0FEOL9JmXXK+q4OQ
[not found] ` <1424977168-19523-1-git-send-email-timur-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2015-03-15 10:05 ` Amir Vadai
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.