From patchwork Wed Jun 29 01:16:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Schmitz X-Patchwork-Id: 586503 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D17BC433EF for ; Wed, 29 Jun 2022 03:10:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230052AbiF2DK5 (ORCPT ); Tue, 28 Jun 2022 23:10:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229625AbiF2DK4 (ORCPT ); Tue, 28 Jun 2022 23:10:56 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A70901A80D; Tue, 28 Jun 2022 20:10:55 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id x138so11112034pfc.3; Tue, 28 Jun 2022 20:10:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=A/ikJJq41Sa7RmyRhS6UjTJSwH1KB0sH75JFtZjXRlM=; b=bZ4k49vQbJgCltNXUA6iH51N4Kdm9tJgLEgc5SeF2xFsQIvyUooWTt4fsp2Ts1FeAO PBX2I8phcAMvxItATQqy9Nug5WsCUE9fIF87noyZQYj8Rkcr+VoDW7M8ghfl13KrVaEQ w+I87IVHoLerkSClA4fpnzx2AuJWwymUJ3cCLn3jIwXu9H7cOWHehQs+aExPQdM2zQU/ 7r8rFnVakUm90XFGgnxBglj9Id3B7ngSpL4CBwEl4sXp25OwCD7hR7NKRYoC4BBjzLIT a/yqr/ARzxtBJ2ugVZuBifU2bnG/wWJubHHp1BdZGJXQyRZ+QuqBLsOBr4qfcuz0ARK5 Sj9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=A/ikJJq41Sa7RmyRhS6UjTJSwH1KB0sH75JFtZjXRlM=; b=7Ua3Q60J3f1nU92SMp/Ixfw+0t7dv0A9Czxzj6KJZtXwO9SylGWpy8mBIfyd0P1IPX xx9dk/Thr1vLKMYwj/pHx6VV1/9yzUU0NGX+WOlFR0xpZj8Xb4ZgE2o7tA4VUP0+40u4 X4ryWn43RfrUjSFLP8BQEO1MwUmpncpYaytYyCc6XeYm2b8+zf4bjm529E1zUBX2W0uL /4dTnR5KAdKtFhL4k1FKn4F+SCofzYkIhZEdK1a5RpmycYFNK9mulIStkGEmIFF0e6ER r7UK0mbLb1Mntz4AhGpG/zc4+kyRnUp1C3p9+ZNcxvij0bZaEGef9yFgDm4awGAcFF0P +LwQ== X-Gm-Message-State: AJIora/Si8/Xn6mVg/vxrZ3qu3ws1XoIqB/v+gzKKNptR/LvgQqOF0um rDmP46toAaf74iR0VrFgZcDPqUTaEhQgwA== X-Google-Smtp-Source: AGRyM1vYPSGJ2bnmTPvDSdrRndpbeAXvmv1IzOXXuPp+idCQ1NdVEVV+94mojDvvIAuGrffiv6x4Yw== X-Received: by 2002:a05:6a00:c91:b0:525:84b6:9a37 with SMTP id a17-20020a056a000c9100b0052584b69a37mr7900131pfv.47.1656472255175; Tue, 28 Jun 2022 20:10:55 -0700 (PDT) Received: from xplor.waratah.dyndns.org (222-155-0-244-adsl.sparkbb.co.nz. [222.155.0.244]) by smtp.gmail.com with ESMTPSA id m14-20020a17090a414e00b001eca01f4860sm697558pjg.12.2022.06.28.20.10.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jun 2022 20:10:54 -0700 (PDT) Received: by xplor.waratah.dyndns.org (Postfix, from userid 1000) id 90F29360330; Wed, 29 Jun 2022 13:16:41 +1200 (NZST) From: Michael Schmitz To: linux-m68k@vger.kernel.org, arnd@kernel.org Cc: linux-scsi@vger.kernel.org, geert@linux-m68k.org, Michael Schmitz Subject: [PATCH v1 1/3] scsi - a3000.c: convert m68k WD33C93 drivers to DMA API Date: Wed, 29 Jun 2022 13:16:36 +1200 Message-Id: <20220629011638.21783-2-schmitzmic@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220629011638.21783-1-schmitzmic@gmail.com> References: <20220629011638.21783-1-schmitzmic@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Use dma_map_single() for a3000 driver (leave bounce buffer logic unchanged). Use dma_set_mask_and_coherent() to avoid explicit cache flushes. Incorporates review comments by ArndB: - drop bounce buffer handling - non-cacheline aligned buffers ought not to happen. Compile-tested only. CC: linux-scsi@vger.kernel.org Link: https://lore.kernel.org/r/6d1d88ee-1cf6-c735-1e6d-bafd2096e322@gmail.com Signed-off-by: Michael Schmitz --- drivers/scsi/a3000.c | 60 ++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/drivers/scsi/a3000.c b/drivers/scsi/a3000.c index dd161885eed1..0e2e0d69118b 100644 --- a/drivers/scsi/a3000.c +++ b/drivers/scsi/a3000.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -25,8 +26,11 @@ struct a3000_hostdata { struct WD33C93_hostdata wh; struct a3000_scsiregs *regs; + struct device *dev; }; +#define DMA_DIR(d) ((d == DATA_OUT_DIR) ? DMA_TO_DEVICE : DMA_FROM_DEVICE) + static irqreturn_t a3000_intr(int irq, void *data) { struct Scsi_Host *instance = data; @@ -49,37 +53,40 @@ static irqreturn_t a3000_intr(int irq, void *data) static int dma_setup(struct scsi_cmnd *cmd, int dir_in) { struct scsi_pointer *scsi_pointer = WD33C93_scsi_pointer(cmd); + unsigned long len = scsi_pointer->this_residual; struct Scsi_Host *instance = cmd->device->host; struct a3000_hostdata *hdata = shost_priv(instance); struct WD33C93_hostdata *wh = &hdata->wh; struct a3000_scsiregs *regs = hdata->regs; unsigned short cntr = CNTR_PDMD | CNTR_INTEN; - unsigned long addr = virt_to_bus(scsi_pointer->ptr); + dma_addr_t addr; + + addr = dma_map_single(hdata->dev, scsi_pointer->ptr, + len, DMA_DIR(dir_in)); + if (dma_mapping_error(hdata->dev, addr)) { + dev_warn(hdata->dev, "cannot map SCSI data block %p\n", + scsi_pointer->ptr); + return 1; + } + scsi_pointer->dma_handle = addr; /* * if the physical address has the wrong alignment, or if * physical address is bad, or if it is a write and at the * end of a physical memory chunk, then allocate a bounce * buffer + * MSch 20220629 - only wrong alignment tested, skip bounce + * buffer set-up and just do PIO here. Buffers not aligned + * to cachelines ought to not happen anymore. */ if (addr & A3000_XFER_MASK) { - wh->dma_bounce_len = (scsi_pointer->this_residual + 511) & ~0x1ff; - wh->dma_bounce_buffer = kmalloc(wh->dma_bounce_len, - GFP_KERNEL); - - /* can't allocate memory; use PIO */ - if (!wh->dma_bounce_buffer) { - wh->dma_bounce_len = 0; - return 1; - } - - if (!dir_in) { - /* copy to bounce buffer for a write */ - memcpy(wh->dma_bounce_buffer, scsi_pointer->ptr, - scsi_pointer->this_residual); - } - - addr = virt_to_bus(wh->dma_bounce_buffer); + WARN_ONCE(1, "Invalid alignment for DMA!"); + /* drop useless mapping */ + dma_unmap_single(hdata->dev, scsi_pointer->dma_handle, + scsi_pointer->this_residual, + DMA_DIR(dir_in)); + scsi_pointer->dma_handle = (dma_addr_t) NULL; + return 1; } /* setup dma direction */ @@ -94,13 +101,7 @@ static int dma_setup(struct scsi_cmnd *cmd, int dir_in) /* setup DMA *physical* address */ regs->ACR = addr; - if (dir_in) { - /* invalidate any cache */ - cache_clear(addr, scsi_pointer->this_residual); - } else { - /* push any dirty cache */ - cache_push(addr, scsi_pointer->this_residual); - } + /* no more cache flush here - coherent DMA setup used */ /* start DMA */ mb(); /* make sure setup is completed */ @@ -166,6 +167,9 @@ static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt, wh->dma_bounce_len = 0; } } + dma_unmap_single(hdata->dev, scsi_pointer->dma_handle, + scsi_pointer->this_residual, + DMA_DIR(wh->dma_dir)); } static struct scsi_host_template amiga_a3000_scsi_template = { @@ -193,6 +197,11 @@ static int __init amiga_a3000_scsi_probe(struct platform_device *pdev) wd33c93_regs wdregs; struct a3000_hostdata *hdata; + if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32))) { + dev_warn(&pdev->dev, "cannot use 32 bit DMA\n"); + return -ENODEV; + } + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) return -ENODEV; @@ -216,6 +225,7 @@ static int __init amiga_a3000_scsi_probe(struct platform_device *pdev) wdregs.SCMD = ®s->SCMD; hdata = shost_priv(instance); + hdata->dev = &pdev->dev; hdata->wh.no_sync = 0xff; hdata->wh.fast = 0; hdata->wh.dma_mode = CTRL_DMA; From patchwork Wed Jun 29 01:16:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Schmitz X-Patchwork-Id: 586039 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58409C433EF for ; Wed, 29 Jun 2022 03:11:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230252AbiF2DLI (ORCPT ); Tue, 28 Jun 2022 23:11:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230169AbiF2DK6 (ORCPT ); Tue, 28 Jun 2022 23:10:58 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E4711A80D; Tue, 28 Jun 2022 20:10:57 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id 65so13758024pfw.11; Tue, 28 Jun 2022 20:10:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=t1+E2APwaN49w4WUjMso01bm3l0X4lKOX1QB208lxbQ=; b=BaTjuiuWo9lwT3iUiy3igT7yXOiZHFpw4juQ8xVOM1qeZVHq/33VHhYv0qcMIUG3qo o3jCAR9lryLtggPF7i0DNuWlhF37/3HAJIeV2bGiGMoxx+4QtSwCYr2q2pA99oI3218A ObK6/z6v0RfpW+tWb9ZSNUOLeHsHmNx2p7g0gSAMLLjSaVzuXshPUlDkDwXPr0gsfRBp aWYfKpAhVTKePkSK93QPPPEO6blaPKzrOSwf1xDJdkOvefiBsIoScxtn/q1XTphye06S YGWggaOwI1dVtmgy4s9j3vhzf6654oID3nEYqQzHN3OAFSH8n2CNpQZx/YWl7uZYo3P2 +7Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=t1+E2APwaN49w4WUjMso01bm3l0X4lKOX1QB208lxbQ=; b=Y4PIbQP9S69GHxhNjAbcwIahUPUNU/4vHv5eFke11YuTfp1GGMLw5g0uyqgc7DKdj3 sxRc+cYm/M8elwHLSeBvkQkM696UZ6a0jgL4SBrGGwHeiic4mYB+jOmdk1Xlm8/VX8H0 hIX/UR7lkCQ1CulNUgdy9DozzNh1mTs9Ra5bIWPz+lmxGsvSBD2nzi1nrmKmf0ABgz76 J9s4xTPIRg7pKEmLoDsLLFyOxMI/3DrifuWynvHFyLW0gyI337AxRmLowqU7+KkJ531Y iwYOOk+68RMgDqFB3D1ImVcWqBlZTzAki2FPnMHMBx/tT040MioZhfgcRpWgDTO+HDag LW3g== X-Gm-Message-State: AJIora9MJh0bl6+JS12ZnQr53Nj+D+ygo7UwiGR/7P9z/iYfrF6xiNk7 tmPSK4IV0BA2Y7GCrqzpbvfNKl46QY9GWA== X-Google-Smtp-Source: AGRyM1szLt8yuidCa+sCeWnEwITld8d7m1R3xpmywFV+QOa9WyqQ9gHt3DLDUa8HMr43lK63ceXQLA== X-Received: by 2002:a65:6044:0:b0:3fc:674:8f5a with SMTP id a4-20020a656044000000b003fc06748f5amr1074632pgp.436.1656472256628; Tue, 28 Jun 2022 20:10:56 -0700 (PDT) Received: from xplor.waratah.dyndns.org (222-155-0-244-adsl.sparkbb.co.nz. [222.155.0.244]) by smtp.gmail.com with ESMTPSA id u34-20020a056a0009a200b005190eea6c37sm10335336pfg.157.2022.06.28.20.10.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jun 2022 20:10:54 -0700 (PDT) Received: by xplor.waratah.dyndns.org (Postfix, from userid 1000) id 57C39360331; Wed, 29 Jun 2022 13:16:42 +1200 (NZST) From: Michael Schmitz To: linux-m68k@vger.kernel.org, arnd@kernel.org Cc: linux-scsi@vger.kernel.org, geert@linux-m68k.org, Michael Schmitz Subject: [PATCH v1 2/3] scsi - a2091.c: convert m68k WD33C93 drivers to DMA API Date: Wed, 29 Jun 2022 13:16:37 +1200 Message-Id: <20220629011638.21783-3-schmitzmic@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220629011638.21783-1-schmitzmic@gmail.com> References: <20220629011638.21783-1-schmitzmic@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Use dma_map_single() for a2091 driver (leave bounce buffer logic unchanged). Use dma_set_mask_and_coherent() to avoid explicit cache flushes. Compile-tested only. CC: linux-scsi@vger.kernel.org Link: https://lore.kernel.org/r/6d1d88ee-1cf6-c735-1e6d-bafd2096e322@gmail.com Signed-off-by: Michael Schmitz Reviewed-by: Arnd Bergmann --- drivers/scsi/a2091.c | 53 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/drivers/scsi/a2091.c b/drivers/scsi/a2091.c index cf703a1ecdda..2338c75c34ed 100644 --- a/drivers/scsi/a2091.c +++ b/drivers/scsi/a2091.c @@ -24,8 +24,11 @@ struct a2091_hostdata { struct WD33C93_hostdata wh; struct a2091_scsiregs *regs; + struct device *dev; }; +#define DMA_DIR(d) ((d == DATA_OUT_DIR) ? DMA_TO_DEVICE : DMA_FROM_DEVICE) + static irqreturn_t a2091_intr(int irq, void *data) { struct Scsi_Host *instance = data; @@ -45,15 +48,31 @@ static irqreturn_t a2091_intr(int irq, void *data) static int dma_setup(struct scsi_cmnd *cmd, int dir_in) { struct scsi_pointer *scsi_pointer = WD33C93_scsi_pointer(cmd); + unsigned long len = scsi_pointer->this_residual; struct Scsi_Host *instance = cmd->device->host; struct a2091_hostdata *hdata = shost_priv(instance); struct WD33C93_hostdata *wh = &hdata->wh; struct a2091_scsiregs *regs = hdata->regs; unsigned short cntr = CNTR_PDMD | CNTR_INTEN; - unsigned long addr = virt_to_bus(scsi_pointer->ptr); + dma_addr_t addr; + + addr = dma_map_single(hdata->dev, scsi_pointer->ptr, + len, DMA_DIR(dir_in)); + if (dma_mapping_error(hdata->dev, addr)) { + dev_warn(hdata->dev, "cannot map SCSI data block %p\n", + scsi_pointer->ptr); + return 1; + } + scsi_pointer->dma_handle = addr; /* don't allow DMA if the physical address is bad */ if (addr & A2091_XFER_MASK) { + /* drop useless mapping */ + dma_unmap_single(hdata->dev, scsi_pointer->dma_handle, + scsi_pointer->this_residual, + DMA_DIR(dir_in)); + scsi_pointer->dma_handle = (dma_addr_t) NULL; + wh->dma_bounce_len = (scsi_pointer->this_residual + 511) & ~0x1ff; wh->dma_bounce_buffer = kmalloc(wh->dma_bounce_len, GFP_KERNEL); @@ -64,9 +83,6 @@ static int dma_setup(struct scsi_cmnd *cmd, int dir_in) return 1; } - /* get the physical address of the bounce buffer */ - addr = virt_to_bus(wh->dma_bounce_buffer); - /* the bounce buffer may not be in the first 16M of physmem */ if (addr & A2091_XFER_MASK) { /* we could use chipmem... maybe later */ @@ -81,6 +97,17 @@ static int dma_setup(struct scsi_cmnd *cmd, int dir_in) memcpy(wh->dma_bounce_buffer, scsi_pointer->ptr, scsi_pointer->this_residual); } + + /* may flush/invalidate cache for us */ + addr = dma_map_single(hdata->dev, wh->dma_bounce_buffer, + wh->dma_bounce_len, DMA_DIR(dir_in)); + /* can't map buffer; use PIO */ + if (dma_mapping_error(hdata->dev, addr)) { + dev_warn(hdata->dev, "cannot map bounce buffer %p\n", + wh->dma_bounce_buffer); + return 1; + } + scsi_pointer->dma_handle = addr; } /* setup dma direction */ @@ -95,13 +122,8 @@ static int dma_setup(struct scsi_cmnd *cmd, int dir_in) /* setup DMA *physical* address */ regs->ACR = addr; - if (dir_in) { - /* invalidate any cache */ - cache_clear(addr, scsi_pointer->this_residual); - } else { - /* push any dirty cache */ - cache_push(addr, scsi_pointer->this_residual); - } + /* no more cache flush here - using coherent DMA alloc */ + /* start DMA */ regs->ST_DMA = 1; @@ -151,6 +173,9 @@ static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt, wh->dma_bounce_buffer = NULL; wh->dma_bounce_len = 0; } + dma_unmap_single(hdata->dev, scsi_pointer->dma_handle, + scsi_pointer->this_residual, + DMA_DIR(wh->dma_dir)); } static struct scsi_host_template a2091_scsi_template = { @@ -178,6 +203,11 @@ static int a2091_probe(struct zorro_dev *z, const struct zorro_device_id *ent) wd33c93_regs wdregs; struct a2091_hostdata *hdata; + if (dma_set_mask_and_coherent(&z->dev, DMA_BIT_MASK(24))) { + dev_warn(&z->dev, "cannot use 24 bit DMA\n"); + return -ENODEV; + } + if (!request_mem_region(z->resource.start, 256, "wd33c93")) return -EBUSY; @@ -198,6 +228,7 @@ static int a2091_probe(struct zorro_dev *z, const struct zorro_device_id *ent) wdregs.SCMD = ®s->SCMD; hdata = shost_priv(instance); + hdata->dev = &z->dev; hdata->wh.no_sync = 0xff; hdata->wh.fast = 0; hdata->wh.dma_mode = CTRL_DMA; From patchwork Wed Jun 29 01:16:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Schmitz X-Patchwork-Id: 586502 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F1D8C43334 for ; Wed, 29 Jun 2022 03:11:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230228AbiF2DLH (ORCPT ); Tue, 28 Jun 2022 23:11:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230133AbiF2DK6 (ORCPT ); Tue, 28 Jun 2022 23:10:58 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC33025C70; Tue, 28 Jun 2022 20:10:56 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id x20so7212863plx.6; Tue, 28 Jun 2022 20:10:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dJAtxvkZd2WYMWMHFKqN/VDP7wgyyYMbpnChf5/5H20=; b=XqjyL5jYmHy8hwuAGOjzG3o+h8uezKsf0b5ad4bjh5Q8FSKJSFNDTQGTwa8FH8aZuz dikIw44LDwQlM29RSAHOk7ZG54bRkS1N9b+ygctjRN3A5lYFDmFf5IAk7ZrgHC2V5Kqd w5nuAD4ndt2gFQ19gmNwbpvEaDHm4CIiWH51pHGS7kyChIEeXUpCbJQhEjT5Kx59bIeL HjbdnTq1GoXoqTm+2zPLtHibMGKAQSRr4EhThiylDezZOqkUOH9PXG3mtG0kRFv6yVum lF6WuHngV89jeGYTxYiradG8HmtqC1VAcFgooBEWRuaF73fr3r8iq/eXQiFTCS2WEu1C zGXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dJAtxvkZd2WYMWMHFKqN/VDP7wgyyYMbpnChf5/5H20=; b=4TDTqYH39duVmPL6cc6umFgavn4/8rNkEvhSOIT3X6R67EJLa6IGiX+QI+0u4y3apq ELSsVxyWdlDyzZAV1J5gXf9W6XZO7Rvs/wXgjWELJqegDpTRHuAlIsrYjGRYJ7PZMaUG wAS0daYvb1u2lIDmT9QRx3QTCR2c1eRIrZkAUtfWPYsOwuzMfmvEe3lqV12kO34sCPFS gs903voOmunX9mzw/NMw1vvQOIqCSEDrUFvaoNGnDLaY3QlFlIpNmgeOx0nnXOqkxDtT VKGIWHxqAjVD8uHPd2fEyKOvvvmCY4rwePp+HO9wp7H3fyWoJFPNKUwJBaa/8NlD2e2G s7Rg== X-Gm-Message-State: AJIora+pV9zhrwD/l6gd8V6UFwZGfHyX5yHvtR6Yx3dFTQKErGxlfiuX bz60xp7xBzWy+4j7afeLRj7hq8MQ9NQ07g== X-Google-Smtp-Source: AGRyM1tPxCkbBSiE6aCv0nv9a3L9b1ggtWe0f9LP4VxjcGf1gqPWN0hNw7e2QMjrX1yVlNiFxae/yA== X-Received: by 2002:a17:90a:6fc5:b0:1ec:87db:b9f6 with SMTP id e63-20020a17090a6fc500b001ec87dbb9f6mr1378614pjk.104.1656472256276; Tue, 28 Jun 2022 20:10:56 -0700 (PDT) Received: from xplor.waratah.dyndns.org (222-155-0-244-adsl.sparkbb.co.nz. [222.155.0.244]) by smtp.gmail.com with ESMTPSA id x15-20020a170902a38f00b0016b8b5b0aa0sm2942508pla.86.2022.06.28.20.10.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jun 2022 20:10:54 -0700 (PDT) Received: by xplor.waratah.dyndns.org (Postfix, from userid 1000) id 0AA10360332; Wed, 29 Jun 2022 13:16:43 +1200 (NZST) From: Michael Schmitz To: linux-m68k@vger.kernel.org, arnd@kernel.org Cc: linux-scsi@vger.kernel.org, geert@linux-m68k.org, Michael Schmitz Subject: [PATCH v1 3/3] scsi - gvp11.c: convert m68k WD33C93 drivers to DMA API Date: Wed, 29 Jun 2022 13:16:38 +1200 Message-Id: <20220629011638.21783-4-schmitzmic@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220629011638.21783-1-schmitzmic@gmail.com> References: <20220629011638.21783-1-schmitzmic@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Use dma_map_single() for gvp11 driver (leave bounce buffer logic unchanged). Use dma_set_mask_and_coherent() to avoid explicit cache flushes. Compile-tested only. CC: linux-scsi@vger.kernel.org Link: https://lore.kernel.org/r/6d1d88ee-1cf6-c735-1e6d-bafd2096e322@gmail.com Signed-off-by: Michael Schmitz --- drivers/scsi/gvp11.c | 78 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 65 insertions(+), 13 deletions(-) diff --git a/drivers/scsi/gvp11.c b/drivers/scsi/gvp11.c index 2f6c56aabe1d..a793323e008f 100644 --- a/drivers/scsi/gvp11.c +++ b/drivers/scsi/gvp11.c @@ -26,8 +26,12 @@ struct gvp11_hostdata { struct WD33C93_hostdata wh; struct gvp11_scsiregs *regs; + struct device *dev; }; +#define DMA_DIR(d) ((d == DATA_OUT_DIR) ? DMA_TO_DEVICE : DMA_FROM_DEVICE) +#define TO_DMA_MASK(m) ((~(m & 0xfffffff0))-1) + static irqreturn_t gvp11_intr(int irq, void *data) { struct Scsi_Host *instance = data; @@ -54,17 +58,33 @@ void gvp11_setup(char *str, int *ints) static int dma_setup(struct scsi_cmnd *cmd, int dir_in) { struct scsi_pointer *scsi_pointer = WD33C93_scsi_pointer(cmd); + unsigned long len = scsi_pointer->this_residual; struct Scsi_Host *instance = cmd->device->host; struct gvp11_hostdata *hdata = shost_priv(instance); struct WD33C93_hostdata *wh = &hdata->wh; struct gvp11_scsiregs *regs = hdata->regs; unsigned short cntr = GVP11_DMAC_INT_ENABLE; - unsigned long addr = virt_to_bus(scsi_pointer->ptr); + dma_addr_t addr; int bank_mask; static int scsi_alloc_out_of_range = 0; + addr = dma_map_single(hdata->dev, scsi_pointer->ptr, + len, DMA_DIR(dir_in)); + if (dma_mapping_error(hdata->dev, addr)) { + dev_warn(hdata->dev, "cannot map SCSI data block %p\n", + scsi_pointer->ptr); + return 1; + } + scsi_pointer->dma_handle = addr; + /* use bounce buffer if the physical address is bad */ if (addr & wh->dma_xfer_mask) { + /* drop useless mapping */ + dma_unmap_single(hdata->dev, scsi_pointer->dma_handle, + scsi_pointer->this_residual, + DMA_DIR(dir_in)); + scsi_pointer->dma_handle = (dma_addr_t) NULL; + wh->dma_bounce_len = (scsi_pointer->this_residual + 511) & ~0x1ff; if (!scsi_alloc_out_of_range) { @@ -87,10 +107,21 @@ static int dma_setup(struct scsi_cmnd *cmd, int dir_in) wh->dma_buffer_pool = BUF_CHIP_ALLOCED; } - /* check if the address of the bounce buffer is OK */ - addr = virt_to_bus(wh->dma_bounce_buffer); + /* may flush/invalidate cache for us */ + addr = dma_map_single(hdata->dev, wh->dma_bounce_buffer, + wh->dma_bounce_len, DMA_DIR(dir_in)); + /* can't map buffer; use PIO */ + if (dma_mapping_error(hdata->dev, addr)) { + dev_warn(hdata->dev, "cannot map bounce buffer %p\n", + wh->dma_bounce_buffer); + return 1; + } if (addr & wh->dma_xfer_mask) { + /* drop useless mapping */ + dma_unmap_single(hdata->dev, scsi_pointer->dma_handle, + scsi_pointer->this_residual, + DMA_DIR(dir_in)); /* fall back to Chip RAM if address out of range */ if (wh->dma_buffer_pool == BUF_SCSI_ALLOCED) { kfree(wh->dma_bounce_buffer); @@ -108,9 +139,19 @@ static int dma_setup(struct scsi_cmnd *cmd, int dir_in) return 1; } - addr = virt_to_bus(wh->dma_bounce_buffer); + /* may flush/invalidate cache for us */ + addr = dma_map_single(hdata->dev, wh->dma_bounce_buffer, + wh->dma_bounce_len, DMA_DIR(dir_in)); + /* can't map buffer; use PIO */ + if (dma_mapping_error(hdata->dev, addr)) { + dev_warn(hdata->dev, "cannot map bounce buffer %p\n", + wh->dma_bounce_buffer); + return 1; + } wh->dma_buffer_pool = BUF_CHIP_ALLOCED; } + /* finally, have OK mapping (punted for PIO else) */ + scsi_pointer->dma_handle = addr; if (!dir_in) { /* copy to bounce buffer for a write */ @@ -129,13 +170,7 @@ static int dma_setup(struct scsi_cmnd *cmd, int dir_in) /* setup DMA *physical* address */ regs->ACR = addr; - if (dir_in) { - /* invalidate any cache */ - cache_clear(addr, scsi_pointer->this_residual); - } else { - /* push any dirty cache */ - cache_push(addr, scsi_pointer->this_residual); - } + /* no more cache flush here - using coherent memory! */ bank_mask = (~wh->dma_xfer_mask >> 18) & 0x01c0; if (bank_mask) @@ -175,6 +210,9 @@ static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt, wh->dma_bounce_buffer = NULL; wh->dma_bounce_len = 0; } + dma_unmap_single(hdata->dev, scsi_pointer->dma_handle, + scsi_pointer->this_residual, + DMA_DIR(wh->dma_dir)); } static struct scsi_host_template gvp11_scsi_template = { @@ -287,6 +325,13 @@ static int gvp11_probe(struct zorro_dev *z, const struct zorro_device_id *ent) default_dma_xfer_mask = ent->driver_data; + if (dma_set_mask_and_coherent(&z->dev, + TO_DMA_MASK(default_dma_xfer_mask))) { + dev_warn(&z->dev, "cannot use DMA mask %x\n", + TO_DMA_MASK(default_dma_xfer_mask)); + return -ENODEV; + } + /* * Rumors state that some GVP ram boards use the same product * code as the SCSI controllers. Therefore if the board-size @@ -327,9 +372,16 @@ static int gvp11_probe(struct zorro_dev *z, const struct zorro_device_id *ent) wdregs.SCMD = ®s->SCMD; hdata = shost_priv(instance); - if (gvp11_xfer_mask) + if (gvp11_xfer_mask) { hdata->wh.dma_xfer_mask = gvp11_xfer_mask; - else + if (dma_set_mask_and_coherent(&z->dev, + TO_DMA_MASK(gvp11_xfer_mask))) { + dev_warn(&z->dev, "cannot use DMA mask %x\n", + TO_DMA_MASK(gvp11_xfer_mask)); + error = -ENODEV; + goto fail_check_or_alloc; + } + } else hdata->wh.dma_xfer_mask = default_dma_xfer_mask; hdata->wh.no_sync = 0xff;