Skip to contentSkip to conversation

drm/amdgpu: Add pcie usage callback to nbio

PATCH In review Asad Kamal 3 participants 4 messages Aug 9, 2023

Subsystems (2)
lore
Share & tools
lore

Asad Kamal

author
#0 lore raw

PATCH 1/2 drm/amdgpu: Add pcie usage callback to nbio

Add a callback in nbio to get pcie usage

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_nbio.c | 8 ++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_nbio.h | 3 +++
 2 files changed, 11 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_nbio.c +8 -0
index a3bc00577a7c..f65903a41e6f 100644
@@ -45,6 +45,14 @@ int amdgpu_nbio_ras_sw_init(struct amdgpu_device *adev)
 	return 0;
 }
 
+void amdgpu_nbio_get_pcie_usage(struct amdgpu_device *adev, uint64_t *count0,
+				uint64_t *count1)
+{
+	if (adev->nbio.funcs->get_pcie_usage)
+		adev->nbio.funcs->get_pcie_usage(adev, count0, count1);
+
+}
+
 int amdgpu_nbio_ras_late_init(struct amdgpu_device *adev, struct ras_common_if *ras_block)
 {
 	int r;
drivers/gpu/drm/amd/amdgpu/amdgpu_nbio.h +3 -0
index 8ab8ae01f87c..39bf845c9cc8 100644
@@ -99,6 +99,8 @@ struct amdgpu_nbio_funcs {
 	int (*get_compute_partition_mode)(struct amdgpu_device *adev);
 	u32 (*get_memory_partition_mode)(struct amdgpu_device *adev,
 					 u32 *supp_modes);
+	void (*get_pcie_usage)(struct amdgpu_device *adevi, uint64_t *count0,
+					uint64_t *count1);
 };
 
 struct amdgpu_nbio {
@@ -111,5 +113,6 @@ struct amdgpu_nbio {
 };
 
 int amdgpu_nbio_ras_sw_init(struct amdgpu_device *adev);
+void amdgpu_nbio_get_pcie_usage(struct amdgpu_device *adev, uint64_t *count0, uint64_t *count1);
 int amdgpu_nbio_ras_late_init(struct amdgpu_device *adev, struct ras_common_if *ras_block);
 #endif
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 2/2 drm/amdgpu: Add pci usage to nbio v7.9

Add implementation to get pcie usage for nbio v7.9.

---
 drivers/gpu/drm/amd/amdgpu/nbio_v7_9.c        | 63 +++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/soc15.c            |  2 +-
 .../asic_reg/nbio/nbio_7_9_0_sh_mask.h        |  8 +++
 3 files changed, 72 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/nbio_v7_9.c +63 -0
index cd1a02d30420..77c9625dfb8e 100644
@@ -32,6 +32,15 @@
 
 #define NPS_MODE_MASK 0x000000FFL
 
+#define smnPCIE_PERF_CNTL_TXCLK3		0x1A38021c
+#define smnPCIE_PERF_CNTL_TXCLK7		0x1A380888
+#define smnPCIE_PERF_COUNT_CNTL			0x1A380200
+#define smnPCIE_PERF_COUNT0_TXCLK3		0x1A380220
+#define smnPCIE_PERF_COUNT0_TXCLK7		0x1A38088C
+#define smnPCIE_PERF_COUNT0_UPVAL_TXCLK3	0x1A3808F8
+#define smnPCIE_PERF_COUNT0_UPVAL_TXCLK7	0x1A380918
+
+
 static void nbio_v7_9_remap_hdp_registers(struct amdgpu_device *adev)
 {
 	WREG32_SOC15(NBIO, 0, regBIF_BX0_REMAP_HDP_MEM_FLUSH_CNTL,
@@ -427,6 +436,59 @@ static void nbio_v7_9_init_registers(struct amdgpu_device *adev)
 	}
 }
 
+static void nbio_v7_9_get_pcie_usage(struct amdgpu_device *adev, uint64_t *count0,
+				     uint64_t *count1)
+{
+	uint32_t perfctrrx = 0;
+	uint32_t perfctrtx = 0;
+
+	/* This reports 0 on APUs, so return to avoid writing/reading registers
+	 * that may or may not be different from their GPU counterparts
+	 */
+	if (adev->flags & AMD_IS_APU)
+		return;
+
+	/* Use TXCLK3 counter group for rx event */
+	/* Use TXCLK7 counter group for tx event */
+	/* Set the 2 events that we wish to watch, defined above */
+	/* 40 is event# for received msgs */
+	/* 2 is event# of posted requests sent */
+	perfctrrx = REG_SET_FIELD(perfctrrx, PCIE_PERF_CNTL_TXCLK3, EVENT0_SEL, 40);
+	perfctrtx = REG_SET_FIELD(perfctrtx, PCIE_PERF_CNTL_TXCLK7, EVENT0_SEL, 2);
+
+	/* Write to enable desired perf counters */
+	WREG32_PCIE(smnPCIE_PERF_CNTL_TXCLK3, perfctrrx);
+	WREG32_PCIE(smnPCIE_PERF_CNTL_TXCLK7, perfctrtx);
+
+	/* Zero out and enable SHADOW_WR
+	 * Write 0x6:
+	 * Bit 1 = Global Shadow wr(1)
+	 * Bit 2 = Global counter reset enable(1)
+	 */
+	WREG32_PCIE(smnPCIE_PERF_COUNT_CNTL, 0x00000006);
+
+	/* Enable Gloabl Counter
+	 * Write 0x1:
+	 * Bit 0 = Global Counter Enable(1)
+	 */
+	WREG32_PCIE(smnPCIE_PERF_COUNT_CNTL, 0x00000001);
+
+	msleep(1000);
+
+	/* Disable Global Counter, Reset and enable SHADOW_WR
+	 * Write 0x6:
+	 * Bit 1 = Global Shadow wr(1)
+	 * Bit 2 = Global counter reset enable(1)
+	 */
+	WREG32_PCIE(smnPCIE_PERF_COUNT_CNTL, 0x00000006);
+
+	/* Get the upper and lower count  */
+	*count0 = RREG32_PCIE(smnPCIE_PERF_COUNT0_TXCLK3) |
+		  ((uint64_t)RREG32_PCIE(smnPCIE_PERF_COUNT0_UPVAL_TXCLK3) << 32);
+	*count1 = RREG32_PCIE(smnPCIE_PERF_COUNT0_TXCLK7) |
+		  ((uint64_t)RREG32_PCIE(smnPCIE_PERF_COUNT0_UPVAL_TXCLK7) << 32);
+}
+
 const struct amdgpu_nbio_funcs nbio_v7_9_funcs = {
 	.get_hdp_flush_req_offset = nbio_v7_9_get_hdp_flush_req_offset,
 	.get_hdp_flush_done_offset = nbio_v7_9_get_hdp_flush_done_offset,
@@ -450,4 +512,5 @@ const struct amdgpu_nbio_funcs nbio_v7_9_funcs = {
 	.get_compute_partition_mode = nbio_v7_9_get_compute_partition_mode,
 	.get_memory_partition_mode = nbio_v7_9_get_memory_partition_mode,
 	.init_registers = nbio_v7_9_init_registers,
+	.get_pcie_usage = nbio_v7_9_get_pcie_usage,
 };
drivers/gpu/drm/amd/amdgpu/soc15.c +1 -1
index afcaeadda4c7..4b8dce091bcd 100644
@@ -893,7 +893,7 @@ static const struct amdgpu_asic_funcs aqua_vanjaram_asic_funcs =
 	.get_config_memsize = &soc15_get_config_memsize,
 	.need_full_reset = &soc15_need_full_reset,
 	.init_doorbell_index = &aqua_vanjaram_doorbell_index_init,
-	.get_pcie_usage = &vega20_get_pcie_usage,
+	.get_pcie_usage = &amdgpu_nbio_get_pcie_usage,
 	.need_reset_on_init = &soc15_need_reset_on_init,
 	.get_pcie_replay_count = &soc15_get_pcie_replay_count,
 	.supports_baco = &soc15_supports_baco,
drivers/gpu/drm/amd/include/asic_reg/nbio/nbio_7_9_0_sh_mask.h +8 -0
index a22481e7bcdb..e0c28c29ddb0 100644
@@ -38896,5 +38896,13 @@
 #define RCC_DEV0_EPF0_VF7_GFXMSIX_PBA__MSIX_PENDING_BITS_0_MASK                                               0x00000001L
 #define RCC_DEV0_EPF0_VF7_GFXMSIX_PBA__MSIX_PENDING_BITS_1_MASK                                               0x00000002L
 
+//PCIE_PERF_CNTL_TXCLK3
+#define PCIE_PERF_CNTL_TXCLK3__EVENT0_SEL__SHIFT							      0x0
+#define PCIE_PERF_CNTL_TXCLK3__EVENT0_SEL_MASK								      0x000000FFL
+
+//PCIE_PERF_CNTL_TXCLK7
+#define PCIE_PERF_CNTL_TXCLK7__EVENT0_SEL__SHIFT							      0x0
+#define PCIE_PERF_CNTL_TXCLK7__EVENT0_SEL_MASK								      0x000000FFL
+
 
 #endif
Signature · 1 line
2.34.1
Reviewed-by Reviewed-by Lijo Lazar Reviewed-by Shiwu Zhang on v1 2/2
#2 lore raw

RE: [PATCH 2/2] drm/amdgpu: Add pci usage to nbio v7.9

[AMD Official Use Only - General]

Series is

Regards,
Hawking
-----Original Message-----
From: Kamal, Asad <[email protected]>
Sent: Wednesday, August 9, 2023 16:30
To: [email protected]
Cc: Kamal, Asad <[email protected]>; Zhang, Hawking <[email protected]>; Lazar, Lijo <[email protected]>; Zhang, Morris <[email protected]>
Subject: [PATCH 2/2] drm/amdgpu: Add pci usage to nbio v7.9

Add implementation to get pcie usage for nbio v7.9.

---
 drivers/gpu/drm/amd/amdgpu/nbio_v7_9.c        | 63 +++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/soc15.c            |  2 +-
 .../asic_reg/nbio/nbio_7_9_0_sh_mask.h        |  8 +++
 3 files changed, 72 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/nbio_v7_9.c +63 -0
index cd1a02d30420..77c9625dfb8e 100644
@@ -32,6 +32,15 @@
 
 #define NPS_MODE_MASK 0x000000FFL
 
+#define smnPCIE_PERF_CNTL_TXCLK3               0x1A38021c
+#define smnPCIE_PERF_CNTL_TXCLK7               0x1A380888
+#define smnPCIE_PERF_COUNT_CNTL                        0x1A380200
+#define smnPCIE_PERF_COUNT0_TXCLK3             0x1A380220
+#define smnPCIE_PERF_COUNT0_TXCLK7             0x1A38088C
+#define smnPCIE_PERF_COUNT0_UPVAL_TXCLK3       0x1A3808F8
+#define smnPCIE_PERF_COUNT0_UPVAL_TXCLK7       0x1A380918
+
+
 static void nbio_v7_9_remap_hdp_registers(struct amdgpu_device *adev)  {
        WREG32_SOC15(NBIO, 0, regBIF_BX0_REMAP_HDP_MEM_FLUSH_CNTL,
@@ -427,6 +436,59 @@ static void nbio_v7_9_init_registers(struct amdgpu_device *adev)
        }
 }
 
+static void nbio_v7_9_get_pcie_usage(struct amdgpu_device *adev, uint64_t *count0,
+                                    uint64_t *count1)
+{
+       uint32_t perfctrrx = 0;
+       uint32_t perfctrtx = 0;
+
+       /* This reports 0 on APUs, so return to avoid writing/reading registers
+        * that may or may not be different from their GPU counterparts
+        */
+       if (adev->flags & AMD_IS_APU)
+               return;
+
+       /* Use TXCLK3 counter group for rx event */
+       /* Use TXCLK7 counter group for tx event */
+       /* Set the 2 events that we wish to watch, defined above */
+       /* 40 is event# for received msgs */
+       /* 2 is event# of posted requests sent */
+       perfctrrx = REG_SET_FIELD(perfctrrx, PCIE_PERF_CNTL_TXCLK3, EVENT0_SEL, 40);
+       perfctrtx = REG_SET_FIELD(perfctrtx, PCIE_PERF_CNTL_TXCLK7,
+EVENT0_SEL, 2);
+
+       /* Write to enable desired perf counters */
+       WREG32_PCIE(smnPCIE_PERF_CNTL_TXCLK3, perfctrrx);
+       WREG32_PCIE(smnPCIE_PERF_CNTL_TXCLK7, perfctrtx);
+
+       /* Zero out and enable SHADOW_WR
+        * Write 0x6:
+        * Bit 1 = Global Shadow wr(1)
+        * Bit 2 = Global counter reset enable(1)
+        */
+       WREG32_PCIE(smnPCIE_PERF_COUNT_CNTL, 0x00000006);
+
+       /* Enable Gloabl Counter
+        * Write 0x1:
+        * Bit 0 = Global Counter Enable(1)
+        */
+       WREG32_PCIE(smnPCIE_PERF_COUNT_CNTL, 0x00000001);
+
+       msleep(1000);
+
+       /* Disable Global Counter, Reset and enable SHADOW_WR
+        * Write 0x6:
+        * Bit 1 = Global Shadow wr(1)
+        * Bit 2 = Global counter reset enable(1)
+        */
+       WREG32_PCIE(smnPCIE_PERF_COUNT_CNTL, 0x00000006);
+
+       /* Get the upper and lower count  */
+       *count0 = RREG32_PCIE(smnPCIE_PERF_COUNT0_TXCLK3) |
+                 ((uint64_t)RREG32_PCIE(smnPCIE_PERF_COUNT0_UPVAL_TXCLK3) << 32);
+       *count1 = RREG32_PCIE(smnPCIE_PERF_COUNT0_TXCLK7) |
+                 ((uint64_t)RREG32_PCIE(smnPCIE_PERF_COUNT0_UPVAL_TXCLK7) << 32); }
+
 const struct amdgpu_nbio_funcs nbio_v7_9_funcs = {
        .get_hdp_flush_req_offset = nbio_v7_9_get_hdp_flush_req_offset,
        .get_hdp_flush_done_offset = nbio_v7_9_get_hdp_flush_done_offset,
@@ -450,4 +512,5 @@ const struct amdgpu_nbio_funcs nbio_v7_9_funcs = {
        .get_compute_partition_mode = nbio_v7_9_get_compute_partition_mode,
        .get_memory_partition_mode = nbio_v7_9_get_memory_partition_mode,
        .init_registers = nbio_v7_9_init_registers,
+       .get_pcie_usage = nbio_v7_9_get_pcie_usage,
 };
drivers/gpu/drm/amd/amdgpu/soc15.c +1 -1
index afcaeadda4c7..4b8dce091bcd 100644
@@ -893,7 +893,7 @@ static const struct amdgpu_asic_funcs aqua_vanjaram_asic_funcs =
        .get_config_memsize = &soc15_get_config_memsize,
        .need_full_reset = &soc15_need_full_reset,
        .init_doorbell_index = &aqua_vanjaram_doorbell_index_init,
-       .get_pcie_usage = &vega20_get_pcie_usage,
+       .get_pcie_usage = &amdgpu_nbio_get_pcie_usage,
        .need_reset_on_init = &soc15_need_reset_on_init,
        .get_pcie_replay_count = &soc15_get_pcie_replay_count,
        .supports_baco = &soc15_supports_baco, diff --git a/drivers/gpu/drm/amd/include/asic_reg/nbio/nbio_7_9_0_sh_mask.h b/drivers/gpu/drm/amd/include/asic_reg/nbio/nbio_7_9_0_sh_mask.h

index a22481e7bcdb..e0c28c29ddb0 100644

drivers/gpu/drm/amd/include/asic_reg/nbio/nbio_7_9_0_sh_mask.h +8 -0
@@ -38896,5 +38896,13 @@
 #define RCC_DEV0_EPF0_VF7_GFXMSIX_PBA__MSIX_PENDING_BITS_0_MASK                                               0x00000001L
 #define RCC_DEV0_EPF0_VF7_GFXMSIX_PBA__MSIX_PENDING_BITS_1_MASK                                               0x00000002L
 
+//PCIE_PERF_CNTL_TXCLK3
+#define PCIE_PERF_CNTL_TXCLK3__EVENT0_SEL__SHIFT                                                             0x0
+#define PCIE_PERF_CNTL_TXCLK3__EVENT0_SEL_MASK                                                               0x000000FFL
+
+//PCIE_PERF_CNTL_TXCLK7
+#define PCIE_PERF_CNTL_TXCLK7__EVENT0_SEL__SHIFT                                                             0x0
+#define PCIE_PERF_CNTL_TXCLK7__EVENT0_SEL_MASK                                                               0x000000FFL
+
 
 #endif

--
2.34.1

#3 lore raw
In reply to Asad Kamal

[Public]

Quoted 48 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Asad Kamal
Sent: Wednesday, August 9, 2023 4:30 PM
To: [email protected]
Cc: Lazar, Lijo <[email protected]>; Zhang, Morris <[email protected]>; Kamal, Asad <[email protected]>; Zhang, Hawking <[email protected]>
Subject: [PATCH 1/2] drm/amdgpu: Add pcie usage callback to nbio

Add a callback in nbio to get pcie usage

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_nbio.c | 8 ++++++++
drivers/gpu/drm/amd/amdgpu/amdgpu_nbio.h | 3 +++
 2 files changed, 11 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_nbio.c +8 -0
index a3bc00577a7c..f65903a41e6f 100644
@@ -45,6 +45,14 @@ int amdgpu_nbio_ras_sw_init(struct amdgpu_device
 *adev)
      return 0;
 }
 
+void amdgpu_nbio_get_pcie_usage(struct amdgpu_device *adev, uint64_t
 *count0,
+                             uint64_t *count1)
+{
+     if (adev->nbio.funcs->get_pcie_usage)
+             adev->nbio.funcs->get_pcie_usage(adev, count0, count1);
+
+}
+
 int amdgpu_nbio_ras_late_init(struct amdgpu_device *adev, struct
ras_common_if *ras_block)  {
      int r;
drivers/gpu/drm/amd/amdgpu/amdgpu_nbio.h +0 -0
index 8ab8ae01f87c..39bf845c9cc8 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_nbio.h struct amdgpu_nbio_funcs { · line 102

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_nbio.h +1 -0
@@ -99,6 +99,8 @@ struct amdgpu_nbio_funcs {
      int (*get_compute_partition_mode)(struct amdgpu_device *adev);
      u32 (*get_memory_partition_mode)(struct amdgpu_device *adev,
                                       u32 *supp_modes);
+     void (*get_pcie_usage)(struct amdgpu_device *adevi, uint64_t

A nit-pick. Use 'adev' instead of 'adevi' for better code consistency.

Regards,
Guchun

Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_nbio.h +1 -0
 *count0,
+                                     uint64_t *count1);
 };
 

struct amdgpu_nbio {

drivers/gpu/drm/amd/amdgpu/amdgpu_nbio.h +2 -0
@@ -111,5 +113,6 @@ struct amdgpu_nbio {  };
 
 int amdgpu_nbio_ras_sw_init(struct amdgpu_device *adev);
+void amdgpu_nbio_get_pcie_usage(struct amdgpu_device *adev, uint64_t
+*count0, uint64_t *count1);
 int amdgpu_nbio_ras_late_init(struct amdgpu_device *adev, struct

ras_common_if *ras_block); #endif
--
2.34.1