Skip to contentSkip to conversation

PCI LNKCTL2 RMW Accessor Cleanup

PATCH Applied Ilpo Järvinen 5 participants 10 messages Feb 15, 2024 – May 5, 2024

Subsystems (4)

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover PCI LNKCTL2 RMW Accessor Cleanup

This series converts open-coded LNKCTL2 RMW accesses to use RMW accessor. These patches used to be part of PCIe BW controller series
[1] which will require RMW ops to LNKCTL2 be properly locked.

However, since these RMW accessor patches are useful as cleanups on their own I chose to send them now separately to reduce the size of the BW controller series.

[1] https://lore.kernel.org/linux-pci/[email protected]/

Ilpo Järvinen (3):
drm/radeon: Use RMW accessors for changing LNKCTL2 drm/amdgpu: Use RMW accessors for changing LNKCTL2 RDMA/hfi1: Use RMW accessors for changing LNKCTL2

 drivers/gpu/drm/amd/amdgpu/cik.c  | 41 +++++++++++--------------------
 drivers/gpu/drm/amd/amdgpu/si.c   | 41 +++++++++++--------------------
 drivers/gpu/drm/radeon/cik.c      | 40 +++++++++++-------------------
 drivers/gpu/drm/radeon/si.c       | 40 +++++++++++-------------------
 drivers/infiniband/hw/hfi1/pcie.c | 30 ++++++----------------
 5 files changed, 68 insertions(+), 124 deletions(-)
Signature · 1 line
2.39.2
#1 lore raw

PATCH 1/3 drm/radeon: Use RMW accessors for changing LNKCTL2

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.

---
 drivers/gpu/drm/radeon/cik.c | 40 ++++++++++++++----------------------
 drivers/gpu/drm/radeon/si.c  | 40 ++++++++++++++----------------------
 2 files changed, 30 insertions(+), 50 deletions(-)
