linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2] net: ethernet: mellanox: correct page conversion
@ 2016-04-16 22:23 Sinan Kaya
  2016-04-18  4:00 ` David Miller
                   ` (3 more replies)
  0 siblings, 4 replies; 30+ messages in thread
From: Sinan Kaya @ 2016-04-16 22:23 UTC (permalink / raw)
  To: linux-rdma, timur, cov; +Cc: Sinan Kaya, Yishai Hadas, netdev, linux-kernel

Current code is assuming that the address returned by dma_alloc_coherent
is a logical address. This is not true on ARM/ARM64 systems. This patch
replaces dma_alloc_coherent with dma_map_page API. The address returned
can later by virtually mapped from the CPU side with vmap API.

Signed-off-by: Sinan Kaya <okaya@codeaurora.org>
---
 drivers/net/ethernet/mellanox/mlx4/alloc.c | 37 ++++++++++++++++++++++--------
 1 file changed, 27 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/alloc.c b/drivers/net/ethernet/mellanox/mlx4/alloc.c
index 0c51c69..22a7ae7 100644
--- a/drivers/net/ethernet/mellanox/mlx4/alloc.c
+++ b/drivers/net/ethernet/mellanox/mlx4/alloc.c
@@ -618,13 +618,26 @@ int mlx4_buf_alloc(struct mlx4_dev *dev, int size, int max_direct,
 			return -ENOMEM;
 
 		for (i = 0; i < buf->nbufs; ++i) {
-			buf->page_list[i].buf =
-				dma_alloc_coherent(&dev->persist->pdev->dev,
-						   PAGE_SIZE,
-						   &t, gfp);
-			if (!buf->page_list[i].buf)
+			struct page *page;
+
+			page = alloc_page(GFP_KERNEL);
+			if (!page)
 				goto err_free;
 
+			t = dma_map_page(&dev->persist->pdev->dev, page, 0,
+					 PAGE_SIZE, DMA_BIDIRECTIONAL);
+
+			if (dma_mapping_error(&dev->persist->pdev->dev, t)) {
+				__free_page(page);
+				goto err_free;
+			}
+
+			buf->page_list[i].buf = page_address(page);
+			if (!buf->page_list[i].buf) {
+				__free_page(page);
+				goto err_free;
+			}
+
 			buf->page_list[i].map = t;
 
 			memset(buf->page_list[i].buf, 0, PAGE_SIZE);
@@ -666,11 +679,15 @@ void mlx4_buf_free(struct mlx4_dev *dev, int size, struct mlx4_buf *buf)
 			vunmap(buf->direct.buf);
 
 		for (i = 0; i < buf->nbufs; ++i)
-			if (buf->page_list[i].buf)
-				dma_free_coherent(&dev->persist->pdev->dev,
-						  PAGE_SIZE,
-						  buf->page_list[i].buf,
-						  buf->page_list[i].map);
+			if (buf->page_list[i].buf) {
+				struct page *page;
+
+				page = virt_to_page(buf->page_list[i].buf);
+				dma_unmap_page(&dev->persist->pdev->dev,
+					       buf->page_list[i].map,
+					       PAGE_SIZE, DMA_BIDIRECTIONAL);
+				__free_page(page);
+			}
 		kfree(buf->page_list);
 	}
 }
-- 
1.8.2.1

^ permalink raw reply related	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2016-04-20 18:42 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-16 22:23 [PATCH V2] net: ethernet: mellanox: correct page conversion Sinan Kaya
2016-04-18  4:00 ` David Miller
2016-04-18  5:06   ` okaya
2016-04-18 15:59     ` David Miller
2016-04-18 16:06       ` Sinan Kaya
2016-04-18  6:54 ` Eli Cohen
2016-04-18 13:53   ` Sinan Kaya
2016-04-18 14:05     ` Eli Cohen
2016-04-18 14:32   ` Christoph Hellwig
2016-04-18 14:39     ` Eli Cohen
2016-04-18 15:17       ` Christoph Hellwig
2016-04-18 15:21         ` Sinan Kaya
2016-04-18 15:40           ` Christoph Hellwig
2016-04-18 17:47             ` Sinan Kaya
2016-04-19  7:50             ` Sinan Kaya
2016-04-18 12:12 ` Christoph Hellwig
2016-04-18 13:06   ` okaya
2016-04-18 13:10     ` Christoph Hellwig
2016-04-18 13:49       ` Sinan Kaya
2016-04-18 13:59         ` Christoph Hellwig
2016-04-18 15:15         ` Timur Tabi
2016-04-18 15:22           ` Sinan Kaya
2016-04-19 18:22 ` Christoph Hellwig
2016-04-19 18:37   ` Sinan Kaya
2016-04-20 11:08     ` Eran Ben Elisha
2016-04-20 13:35   ` Sinan Kaya
2016-04-20 13:38     ` Sinan Kaya
2016-04-20 13:41       ` Timur Tabi
2016-04-20 18:40     ` Eran Ben Elisha
2016-04-20 18:42       ` Sinan Kaya

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).