From patchwork Tue Jul 24 14:13:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugeniy Paltsev X-Patchwork-Id: 948501 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=synopsys.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Sh9Za9Pk"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=synopsys.com header.i=@synopsys.com header.b="h+PS+Daw"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41ZgLr32J7z9s21 for ; Wed, 25 Jul 2018 00:13:24 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=YjHkLvjwfbJwKCM/HF+l1HsxmOLGViGSJPnpwlT+Psc=; b=Sh9 Za9PkrdMS3dJPd8SB1oCsAk64I+JB4kfKF75M6fOlr7XxXRsbIBiV7UM52V8ca3Afc/Ri1RZHnN66 9M2KnrCXxY8bvAaOTIQS+UVbbDNu0sDI8Q05LV8MEube2xTV0jwTUs9/kJeLQmCh4MMzXpz7a3leW G0EaL2/yYaaOf/VRPb95PFZhlRoZdCRVFLvWVW2yJvnIxwcdkSc2v6bwgw/lIT8pIh01pVBu6+qG3 Ctkgd4P+DdfaWpCUmxXdaqOLnKEZAAsCGtB3L/0KsXB1JnkADyFQE5pL9JsgRpPpM7nw9/4ymt5zb Qdo/rF5h+dtJdwUCNfkHFvqDxJluwYg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fhy42-0004Pz-CO; Tue, 24 Jul 2018 14:13:22 +0000 Received: from smtprelay4.synopsys.com ([198.182.47.9] helo=smtprelay.synopsys.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fhy3z-0004OE-6j for linux-snps-arc@lists.infradead.org; Tue, 24 Jul 2018 14:13:20 +0000 Received: from mailhost.synopsys.com (mailhost1.synopsys.com [10.12.238.239]) by smtprelay.synopsys.com (Postfix) with ESMTP id EA6D624E046A; Tue, 24 Jul 2018 07:13:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1532441586; bh=oNcZm8GFAc4g5NeW9IE36g/mmrk6HvEF1vCDuijychM=; h=From:To:Cc:Subject:Date:From; b=h+PS+Daw+I3e+sb7N9+OvL2iljS2GJhPvZXO29RuZ4b8ReQ0KaqymFG37tJMTzaZX HkviZJl5QdUHLvoGEKk/nDL6ZrfL9sTrBW+E7QlpD8xL8EQ0qVlk7xCOl9xiJQ4tXK 1Lp3+aoCmZasLuIiXujgs32e7PhlS7d4YYhyonzIjlLqBCAdWVmxeBiYGhXgQnvkEN +rT2xJE5mfE3aqO4WMyoT55Ljw68P1QPD+vq9CTXoSnnqDbSdMtWKvRUFJJtcgzXMx ql7ive04O5zFYy06bNHhlyS/TaKoRGE5k7SCP+XmGn2RBDEUf6iLaYd0Rc95FN8MI6 JP+1VWmUnOzug== Received: from paltsev-e7480.internal.synopsys.com (unknown [10.121.8.86]) by mailhost.synopsys.com (Postfix) with ESMTP id 38A835CFD; Tue, 24 Jul 2018 07:13:05 -0700 (PDT) From: Eugeniy Paltsev To: linux-snps-arc@lists.infradead.org Subject: [PATCH] ARC: fix broken noncoherent cache ops Date: Tue, 24 Jul 2018 17:13:02 +0300 Message-Id: <20180724141302.4305-1-Eugeniy.Paltsev@synopsys.com> X-Mailer: git-send-email 2.14.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180724_071319_261714_49D5D593 X-CRM114-Status: GOOD ( 10.24 ) X-Spam-Score: -0.1 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-0.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [198.182.47.9 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-snps-arc@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux on Synopsys ARC Processors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, Vineet Gupta , Alexey Brodkin , linux-kernel@vger.kernel.org, Eugeniy Paltsev , hch@lst.de MIME-Version: 1.0 Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org All DMA devices on ARC haven't worked with SW cache control since commit a8eb92d02dd7 ("arc: fix arc_dma_{map,unmap}_page") This happens because we don't check direction argument at all in new implementation. Fix that. Fixies: commit a8eb92d02dd7 ("arc: fix arc_dma_{map,unmap}_page") Signed-off-by: Eugeniy Paltsev --- NOTE: * This patch was stress tested on HSDK with bonie++ (usb and sdio) with IOC disabled. The ethernet wasn't tested because it doesn't work with SW cache control as for today (see STAR 9001336019) arch/arc/mm/dma.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/arch/arc/mm/dma.c b/arch/arc/mm/dma.c index 8c1071840979..cefb776a99ff 100644 --- a/arch/arc/mm/dma.c +++ b/arch/arc/mm/dma.c @@ -129,14 +129,56 @@ int arch_dma_mmap(struct device *dev, struct vm_area_struct *vma, return ret; } +/* + * Cache operations depending on function and direction argument, inspired by + * https://lkml.org/lkml/2018/5/18/979 + * "dma_sync_*_for_cpu and direction=TO_DEVICE (was Re: [PATCH 02/20] + * dma-mapping: provide a generic dma-noncoherent implementation)" + * + * | map == for_device | unmap == for_cpu + * |---------------------------------------------------------------- + * TO_DEV | writeback writeback | none none + * FROM_DEV | invalidate invalidate | invalidate invalidate + * BIDIR | writeback+inv writeback+inv | invalidate invalidate + * + * NOTE: we don't check the validity of direction argument as it is done in + * upper layer functions (in include/linux/dma-mapping.h) + */ + void arch_sync_dma_for_device(struct device *dev, phys_addr_t paddr, size_t size, enum dma_data_direction dir) { - dma_cache_wback(paddr, size); + switch (dir) { + case DMA_TO_DEVICE: + dma_cache_wback(paddr, size); + break; + + case DMA_FROM_DEVICE: + dma_cache_inv(paddr, size); + break; + + case DMA_BIDIRECTIONAL: + dma_cache_wback_inv(paddr, size); + break; + + default: + break; + } } void arch_sync_dma_for_cpu(struct device *dev, phys_addr_t paddr, size_t size, enum dma_data_direction dir) { - dma_cache_inv(paddr, size); + switch (dir) { + case DMA_TO_DEVICE: + break; + + case DMA_FROM_DEVICE: + case DMA_BIDIRECTIONAL: + dma_cache_inv(paddr, size); + break; + + default: + break; + } }