drivers/gpu/drm/radeon/cik.c +15 -25
index 10be30366c2b..b5e96a8fc2c1 100644
@@ -9592,28 +9592,18 @@ static void cik_pcie_gen3_enable(struct radeon_device *rdev)
 								   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(rdev->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(rdev->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(rdev->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;
@@ -9627,15 +9617,15 @@ static void cik_pcie_gen3_enable(struct radeon_device *rdev)
 	speed_cntl &= ~LC_FORCE_DIS_SW_SPEED_CHANGE;
 	WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
 
-	pcie_capability_read_word(rdev->pdev, PCI_EXP_LNKCTL2, &tmp16);
-	tmp16 &= ~PCI_EXP_LNKCTL2_TLS;
+	tmp16 = 0;
 	if (speed_cap == PCIE_SPEED_8_0GT)
 		tmp16 |= PCI_EXP_LNKCTL2_TLS_8_0GT; /* gen3 */
 	else if (speed_cap == PCIE_SPEED_5_0GT)
 		tmp16 |= PCI_EXP_LNKCTL2_TLS_5_0GT; /* gen2 */
 	else
 		tmp16 |= PCI_EXP_LNKCTL2_TLS_2_5GT; /* gen1 */
-	pcie_capability_write_word(rdev->pdev, PCI_EXP_LNKCTL2, tmp16);
+	pcie_capability_clear_and_set_word(rdev->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;
drivers/gpu/drm/radeon/si.c +15 -25
index 85e9cba49cec..8eeaea64c75d 100644
@@ -7193,28 +7193,18 @@ static void si_pcie_gen3_enable(struct radeon_device *rdev)
 								   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(rdev->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(rdev->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(rdev->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;
@@ -7228,15 +7218,15 @@ static void si_pcie_gen3_enable(struct radeon_device *rdev)
 	speed_cntl &= ~LC_FORCE_DIS_SW_SPEED_CHANGE;
 	WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
 
-	pcie_capability_read_word(rdev->pdev, PCI_EXP_LNKCTL2, &tmp16);
-	tmp16 &= ~PCI_EXP_LNKCTL2_TLS;
+	tmp16 = 0;
 	if (speed_cap == PCIE_SPEED_8_0GT)
 		tmp16 |= PCI_EXP_LNKCTL2_TLS_8_0GT; /* gen3 */
 	else if (speed_cap == PCIE_SPEED_5_0GT)
 		tmp16 |= PCI_EXP_LNKCTL2_TLS_5_0GT; /* gen2 */
 	else
 		tmp16 |= PCI_EXP_LNKCTL2_TLS_2_5GT; /* gen1 */
-	pcie_capability_write_word(rdev->pdev, PCI_EXP_LNKCTL2, tmp16);
+	pcie_capability_clear_and_set_word(rdev->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;
Signature · 1 line
2.39.2
maintainer Acked-by on v1 1/3
#2 lore raw

RE: [PATCH 1/3] drm/radeon: Use RMW accessors for changing LNKCTL2

[Public]

Quoted 19 lines

-----Original Message-----
From: Ilpo Järvinen <[email protected]>
Sent: Thursday, February 15, 2024 8:32 AM
To: Deucher, Alexander <[email protected]>; amd- [email protected]; Daniel Vetter <[email protected]>; David Airlie <[email protected]>; Dennis Dalessandro <[email protected]>; dri- [email protected]; Jason Gunthorpe <[email protected]>; Leon Romanovsky <[email protected]>; [email protected]; linux- [email protected]; Pan, Xinhui <[email protected]>; Koenig, Christian <[email protected]>
Cc: Ilpo Järvinen <[email protected]>; Lukas Wunner <[email protected]>
Subject: [PATCH 1/3] drm/radeon: Use RMW accessors for changing LNKCTL2

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.

Quoted 8 lines

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.

The radeon and amdgpu patches are:

Are you looking for me to pick them up or do you want to land them as part of some larger change? Either way is fine with me.

Alex

Quoted 169 lines
---
 drivers/gpu/drm/radeon/cik.c | 40 ++++++++++++++----------------------
 drivers/gpu/drm/radeon/si.c  | 40 ++++++++++++++----------------------
 2 files changed, 30 insertions(+), 50 deletions(-)
drivers/gpu/drm/radeon/cik.c +0 -3
index 10be30366c2b..b5e96a8fc2c1 100644
@@ -9592,28 +9592,18 @@ static void cik_pcie_gen3_enable(struct
 radeon_device *rdev)
 
 PCI_EXP_LNKCTL_HAWD);
 
                              /* linkctl2 */
-                             pcie_capability_read_word(root,
 PCI_EXP_LNKCTL2,
-                                                       &tmp16);
-                             tmp16 &= ~(PCI_EXP_LNKCTL2_ENTER_COMP

|

drivers/gpu/drm/radeon/cik.c +0 -12
-                                        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(rdev->pdev,
-                                                       PCI_EXP_LNKCTL2,
-                                                       &tmp16);
-                             tmp16 &= ~(PCI_EXP_LNKCTL2_ENTER_COMP

|

drivers/gpu/drm/radeon/cik.c +1 -7
-                                        PCI_EXP_LNKCTL2_TX_MARGIN);
-                             tmp16 |= (gpu_cfg2 &
-                                       (PCI_EXP_LNKCTL2_ENTER_COMP |
-                                        PCI_EXP_LNKCTL2_TX_MARGIN));
-                             pcie_capability_write_word(rdev->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(rdev-

Quoted 1 line

pdev, PCI_EXP_LNKCTL2,

+
PCI_EXP_LNKCTL2_ENTER_COMP |
+
PCI_EXP_LNKCTL2_TX_MARGIN,

drivers/gpu/drm/radeon/cik.c +2 -0
+                                                                gpu_cfg2 |
+

(PCI_EXP_LNKCTL2_ENTER_COMP |
+
PCI_EXP_LNKCTL2_TX_MARGIN));

                              tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
                              tmp &= ~LC_SET_QUIESCE;
drivers/gpu/drm/radeon/cik.c +3 -3
@@ -9627,15 +9617,15 @@ static void cik_pcie_gen3_enable(struct
 radeon_device *rdev)
      speed_cntl &= ~LC_FORCE_DIS_SW_SPEED_CHANGE;
      WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
 
-     pcie_capability_read_word(rdev->pdev, PCI_EXP_LNKCTL2, &tmp16);
-     tmp16 &= ~PCI_EXP_LNKCTL2_TLS;
+     tmp16 = 0;
      if (speed_cap == PCIE_SPEED_8_0GT)
              tmp16 |= PCI_EXP_LNKCTL2_TLS_8_0GT; /* gen3 */
      else if (speed_cap == PCIE_SPEED_5_0GT)
              tmp16 |= PCI_EXP_LNKCTL2_TLS_5_0GT; /* gen2 */
      else
              tmp16 |= PCI_EXP_LNKCTL2_TLS_2_5GT; /* gen1 */
-     pcie_capability_write_word(rdev->pdev, PCI_EXP_LNKCTL2, tmp16);
+     pcie_capability_clear_and_set_word(rdev->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; diff --git

a/drivers/gpu/drm/radeon/si.c b/drivers/gpu/drm/radeon/si.c index 85e9cba49cec..8eeaea64c75d 100644

drivers/gpu/drm/radeon/si.c +0 -3
@@ -7193,28 +7193,18 @@ static void si_pcie_gen3_enable(struct
 radeon_device *rdev)
 
 PCI_EXP_LNKCTL_HAWD);
 
                              /* linkctl2 */
-                             pcie_capability_read_word(root,
 PCI_EXP_LNKCTL2,
-                                                       &tmp16);
-                             tmp16 &= ~(PCI_EXP_LNKCTL2_ENTER_COMP

|

drivers/gpu/drm/radeon/si.c +0 -12
-                                        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(rdev->pdev,
-                                                       PCI_EXP_LNKCTL2,
-                                                       &tmp16);
-                             tmp16 &= ~(PCI_EXP_LNKCTL2_ENTER_COMP

|

drivers/gpu/drm/radeon/si.c +1 -7
-                                        PCI_EXP_LNKCTL2_TX_MARGIN);
-                             tmp16 |= (gpu_cfg2 &
-                                       (PCI_EXP_LNKCTL2_ENTER_COMP |
-                                        PCI_EXP_LNKCTL2_TX_MARGIN));
-                             pcie_capability_write_word(rdev->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(rdev-

Quoted 1 line

pdev, PCI_EXP_LNKCTL2,

+
PCI_EXP_LNKCTL2_ENTER_COMP |
+
PCI_EXP_LNKCTL2_TX_MARGIN,

drivers/gpu/drm/radeon/si.c +2 -0
+                                                                gpu_cfg2 &
+

(PCI_EXP_LNKCTL2_ENTER_COMP |
+
PCI_EXP_LNKCTL2_TX_MARGIN));

                              tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
                              tmp &= ~LC_SET_QUIESCE;
drivers/gpu/drm/radeon/si.c +3 -3
@@ -7228,15 +7218,15 @@ static void si_pcie_gen3_enable(struct
 radeon_device *rdev)
      speed_cntl &= ~LC_FORCE_DIS_SW_SPEED_CHANGE;
      WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
 
-     pcie_capability_read_word(rdev->pdev, PCI_EXP_LNKCTL2, &tmp16);
-     tmp16 &= ~PCI_EXP_LNKCTL2_TLS;
+     tmp16 = 0;
      if (speed_cap == PCIE_SPEED_8_0GT)
              tmp16 |= PCI_EXP_LNKCTL2_TLS_8_0GT; /* gen3 */
      else if (speed_cap == PCIE_SPEED_5_0GT)
              tmp16 |= PCI_EXP_LNKCTL2_TLS_5_0GT; /* gen2 */
      else
              tmp16 |= PCI_EXP_LNKCTL2_TLS_2_5GT; /* gen1 */
-     pcie_capability_write_word(rdev->pdev, PCI_EXP_LNKCTL2, tmp16);
+     pcie_capability_clear_and_set_word(rdev->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;

--
2.39.2

#3 lore raw

RE: [PATCH 1/3] drm/radeon: Use RMW accessors for changing LNKCTL2

Quoted 27 lines · Alexander

[Public]

Quoted 25 lines

-----Original Message-----
From: Ilpo Järvinen <[email protected]>
Sent: Thursday, February 15, 2024 8:32 AM
To: Deucher, Alexander <[email protected]>; amd- [email protected]; Daniel Vetter <[email protected]>; David Airlie <[email protected]>; Dennis Dalessandro <[email protected]>; dri- [email protected]; Jason Gunthorpe <[email protected]>; Leon Romanovsky <[email protected]>; [email protected]; linux- [email protected]; Pan, Xinhui <[email protected]>; Koenig, Christian <[email protected]>
Cc: Ilpo Järvinen <[email protected]>; Lukas Wunner <[email protected]>
Subject: [PATCH 1/3] drm/radeon: Use RMW accessors for changing LNKCTL2

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.

Quoted 8 lines
Quoted 2 lines

The radeon and amdgpu patches are:

Are you looking for me to pick them up or do you want to land them as part of some larger change? Either way is fine with me.

Hi,

You please take them, I intentionally took them apart from the BW controller series so they can go through the usual trees, not along with the BW controller. (I don't expect the BW controller to be accepted during this cycle).

Signature · 1 line
 i.
Applied
#4 lore raw

Re: [PATCH 1/3] drm/radeon: Use RMW accessors for changing LNKCTL2

Applied. Thanks.

Alex

Quoted 48 lines · Ilpo Järvinen
Quoted 27 lines · Alexander

[Public]

Quoted 25 lines

-----Original Message-----
From: Ilpo Järvinen <[email protected]>
Sent: Thursday, February 15, 2024 8:32 AM
To: Deucher, Alexander <[email protected]>; amd- [email protected]; Daniel Vetter <[email protected]>; David Airlie <[email protected]>; Dennis Dalessandro <[email protected]>; dri- [email protected]; Jason Gunthorpe <[email protected]>; Leon Romanovsky <[email protected]>; [email protected]; linux- [email protected]; Pan, Xinhui <[email protected]>; Koenig, Christian <[email protected]>
Cc: Ilpo Järvinen <[email protected]>; Lukas Wunner <[email protected]>
Subject: [PATCH 1/3] drm/radeon: Use RMW accessors for changing LNKCTL2

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.

Quoted 8 lines
Quoted 2 lines

The radeon and amdgpu patches are:

Are you looking for me to pick them up or do you want to land them as part of some larger change? Either way is fine with me.

Hi,

You please take them, I intentionally took them apart from the BW controller series so they can go through the usual trees, not along with the BW controller. (I don't expect the BW controller to be accepted during this cycle).

--
i.

#5 lore raw

PATCH 2/3 drm/amdgpu: Use RMW accessors for changing LNKCTL2

In reply to Ilpo Järvinen

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.

---
 drivers/gpu/drm/amd/amdgpu/cik.c | 41 ++++++++++++--------------------
 drivers/gpu/drm/amd/amdgpu/si.c  | 41 ++++++++++++--------------------
 2 files changed, 30 insertions(+), 52 deletions(-)
drivers/gpu/drm/amd/amdgpu/cik.c +15 -26
index 4dfaa017cf7f..a3a643254d7a 100644
@@ -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;
drivers/gpu/drm/amd/amdgpu/si.c +15 -26

59 lines not on this page · raw message

Signature · 1 line
2.39.2
#6 lore raw

PATCH 3/3 RDMA/hfi1: Use RMW accessors for changing LNKCTL2

In reply to Ilpo Järvinen

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.

---
 drivers/infiniband/hw/hfi1/pcie.c | 30 ++++++++----------------------
 1 file changed, 8 insertions(+), 22 deletions(-)
drivers/infiniband/hw/hfi1/pcie.c +8 -22
index 119ec2f1382b..7133964749f8 100644
@@ -1207,14 +1207,11 @@ int do_pcie_gen3_transition(struct hfi1_devdata *dd)
 		    (u32)lnkctl2);
 	/* only write to parent if target is not as high as ours */
 	if ((lnkctl2 & PCI_EXP_LNKCTL2_TLS) < target_vector) {
-		lnkctl2 &= ~PCI_EXP_LNKCTL2_TLS;
-		lnkctl2 |= target_vector;
-		dd_dev_info(dd, "%s: ..new link control2: 0x%x\n", __func__,
-			    (u32)lnkctl2);
-		ret = pcie_capability_write_word(parent,
-						 PCI_EXP_LNKCTL2, lnkctl2);
+		ret = pcie_capability_clear_and_set_word(parent, PCI_EXP_LNKCTL2,
+							 PCI_EXP_LNKCTL2_TLS,
+							 target_vector);
 		if (ret) {
-			dd_dev_err(dd, "Unable to write to PCI config\n");
+			dd_dev_err(dd, "Unable to change parent PCI target speed\n");
 			return_error = 1;
 			goto done;
 		}
@@ -1223,22 +1220,11 @@ int do_pcie_gen3_transition(struct hfi1_devdata *dd)
 	}
 
 	dd_dev_info(dd, "%s: setting target link speed\n", __func__);
-	ret = pcie_capability_read_word(dd->pcidev, PCI_EXP_LNKCTL2, &lnkctl2);
+	ret = pcie_capability_clear_and_set_word(dd->pcidev, PCI_EXP_LNKCTL2,
+						 PCI_EXP_LNKCTL2_TLS,
+						 target_vector);
 	if (ret) {
-		dd_dev_err(dd, "Unable to read from PCI config\n");
-		return_error = 1;
-		goto done;
-	}
-
-	dd_dev_info(dd, "%s: ..old link control2: 0x%x\n", __func__,
-		    (u32)lnkctl2);
-	lnkctl2 &= ~PCI_EXP_LNKCTL2_TLS;
-	lnkctl2 |= target_vector;
-	dd_dev_info(dd, "%s: ..new link control2: 0x%x\n", __func__,
-		    (u32)lnkctl2);
-	ret = pcie_capability_write_word(dd->pcidev, PCI_EXP_LNKCTL2, lnkctl2);
-	if (ret) {
-		dd_dev_err(dd, "Unable to write to PCI config\n");
+		dd_dev_err(dd, "Unable to change device PCI target speed\n");
 		return_error = 1;
 		goto done;
 	}
Signature · 1 line
2.39.2
#7 lore raw

Re: [PATCH 3/3] RDMA/hfi1: Use RMW accessors for changing LNKCTL2

Quoted 10 lines · Ilpo Järvinen

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.

Quoted 3 lines

I found out from Linux RDMA and InfiniBand patchwork that this patch had been silently closed as "Not Applicable". Is there some reason for that?

I was sending this change independently out (among 2 similar ones that already got applied) so I wouldn't need to keep carrying it within my PCIe bandwidth controller series. It seemed useful enough as cleanups to stand on its own legs w/o requiring it to be part of PCIe bw controller series.

Should I resend the patch or do RDMA/IB maintainers prefer it to remain as a part of PCIe BW controller series?

Signature · 1 line
 i.
Quoted 55 lines
---
 drivers/infiniband/hw/hfi1/pcie.c | 30 ++++++++----------------------
 1 file changed, 8 insertions(+), 22 deletions(-)
drivers/infiniband/hw/hfi1/pcie.c +8 -22
index 119ec2f1382b..7133964749f8 100644
@@ -1207,14 +1207,11 @@ int do_pcie_gen3_transition(struct hfi1_devdata *dd)
 		    (u32)lnkctl2);
 	/* only write to parent if target is not as high as ours */
 	if ((lnkctl2 & PCI_EXP_LNKCTL2_TLS) < target_vector) {
-		lnkctl2 &= ~PCI_EXP_LNKCTL2_TLS;
-		lnkctl2 |= target_vector;
-		dd_dev_info(dd, "%s: ..new link control2: 0x%x\n", __func__,
-			    (u32)lnkctl2);
-		ret = pcie_capability_write_word(parent,
-						 PCI_EXP_LNKCTL2, lnkctl2);
+		ret = pcie_capability_clear_and_set_word(parent, PCI_EXP_LNKCTL2,
+							 PCI_EXP_LNKCTL2_TLS,
+							 target_vector);
 		if (ret) {
-			dd_dev_err(dd, "Unable to write to PCI config\n");
+			dd_dev_err(dd, "Unable to change parent PCI target speed\n");
 			return_error = 1;
 			goto done;
 		}
@@ -1223,22 +1220,11 @@ int do_pcie_gen3_transition(struct hfi1_devdata *dd)
 	}
 
 	dd_dev_info(dd, "%s: setting target link speed\n", __func__);
-	ret = pcie_capability_read_word(dd->pcidev, PCI_EXP_LNKCTL2, &lnkctl2);
+	ret = pcie_capability_clear_and_set_word(dd->pcidev, PCI_EXP_LNKCTL2,
+						 PCI_EXP_LNKCTL2_TLS,
+						 target_vector);
 	if (ret) {
-		dd_dev_err(dd, "Unable to read from PCI config\n");
-		return_error = 1;
-		goto done;
-	}
-
-	dd_dev_info(dd, "%s: ..old link control2: 0x%x\n", __func__,
-		    (u32)lnkctl2);
-	lnkctl2 &= ~PCI_EXP_LNKCTL2_TLS;
-	lnkctl2 |= target_vector;
-	dd_dev_info(dd, "%s: ..new link control2: 0x%x\n", __func__,
-		    (u32)lnkctl2);
-	ret = pcie_capability_write_word(dd->pcidev, PCI_EXP_LNKCTL2, lnkctl2);
-	if (ret) {
-		dd_dev_err(dd, "Unable to write to PCI config\n");
+		dd_dev_err(dd, "Unable to change device PCI target speed\n");
 		return_error = 1;
 		goto done;
 	}
#8 lore raw

Re: [PATCH 3/3] RDMA/hfi1: Use RMW accessors for changing LNKCTL2

Quoted 12 lines · Ilpo Järvinen
Quoted 10 lines · Ilpo Järvinen

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.

Quoted 7 lines
Quoted 3 lines

I found out from Linux RDMA and InfiniBand patchwork that this patch had been silently closed as "Not Applicable". Is there some reason for that?

It is part of a series that crosses subsystems, series like that usually go through some other trees.

If you want single patches applied then please send single patches.. It is hard to understand intent from mixed series.

Jason

#9 lore raw

Re: [PATCH 3/3] RDMA/hfi1: Use RMW accessors for changing LNKCTL2

Quoted 17 lines · Jason Gunthorpe
Quoted 16 lines · Ilpo Järvinen
Quoted 13 lines · Ilpo Järvinen

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.

Quoted 6 lines
Quoted 3 lines

I found out from Linux RDMA and InfiniBand patchwork that this patch had been silently closed as "Not Applicable". Is there some reason for that?

It is part of a series that crosses subsystems, series like that usually go through some other trees.

Exactly, this is why I marked it as "Not Applicable".

Quoted 5 lines

If you want single patches applied then please send single patches.. It is hard to understand intent from mixed series.

Jason