mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-11-01 09:13:37 +00:00
net: hns3: use dma_zalloc_coherent instead of kzalloc/dma_map_single
Reference to Documentation/DMA-API-HOWTO.txt, Streaming DMA mappings which are usually mapped for one DMA transfer, Network card DMA ring descriptors should use Consistent DMA mappings. Signed-off-by: Huazhong Tan <tanhuazhong@huawei.com> Signed-off-by: Peng Li <lipeng321@huawei.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
7a7056e3df
commit
024cc792f9
3 changed files with 28 additions and 49 deletions
|
|
@ -1780,33 +1780,27 @@ static void hns3_free_buffers(struct hns3_enet_ring *ring)
|
||||||
/* free desc along with its attached buffer */
|
/* free desc along with its attached buffer */
|
||||||
static void hns3_free_desc(struct hns3_enet_ring *ring)
|
static void hns3_free_desc(struct hns3_enet_ring *ring)
|
||||||
{
|
{
|
||||||
|
int size = ring->desc_num * sizeof(ring->desc[0]);
|
||||||
|
|
||||||
hns3_free_buffers(ring);
|
hns3_free_buffers(ring);
|
||||||
|
|
||||||
dma_unmap_single(ring_to_dev(ring), ring->desc_dma_addr,
|
if (ring->desc) {
|
||||||
ring->desc_num * sizeof(ring->desc[0]),
|
dma_free_coherent(ring_to_dev(ring), size,
|
||||||
DMA_BIDIRECTIONAL);
|
ring->desc, ring->desc_dma_addr);
|
||||||
ring->desc_dma_addr = 0;
|
ring->desc = NULL;
|
||||||
kfree(ring->desc);
|
}
|
||||||
ring->desc = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int hns3_alloc_desc(struct hns3_enet_ring *ring)
|
static int hns3_alloc_desc(struct hns3_enet_ring *ring)
|
||||||
{
|
{
|
||||||
int size = ring->desc_num * sizeof(ring->desc[0]);
|
int size = ring->desc_num * sizeof(ring->desc[0]);
|
||||||
|
|
||||||
ring->desc = kzalloc(size, GFP_KERNEL);
|
ring->desc = dma_zalloc_coherent(ring_to_dev(ring), size,
|
||||||
|
&ring->desc_dma_addr,
|
||||||
|
GFP_KERNEL);
|
||||||
if (!ring->desc)
|
if (!ring->desc)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
ring->desc_dma_addr = dma_map_single(ring_to_dev(ring), ring->desc,
|
|
||||||
size, DMA_BIDIRECTIONAL);
|
|
||||||
if (dma_mapping_error(ring_to_dev(ring), ring->desc_dma_addr)) {
|
|
||||||
ring->desc_dma_addr = 0;
|
|
||||||
kfree(ring->desc);
|
|
||||||
ring->desc = NULL;
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,31 +45,24 @@ static int hclge_alloc_cmd_desc(struct hclge_cmq_ring *ring)
|
||||||
{
|
{
|
||||||
int size = ring->desc_num * sizeof(struct hclge_desc);
|
int size = ring->desc_num * sizeof(struct hclge_desc);
|
||||||
|
|
||||||
ring->desc = kzalloc(size, GFP_KERNEL);
|
ring->desc = dma_zalloc_coherent(cmq_ring_to_dev(ring),
|
||||||
|
size, &ring->desc_dma_addr,
|
||||||
|
GFP_KERNEL);
|
||||||
if (!ring->desc)
|
if (!ring->desc)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
ring->desc_dma_addr = dma_map_single(cmq_ring_to_dev(ring), ring->desc,
|
|
||||||
size, DMA_BIDIRECTIONAL);
|
|
||||||
if (dma_mapping_error(cmq_ring_to_dev(ring), ring->desc_dma_addr)) {
|
|
||||||
ring->desc_dma_addr = 0;
|
|
||||||
kfree(ring->desc);
|
|
||||||
ring->desc = NULL;
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hclge_free_cmd_desc(struct hclge_cmq_ring *ring)
|
static void hclge_free_cmd_desc(struct hclge_cmq_ring *ring)
|
||||||
{
|
{
|
||||||
dma_unmap_single(cmq_ring_to_dev(ring), ring->desc_dma_addr,
|
int size = ring->desc_num * sizeof(struct hclge_desc);
|
||||||
ring->desc_num * sizeof(ring->desc[0]),
|
|
||||||
DMA_BIDIRECTIONAL);
|
|
||||||
|
|
||||||
ring->desc_dma_addr = 0;
|
if (ring->desc) {
|
||||||
kfree(ring->desc);
|
dma_free_coherent(cmq_ring_to_dev(ring), size,
|
||||||
ring->desc = NULL;
|
ring->desc, ring->desc_dma_addr);
|
||||||
|
ring->desc = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int hclge_alloc_cmd_queue(struct hclge_dev *hdev, int ring_type)
|
static int hclge_alloc_cmd_queue(struct hclge_dev *hdev, int ring_type)
|
||||||
|
|
|
||||||
|
|
@ -76,32 +76,24 @@ static int hclgevf_alloc_cmd_desc(struct hclgevf_cmq_ring *ring)
|
||||||
{
|
{
|
||||||
int size = ring->desc_num * sizeof(struct hclgevf_desc);
|
int size = ring->desc_num * sizeof(struct hclgevf_desc);
|
||||||
|
|
||||||
ring->desc = kzalloc(size, GFP_KERNEL);
|
ring->desc = dma_zalloc_coherent(cmq_ring_to_dev(ring),
|
||||||
|
size, &ring->desc_dma_addr,
|
||||||
|
GFP_KERNEL);
|
||||||
if (!ring->desc)
|
if (!ring->desc)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
ring->desc_dma_addr = dma_map_single(cmq_ring_to_dev(ring), ring->desc,
|
|
||||||
size, DMA_BIDIRECTIONAL);
|
|
||||||
|
|
||||||
if (dma_mapping_error(cmq_ring_to_dev(ring), ring->desc_dma_addr)) {
|
|
||||||
ring->desc_dma_addr = 0;
|
|
||||||
kfree(ring->desc);
|
|
||||||
ring->desc = NULL;
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hclgevf_free_cmd_desc(struct hclgevf_cmq_ring *ring)
|
static void hclgevf_free_cmd_desc(struct hclgevf_cmq_ring *ring)
|
||||||
{
|
{
|
||||||
dma_unmap_single(cmq_ring_to_dev(ring), ring->desc_dma_addr,
|
int size = ring->desc_num * sizeof(struct hclgevf_desc);
|
||||||
ring->desc_num * sizeof(ring->desc[0]),
|
|
||||||
hclgevf_ring_to_dma_dir(ring));
|
|
||||||
|
|
||||||
ring->desc_dma_addr = 0;
|
if (ring->desc) {
|
||||||
kfree(ring->desc);
|
dma_free_coherent(cmq_ring_to_dev(ring), size,
|
||||||
ring->desc = NULL;
|
ring->desc, ring->desc_dma_addr);
|
||||||
|
ring->desc = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int hclgevf_init_cmd_queue(struct hclgevf_dev *hdev,
|
static int hclgevf_init_cmd_queue(struct hclgevf_dev *hdev,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue