Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3533194imm; Mon, 2 Jul 2018 00:23:32 -0700 (PDT) X-Google-Smtp-Source: AAOMgpds0XZaiCf9PyjpLQkKeC5xe5QU3t9vpGEzsjtp7MKxICG4aqoIHg+yXr5Hr6By+cmLoXdh X-Received: by 2002:a62:843:: with SMTP id c64-v6mr4119703pfd.14.1530516212584; Mon, 02 Jul 2018 00:23:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530516212; cv=none; d=google.com; s=arc-20160816; b=sf1N+snVKNc+ksToeM0sgCkdEQqc4jQh2Tuc1fsCTPpYz+vOYWaxCKjwfDhN1ysfSQ rcBTuJvV8IHjziEBt9NQZfOQySId/UATQAnK9NqEmnqEL+oZbAEmUiqRa1PJuUVv+mjM 4xptTo8a3J7notzQBQCU+s6mXfWXTyfdTPi7IPEVTq0WCUGQ4t+49MgFBy4sqR9tOfWy PbV0wR/fpWItaWFxrc8gL8tOG1M1O6Z9pF5OoqvYoNz74XV497Ub/U43J6kN3g4h2DJ9 sPAR8JFurq7SkPQgJRn5ccEgesAmFS75AXkK12YWvQ4/HMj6PFb4GFeQfKPzPNBeucGs o0nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=j2rnVvc06AHNpyEdvolbVQJKHV2AYe/M57TFNDBBvz4=; b=a6h/EPI+vaczT3jgjNNEzJzbORb2SY2trBTiZjpG34TwITjGPooawr5wrQ2x50pGV4 D20uLx2c35P97Y1PLYPVi7t2HFhIfa6EtxAI9GTo+SRfixBQTT1dn7cNl32ScUHzmZId AQsoPKwjgnRordzhgSEPNjT9GWuMK/FboZsxFXI4L0w0efrjVxDhuepmqf5+6BxOPvFu 7PcRT2BjY+Oyr8+tK60DbtdInWAdxjXwSMr/J0b5cS7IhQq1ntB+G0KyCpVhNDY0ZP8T smJsYheFPLHOiDQG/wR7kg4F/7v34ckrgLxC5yKU7lVs92c2MAexmG56PwA764wNRCox M1IA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d132-v6si13760831pga.355.2018.07.02.00.23.18; Mon, 02 Jul 2018 00:23:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932879AbeGBHTX (ORCPT + 99 others); Mon, 2 Jul 2018 03:19:23 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:9150 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753528AbeGBHTO (ORCPT ); Mon, 2 Jul 2018 03:19:14 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id A110319251CF9; Mon, 2 Jul 2018 15:18:57 +0800 (CST) Received: from linux-ioko.site (10.71.200.31) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.382.0; Mon, 2 Jul 2018 15:18:51 +0800 From: Peng Li To: CC: , , , , , Subject: [PATCH V2 net-next 8/9] net: hns3: use dma_zalloc_coherent instead of kzalloc/dma_map_single Date: Mon, 2 Jul 2018 15:50:25 +0800 Message-ID: <1530517826-69226-9-git-send-email-lipeng321@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1530517826-69226-1-git-send-email-lipeng321@huawei.com> References: <1530517826-69226-1-git-send-email-lipeng321@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.71.200.31] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Huazhong Tan 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 Signed-off-by: Peng Li --- drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 26 +++++++++------------- .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c | 25 ++++++++------------- .../ethernet/hisilicon/hns3/hns3vf/hclgevf_cmd.c | 26 ++++++++-------------- 3 files changed, 28 insertions(+), 49 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c index beca364..8fce363 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c @@ -1780,33 +1780,27 @@ static void hns3_free_buffers(struct hns3_enet_ring *ring) /* free desc along with its attached buffer */ static void hns3_free_desc(struct hns3_enet_ring *ring) { + int size = ring->desc_num * sizeof(ring->desc[0]); + hns3_free_buffers(ring); - dma_unmap_single(ring_to_dev(ring), ring->desc_dma_addr, - ring->desc_num * sizeof(ring->desc[0]), - DMA_BIDIRECTIONAL); - ring->desc_dma_addr = 0; - kfree(ring->desc); - ring->desc = NULL; + if (ring->desc) { + dma_free_coherent(ring_to_dev(ring), size, + ring->desc, ring->desc_dma_addr); + ring->desc = NULL; + } } static int hns3_alloc_desc(struct hns3_enet_ring *ring) { 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) 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; } diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c index db80485..82cf12a 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c @@ -45,31 +45,24 @@ static int hclge_alloc_cmd_desc(struct hclge_cmq_ring *ring) { 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) 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; } static void hclge_free_cmd_desc(struct hclge_cmq_ring *ring) { - dma_unmap_single(cmq_ring_to_dev(ring), ring->desc_dma_addr, - ring->desc_num * sizeof(ring->desc[0]), - DMA_BIDIRECTIONAL); + int size = ring->desc_num * sizeof(struct hclge_desc); - ring->desc_dma_addr = 0; - kfree(ring->desc); - ring->desc = NULL; + if (ring->desc) { + dma_free_coherent(cmq_ring_to_dev(ring), size, + ring->desc, ring->desc_dma_addr); + ring->desc = NULL; + } } static int hclge_alloc_cmd_queue(struct hclge_dev *hdev, int ring_type) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_cmd.c b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_cmd.c index 1bbfe13..fb471fe 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_cmd.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_cmd.c @@ -76,32 +76,24 @@ static int hclgevf_alloc_cmd_desc(struct hclgevf_cmq_ring *ring) { 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) 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; } static void hclgevf_free_cmd_desc(struct hclgevf_cmq_ring *ring) { - dma_unmap_single(cmq_ring_to_dev(ring), ring->desc_dma_addr, - ring->desc_num * sizeof(ring->desc[0]), - hclgevf_ring_to_dma_dir(ring)); + int size = ring->desc_num * sizeof(struct hclgevf_desc); - ring->desc_dma_addr = 0; - kfree(ring->desc); - ring->desc = NULL; + if (ring->desc) { + dma_free_coherent(cmq_ring_to_dev(ring), size, + ring->desc, ring->desc_dma_addr); + ring->desc = NULL; + } } static int hclgevf_init_cmd_queue(struct hclgevf_dev *hdev, -- 1.9.1