<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
</head>
<body>
<p style="font-family:Arial;font-size:10pt;color:#0000FF;margin:5pt;font-style:normal;font-weight:normal;text-decoration:none;" align="Left">
[AMD Official Use Only - General]<br>
</p>
<br>
<div>
<div dir="auto">> <span style="font-family: "Times New Roman"; font-size: 14.6667px; display: inline !important; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">'j' was initially set as 'num_of_wbrf_ranges - 1'. So, I suppose 'num_of_wbrf_ranges'
should be set as 'j' instead of 'j - 1'. Right?</span></div>
<div dir="auto"><span style="font-family: "Times New Roman"; font-size: 14.6667px; display: inline !important; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);"><br>
</span></div>
<div dir="auto"><span style="font-family: "Times New Roman"; font-size: 14.6667px; display: inline !important; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">Yes.</span></div>
<div id="ms-outlook-mobile-signature" dir="auto">
<div><br>
</div>
Thanks,<br>
Lijo</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Quan, Evan <Evan.Quan@amd.com><br>
<b>Sent:</b> Monday, August 28, 2023 7:23:55 AM<br>
<b>To:</b> Lazar, Lijo <Lijo.Lazar@amd.com>; lenb@kernel.org <lenb@kernel.org>; johannes@sipsolutions.net <johannes@sipsolutions.net>; davem@davemloft.net <davem@davemloft.net>; edumazet@google.com <edumazet@google.com>; kuba@kernel.org <kuba@kernel.org>; pabeni@redhat.com
<pabeni@redhat.com>; Deucher, Alexander <Alexander.Deucher@amd.com>; rafael@kernel.org <rafael@kernel.org>; Limonciello, Mario <Mario.Limonciello@amd.com><br>
<b>Cc:</b> linux-kernel@vger.kernel.org <linux-kernel@vger.kernel.org>; linux-acpi@vger.kernel.org <linux-acpi@vger.kernel.org>; amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org>; dri-devel@lists.freedesktop.org <dri-devel@lists.freedesktop.org>;
linux-wireless@vger.kernel.org <linux-wireless@vger.kernel.org>; netdev@vger.kernel.org <netdev@vger.kernel.org><br>
<b>Subject:</b> RE: [V10 5/8] drm/amd/pm: setup the framework to support Wifi RFI mitigation feature</font>
<div> </div>
</div>
<div class="BodyFragment"><font face="Times New Roman" size="3"><span style="font-size:12pt;"><a name="BM_BEGIN"></a>
<div><font size="2"><span style="font-size:11pt;">[AMD Official Use Only - General]<br>
<br>
> -----Original Message-----<br>
> From: Lazar, Lijo <Lijo.Lazar@amd.com><br>
> Sent: Friday, August 25, 2023 10:09 PM<br>
> To: Quan, Evan <Evan.Quan@amd.com>; lenb@kernel.org;<br>
> johannes@sipsolutions.net; davem@davemloft.net; edumazet@google.com;<br>
> kuba@kernel.org; pabeni@redhat.com; Deucher, Alexander<br>
> <Alexander.Deucher@amd.com>; rafael@kernel.org; Limonciello, Mario<br>
> <Mario.Limonciello@amd.com><br>
> Cc: linux-kernel@vger.kernel.org; linux-acpi@vger.kernel.org; amd-<br>
> gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org; linux-<br>
> wireless@vger.kernel.org; netdev@vger.kernel.org<br>
> Subject: Re: [V10 5/8] drm/amd/pm: setup the framework to support Wifi<br>
> RFI mitigation feature<br>
><br>
><br>
><br>
> On 8/25/2023 2:08 PM, Evan Quan wrote:<br>
> > With WBRF feature supported, as a driver responding to the<br>
> > frequencies, amdgpu driver is able to do shadow pstate switching to<br>
> > mitigate possible interference(between its (G-)DDR memory clocks and<br>
> > local radio module frequency bands used by Wifi 6/6e/7).<br>
> ><br>
> > Signed-off-by: Evan Quan <evan.quan@amd.com><br>
> > Reviewed-by: Mario Limonciello <mario.limonciello@amd.com><br>
> > --<br>
> > v1->v2:<br>
> > - update the prompt for feature support(Lijo)<br>
> > v8->v9:<br>
> > - update parameter document for smu_wbrf_event_handler(Simon)<br>
> > v9->v10:<br>
> > - correct the logics for wbrf range sorting(Lijo)<br>
> > ---<br>
> > drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 +<br>
> > drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 17 ++<br>
> > drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 195<br>
> ++++++++++++++++++<br>
> > drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h | 23 +++<br>
> > drivers/gpu/drm/amd/pm/swsmu/smu_internal.h | 3 +<br>
> > 5 files changed, 240 insertions(+)<br>
> ><br>
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
> > index a3b86b86dc47..2bfc9111ab00 100644<br>
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
> > @@ -247,6 +247,8 @@ extern int amdgpu_sg_display;<br>
> ><br>
> > extern int amdgpu_user_partt_mode;<br>
> ><br>
> > +extern int amdgpu_wbrf;<br>
> > +<br>
> > #define AMDGPU_VM_MAX_NUM_CTX 4096<br>
> > #define AMDGPU_SG_THRESHOLD (256*1024*1024)<br>
> > #define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS 3000<br>
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c<br>
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c<br>
> > index 0593ef8fe0a6..1c574bd3b60d 100644<br>
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c<br>
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c<br>
> > @@ -195,6 +195,7 @@ int amdgpu_use_xgmi_p2p = 1;<br>
> > int amdgpu_vcnfw_log;<br>
> > int amdgpu_sg_display = -1; /* auto */<br>
> > int amdgpu_user_partt_mode =<br>
> AMDGPU_AUTO_COMPUTE_PARTITION_MODE;<br>
> > +int amdgpu_wbrf = -1;<br>
> ><br>
> > static void amdgpu_drv_delayed_reset_work_handler(struct work_struct<br>
> > *work);<br>
> ><br>
> > @@ -981,6 +982,22 @@ module_param_named(user_partt_mode,<br>
> amdgpu_user_partt_mode, uint, 0444);<br>
> > module_param(enforce_isolation, bool, 0444);<br>
> > MODULE_PARM_DESC(enforce_isolation, "enforce process isolation<br>
> > between graphics and compute . enforce_isolation = on");<br>
> ><br>
> > +/**<br>
> > + * DOC: wbrf (int)<br>
> > + * Enable Wifi RFI interference mitigation feature.<br>
> > + * Due to electrical and mechanical constraints there may be likely<br>
> > +interference of<br>
> > + * relatively high-powered harmonics of the (G-)DDR memory clocks<br>
> > +with local radio<br>
> > + * module frequency bands used by Wifi 6/6e/7. To mitigate the<br>
> > +possible RFI interference,<br>
> > + * with this feature enabled, PMFW will use either “shadowed P-State”<br>
> > +or “P-State” based<br>
> > + * on active list of frequencies in-use (to be avoided) as part of<br>
> > +initial setting or<br>
> > + * P-state transition. However, there may be potential performance<br>
> > +impact with this<br>
> > + * feature enabled.<br>
> > + * (0 = disabled, 1 = enabled, -1 = auto (default setting, will be<br>
> > +enabled if supported)) */ MODULE_PARM_DESC(wbrf,<br>
> > + "Enable Wifi RFI interference mitigation (0 = disabled, 1 = enabled,<br>
> > +-1 = auto(default)"); module_param_named(wbrf, amdgpu_wbrf, int,<br>
> > +0444);<br>
> > +<br>
> > /* These devices are not supported by amdgpu.<br>
> > * They are supported by the mach64, r128, radeon drivers<br>
> > */<br>
> > diff --git a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c<br>
> > b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c<br>
> > index ce41a8309582..bdfd234d1558 100644<br>
> > --- a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c<br>
> > +++ b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c<br>
> > @@ -1228,6 +1228,174 @@ static int<br>
> smu_get_thermal_temperature_range(struct smu_context *smu)<br>
> > return ret;<br>
> > }<br>
> ><br>
> > +/**<br>
> > + * smu_wbrf_handle_exclusion_ranges - consume the wbrf exclusion<br>
> > +ranges<br>
> > + *<br>
> > + * @smu: smu_context pointer<br>
> > + *<br>
> > + * Retrieve the wbrf exclusion ranges and send them to PMFW for proper<br>
> handling.<br>
> > + * Returns 0 on success, error on failure.<br>
> > + */<br>
> > +static int smu_wbrf_handle_exclusion_ranges(struct smu_context *smu)<br>
> > +{<br>
> > + struct wbrf_ranges_in_out wbrf_exclusion = {0};<br>
> > + struct exclusion_range *wifi_bands = wbrf_exclusion.band_list;<br>
> > + struct amdgpu_device *adev = smu->adev;<br>
> > + uint32_t num_of_wbrf_ranges = MAX_NUM_OF_WBRF_RANGES;<br>
> > + uint64_t start, end;<br>
> > + int ret, i, j;<br>
> > +<br>
> > + ret = acpi_amd_wbrf_retrieve_exclusions(adev->dev,<br>
> &wbrf_exclusion);<br>
> > + if (ret) {<br>
> > + dev_err(adev->dev, "Failed to retrieve exclusion ranges!\n");<br>
> > + return ret;<br>
> > + }<br>
> > +<br>
> > + /*<br>
> > + * The exclusion ranges array we got might be filled with holes and<br>
> duplicate<br>
> > + * entries. For example:<br>
> > + * {(2400, 2500), (0, 0), (6882, 6962), (2400, 2500), (0, 0), (6117,<br>
> 6189), (0, 0)...}<br>
> > + * We need to do some sortups to eliminate those holes and duplicate<br>
> entries.<br>
> > + * Expected output: {(2400, 2500), (6117, 6189), (6882, 6962), (0,<br>
> 0)...}<br>
> > + */<br>
> > + for (i = 0; i < num_of_wbrf_ranges; i++) {<br>
> > + start = wifi_bands[i].start;<br>
> > + end = wifi_bands[i].end;<br>
> > +<br>
> > + /* get the last valid entry to fill the intermediate hole */<br>
> > + if (!start && !end) {<br>
> > + for (j = num_of_wbrf_ranges - 1; j > i; j--)<br>
> > + if (wifi_bands[j].start &&<br>
> > + wifi_bands[j].end)<br>
> > + break;<br>
> > +<br>
> > + /* no valid entry left */<br>
> > + if (j <= i)<br>
> > + break;<br>
> > +<br>
> > + wifi_bands[i].start = wifi_bands[j].start;<br>
> > + wifi_bands[i].end = wifi_bands[j].end;<br>
><br>
> start/end variables remain 0. Thus it won't have any effect on the loop below<br>
> which looks for duplicates. start/end need to be reassigned here.<br>
Ah, right. Thanks, I can fix that.<br>
><br>
> > + wifi_bands[j].start = 0;<br>
> > + wifi_bands[j].end = 0;<br>
> > + num_of_wbrf_ranges--;<br>
><br>
> Instead of decrementing by 1, this can be kept equal to j - 1 as jth entry is 0<br>
> now.<br>
'j' was initially set as 'num_of_wbrf_ranges - 1'. So, I suppose 'num_of_wbrf_ranges' should be set as 'j' instead of 'j - 1'. Right?<br>
<br>
Evan<br>
><br>
> Thanks,<br>
> Lijo<br>
><br>
> > + }<br>
> > +<br>
> > + /* eliminate duplicate entries */<br>
> > + for (j = i + 1; j < num_of_wbrf_ranges; j++) {<br>
> > + if ((wifi_bands[j].start == start) &&<br>
> > + (wifi_bands[j].end == end)) {<br>
> > + wifi_bands[j].start = 0;<br>
> > + wifi_bands[j].end = 0;<br>
> > + }<br>
> > + }<br>
> > + }<br>
> > +<br>
> > + /* Send the sorted wifi_bands to PMFW */<br>
> > + ret = smu_set_wbrf_exclusion_ranges(smu, wifi_bands);<br>
> > + /* Give it another chance */<br>
> > + if (unlikely(ret == -EBUSY)) {<br>
> > + mdelay(5);<br>
> > + ret = smu_set_wbrf_exclusion_ranges(smu, wifi_bands);<br>
> > + }<br>
> > +<br>
> > + return ret;<br>
> > +}<br>
> > +<br>
> > +/**<br>
> > + * smu_wbrf_event_handler - handle notify events<br>
> > + *<br>
> > + * @nb: notifier block<br>
> > + * @action: event type<br>
> > + * @_arg: event data<br>
> > + *<br>
> > + * Calls relevant amdgpu function in response to wbrf event<br>
> > + * notification from kernel.<br>
> > + */<br>
> > +static int smu_wbrf_event_handler(struct notifier_block *nb,<br>
> > + unsigned long action, void *_arg) {<br>
> > + struct smu_context *smu = container_of(nb, struct smu_context,<br>
> > + wbrf_notifier);<br>
> > +<br>
> > + switch (action) {<br>
> > + case WBRF_CHANGED:<br>
> > + smu_wbrf_handle_exclusion_ranges(smu);<br>
> > + break;<br>
> > + default:<br>
> > + return NOTIFY_DONE;<br>
> > + };<br>
> > +<br>
> > + return NOTIFY_OK;<br>
> > +}<br>
> > +<br>
> > +/**<br>
> > + * smu_wbrf_support_check - check wbrf support<br>
> > + *<br>
> > + * @smu: smu_context pointer<br>
> > + *<br>
> > + * Verifies the ACPI interface whether wbrf is supported.<br>
> > + */<br>
> > +static void smu_wbrf_support_check(struct smu_context *smu) {<br>
> > + struct amdgpu_device *adev = smu->adev;<br>
> > +<br>
> > + smu->wbrf_supported = smu_is_asic_wbrf_supported(smu) &&<br>
> > + !!amdgpu_wbrf &&<br>
> > + acpi_amd_wbrf_supported_consumer(adev->dev);<br>
> > +<br>
> > + if (smu->wbrf_supported)<br>
> > + dev_info(adev->dev, "RF interference mitigation is<br>
> supported\n"); }<br>
> > +<br>
> > +/**<br>
> > + * smu_wbrf_init - init driver wbrf support<br>
> > + *<br>
> > + * @smu: smu_context pointer<br>
> > + *<br>
> > + * Verifies the AMD ACPI interfaces and registers with the wbrf<br>
> > + * notifier chain if wbrf feature is supported.<br>
> > + * Returns 0 on success, error on failure.<br>
> > + */<br>
> > +static int smu_wbrf_init(struct smu_context *smu) {<br>
> > + struct amdgpu_device *adev = smu->adev;<br>
> > + int ret;<br>
> > +<br>
> > + if (!smu->wbrf_supported)<br>
> > + return 0;<br>
> > +<br>
> > + smu->wbrf_notifier.notifier_call = smu_wbrf_event_handler;<br>
> > + ret = acpi_amd_wbrf_register_notifier(&smu->wbrf_notifier);<br>
> > + if (ret)<br>
> > + return ret;<br>
> > +<br>
> > + /*<br>
> > + * Some wifiband exclusion ranges may be already there<br>
> > + * before our driver loaded. To make sure our driver<br>
> > + * is awared of those exclusion ranges.<br>
> > + */<br>
> > + ret = smu_wbrf_handle_exclusion_ranges(smu);<br>
> > + if (ret)<br>
> > + dev_err(adev->dev, "Failed to handle wbrf exclusion<br>
> ranges\n");<br>
> > +<br>
> > + return ret;<br>
> > +}<br>
> > +<br>
> > +/**<br>
> > + * smu_wbrf_fini - tear down driver wbrf support<br>
> > + *<br>
> > + * @smu: smu_context pointer<br>
> > + *<br>
> > + * Unregisters with the wbrf notifier chain.<br>
> > + */<br>
> > +static void smu_wbrf_fini(struct smu_context *smu) {<br>
> > + if (!smu->wbrf_supported)<br>
> > + return;<br>
> > +<br>
> > + acpi_amd_wbrf_unregister_notifier(&smu->wbrf_notifier);<br>
> > +}<br>
> > +<br>
> > static int smu_smc_hw_setup(struct smu_context *smu)<br>
> > {<br>
> > struct smu_feature *feature = &smu->smu_feature; @@ -1320,6<br>
> > +1488,15 @@ static int smu_smc_hw_setup(struct smu_context *smu)<br>
> > if (ret)<br>
> > return ret;<br>
> ><br>
> > + /* Enable UclkShadow on wbrf supported */<br>
> > + if (smu->wbrf_supported) {<br>
> > + ret = smu_enable_uclk_shadow(smu, true);<br>
> > + if (ret) {<br>
> > + dev_err(adev->dev, "Failed to enable UclkShadow<br>
> feature to support wbrf!\n");<br>
> > + return ret;<br>
> > + }<br>
> > + }<br>
> > +<br>
> > /*<br>
> > * With SCPM enabled, these actions(and relevant messages) are<br>
> > * not needed and permitted.<br>
> > @@ -1416,6 +1593,15 @@ static int smu_smc_hw_setup(struct<br>
> smu_context *smu)<br>
> > */<br>
> > ret = smu_set_min_dcef_deep_sleep(smu,<br>
> > smu->smu_table.boot_values.dcefclk<br>
> / 100);<br>
> > + if (ret) {<br>
> > + dev_err(adev->dev, "Error setting min deepsleep dcefclk\n");<br>
> > + return ret;<br>
> > + }<br>
> > +<br>
> > + /* Init wbrf support. Properly setup the notifier */<br>
> > + ret = smu_wbrf_init(smu);<br>
> > + if (ret)<br>
> > + dev_err(adev->dev, "Error during wbrf init call\n");<br>
> ><br>
> > return ret;<br>
> > }<br>
> > @@ -1471,6 +1657,13 @@ static int smu_hw_init(void *handle)<br>
> > return ret;<br>
> > }<br>
> ><br>
> > + /*<br>
> > + * Check whether wbrf is supported. This needs to be done<br>
> > + * before SMU setup starts since part of SMU configuration<br>
> > + * relies on this.<br>
> > + */<br>
> > + smu_wbrf_support_check(smu);<br>
> > +<br>
> > if (smu->is_apu) {<br>
> > ret = smu_set_gfx_imu_enable(smu);<br>
> > if (ret)<br>
> > @@ -1623,6 +1816,8 @@ static int smu_smc_hw_cleanup(struct<br>
> smu_context *smu)<br>
> > struct amdgpu_device *adev = smu->adev;<br>
> > int ret = 0;<br>
> ><br>
> > + smu_wbrf_fini(smu);<br>
> > +<br>
> > cancel_work_sync(&smu->throttling_logging_work);<br>
> > cancel_work_sync(&smu->interrupt_work);<br>
> ><br>
> > diff --git a/drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h<br>
> > b/drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h<br>
> > index 6e2069dcb6b9..3eb1c72a76f1 100644<br>
> > --- a/drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h<br>
> > +++ b/drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h<br>
> > @@ -22,6 +22,8 @@<br>
> > #ifndef __AMDGPU_SMU_H__<br>
> > #define __AMDGPU_SMU_H__<br>
> ><br>
> > +#include <linux/acpi_amd_wbrf.h><br>
> > +<br>
> > #include "amdgpu.h"<br>
> > #include "kgd_pp_interface.h"<br>
> > #include "dm_pp_interface.h"<br>
> > @@ -575,6 +577,10 @@ struct smu_context<br>
> > u32 debug_resp_reg;<br>
> ><br>
> > struct delayed_work swctf_delayed_work;<br>
> > +<br>
> > + /* data structures for wbrf feature support */<br>
> > + bool wbrf_supported;<br>
> > + struct notifier_block wbrf_notifier;<br>
> > };<br>
> ><br>
> > struct i2c_adapter;<br>
> > @@ -1356,6 +1362,23 @@ struct pptable_funcs {<br>
> > * @init_pptable_microcode: Prepare the pptable microcode to upload<br>
> via PSP<br>
> > */<br>
> > int (*init_pptable_microcode)(struct smu_context *smu);<br>
> > +<br>
> > + /**<br>
> > + * @is_asic_wbrf_supported: check whether PMFW supports the wbrf<br>
> feature<br>
> > + */<br>
> > + bool (*is_asic_wbrf_supported)(struct smu_context *smu);<br>
> > +<br>
> > + /**<br>
> > + * @enable_uclk_shadow: Enable the uclk shadow feature on wbrf<br>
> supported<br>
> > + */<br>
> > + int (*enable_uclk_shadow)(struct smu_context *smu,<br>
> > + bool enablement);<br>
> > +<br>
> > + /**<br>
> > + * @set_wbrf_exclusion_ranges: notify SMU the wifi bands occupied<br>
> > + */<br>
> > + int (*set_wbrf_exclusion_ranges)(struct smu_context *smu,<br>
> > + struct exclusion_range<br>
> *exclusion_ranges);<br>
> > };<br>
> ><br>
> > typedef enum {<br>
> > diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu_internal.h<br>
> > b/drivers/gpu/drm/amd/pm/swsmu/smu_internal.h<br>
> > index ceb13c838067..67d7495ab49e 100644<br>
> > --- a/drivers/gpu/drm/amd/pm/swsmu/smu_internal.h<br>
> > +++ b/drivers/gpu/drm/amd/pm/swsmu/smu_internal.h<br>
> > @@ -97,6 +97,9 @@<br>
> > #define smu_get_default_config_table_settings(smu, config_table)<br>
> smu_ppt_funcs(get_default_config_table_settings, -EOPNOTSUPP,<br>
> smu, config_table)<br>
> > #define smu_set_config_table(smu, config_table)<br>
> smu_ppt_funcs(set_config_table, -EOPNOTSUPP, smu, config_table)<br>
> > #define smu_init_pptable_microcode(smu)<br>
> smu_ppt_funcs(init_pptable_microcode, 0, smu)<br>
> > +#define smu_is_asic_wbrf_supported(smu)<br>
> smu_ppt_funcs(is_asic_wbrf_supported, false, smu)<br>
> > +#define smu_enable_uclk_shadow(smu, enablement)<br>
> smu_ppt_funcs(enable_uclk_shadow, 0, smu, enablement)<br>
> > +#define smu_set_wbrf_exclusion_ranges(smu, exclusion_ranges)<br>
> smu_ppt_funcs(set_wbrf_exclusion_ranges, -EOPNOTSUPP, smu,<br>
> exclusion_ranges)<br>
> ><br>
> > #endif<br>
> > #endif<br>
</span></font></div>
</span></font></div>
</div>
</body>
</html>