[PATCH v2 2/2] drm/amd/pm: Update pci link speed and speed format

Lazar, Lijo lijo.lazar at amd.com
Sat Aug 12 17:17:03 UTC 2023



On 8/12/2023 4:03 PM, Asad Kamal wrote:
> 1) Update pcie link speed for smu v13_0_6 from correct register
> 
> 2) Populate gpu metric table with pcie link speed rather than
>     gen for smu v13_0_0, smu v13_0_6 & smu v13_0_7
> 
> v2:
> Update ESM register address
> Used macro to convert pcie gen to speed
> 
> Signed-off-by: Asad Kamal <asad.kamal at amd.com>
> ---
>   drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h     |  2 ++
>   drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c   |  1 -
>   .../gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c |  7 ++++++-
>   .../gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c | 16 ++++++++++++++--
>   .../gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c |  7 ++++++-
>   drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c           |  2 ++
>   6 files changed, 30 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h b/drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h
> index 355c156d871a..3a03f84d3288 100644
> --- a/drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h
> +++ b/drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h
> @@ -52,7 +52,9 @@
>   #define CTF_OFFSET_MEM			5
>   
>   #define SMU_13_VCLK_SHIFT		16
> +#define pci_gen_to_speed(gen)		((gen <= 0) ? link_speed[0] : link_speed[gen - 1])

Rename from 'pci_' to 'pcie_', it's only converting PCI express 
generation. Also, move this to smu_cmn.h and keep a comment like convert 
from Gen1/2/3 to 'X speed units'.

Other than that, the series is -
	Reviewed-by: Lijo Lazar <lijo.lazar at amd.com>

Thanks,
Lijo
	
