From: Finn Thain <fthain@linux-m68k.org>
To: Cai Huoqing <caihuoqing@baidu.com>
Cc: hch@infradead.org, Michael Cyr <mikecyr@linux.ibm.com>,
"James E.J. Bottomley" <jejb@linux.ibm.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
linux-scsi@vger.kernel.org, target-devel@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] scsi: ibmvscsi_tgt: Use dma_alloc_noncoherent() instead of get_zeroed_page/dma_map_single()
Date: Wed, 13 Oct 2021 10:37:56 +1100 (AEDT) [thread overview]
Message-ID: <f8c34711-18a5-6c9d-8066-99cf19c2b2@linux-m68k.org> (raw)
In-Reply-To: <20211012032110.2224-1-caihuoqing@baidu.com>
On Tue, 12 Oct 2021, Cai Huoqing wrote:
> 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 <caihuoqing@baidu.com>
> ---
> 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;
Shouldn't that be goto destroy_queue?
> }
>
> @@ -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;
And goto free_buf?
> }
>
> 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);
>
prev parent reply other threads:[~2021-10-12 23:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-12 3:21 Cai Huoqing
2021-10-12 5:20 ` Christoph Hellwig
2021-10-12 23:37 ` Finn Thain [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f8c34711-18a5-6c9d-8066-99cf19c2b2@linux-m68k.org \
--to=fthain@linux-m68k.org \
--cc=caihuoqing@baidu.com \
--cc=hch@infradead.org \
--cc=jejb@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=mikecyr@linux.ibm.com \
--cc=target-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®