From patchwork Thu Feb 15 13:31:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 201604 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:b825:b0:106:860b:bbdd with SMTP id da37csp496718dyb; Thu, 15 Feb 2024 08:01:32 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVvjwGXZMzfoWhLzvyxbMvrwoi6RWekKRpj98+Nb5mzxHQC5vuR7u3GNW8K3WivZP5SwLO2D2AOKwxoWZj6kvCq8dz7vg== X-Google-Smtp-Source: AGHT+IEhNVDjZo8+MCaGh+8S9KhwSS/2ZN8Lovk/NA+BVnN0xpxfZH3IeM4ocj/oONbwhkNCiw1V X-Received: by 2002:a17:906:c2d3:b0:a3d:6592:a7d with SMTP id ch19-20020a170906c2d300b00a3d65920a7dmr1471563ejb.1.1708012892308; Thu, 15 Feb 2024 08:01:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708012892; cv=pass; d=google.com; s=arc-20160816; b=UYfyluVulZsa8FsW6PXDCuqAPrHBgnAgAVnFa5ulD3XpJpXQRFO6Z8mgIMjqAZy+2m CTHKQHgFZ/MAKuiJHATnCHJZ2Qtk4a3kbOV0qGaBqm6l3qGDBYBa7XbyUi1kW3AtNmHF ySoVGCfZC7HxSOubQKjeCP2RGZPjlMgG7evri5QGTwkff27RVXHIOKci19AtSPE9oJym awxBX+d2lQ5z1Ydk5T+vKeF4pqOHzGO0ftCFcI9SBuHGXX2za/Qs4UhPwuA7XHCfGsR0 eZ7knCaaa/7e962WHHwUp+8cYQX/s5KDj3cFsQT3zsqP1RtwZY5Z9hEKGgu4oX5dNDcO Zlwg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=wjk1qFbJBmGk9C/+D0+ax8atfB1YOLelZcleFPS86co=; fh=EJSy5Mttpwm45VeGKFe2p+7+XG9eKEz2uHQ9slSniGM=; b=djWb9hqzP+FjBNLsAna6qsOy/1DRk6rPJpgfe3if0idt+Gg9EKqLShvWUGi9by2Gc6 KzDguv6tVI1mJivk7FF+nBgSYwreuYottDtZyb/yHKmeWQo499IYUAAlDWPV/SDm9ZTN c5+UFjLBOPfyYgQOneWj+NA0U/Mvhi7ERCPvzbqOh8G9okoiRsW3uBc4wUeKwirmAb1c emWV1uYmRH1nGjJ07g68FnTYDOcYhm+MjpdCo7rOPdyBZTHbGLJcUPo8OA+/YGx4eAD4 Ba+HmrnqNqIl9MOs2vs37SbpFyLGOHHEt7bHhP+aWveB5ruhuiXEp+hIxFDADVhzqWGf NGRg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CchMb6Bs; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-66985-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66985-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id jg41-20020a170907972900b00a3d94bffa38si721251ejc.157.2024.02.15.08.01.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 08:01:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-66985-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CchMb6Bs; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-66985-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66985-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 80DCB1F23749 for ; Thu, 15 Feb 2024 13:33:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E5F63131720; Thu, 15 Feb 2024 13:32:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="CchMb6Bs" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 54F26130AFA; Thu, 15 Feb 2024 13:32:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.21 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708003951; cv=none; b=j+HEPLUGeRkjgMiFkQa1NuJxdStXGtSZp0iFxWZVFnJdct9lWvcyhqWaHfIUnQG2QZdXTwvUUjW5xP3As6kU6oIVYVbsVzmKZNeJcb9Txn7phY5xVvjYi5V3pv5QBHCv+l8TWhUuQoS+QSjU8C5vodpf2jxYW4EalgvhWh5Yr6Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708003951; c=relaxed/simple; bh=i2fuVggBbnbCjol88U7iVdUFysFmRhtcVImBwPONEDY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=NlKCFXIyAQekDVPD+Obf+TN+JPHWPtjONIvEDytCAHbrAx1C9noEVSYwKmoE16vABzgSNPjYpofpbuNQQGyjCQdc0dNq75D+A3DcRMvhegUqh0a/SE6zgy2B8aJ/lAYVr8ZWpzTg76IzyzbWI3QoTkPY1agE0ixwrYAb/4KBVXA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=CchMb6Bs; arc=none smtp.client-ip=198.175.65.21 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708003951; x=1739539951; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=i2fuVggBbnbCjol88U7iVdUFysFmRhtcVImBwPONEDY=; b=CchMb6Bs8U2r/9eamf4uTFZwtJbMA0CnQORPCgeCQEFOo3OsPIYFGULD 73nFCzL8jfKfIobOjzwtzgjiV6JRLT7rJ3jRx5fZajz56zVhWr85iEmS+ 28SbVhm8puXD2AxhPBC55CTe36faqcKp2JT7ba9BLhoc+e0KFT8lBxy/T ebbIS69GxnsjX5qllSoGkXdE8OCdsbfWc24dQLi5pFtV74SCTGiVGe8xG kXI9qVJATqm1AemRuUqb270sofIue2p2RJq3ZUI23vvgzJEFPj2SsoW1x ohUGd2IQ+/Y/BPiv8OWqjO3YMJe6gGC5t7LEDLPXP5/dmEyf25K5cTlBg w==; X-IronPort-AV: E=McAfee;i="6600,9927,10984"; a="2000349" X-IronPort-AV: E=Sophos;i="6.06,161,1705392000"; d="scan'208";a="2000349" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Feb 2024 05:32:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,161,1705392000"; d="scan'208";a="3489858" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.246.32.150]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Feb 2024 05:32:25 -0800 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: Alex Deucher , amd-gfx@lists.freedesktop.org, Daniel Vetter , David Airlie , Dennis Dalessandro , dri-devel@lists.freedesktop.org, Jason Gunthorpe , Leon Romanovsky , linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, "Pan, Xinhui" , =?utf-8?q?C?= =?utf-8?q?hristian_K=C3=B6nig?= Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Lukas Wunner Subject: [PATCH 2/3] drm/amdgpu: Use RMW accessors for changing LNKCTL2 Date: Thu, 15 Feb 2024 15:31:54 +0200 Message-Id: <20240215133155.9198-3-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240215133155.9198-1-ilpo.jarvinen@linux.intel.com> References: <20240215133155.9198-1-ilpo.jarvinen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790981326721968933 X-GMAIL-MSGID: 1790981326721968933 Convert open coded RMW accesses for LNKCTL2 to use pcie_capability_clear_and_set_word() which makes its easier to understand what the code tries to do. LNKCTL2 is not really owned by any driver because it is a collection of control bits that PCI core might need to touch. RMW accessors already have support for proper locking for a selected set of registers (LNKCTL2 is not yet among them but likely will be in the future) to avoid losing concurrent updates. Suggested-by: Lukas Wunner Signed-off-by: Ilpo Järvinen --- drivers/gpu/drm/amd/amdgpu/cik.c | 41 ++++++++++++-------------------- drivers/gpu/drm/amd/amdgpu/si.c | 41 ++++++++++++-------------------- 2 files changed, 30 insertions(+), 52 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/cik.c b/drivers/gpu/drm/amd/amdgpu/cik.c index 4dfaa017cf7f..a3a643254d7a 100644 --- a/drivers/gpu/drm/amd/amdgpu/cik.c +++ b/drivers/gpu/drm/amd/amdgpu/cik.c @@ -1638,28 +1638,18 @@ static void cik_pcie_gen3_enable(struct amdgpu_device *adev) PCI_EXP_LNKCTL_HAWD); /* linkctl2 */ - pcie_capability_read_word(root, PCI_EXP_LNKCTL2, - &tmp16); - tmp16 &= ~(PCI_EXP_LNKCTL2_ENTER_COMP | - PCI_EXP_LNKCTL2_TX_MARGIN); - tmp16 |= (bridge_cfg2 & - (PCI_EXP_LNKCTL2_ENTER_COMP | - PCI_EXP_LNKCTL2_TX_MARGIN)); - pcie_capability_write_word(root, - PCI_EXP_LNKCTL2, - tmp16); - - pcie_capability_read_word(adev->pdev, - PCI_EXP_LNKCTL2, - &tmp16); - tmp16 &= ~(PCI_EXP_LNKCTL2_ENTER_COMP | - PCI_EXP_LNKCTL2_TX_MARGIN); - tmp16 |= (gpu_cfg2 & - (PCI_EXP_LNKCTL2_ENTER_COMP | - PCI_EXP_LNKCTL2_TX_MARGIN)); - pcie_capability_write_word(adev->pdev, - PCI_EXP_LNKCTL2, - tmp16); + pcie_capability_clear_and_set_word(root, PCI_EXP_LNKCTL2, + PCI_EXP_LNKCTL2_ENTER_COMP | + PCI_EXP_LNKCTL2_TX_MARGIN, + bridge_cfg2 & + (PCI_EXP_LNKCTL2_ENTER_COMP | + PCI_EXP_LNKCTL2_TX_MARGIN)); + pcie_capability_clear_and_set_word(adev->pdev, PCI_EXP_LNKCTL2, + PCI_EXP_LNKCTL2_ENTER_COMP | + PCI_EXP_LNKCTL2_TX_MARGIN, + gpu_cfg2 & + (PCI_EXP_LNKCTL2_ENTER_COMP | + PCI_EXP_LNKCTL2_TX_MARGIN)); tmp = RREG32_PCIE(ixPCIE_LC_CNTL4); tmp &= ~PCIE_LC_CNTL4__LC_SET_QUIESCE_MASK; @@ -1674,16 +1664,15 @@ static void cik_pcie_gen3_enable(struct amdgpu_device *adev) speed_cntl &= ~PCIE_LC_SPEED_CNTL__LC_FORCE_DIS_SW_SPEED_CHANGE_MASK; WREG32_PCIE(ixPCIE_LC_SPEED_CNTL, speed_cntl); - pcie_capability_read_word(adev->pdev, PCI_EXP_LNKCTL2, &tmp16); - tmp16 &= ~PCI_EXP_LNKCTL2_TLS; - + tmp16 = 0; if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3) tmp16 |= PCI_EXP_LNKCTL2_TLS_8_0GT; /* gen3 */ else if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2) tmp16 |= PCI_EXP_LNKCTL2_TLS_5_0GT; /* gen2 */ else tmp16 |= PCI_EXP_LNKCTL2_TLS_2_5GT; /* gen1 */ - pcie_capability_write_word(adev->pdev, PCI_EXP_LNKCTL2, tmp16); + pcie_capability_clear_and_set_word(adev->pdev, PCI_EXP_LNKCTL2, + PCI_EXP_LNKCTL2_TLS, tmp16); speed_cntl = RREG32_PCIE(ixPCIE_LC_SPEED_CNTL); speed_cntl |= PCIE_LC_SPEED_CNTL__LC_INITIATE_LINK_SPEED_CHANGE_MASK; diff --git a/drivers/gpu/drm/amd/amdgpu/si.c b/drivers/gpu/drm/amd/amdgpu/si.c index a757526153e5..23e4ef4fff7c 100644 --- a/drivers/gpu/drm/amd/amdgpu/si.c +++ b/drivers/gpu/drm/amd/amdgpu/si.c @@ -2331,28 +2331,18 @@ static void si_pcie_gen3_enable(struct amdgpu_device *adev) gpu_cfg & PCI_EXP_LNKCTL_HAWD); - pcie_capability_read_word(root, PCI_EXP_LNKCTL2, - &tmp16); - tmp16 &= ~(PCI_EXP_LNKCTL2_ENTER_COMP | - PCI_EXP_LNKCTL2_TX_MARGIN); - tmp16 |= (bridge_cfg2 & - (PCI_EXP_LNKCTL2_ENTER_COMP | - PCI_EXP_LNKCTL2_TX_MARGIN)); - pcie_capability_write_word(root, - PCI_EXP_LNKCTL2, - tmp16); - - pcie_capability_read_word(adev->pdev, - PCI_EXP_LNKCTL2, - &tmp16); - tmp16 &= ~(PCI_EXP_LNKCTL2_ENTER_COMP | - PCI_EXP_LNKCTL2_TX_MARGIN); - tmp16 |= (gpu_cfg2 & - (PCI_EXP_LNKCTL2_ENTER_COMP | - PCI_EXP_LNKCTL2_TX_MARGIN)); - pcie_capability_write_word(adev->pdev, - PCI_EXP_LNKCTL2, - tmp16); + pcie_capability_clear_and_set_word(root, PCI_EXP_LNKCTL2, + PCI_EXP_LNKCTL2_ENTER_COMP | + PCI_EXP_LNKCTL2_TX_MARGIN, + bridge_cfg2 & + (PCI_EXP_LNKCTL2_ENTER_COMP | + PCI_EXP_LNKCTL2_TX_MARGIN)); + pcie_capability_clear_and_set_word(adev->pdev, PCI_EXP_LNKCTL2, + PCI_EXP_LNKCTL2_ENTER_COMP | + PCI_EXP_LNKCTL2_TX_MARGIN, + gpu_cfg2 & + (PCI_EXP_LNKCTL2_ENTER_COMP | + PCI_EXP_LNKCTL2_TX_MARGIN)); tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4); tmp &= ~LC_SET_QUIESCE; @@ -2365,16 +2355,15 @@ static void si_pcie_gen3_enable(struct amdgpu_device *adev) speed_cntl &= ~LC_FORCE_DIS_SW_SPEED_CHANGE; WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl); - pcie_capability_read_word(adev->pdev, PCI_EXP_LNKCTL2, &tmp16); - tmp16 &= ~PCI_EXP_LNKCTL2_TLS; - + tmp16 = 0; if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3) tmp16 |= PCI_EXP_LNKCTL2_TLS_8_0GT; /* gen3 */ else if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2) tmp16 |= PCI_EXP_LNKCTL2_TLS_5_0GT; /* gen2 */ else tmp16 |= PCI_EXP_LNKCTL2_TLS_2_5GT; /* gen1 */ - pcie_capability_write_word(adev->pdev, PCI_EXP_LNKCTL2, tmp16); + pcie_capability_clear_and_set_word(adev->pdev, PCI_EXP_LNKCTL2, + PCI_EXP_LNKCTL2_TLS, tmp16); speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL); speed_cntl |= LC_INITIATE_LINK_SPEED_CHANGE;