Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp714713pxb; Sun, 10 Oct 2021 09:22:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxlutgXG/2enHzcUmVVEo4FvTYqvnqHIK7M1TGTL01um6q3QKckEdxp8pJ82mPaY6Druu9v X-Received: by 2002:a17:906:e287:: with SMTP id gg7mr13137227ejb.387.1633882973788; Sun, 10 Oct 2021 09:22:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633882973; cv=none; d=google.com; s=arc-20160816; b=R5+5qBfMeAvHi9oUd+X0fXjyZU885K18lHWuQaoHdZN3YxtYP2lfUILlfAtYdnWOTX alQh1AIXMQiE4TqBiQwjcscWnYgfLtajIDpRchbgnw/3YGsW0+w0XeWZVLqqV6OcCQ03 OjTRvpwyvxJhp5DMGKgl4BxbXsvYCdu5iqF74KjzEqdHY2HT52VxqUHqU8tF4cT2pZJ2 YvT6n/WWnSn/iAtRir1SSOLyGgO6GYL9BXmX4gGv1NlyNguS1/DhRcv4JLU7VVXWvhbT ZB3bDMW4zBTnFZyUOGw2cyIg/g5h2OSAolnaLcXOPP8fHIRNy3UuQM/+yPjh8vFd1Gw1 P+PQ== 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=o7A91nF0LZz0IDASUiI64LaSHY3CMKQqlqnPYrcho9Y=; b=Xs0Vy7zWuBnwSt3i7wJgwY9bcqFnaNhuRB8PtZl/PQ9B0vgHLTdPnsNCMgVCZ4NQxY 9y7e8uOG6XwFsUnP4v/vYTyT8uHKHcwh21pfAKweVO4TCgx9fJi6fljL0sWcgjL5GbZR 1+fpTcfn51FBxF604pWjxIDCPiKiBSZpwh75CsCEWxG/qmCL9cJ7p1DDbaCarhmsFkLq AYIFrJI1u3RqWT8jZwIhXjoTXfBSG2Emf9OXppfPHinOqQxaaMpmNPV6zTJUu1albPBp T/B9zGgASNWOtY5x5kYBAEjD+78t4EXgI5L0JXGgRZUgX+yN0CkAV1dg0CO//QF7AoH9 Wx/g== 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 13si7791269ejr.134.2021.10.10.09.22.29; Sun, 10 Oct 2021 09:22:53 -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 S231229AbhJJQDp (ORCPT + 99 others); Sun, 10 Oct 2021 12:03:45 -0400 Received: from mx22.baidu.com ([220.181.50.185]:53298 "EHLO baidu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230271AbhJJQDo (ORCPT ); Sun, 10 Oct 2021 12:03:44 -0400 Received: from BC-Mail-Ex18.internal.baidu.com (unknown [172.31.51.12]) by Forcepoint Email with ESMTPS id F423C628CB139476D543; Mon, 11 Oct 2021 00:01:43 +0800 (CST) Received: from BJHW-MAIL-EX27.internal.baidu.com (10.127.64.42) by BC-Mail-Ex18.internal.baidu.com (172.31.51.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2242.12; Mon, 11 Oct 2021 00:01:43 +0800 Received: from localhost.localdomain (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; Mon, 11 Oct 2021 00:01:42 +0800 From: Cai Huoqing To: CC: Tyrel Datwyler , Michael Ellerman , Benjamin Herrenschmidt , "Paul Mackerras" , "James E.J. Bottomley" , "Martin K. Petersen" , , , Subject: [PATCH] scsi: ibmvscsi: Use dma_alloc_coherent() instead of get_zeroed_page/dma_map_single() Date: Mon, 11 Oct 2021 00:01:19 +0800 Message-ID: <20211010160121.539-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: BJHW-Mail-Ex16.internal.baidu.com (10.127.64.39) To BJHW-MAIL-EX27.internal.baidu.com (10.127.64.42) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Replacing get_zeroed_page/free_page/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/scsi/ibmvscsi/ibmvfc.c | 15 +++------------ drivers/scsi/ibmvscsi/ibmvscsi.c | 26 ++++++-------------------- 2 files changed, 9 insertions(+), 32 deletions(-) diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c index 1f1586ad48fe..f65d1a78b272 100644 --- a/drivers/scsi/ibmvscsi/ibmvfc.c +++ b/drivers/scsi/ibmvscsi/ibmvfc.c @@ -869,8 +869,7 @@ static void ibmvfc_free_queue(struct ibmvfc_host *vhost, { struct device *dev = vhost->dev; - dma_unmap_single(dev, queue->msg_token, PAGE_SIZE, DMA_BIDIRECTIONAL); - free_page((unsigned long)queue->msgs.handle); + dma_free_coherent(dev, PAGE_SIZE, queue->msgs.handle, queue->msg_token); queue->msgs.handle = NULL; ibmvfc_free_event_pool(vhost, queue); @@ -5663,19 +5662,11 @@ static int ibmvfc_alloc_queue(struct ibmvfc_host *vhost, return -ENOMEM; } - queue->msgs.handle = (void *)get_zeroed_page(GFP_KERNEL); + queue->msgs.handle = dma_alloc_coherent(dev, PAGE_SIZE, + &queue->msg_token, GFP_KERNEL); if (!queue->msgs.handle) return -ENOMEM; - queue->msg_token = dma_map_single(dev, queue->msgs.handle, PAGE_SIZE, - DMA_BIDIRECTIONAL); - - if (dma_mapping_error(dev, queue->msg_token)) { - free_page((unsigned long)queue->msgs.handle); - queue->msgs.handle = NULL; - return -ENOMEM; - } - queue->cur = 0; queue->fmt = fmt; queue->size = PAGE_SIZE / fmt_size; diff --git a/drivers/scsi/ibmvscsi/ibmvscsi.c b/drivers/scsi/ibmvscsi/ibmvscsi.c index ea8e01f49cba..61b315d1edbc 100644 --- a/drivers/scsi/ibmvscsi/ibmvscsi.c +++ b/drivers/scsi/ibmvscsi/ibmvscsi.c @@ -151,10 +151,7 @@ static void ibmvscsi_release_crq_queue(struct crq_queue *queue, msleep(100); rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address); } while ((rc == H_BUSY) || (H_IS_LONG_BUSY(rc))); - dma_unmap_single(hostdata->dev, - queue->msg_token, - queue->size * sizeof(*queue->msgs), DMA_BIDIRECTIONAL); - free_page((unsigned long)queue->msgs); + dma_free_coherent(hostdata->dev, PAGE_SIZE, queue->msgs, queue->msg_token); } /** @@ -331,18 +328,11 @@ static int ibmvscsi_init_crq_queue(struct crq_queue *queue, int retrc; struct vio_dev *vdev = to_vio_dev(hostdata->dev); - queue->msgs = (struct viosrp_crq *)get_zeroed_page(GFP_KERNEL); - - if (!queue->msgs) - goto malloc_failed; queue->size = PAGE_SIZE / sizeof(*queue->msgs); - - queue->msg_token = dma_map_single(hostdata->dev, queue->msgs, - queue->size * sizeof(*queue->msgs), - DMA_BIDIRECTIONAL); - - if (dma_mapping_error(hostdata->dev, queue->msg_token)) - goto map_failed; + queue->msgs = dma_alloc_coherent(hostdata->dev, PAGE_SIZE, + &queue->msg_token, GFP_KERNEL); + if (!queue->msg) + goto malloc_failed; gather_partition_info(); set_adapter_info(hostdata); @@ -395,11 +385,7 @@ static int ibmvscsi_init_crq_queue(struct crq_queue *queue, rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address); } while ((rc == H_BUSY) || (H_IS_LONG_BUSY(rc))); reg_crq_failed: - dma_unmap_single(hostdata->dev, - queue->msg_token, - queue->size * sizeof(*queue->msgs), DMA_BIDIRECTIONAL); - map_failed: - free_page((unsigned long)queue->msgs); + dma_free_coherent(hostdata->dev, PAGE_SIZE, queue->msg, queue->msg_token); malloc_failed: return -1; } -- 2.25.1