Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2916638pxb; Sat, 25 Sep 2021 23:14:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDKX4KrtNse0ZAHzLzJ5U8MydcjB6n4bzD/mAJ78hcAoTO9atPwwurU2GG8g9tmio4VcxR X-Received: by 2002:a17:906:f6d3:: with SMTP id jo19mr10655051ejb.99.1632636843324; Sat, 25 Sep 2021 23:14:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632636843; cv=none; d=google.com; s=arc-20160816; b=BLT86Ax1jhFD+zzcb5ovcVxYF+W0uq6b4QXt/qWKJJN03F519inTioXdGM6wCsg5tZ vnHzp43l1olPd1/cFhBMuCvnpUTY9iM63EWXgHPopCnV9nXawFyHbPjzDirZG7VvoWhC kzOlzhQXfrMSwdRvbXbhNAVUM8kaiphcwW5SjPywNZLHUpo2B5nktWFg+6i3bUYuYtg0 pTVxWLbekFpYNepGZCtb6z68xp8f5mMBsb735ME5lHJ44FmMzyDFszrUFn+w2XoQwglV 4fYtuwq5Y50ttkAKWirIKBr0bM3SZEgge/RDgWMHTv2ArsXEzpqL1sILVmFdBCJb53U9 P8wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=sNsh/iJqx/cwO0MGxIQemSrB/B0tnkMtzBZFqLdYbp4=; b=s2CAjevLeTT3cXFxTOmNqFl2JLzeF2NCXSnGI+/BYsgWvMUmu5YqySWE3Ctf4xlZ8p kTIUJRBnybwxLSKwI2JCLVfoezcIhsb7CQp1lI/foJgJAN8K3UAtN8HeDoszA7vzhijF nHLqScpbNUGFXr6D7+cCBgcg+ZN6/n3/iQdVAojF10LTY231kMh0RFdV37S42Qd+Tkou UXIX7ppMif3yE2gA5D4GQt6mK+2B5xHqHxLxh7xoff74XvZ6M+4rYKssdfkN4fC3cZKh iIhrur9leoUYMG5+XvlnjWB3K44OKteHvRr2dWfUICCPxYFiwIUJAHVwWhXtCChP2HJ+ DE2A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a9si13965219edb.327.2021.09.25.23.13.26; Sat, 25 Sep 2021 23:14:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230522AbhIZGNC (ORCPT + 99 others); Sun, 26 Sep 2021 02:13:02 -0400 Received: from mx22.baidu.com ([220.181.50.185]:48924 "EHLO baidu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229485AbhIZGNC (ORCPT ); Sun, 26 Sep 2021 02:13:02 -0400 Received: from BC-Mail-Ex11.internal.baidu.com (unknown [172.31.51.51]) by Forcepoint Email with ESMTPS id 8FCD1700013123366D75; Sun, 26 Sep 2021 14:11:23 +0800 (CST) Received: from BJHW-MAIL-EX27.internal.baidu.com (10.127.64.42) by BC-Mail-Ex11.internal.baidu.com (172.31.51.51) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2242.12; Sun, 26 Sep 2021 14:11:23 +0800 Received: from LAPTOP-UKSR4ENP.internal.baidu.com (172.31.63.8) by BJHW-MAIL-EX27.internal.baidu.com (10.127.64.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.14; Sun, 26 Sep 2021 14:11:22 +0800 From: Cai Huoqing To: CC: Lijun Ou , Weihang Li , "Doug Ledford" , Jason Gunthorpe , , Subject: [PATCH] RDMA/hns: Use dma_alloc_coherent() instead of kmalloc/dma_map_single() Date: Sun, 26 Sep 2021 14:11:15 +0800 Message-ID: <20210926061116.282-1-caihuoqing@baidu.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [172.31.63.8] X-ClientProxiedBy: BC-Mail-Ex22.internal.baidu.com (172.31.51.16) To BJHW-MAIL-EX27.internal.baidu.com (10.127.64.42) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Cai Huoqing --- drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c index 5b9953105752..380445f98a49 100644 --- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c @@ -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); - ring->desc = kzalloc(size, GFP_KERNEL); + ring->desc = dma_alloc_coherent(hr_dev->dev, size, + &ring->desc_dma_addr, GFP_KERNEL); if (!ring->desc) 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; } static void hns_roce_free_cmq_desc(struct hns_roce_dev *hr_dev, struct hns_roce_v2_cmq_ring *ring) { - dma_unmap_single(hr_dev->dev, ring->desc_dma_addr, - ring->desc_num * sizeof(struct hns_roce_cmq_desc), - DMA_BIDIRECTIONAL); + dma_free_coherent(hr_dev->dev, + ring->desc_num * sizeof(struct hns_roce_cmq_desc), + ring->desc, ring->desc_dma_addr); ring->desc_dma_addr = 0; - kfree(ring->desc); } static int init_csq(struct hns_roce_dev *hr_dev, -- 2.25.1