>   
> +extern const int link_speed[];
>   extern const int pmfw_decoded_link_speed[5];
>   extern const int pmfw_decoded_link_width[7];
>   
> diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c
> index 895cda8e6934..6863186937f7 100644
> --- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c
> +++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c
> @@ -83,7 +83,6 @@ MODULE_FIRMWARE("amdgpu/smu_13_0_10.bin");
>   #define PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE__SHIFT 0xE
>   
>   static const int link_width[] = {0, 1, 2, 4, 8, 12, 16};
> -static const int link_speed[] = {25, 50, 80, 160};
>   
>   const int pmfw_decoded_link_speed[5] = {1, 2, 3, 4, 5};
>   const int pmfw_decoded_link_width[7] = {0, 1, 2, 4, 8, 12, 16};
> diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c
> index fddcd834bcec..164fbfbc70fb 100644
> --- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c
> +++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c
> @@ -96,6 +96,8 @@
>    */
>   #define SUPPORT_ECCTABLE_SMU_13_0_10_VERSION 0x00502200
>   
> +#define LINK_SPEED_MAX                          3
> +
>   static struct cmn2asic_msg_mapping smu_v13_0_0_message_map[SMU_MSG_MAX_COUNT] = {
>   	MSG_MAP(TestMessage,			PPSMC_MSG_TestMessage,                 1),
>   	MSG_MAP(GetSmuVersion,			PPSMC_MSG_GetSmuVersion,               1),
> @@ -1761,7 +1763,10 @@ static ssize_t smu_v13_0_0_get_gpu_metrics(struct smu_context *smu,
>   	gpu_metrics->current_fan_speed = metrics->AvgFanRpm;
>   
>   	gpu_metrics->pcie_link_width = metrics->PcieWidth;
> -	gpu_metrics->pcie_link_speed = metrics->PcieRate;
> +	if ((metrics->PcieRate - 1) > LINK_SPEED_MAX)
> +		gpu_metrics->pcie_link_speed = pci_gen_to_speed(1);
> +	else
> +		gpu_metrics->pcie_link_speed = pci_gen_to_speed(metrics->PcieRate);
>   
>   	gpu_metrics->system_clock_counter = ktime_get_boottime_ns();
>   
> diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c
> index 2572dc210739..a8e90a1e6ed9 100644
> --- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c
> +++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c
> @@ -80,12 +80,17 @@
>   /* possible frequency drift (1Mhz) */
>   #define EPSILON 1
>   
> -#define smnPCIE_ESM_CTRL 0x193D0
> +#define smnPCIE_ESM_CTRL 0x93D0
>   #define smnPCIE_LC_LINK_WIDTH_CNTL 0x1a340288
>   #define PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH_RD_MASK 0x00000070L
>   #define PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH_RD__SHIFT 0x4
>   #define MAX_LINK_WIDTH 6
>   
> +#define smnPCIE_LC_SPEED_CNTL                   0x1a340290
> +#define PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE_MASK 0xE0
> +#define PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE__SHIFT 0x5
> +#define LINK_SPEED_MAX				4
> +
>   static const struct cmn2asic_msg_mapping smu_v13_0_6_message_map[SMU_MSG_MAX_COUNT] = {
>   	MSG_MAP(TestMessage,			     PPSMC_MSG_TestMessage,			0),
>   	MSG_MAP(GetSmuVersion,			     PPSMC_MSG_GetSmuVersion,			1),
> @@ -1923,6 +1928,7 @@ smu_v13_0_6_get_current_pcie_link_width_level(struct smu_context *smu)
>   static int smu_v13_0_6_get_current_pcie_link_speed(struct smu_context *smu)
>   {
>   	struct amdgpu_device *adev = smu->adev;
> +	uint32_t speed_level;
>   	uint32_t esm_ctrl;
>   
>   	/* TODO: confirm this on real target */
> @@ -1930,7 +1936,13 @@ static int smu_v13_0_6_get_current_pcie_link_speed(struct smu_context *smu)
>   	if ((esm_ctrl >> 15) & 0x1FFFF)
>   		return (((esm_ctrl >> 8) & 0x3F) + 128);
>   
> -	return smu_v13_0_get_current_pcie_link_speed(smu);
> +	speed_level = (RREG32_PCIE(smnPCIE_LC_SPEED_CNTL) &
> +		PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE_MASK)
> +		>> PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE__SHIFT;
> +	if (speed_level > LINK_SPEED_MAX)
> +		speed_level = 0;
> +
> +	return pci_gen_to_speed(speed_level + 1);
>   }
>   
>   static ssize_t smu_v13_0_6_get_gpu_metrics(struct smu_context *smu, void **table)
> diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c
> index b43c5d13f8d9..915e57d3afa3 100644
> --- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c
> +++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c
> @@ -72,6 +72,8 @@
>   
>   #define MP0_MP1_DATA_REGION_SIZE_COMBOPPTABLE	0x4000
>   
> +#define LINK_SPEED_MAX                          3
> +
>   static struct cmn2asic_msg_mapping smu_v13_0_7_message_map[SMU_MSG_MAX_COUNT] = {
>   	MSG_MAP(TestMessage,			PPSMC_MSG_TestMessage,                 1),
>   	MSG_MAP(GetSmuVersion,			PPSMC_MSG_GetSmuVersion,               1),
> @@ -1741,7 +1743,10 @@ static ssize_t smu_v13_0_7_get_gpu_metrics(struct smu_context *smu,
>   	gpu_metrics->current_fan_speed = metrics->AvgFanRpm;
>   
>   	gpu_metrics->pcie_link_width = metrics->PcieWidth;
> -	gpu_metrics->pcie_link_speed = metrics->PcieRate;
> +	if ((metrics->PcieRate - 1) > LINK_SPEED_MAX)
> +		gpu_metrics->pcie_link_speed = pci_gen_to_speed(1);
> +	else
> +		gpu_metrics->pcie_link_speed = pci_gen_to_speed(metrics->PcieRate);
>   
>   	gpu_metrics->system_clock_counter = ktime_get_boottime_ns();
>   
> diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c b/drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c
> index 442d267088bc..c1d377e58b3e 100644
> --- a/drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c
> +++ b/drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c
> @@ -39,6 +39,8 @@
>   
>   #define MP1_C2PMSG_90__CONTENT_MASK                                                                    0xFFFFFFFFL
>   
> +const int link_speed[] = {25, 50, 80, 160, 320};
> +
>   #undef __SMU_DUMMY_MAP
>   #define __SMU_DUMMY_MAP(type)	#type
>   static const char * const __smu_message_names[] = {


More information about the amd-gfx mailing list