Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2055429pxb; Mon, 11 Oct 2021 20:24:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwN4w6Mp1gNl9on0c1YcpmIHhnixIhHqt/jmip8zFhlzUIW80oI1qYskvqBGa2wFaY8toD9 X-Received: by 2002:a17:906:9241:: with SMTP id c1mr31285037ejx.125.1634009080165; Mon, 11 Oct 2021 20:24:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634009080; cv=none; d=google.com; s=arc-20160816; b=kt8/zSR/gNeyBl5Oxti8B4/WhFa3t5QKg+et0a4kPX/s3V7EtcMMvVgGxx1bI97Pwu Ub4bM65SZUg5tt9ufJbpqhez6ubZt+TAdQhV8DuoN1OHvM/k4RExpjt/XucGqUj1krv2 Zi0quJplHBmwGo8AAPssMJWGUKkvJLC+7jgnpNQrc3kO9lvutQKzyyzQ0Ok6ikzHPaYJ hx+onQGBKuAPtz2Zo4E0QYfV76WaZ80haxAzy5cFy/3E73eZ4/Wb9uxFOJUqKjeDHX7v QemWvavCPgyVzWvXuuUrblLRG/HwOE+tbKw3FArrWv6HC2dH6s/bVJqWRUXmPDb1c54h zfzw== 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=UcRBR8fRIBm7/MieUV3POP6gZ75SuXSHdpx3phn3xJE=; b=TKBPx/Y+Q2ePlu52ow9ZN9CcWEf0Fb46N8ugf6ZT0S5NWl6268iffMH92XQSn9RorV ZfYw1CRUA1p3nL+NkhIBN/XUVuOaNBJwus+4Vp0AThLBE8EbsKuPpcC2oZrsFMAnbOkl nPdlXS+nVkqMizlZBNHWc4hukCit5GDUyxOrjAbnvWy0j9e+os2UJqKNqdGOZmmK68MA ovw3GPlnd7xf8q64PCIa0/yHxOHREnN2FASscTH/NE/OTsfaoR1ZGVjc2ybBzDzQwdDf T4iw6It98ghTOlImI34EOOTwuH7QHoA2Shnhe+ZKadSKFZ7vikibEX1K6NEvT+wNRqp0 mdDg== 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 j4si12887151eds.47.2021.10.11.20.24.08; Mon, 11 Oct 2021 20:24:40 -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 S232070AbhJLDXa (ORCPT + 99 others); Mon, 11 Oct 2021 23:23:30 -0400 Received: from mx24.baidu.com ([111.206.215.185]:35986 "EHLO baidu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231742AbhJLDX3 (ORCPT ); Mon, 11 Oct 2021 23:23:29 -0400 Received: from BC-Mail-Ex07.internal.baidu.com (unknown [172.31.51.47]) by Forcepoint Email with ESMTPS id 4E7EAD74461F2518E7E5; Tue, 12 Oct 2021 11:21:17 +0800 (CST) Received: from BJHW-MAIL-EX27.internal.baidu.com (10.127.64.42) by BC-Mail-EX07.internal.baidu.com (172.31.51.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2242.12; Tue, 12 Oct 2021 11:21:17 +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; Tue, 12 Oct 2021 11:21:16 +0800 From: Cai Huoqing To: CC: Cai Huoqing , Michael Cyr , "James E.J. Bottomley" , "Martin K. Petersen" , , , Subject: [PATCH v2] scsi: ibmvscsi_tgt: Use dma_alloc_noncoherent() instead of get_zeroed_page/dma_map_single() Date: Tue, 12 Oct 2021 11:21:09 +0800 Message-ID: <20211012032110.2224-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-Ex12.internal.baidu.com (172.31.51.52) 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_noncoherent/dma_free_noncoherent() helps to reduce code size, and simplify the code, and the hardware keep DMA coherent itself. Signed-off-by: Cai Huoqing --- v1->v2: *Change to dma_alloc/free_noncoherent from dma_alloc/free_coherent. *Update changelog. drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c | 46 ++++++++---------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c b/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c index 61f06f6885a5..91199b969718 100644 --- a/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c +++ b/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c @@ -3007,20 +3007,13 @@ static long ibmvscsis_create_command_q(struct scsi_info *vscsi, int num_cmds) vscsi->cmd_q.size = pages; - vscsi->cmd_q.base_addr = - (struct viosrp_crq *)get_zeroed_page(GFP_KERNEL); - if (!vscsi->cmd_q.base_addr) - return -ENOMEM; - vscsi->cmd_q.mask = ((uint)pages * CRQ_PER_PAGE) - 1; - vscsi->cmd_q.crq_token = dma_map_single(&vdev->dev, - vscsi->cmd_q.base_addr, - PAGE_SIZE, DMA_BIDIRECTIONAL); - if (dma_mapping_error(&vdev->dev, vscsi->cmd_q.crq_token)) { - free_page((unsigned long)vscsi->cmd_q.base_addr); + vscsi->cmd_q.base_addr = dma_alloc_noncoherent(&vdev->dev, PAGE_SIZE, + &vscsi->cmd_q.crq_token, + DMA_BIDIRECTIONAL, GFP_KERNEL); + if (!vscsi->cmd_q.base_addr) return -ENOMEM; - } return 0; } @@ -3036,9 +3029,9 @@ static long ibmvscsis_create_command_q(struct scsi_info *vscsi, int num_cmds) */ static void ibmvscsis_destroy_command_q(struct scsi_info *vscsi) { - dma_unmap_single(&vscsi->dma_dev->dev, vscsi->cmd_q.crq_token, - PAGE_SIZE, DMA_BIDIRECTIONAL); - free_page((unsigned long)vscsi->cmd_q.base_addr); + dma_free_noncoherent(&vscsi->dma_dev->dev, + PAGE_SIZE, vscsi->cmd_q.base_addr, + vscsi->cmd_q.crq_token, DMA_BIDIRECTIONAL); vscsi->cmd_q.base_addr = NULL; vscsi->state = NO_QUEUE; } @@ -3504,18 +3497,12 @@ static int ibmvscsis_probe(struct vio_dev *vdev, goto free_timer; } - vscsi->map_buf = kzalloc(PAGE_SIZE, GFP_KERNEL); + vscsi->map_buf = dma_alloc_noncoherent(&vdev->dev, + PAGE_SIZE, &vscsi->map_ioba, + DMA_BIDIRECTIONAL, GFP_KERNEL); if (!vscsi->map_buf) { rc = -ENOMEM; dev_err(&vscsi->dev, "probe: allocating cmd buffer failed\n"); - goto destroy_queue; - } - - vscsi->map_ioba = dma_map_single(&vdev->dev, vscsi->map_buf, PAGE_SIZE, - DMA_BIDIRECTIONAL); - if (dma_mapping_error(&vdev->dev, vscsi->map_ioba)) { - rc = -ENOMEM; - dev_err(&vscsi->dev, "probe: error mapping command buffer\n"); goto free_buf; } @@ -3544,7 +3531,7 @@ static int ibmvscsis_probe(struct vio_dev *vdev, if (!vscsi->work_q) { rc = -ENOMEM; dev_err(&vscsi->dev, "create_workqueue failed\n"); - goto unmap_buf; + goto destroy_queue; } rc = request_irq(vdev->irq, ibmvscsis_interrupt, 0, "ibmvscsis", vscsi); @@ -3562,11 +3549,9 @@ static int ibmvscsis_probe(struct vio_dev *vdev, destroy_WQ: destroy_workqueue(vscsi->work_q); -unmap_buf: - dma_unmap_single(&vdev->dev, vscsi->map_ioba, PAGE_SIZE, - DMA_BIDIRECTIONAL); free_buf: - kfree(vscsi->map_buf); + dma_free_noncoherent(&vdev->dev, PAGE_SIZE, vscsi->map_buf, + vscsi->map_ioba, DMA_BIDIRECTIONAL); destroy_queue: tasklet_kill(&vscsi->work_task); ibmvscsis_unregister_command_q(vscsi); @@ -3602,9 +3587,8 @@ static void ibmvscsis_remove(struct vio_dev *vdev) vio_disable_interrupts(vdev); free_irq(vdev->irq, vscsi); destroy_workqueue(vscsi->work_q); - dma_unmap_single(&vdev->dev, vscsi->map_ioba, PAGE_SIZE, - DMA_BIDIRECTIONAL); - kfree(vscsi->map_buf); + dma_free_noncoherent(&vdev->dev, PAGE_SIZE, vscsi->map_buf, + vscsi->map_ioba, DMA_BIDIRECTIONAL); tasklet_kill(&vscsi->work_task); ibmvscsis_destroy_command_q(vscsi); ibmvscsis_freetimer(vscsi); -- 2.25.1