aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Russell <kent.russell@amd.com>2019-04-30 06:43:33 -0400
committerAlex Deucher <alexander.deucher@amd.com>2019-05-24 13:20:48 -0400
commitdcea6e65d41f4696571d5d391d3a760cfbb8ee00 (patch)
tree156db83858b303fc6ee3a02dd1fbb398b48259c7
parent673b366b41e216309c830d86d628e08736172067 (diff)
drm/amdgpu: Add PCIe replay count sysfs file
Add a sysfs file for reporting the number of PCIe replays (NAKs). This returns the sum of NAKs received and NAKs generated Signed-off-by: Kent Russell <kent.russell@amd.com> Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu.h3
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_device.c29
-rw-r--r--drivers/gpu/drm/amd/amdgpu/cik.c13
-rw-r--r--drivers/gpu/drm/amd/amdgpu/si.c13
-rw-r--r--drivers/gpu/drm/amd/amdgpu/soc15.c14
-rw-r--r--drivers/gpu/drm/amd/amdgpu/vi.c13
6 files changed, 85 insertions, 0 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 30165487dabd..4b10f3c1c6c4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -558,6 +558,8 @@ struct amdgpu_asic_funcs {
558 uint64_t *count1); 558 uint64_t *count1);
559 /* do we need to reset the asic at init time (e.g., kexec) */ 559 /* do we need to reset the asic at init time (e.g., kexec) */
560 bool (*need_reset_on_init)(struct amdgpu_device *adev); 560 bool (*need_reset_on_init)(struct amdgpu_device *adev);
561 /* PCIe replay counter */
562 uint64_t (*get_pcie_replay_count)(struct amdgpu_device *adev);
561}; 563};
562 564
563/* 565/*
@@ -1077,6 +1079,7 @@ int emu_soc_asic_init(struct amdgpu_device *adev);
1077#define amdgpu_asic_init_doorbell_index(adev) (adev)->asic_funcs->init_doorbell_index((adev)) 1079#define amdgpu_asic_init_doorbell_index(adev) (adev)->asic_funcs->init_doorbell_index((adev))
1078#define amdgpu_asic_get_pcie_usage(adev, cnt0, cnt1) ((adev)->asic_funcs->get_pcie_usage((adev), (cnt0), (cnt1))) 1080#define amdgpu_asic_get_pcie_usage(adev, cnt0, cnt1) ((adev)->asic_funcs->get_pcie_usage((adev), (cnt0), (cnt1)))
1079#define amdgpu_asic_need_reset_on_init(adev) (adev)->asic_funcs->need_reset_on_init((adev)) 1081#define amdgpu_asic_need_reset_on_init(adev) (adev)->asic_funcs->need_reset_on_init((adev))
1082#define amdgpu_asic_get_pcie_replay_count(adev) ((adev)->asic_funcs->get_pcie_replay_count((adev)))
1080 1083
1081/* Common functions */ 1084/* Common functions */
1082bool amdgpu_device_should_recover_gpu(struct amdgpu_device *adev); 1085bool amdgpu_device_should_recover_gpu(struct amdgpu_device *adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 0237513086e8..665764ff7eb7 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -97,6 +97,28 @@ static const char *amdgpu_asic_name[] = {
97 "LAST", 97 "LAST",
98}; 98};
99 99
100/**
101 * DOC: pcie_replay_count
102 *
103 * The amdgpu driver provides a sysfs API for reporting the total number
104 * of PCIe replays (NAKs)
105 * The file pcie_replay_count is used for this and returns the total
106 * number of replays as a sum of the NAKs generated and NAKs received
107 */
108
109static ssize_t amdgpu_device_get_pcie_replay_count(struct device *dev,
110 struct device_attribute *attr, char *buf)
111{
112 struct drm_device *ddev = dev_get_drvdata(dev);
113 struct amdgpu_device *adev = ddev->dev_private;
114 uint64_t cnt = amdgpu_asic_get_pcie_replay_count(adev);
115
116 return snprintf(buf, PAGE_SIZE, "%llu\n", cnt);
117}
118
119static DEVICE_ATTR(pcie_replay_count, S_IRUGO,
120 amdgpu_device_get_pcie_replay_count, NULL);
121
100static void amdgpu_device_get_pcie_info(struct amdgpu_device *adev); 122static void amdgpu_device_get_pcie_info(struct amdgpu_device *adev);
101 123
102/** 124/**
@@ -2721,6 +2743,12 @@ fence_driver_init:
2721 /* must succeed. */ 2743 /* must succeed. */
2722 amdgpu_ras_post_init(adev); 2744 amdgpu_ras_post_init(adev);
2723 2745
2746 r = device_create_file(adev->dev, &dev_attr_pcie_replay_count);
2747 if (r) {
2748 dev_err(adev->dev, "Could not create pcie_replay_count");
2749 return r;
2750 }
2751
2724 return 0; 2752 return 0;
2725 2753
2726failed: 2754failed:
@@ -2784,6 +2812,7 @@ void amdgpu_device_fini(struct amdgpu_device *adev)
2784 adev->rmmio = NULL; 2812 adev->rmmio = NULL;
2785 amdgpu_device_doorbell_fini(adev); 2813 amdgpu_device_doorbell_fini(adev);
2786 amdgpu_debugfs_regs_cleanup(adev); 2814 amdgpu_debugfs_regs_cleanup(adev);
2815 device_remove_file(adev->dev, &dev_attr_pcie_replay_count);
2787} 2816}
2788 2817
2789 2818
diff --git a/drivers/gpu/drm/amd/amdgpu/cik.c b/drivers/gpu/drm/amd/amdgpu/cik.c
index 07c1f239e9c3..3a4f20766a39 100644
--- a/drivers/gpu/drm/amd/amdgpu/cik.c
+++ b/drivers/gpu/drm/amd/amdgpu/cik.c
@@ -1804,6 +1804,18 @@ static bool cik_need_reset_on_init(struct amdgpu_device *adev)
1804 return false; 1804 return false;
1805} 1805}
1806 1806
1807static uint64_t cik_get_pcie_replay_count(struct amdgpu_device *adev)
1808{
1809 uint64_t nak_r, nak_g;
1810
1811 /* Get the number of NAKs received and generated */
1812 nak_r = RREG32_PCIE(ixPCIE_RX_NUM_NAK);
1813 nak_g = RREG32_PCIE(ixPCIE_RX_NUM_NAK_GENERATED);
1814
1815 /* Add the total number of NAKs, i.e the number of replays */
1816 return (nak_r + nak_g);
1817}
1818
1807static const struct amdgpu_asic_funcs cik_asic_funcs = 1819static const struct amdgpu_asic_funcs cik_asic_funcs =
1808{ 1820{
1809 .read_disabled_bios = &cik_read_disabled_bios, 1821 .read_disabled_bios = &cik_read_disabled_bios,
@@ -1821,6 +1833,7 @@ static const struct amdgpu_asic_funcs cik_asic_funcs =
1821 .init_doorbell_index = &legacy_doorbell_index_init, 1833 .init_doorbell_index = &legacy_doorbell_index_init,
1822 .get_pcie_usage = &cik_get_pcie_usage, 1834 .get_pcie_usage = &cik_get_pcie_usage,
1823 .need_reset_on_init = &cik_need_reset_on_init, 1835 .need_reset_on_init = &cik_need_reset_on_init,
1836 .get_pcie_replay_count = &cik_get_pcie_replay_count,
1824}; 1837};
1825 1838
1826static int cik_common_early_init(void *handle) 1839static int cik_common_early_init(void *handle)
diff --git a/drivers/gpu/drm/amd/amdgpu/si.c b/drivers/gpu/drm/amd/amdgpu/si.c
index 9d8df68893b9..4ff930a47e10 100644
--- a/drivers/gpu/drm/amd/amdgpu/si.c
+++ b/drivers/gpu/drm/amd/amdgpu/si.c
@@ -1375,6 +1375,18 @@ static void si_get_pcie_usage(struct amdgpu_device *adev, uint64_t *count0,
1375 *count1 = RREG32_PCIE(ixPCIE_PERF_COUNT1_TXCLK) | (cnt1_of << 32); 1375 *count1 = RREG32_PCIE(ixPCIE_PERF_COUNT1_TXCLK) | (cnt1_of << 32);
1376} 1376}
1377 1377
1378static uint64_t si_get_pcie_replay_count(struct amdgpu_device *adev)
1379{
1380 uint64_t nak_r, nak_g;
1381
1382 /* Get the number of NAKs received and generated */
1383 nak_r = RREG32_PCIE(ixPCIE_RX_NUM_NAK);
1384 nak_g = RREG32_PCIE(ixPCIE_RX_NUM_NAK_GENERATED);
1385
1386 /* Add the total number of NAKs, i.e the number of replays */
1387 return (nak_r + nak_g);
1388}
1389
1378static const struct amdgpu_asic_funcs si_asic_funcs = 1390static const struct amdgpu_asic_funcs si_asic_funcs =
1379{ 1391{
1380 .read_disabled_bios = &si_read_disabled_bios, 1392 .read_disabled_bios = &si_read_disabled_bios,
@@ -1393,6 +1405,7 @@ static const struct amdgpu_asic_funcs si_asic_funcs =
1393 .need_full_reset = &si_need_full_reset, 1405 .need_full_reset = &si_need_full_reset,
1394 .get_pcie_usage = &si_get_pcie_usage, 1406 .get_pcie_usage = &si_get_pcie_usage,
1395 .need_reset_on_init = &si_need_reset_on_init, 1407 .need_reset_on_init = &si_need_reset_on_init,
1408 .get_pcie_replay_count = &si_get_pcie_replay_count,
1396}; 1409};
1397 1410
1398static uint32_t si_get_rev_id(struct amdgpu_device *adev) 1411static uint32_t si_get_rev_id(struct amdgpu_device *adev)
diff --git a/drivers/gpu/drm/amd/amdgpu/soc15.c b/drivers/gpu/drm/amd/amdgpu/soc15.c
index 78bd00a0142f..78b27c03b8c2 100644
--- a/drivers/gpu/drm/amd/amdgpu/soc15.c
+++ b/drivers/gpu/drm/amd/amdgpu/soc15.c
@@ -745,6 +745,18 @@ static bool soc15_need_reset_on_init(struct amdgpu_device *adev)
745 return false; 745 return false;
746} 746}
747 747
748static uint64_t soc15_get_pcie_replay_count(struct amdgpu_device *adev)
749{
750 uint64_t nak_r, nak_g;
751
752 /* Get the number of NAKs received and generated */
753 nak_r = RREG32_PCIE(smnPCIE_RX_NUM_NAK);
754 nak_g = RREG32_PCIE(smnPCIE_RX_NUM_NAK_GENERATED);
755
756 /* Add the total number of NAKs, i.e the number of replays */
757 return (nak_r + nak_g);
758}
759
748static const struct amdgpu_asic_funcs soc15_asic_funcs = 760static const struct amdgpu_asic_funcs soc15_asic_funcs =
749{ 761{
750 .read_disabled_bios = &soc15_read_disabled_bios, 762 .read_disabled_bios = &soc15_read_disabled_bios,
@@ -762,6 +774,7 @@ static const struct amdgpu_asic_funcs soc15_asic_funcs =
762 .init_doorbell_index = &vega10_doorbell_index_init, 774 .init_doorbell_index = &vega10_doorbell_index_init,
763 .get_pcie_usage = &soc15_get_pcie_usage, 775 .get_pcie_usage = &soc15_get_pcie_usage,
764 .need_reset_on_init = &soc15_need_reset_on_init, 776 .need_reset_on_init = &soc15_need_reset_on_init,
777 .get_pcie_replay_count = &soc15_get_pcie_replay_count,
765}; 778};
766 779
767static const struct amdgpu_asic_funcs vega20_asic_funcs = 780static const struct amdgpu_asic_funcs vega20_asic_funcs =
@@ -781,6 +794,7 @@ static const struct amdgpu_asic_funcs vega20_asic_funcs =
781 .init_doorbell_index = &vega20_doorbell_index_init, 794 .init_doorbell_index = &vega20_doorbell_index_init,
782 .get_pcie_usage = &soc15_get_pcie_usage, 795 .get_pcie_usage = &soc15_get_pcie_usage,
783 .need_reset_on_init = &soc15_need_reset_on_init, 796 .need_reset_on_init = &soc15_need_reset_on_init,
797 .get_pcie_replay_count = &soc15_get_pcie_replay_count,
784}; 798};
785 799
786static int soc15_common_early_init(void *handle) 800static int soc15_common_early_init(void *handle)
diff --git a/drivers/gpu/drm/amd/amdgpu/vi.c b/drivers/gpu/drm/amd/amdgpu/vi.c
index 5e5b42a0744a..b8adf3808de2 100644
--- a/drivers/gpu/drm/amd/amdgpu/vi.c
+++ b/drivers/gpu/drm/amd/amdgpu/vi.c
@@ -987,6 +987,18 @@ static void vi_get_pcie_usage(struct amdgpu_device *adev, uint64_t *count0,
987 *count1 = RREG32_PCIE(ixPCIE_PERF_COUNT1_TXCLK) | (cnt1_of << 32); 987 *count1 = RREG32_PCIE(ixPCIE_PERF_COUNT1_TXCLK) | (cnt1_of << 32);
988} 988}
989 989
990static uint64_t vi_get_pcie_replay_count(struct amdgpu_device *adev)
991{
992 uint64_t nak_r, nak_g;
993
994 /* Get the number of NAKs received and generated */
995 nak_r = RREG32_PCIE(ixPCIE_RX_NUM_NAK);
996 nak_g = RREG32_PCIE(ixPCIE_RX_NUM_NAK_GENERATED);
997
998 /* Add the total number of NAKs, i.e the number of replays */
999 return (nak_r + nak_g);
1000}
1001
990static bool vi_need_reset_on_init(struct amdgpu_device *adev) 1002static bool vi_need_reset_on_init(struct amdgpu_device *adev)
991{ 1003{
992 u32 clock_cntl, pc; 1004 u32 clock_cntl, pc;
@@ -1021,6 +1033,7 @@ static const struct amdgpu_asic_funcs vi_asic_funcs =
1021 .init_doorbell_index = &legacy_doorbell_index_init, 1033 .init_doorbell_index = &legacy_doorbell_index_init,
1022 .get_pcie_usage = &vi_get_pcie_usage, 1034 .get_pcie_usage = &vi_get_pcie_usage,
1023 .need_reset_on_init = &vi_need_reset_on_init, 1035 .need_reset_on_init = &vi_need_reset_on_init,
1036 .get_pcie_replay_count = &vi_get_pcie_replay_count,
1024}; 1037};
1025 1038
1026#define CZ_REV_BRISTOL(rev) \ 1039#define CZ_REV_BRISTOL(rev) \