提交 9a33f398 编写于 作者: C Cai Huoqing 提交者: Jason Gunthorpe

RDMA/hns: Use dma_alloc_coherent() instead of kmalloc/dma_map_single()

Replacing kmalloc/kfree/dma_map_single/dma_unmap_single() with
dma_alloc_coherent/dma_free_coherent() helps to reduce code size, and
simplify the code, and coherent DMA will not clear the cache every time.

The SOC that this driver supports does not have incoherent DMA, so this
makes the code follow the DMA API properly with no performance
impact. Currently there are missing dma sync calls around the DMA
transfers.

Link: https://lore.kernel.org/r/20210926061116.282-1-caihuoqing@baidu.comSigned-off-by: NCai Huoqing <caihuoqing@baidu.com>
Reviewed-by: NWenpeng Liang <liangwenpeng@huawei.com>
Tested-by: NWenpeng Liang <liangwenpeng@huawei.com>
Signed-off-by: NJason Gunthorpe <jgg@nvidia.com>
上级 a0200940
...@@ -1165,32 +1165,22 @@ static int hns_roce_alloc_cmq_desc(struct hns_roce_dev *hr_dev, ...@@ -1165,32 +1165,22 @@ static int hns_roce_alloc_cmq_desc(struct hns_roce_dev *hr_dev,
{ {
int size = ring->desc_num * sizeof(struct hns_roce_cmq_desc); int size = ring->desc_num * sizeof(struct hns_roce_cmq_desc);
ring->desc = kzalloc(size, GFP_KERNEL); ring->desc = dma_alloc_coherent(hr_dev->dev, size,
&ring->desc_dma_addr, GFP_KERNEL);
if (!ring->desc) if (!ring->desc)
return -ENOMEM; return -ENOMEM;
ring->desc_dma_addr = dma_map_single(hr_dev->dev, ring->desc, size,
DMA_BIDIRECTIONAL);
if (dma_mapping_error(hr_dev->dev, ring->desc_dma_addr)) {
ring->desc_dma_addr = 0;
kfree(ring->desc);
ring->desc = NULL;
return -ENOMEM;
}
return 0; return 0;
} }
static void hns_roce_free_cmq_desc(struct hns_roce_dev *hr_dev, static void hns_roce_free_cmq_desc(struct hns_roce_dev *hr_dev,
struct hns_roce_v2_cmq_ring *ring) struct hns_roce_v2_cmq_ring *ring)
{ {
dma_unmap_single(hr_dev->dev, ring->desc_dma_addr, dma_free_coherent(hr_dev->dev,
ring->desc_num * sizeof(struct hns_roce_cmq_desc), ring->desc_num * sizeof(struct hns_roce_cmq_desc),
DMA_BIDIRECTIONAL); ring->desc, ring->desc_dma_addr);
ring->desc_dma_addr = 0; ring->desc_dma_addr = 0;
kfree(ring->desc);
} }
static int init_csq(struct hns_roce_dev *hr_dev, static int init_csq(struct hns_roce_dev *hr_dev,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册