Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp176058ybt; Thu, 18 Jun 2020 22:13:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/bvQ+HayxU2QCyeLOpsX7uqgzkbnuJvG7DX2NinuXWUpUxDY+pu6WX5gjbapCH2JJfQH+ X-Received: by 2002:a05:6402:6cc:: with SMTP id n12mr1511801edy.266.1592543612160; Thu, 18 Jun 2020 22:13:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592543612; cv=none; d=google.com; s=arc-20160816; b=JkvVXQzfGkBSkjCDbYafjuitm5SOTlq1BcfJKs/8tESayn1+UjG21TiYpWTPRj38W+ aJFipTQhll48HUWsjqz1x3oMw9C6IPv/KNtTyVcJK1xXUGLYGlBwyeb4A88sw/6JDrZa 9MCVX+Sn5WsZLDUcEOthKtHxT5vNeWGC79twV5Ab5HSp2OF7gxhCEd8dFq5bHp0yQnoq akz/n1U6jGYXFISxxkaL8Th3MyZiQzaG6SQmH/6RHK1m6gIlsdPsIo4SYvcbCYPqX1ut oSvpgMaFBm9wqaY00s3zy0dC7RZS6ZqygDAb7peVQQm+dh5FfYnc0+Y7vRhKTdREWr4O jI6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LxhuxQycNieQ16w87JkTA9DQfwrE4fTWZ8DvCETKWbk=; b=cYEc4ZWwvwjtnUw/Nhax2Ct4ZWAYmQdg46d/z+qJYozQLg8Ou32sK0+ofHoKke6ztu neLmRIgLzB4eQr75CokCqtuxNeCtxwBfEVW37Sfsa8U6FN0Zs3C5kAqT3XyD3cm+8ZU+ E+TifoTocY3LeFfj0j7XY2BubloLoZcCuad8WWWfDcHv+S6raKFKVDgRxWHlVJjfyvQz Nw1Y6BH4o/lejRu/S6hWTtYSaOnCF1lmnDOrOZE7QPBjE/inrd2S3Z7elvmYLtvqosrl qz15513LOZv6F3hFeWWLQD6Rr9Z6sQ6ciGF92aUy6oBh0ufOf831GXLM0zBpRHnvJRl3 xRrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=N8EWbXE3; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z4si3263208ejj.723.2020.06.18.22.13.09; Thu, 18 Jun 2020 22:13:32 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=N8EWbXE3; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728529AbgFSFHl (ORCPT + 99 others); Fri, 19 Jun 2020 01:07:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727869AbgFSFHl (ORCPT ); Fri, 19 Jun 2020 01:07:41 -0400 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33593C06174E for ; Thu, 18 Jun 2020 22:07:40 -0700 (PDT) Received: by mail-qk1-x743.google.com with SMTP id l17so7868557qki.9 for ; Thu, 18 Jun 2020 22:07:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LxhuxQycNieQ16w87JkTA9DQfwrE4fTWZ8DvCETKWbk=; b=N8EWbXE33GuLRhB4nF/r7qebEqLn6wGSnJRbNKKhK5CKbMgeUNWwwLSOVtNoB2MWTg 6hYDMpCLOhswyz5LBmFFbLVrj7SZh7DbmtJx748+o7XwX5IyztICXLe/F4R14xuUallm 5KXaGE4CirCMYqEmvdSQTY0uv4F0fEWNLYct/ITrZ8o90JDMR6W95hNCxaZxchQtn6HY s1IYQOUgZ2gVSXnQpK23D9Nd2Gol2iys92eXiZ2xOdqeC0ibK0SgRYhFF4BA3o1wVvSI iduaOHHbGnwNjSWUl4r4pfnlQxnCCbPSEJOxi6O2zxekqyp5fl6h1HQUhssB4yVP4Zx5 m7nQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LxhuxQycNieQ16w87JkTA9DQfwrE4fTWZ8DvCETKWbk=; b=dhbVTQHGRkBG4bHesfF4iDnxFY1JBW1GMxBHTj1JloJUOAotlUfLsCJNM9eL98/X60 jVXPFLlmxK8j5VzAkrJH0mmE9lbwHJqnX9IY8XkU3joWGT32/wPwuPr4HLgeaU19HsEz ROZBKqbXQlBPebHIYVJgNYpU9iVn5pt1M8xkDvhUv6fvfnqph1E4OeutUpr2V9wiRyyN J1ZnfmFDgQnlx0wISxY9YcYC/iRCcULxcbF+I7oLgCLHGePgWrEeRUJHmbg/sjJfu/1+ frEDxW13RUKYdtA8mywImRiUJFPnQH46zVHXjJM7q8sMxXYZXPpd6tPtjWQiG+BnVvvk toDw== X-Gm-Message-State: AOAM533U0FjJiGAxNFQf3y/GCt7naOgPqAEtc/BqRwz4UPbUZbj2juv0 stBu8/Vg4JlliegwQXiXAtM= X-Received: by 2002:a37:4b17:: with SMTP id y23mr1809929qka.73.1592543259489; Thu, 18 Jun 2020 22:07:39 -0700 (PDT) Received: from LeoBras.ibmuc.com (177-131-65-187.dynamic.desktop.com.br. [177.131.65.187]) by smtp.gmail.com with ESMTPSA id o6sm5235503qtd.59.2020.06.18.22.07.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jun 2020 22:07:38 -0700 (PDT) From: Leonardo Bras To: Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Alexey Kardashevskiy , Leonardo Bras , Thiago Jung Bauermann , Ram Pai Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] powerpc/pseries/iommu: Remove default DMA window before creating DDW Date: Fri, 19 Jun 2020 02:06:20 -0300 Message-Id: <20200619050619.266888-5-leobras.c@gmail.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200619050619.266888-1-leobras.c@gmail.com> References: <20200619050619.266888-1-leobras.c@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On LoPAR "DMA Window Manipulation Calls", it's recommended to remove the default DMA window for the device, before attempting to configure a DDW, in order to make the maximum resources available for the next DDW to be created. This is a requirement for some devices to use DDW, given they only allow one DMA window. If setting up a new DDW fails anywhere after the removal of this default DMA window, restore it using reset_dma_window. Signed-off-by: Leonardo Bras --- arch/powerpc/platforms/pseries/iommu.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/platforms/pseries/iommu.c b/arch/powerpc/platforms/pseries/iommu.c index de633f6ae093..68d1ea957ac7 100644 --- a/arch/powerpc/platforms/pseries/iommu.c +++ b/arch/powerpc/platforms/pseries/iommu.c @@ -1074,8 +1074,9 @@ static u64 enable_ddw(struct pci_dev *dev, struct device_node *pdn) u64 dma_addr, max_addr; struct device_node *dn; u32 ddw_avail[3]; + struct direct_window *window; - struct property *win64; + struct property *win64, *dfl_win; struct dynamic_dma_window_prop *ddwprop; struct failed_ddw_pdn *fpdn; @@ -1110,8 +1111,19 @@ static u64 enable_ddw(struct pci_dev *dev, struct device_node *pdn) if (ret) goto out_failed; - /* - * Query if there is a second window of size to map the + /* + * First step of setting up DDW is removing the default DMA window, + * if it's present. It will make all the resources available to the + * new DDW window. + * If anything fails after this, we need to restore it. + */ + + dfl_win = of_find_property(pdn, "ibm,dma-window", NULL); + if (dfl_win) + remove_dma_window(pdn, ddw_avail, dfl_win); + + /* + * Query if there is a window of size to map the * whole partition. Query returns number of windows, largest * block assigned to PE (partition endpoint), and two bitmasks * of page sizes: supported and supported for migrate-dma. @@ -1219,6 +1231,8 @@ static u64 enable_ddw(struct pci_dev *dev, struct device_node *pdn) kfree(win64); out_failed: + if (dfl_win) + reset_dma_window(dev, pdn); fpdn = kzalloc(sizeof(*fpdn), GFP_KERNEL); if (!fpdn) -- 2.25.4