Skip to contentSkip to conversation

Enable Wifi RFI interference mitigation feature support

PATCH Superseded Evan Quan 5 participants 28 messages Jun 30, 2023 – Jul 6, 2023

Subsystems (9)

v5 of 11 Superseded Latest is v11 →

lore
Share & tools
lore

Evan Quan

author
#0 lore raw

v5 cover Enable Wifi RFI interference mitigation feature support

Due to electrical and mechanical constraints in certain platform designs there may be likely interference of relatively high-powered harmonics of the (G-)DDR memory clocks with local radio module frequency bands used by Wifi 6/6e/7. To mitigate possible RFI interference producers can advertise the frequencies in use and consumers can use this information to avoid using these frequencies for sensitive features.

The whole patch set is based on Linux 6.4. With some brief introductions as below:

Patch1 - 2:  Core functionality setup for WBRF feature support
Patch3 - 4:  Bring WBRF support to wifi subsystem.
Patch5 - 9:  Bring WBRF support to AMD graphics driver.

Evan Quan (9):
drivers core: Add support for Wifi band RF mitigations driver core: add ACPI based WBRF mechanism introduced by AMD
cfg80211: expose nl80211_chan_width_to_mhz for wide sharing
wifi: mac80211: Add support for ACPI WBRF
drm/amd/pm: update driver_if and ppsmc headers for coming wbrf feature drm/amd/pm: setup the framework to support Wifi RFI mitigation feature drm/amd/pm: add flood detection for wbrf events drm/amd/pm: enable Wifi RFI mitigation feature support for SMU13.0.0 drm/amd/pm: enable Wifi RFI mitigation feature support for SMU13.0.7

 drivers/acpi/Makefile                         |   2 +
 drivers/acpi/amd_wbrf.c                       | 236 +++++++++++++++++
 drivers/base/Kconfig                          |  37 +++
 drivers/base/Makefile                         |   1 +
 drivers/base/wbrf.c                           | 250 ++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu.h           |   1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |  19 ++
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     | 214 +++++++++++++++
 drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h |  33 +++
 .../inc/pmfw_if/smu13_driver_if_v13_0_0.h     |  14 +-
 .../inc/pmfw_if/smu13_driver_if_v13_0_7.h     |  14 +-
 .../pm/swsmu/inc/pmfw_if/smu_v13_0_0_ppsmc.h  |   3 +-
 .../pm/swsmu/inc/pmfw_if/smu_v13_0_7_ppsmc.h  |   3 +-
 drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h  |   3 +-
 drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h  |   3 +
 .../gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c    |   9 +
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c  |  60 +++++
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c  |  59 +++++
 drivers/gpu/drm/amd/pm/swsmu/smu_internal.h   |   3 +
 include/linux/acpi_amd_wbrf.h                 |  38 +++
 include/linux/ieee80211.h                     |   1 +
 include/linux/wbrf.h                          |  67 +++++
 include/net/cfg80211.h                        |   8 +
 net/mac80211/Makefile                         |   2 +
 net/mac80211/chan.c                           |   9 +
 net/mac80211/ieee80211_i.h                    |  19 ++
 net/mac80211/main.c                           |   2 +
 net/mac80211/wbrf.c                           | 103 ++++++++
 net/wireless/chan.c                           |   3 +-
 29 files changed, 1210 insertions(+), 6 deletions(-)
 create mode 100644 drivers/acpi/amd_wbrf.c
 create mode 100644 drivers/base/wbrf.c
 create mode 100644 include/linux/acpi_amd_wbrf.h
 create mode 100644 include/linux/wbrf.h
 create mode 100644 net/mac80211/wbrf.c
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v5 1/9 drivers core: Add support for Wifi band RF mitigations

Due to electrical and mechanical constraints in certain platform designs there may be likely interference of relatively high-powered harmonics of the (G-)DDR memory clocks with local radio module frequency bands used by Wifi 6/6e/7.

To mitigate this, AMD has introduced a mechanism that devices can use to notify active use of particular frequencies so that other devices can make relative internal adjustments as necessary to avoid this resonance.

In order for a device to support this, the expected flow for device driver or subsystems:

Drivers/subsystems contributing frequencies:

1) During probe, check wbrf_supported_producer to see if WBRF supported for the device.
2) If adding frequencies, then call wbrf_add_exclusion with the start and end ranges of the frequencies.
3) If removing frequencies, then call wbrf_remove_exclusion with start and end ranges of the frequencies.

Drivers/subsystems responding to frequencies:

1) During probe, check wbrf_supported_consumer to see if WBRF is supported for the device.
2) Call the wbrf_retrieve_exclusions to retrieve the current exclusions on receiving an ACPI notification for a new frequency change.

--
v4->v5:
- promote this to be a more generic solution with input argument taking struct device and provide better scalability to support non-ACPI scenarios(Andrew)
- update the APIs naming and some other minor fixes(Rafael)

---
 drivers/base/Kconfig  |   8 ++
 drivers/base/Makefile |   1 +
 drivers/base/wbrf.c   | 227 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/wbrf.h  |  65 ++++++++++++
 4 files changed, 301 insertions(+)
 create mode 100644 drivers/base/wbrf.c
 create mode 100644 include/linux/wbrf.h
drivers/base/Kconfig +8 -0
index 2b8fd6bb7da0..5b441017b225 100644
@@ -242,4 +242,12 @@ config FW_DEVLINK_SYNC_STATE_TIMEOUT
 	  command line option on every system/board your kernel is expected to
 	  work on.
 
+config WBRF
+	bool "Wifi band RF mitigation mechanism"
+	default n
+	help
+	  Wifi band RF mitigation mechanism allows multiple drivers from
+	  different domains to notify the frequencies in use so that hardware
+	  can be reconfigured to avoid harmonic conflicts.
+
 endmenu
drivers/base/Makefile +1 -0
index 3079bfe53d04..c844f68a6830 100644
@@ -26,6 +26,7 @@ obj-$(CONFIG_GENERIC_MSI_IRQ) += platform-msi.o
 obj-$(CONFIG_GENERIC_ARCH_TOPOLOGY) += arch_topology.o
 obj-$(CONFIG_GENERIC_ARCH_NUMA) += arch_numa.o
 obj-$(CONFIG_ACPI) += physical_location.o
+obj-$(CONFIG_WBRF) += wbrf.o
 
 obj-y			+= test/
 
drivers/base/wbrf.c new file +227 -0

227 lines not on this page · raw message

include/linux/wbrf.h new file +65 -0

65 lines not on this page · raw message

Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH V5 1/9] drivers core: Add support for Wifi band RF mitigations

On Fri, Jun 30, 2023 at 06:32:32PM +0800, Evan Quan wrote:

...

Quoted 34 lines
include/linux/wbrf.h new file +28 -0
new file mode 100644
index 000000000000..3ca95786cef5
@@ -0,0 +1,65 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Wifi Band Exclusion Interface
+ * Copyright (C) 2023 Advanced Micro Devices
+ */
+
+#ifndef _LINUX_WBRF_H
+#define _LINUX_WBRF_H
+
+#include <linux/device.h>
+
+/* Maximum number of wbrf ranges */
+#define MAX_NUM_OF_WBRF_RANGES		11
+
+struct exclusion_range {
+	/* start and end point of the frequency range in Hz */
+	uint64_t	start;
+	uint64_t	end;
+};
+
+struct exclusion_range_pool {
+	struct exclusion_range	band_list[MAX_NUM_OF_WBRF_RANGES];
+	uint64_t		ref_counter[MAX_NUM_OF_WBRF_RANGES];
+};
+
+struct wbrf_ranges_in {
+	/* valid entry: `start` and `end` filled with non-zero values */
+	struct exclusion_range	band_list[MAX_NUM_OF_WBRF_RANGES];

include/linux/wbrf.h line 38

Quoted 10 lines
include/linux/wbrf.h new file +10 -0
+};
+
+struct wbrf_ranges_out {
+	uint32_t		num_of_ranges;
+	struct exclusion_range	band_list[MAX_NUM_OF_WBRF_RANGES];
+} __packed;
+
+enum wbrf_notifier_actions {
+	WBRF_CHANGED,
+};

Hi Evan,

checkpatch suggests that u64 and u32 might be more appropriate types here, as they are Kernel types, whereas the ones use are user-space types.

...

author
#3 lore raw

RE: [PATCH V5 1/9] drivers core: Add support for Wifi band RF mitigations

[AMD Official Use Only - General]

Quoted 73 lines

-----Original Message-----
From: Simon Horman <[email protected]>
Sent: Friday, June 30, 2023 9:39 PM
To: Quan, Evan <[email protected]>
Cc: [email protected]; [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Limonciello, Mario <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Lazar, Lijo <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; dri- [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH V5 1/9] drivers core: Add support for Wifi band RF mitigations

On Fri, Jun 30, 2023 at 06:32:32PM +0800, Evan Quan wrote:

...

Quoted 19 lines
include/linux/wbrf.h new file +13 -0
new file mode 100644
index 000000000000..3ca95786cef5
@@ -0,0 +1,65 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Wifi Band Exclusion Interface
+ * Copyright (C) 2023 Advanced Micro Devices
+ */
+
+#ifndef _LINUX_WBRF_H
+#define _LINUX_WBRF_H
+
+#include <linux/device.h>
+
+/* Maximum number of wbrf ranges */
+#define MAX_NUM_OF_WBRF_RANGES             11

include/linux/wbrf.h line 23

Quoted 10 lines
include/linux/wbrf.h new file +10 -0
+
+struct exclusion_range {
+   /* start and end point of the frequency range in Hz */
+   uint64_t        start;
+   uint64_t        end;
+};
+
+struct exclusion_range_pool {
+   struct exclusion_range  band_list[MAX_NUM_OF_WBRF_RANGES];
+   uint64_t
      ref_counter[MAX_NUM_OF_WBRF_RANGES];
Quoted 5 lines
include/linux/wbrf.h new file +5 -0
+};
+
+struct wbrf_ranges_in {
+   /* valid entry: `start` and `end` filled with non-zero values */
+   struct exclusion_range  band_list[MAX_NUM_OF_WBRF_RANGES];

include/linux/wbrf.h line 38

Quoted 10 lines
include/linux/wbrf.h new file +10 -0
+};
+
+struct wbrf_ranges_out {
+   uint32_t                num_of_ranges;
+   struct exclusion_range  band_list[MAX_NUM_OF_WBRF_RANGES];
+} __packed;
+
+enum wbrf_notifier_actions {
+   WBRF_CHANGED,
+};

Hi Evan,

Quoted 2 lines

checkpatch suggests that u64 and u32 might be more appropriate types here, as they are Kernel types, whereas the ones use are user-space types.

Thanks for pointing this out. Will update them accordingly.

Evan

Quoted 2 lines

...

#4 lore raw

Re: [PATCH V5 1/9] drivers core: Add support for Wifi band RF mitigations

In reply to Evan Quan
Quoted 370 lines · Evan Quan

Due to electrical and mechanical constraints in certain platform designs there may be likely interference of relatively high-powered harmonics of the (G-)DDR memory clocks with local radio module frequency bands used by Wifi 6/6e/7.

To mitigate this, AMD has introduced a mechanism that devices can use to notify active use of particular frequencies so that other devices can make relative internal adjustments as necessary to avoid this resonance.

In order for a device to support this, the expected flow for device driver or subsystems:

Drivers/subsystems contributing frequencies:

1) During probe, check wbrf_supported_producer to see if WBRF supported for the device.
2) If adding frequencies, then call wbrf_add_exclusion with the start and end ranges of the frequencies.
3) If removing frequencies, then call wbrf_remove_exclusion with start and end ranges of the frequencies.

Drivers/subsystems responding to frequencies:

1) During probe, check wbrf_supported_consumer to see if WBRF is supported for the device.
2) Call the wbrf_retrieve_exclusions to retrieve the current exclusions on receiving an ACPI notification for a new frequency change.

--
v4->v5:
- promote this to be a more generic solution with input argument taking struct device and provide better scalability to support non-ACPI scenarios(Andrew)
- update the APIs naming and some other minor fixes(Rafael)

---
  drivers/base/Kconfig  |   8 ++
  drivers/base/Makefile |   1 +
  drivers/base/wbrf.c   | 227 ++++++++++++++++++++++++++++++++++++++++++
  include/linux/wbrf.h  |  65 ++++++++++++
  4 files changed, 301 insertions(+)

create mode 100644 drivers/base/wbrf.c
create mode 100644 include/linux/wbrf.h

drivers/base/Kconfig +8 -0
index 2b8fd6bb7da0..5b441017b225 100644
@@ -242,4 +242,12 @@ config FW_DEVLINK_SYNC_STATE_TIMEOUT
  	  command line option on every system/board your kernel is expected to
  	  work on.
 
+config WBRF
+	bool "Wifi band RF mitigation mechanism"
+	default n
+	help
+	  Wifi band RF mitigation mechanism allows multiple drivers from
+	  different domains to notify the frequencies in use so that hardware
+	  can be reconfigured to avoid harmonic conflicts.
+
  endmenu
drivers/base/Makefile +1 -0
index 3079bfe53d04..c844f68a6830 100644
@@ -26,6 +26,7 @@ obj-$(CONFIG_GENERIC_MSI_IRQ) += platform-msi.o
  obj-$(CONFIG_GENERIC_ARCH_TOPOLOGY) += arch_topology.o
  obj-$(CONFIG_GENERIC_ARCH_NUMA) += arch_numa.o
  obj-$(CONFIG_ACPI) += physical_location.o
+obj-$(CONFIG_WBRF) += wbrf.o
 
  obj-y			+= test/
 
drivers/base/wbrf.c new file +227 -0
new file mode 100644
index 000000000000..2163a8ec8a9a
@@ -0,0 +1,227 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Wifi Band Exclusion Interface
+ * Copyright (C) 2023 Advanced Micro Devices
+ *
+ */
+
+#include <linux/wbrf.h>
+
+static BLOCKING_NOTIFIER_HEAD(wbrf_chain_head);
+static DEFINE_MUTEX(wbrf_mutex);
+static struct exclusion_range_pool wbrf_pool;
+
+static int _wbrf_add_exclusion_ranges(struct wbrf_ranges_in *in)
+{
+	int i, j;
+
+	for (i = 0; i < ARRAY_SIZE(in->band_list); i++) {
+		if (!in->band_list[i].start &&
+		    !in->band_list[i].end)
+			continue;
+
+		for (j = 0; j < ARRAY_SIZE(wbrf_pool.band_list); j++) {
+			if (wbrf_pool.band_list[j].start == in->band_list[i].start &&
+			    wbrf_pool.band_list[j].end == in->band_list[i].end) {
+				wbrf_pool.ref_counter[j]++;
+				break;
+			}
+		}
+		if (j < ARRAY_SIZE(wbrf_pool.band_list))
+			continue;
+
+		for (j = 0; j < ARRAY_SIZE(wbrf_pool.band_list); j++) {
+			if (!wbrf_pool.band_list[j].start &&
+			    !wbrf_pool.band_list[j].end) {
+				wbrf_pool.band_list[j].start = in->band_list[i].start;
+				wbrf_pool.band_list[j].end = in->band_list[i].end;
+				wbrf_pool.ref_counter[j] = 1;
+				break;
+			}
+		}
+		if (j >= ARRAY_SIZE(wbrf_pool.band_list))
+			return -ENOSPC;
+	}
+
+	return 0;
+}
+
+static int _wbrf_remove_exclusion_ranges(struct wbrf_ranges_in *in)
+{
+	int i, j;
+
+	for (i = 0; i < ARRAY_SIZE(in->band_list); i++) {
+		if (!in->band_list[i].start &&
+		    !in->band_list[i].end)
+			continue;
+
+		for (j = 0; j < ARRAY_SIZE(wbrf_pool.band_list); j++) {
+			if (wbrf_pool.band_list[j].start == in->band_list[i].start &&
+			    wbrf_pool.band_list[j].end == in->band_list[i].end) {
+				wbrf_pool.ref_counter[j]--;
+				if (!wbrf_pool.ref_counter[j]) {
+					wbrf_pool.band_list[j].start = 0;
+					wbrf_pool.band_list[j].end = 0;
+				}
+				break;
+			}
+		}
+	}
+
+	return 0;
+}
+
+static int _wbrf_retrieve_exclusion_ranges(struct wbrf_ranges_out *out)
+{
+	int out_idx = 0;
+	int i;
+
+	memset(out, 0, sizeof(*out));
+
+	for (i = 0; i < ARRAY_SIZE(wbrf_pool.band_list); i++) {
+		if (!wbrf_pool.band_list[i].start &&
+		    !wbrf_pool.band_list[i].end)
+			continue;
+
+		out->band_list[out_idx].start = wbrf_pool.band_list[i].start;
+		out->band_list[out_idx++].end = wbrf_pool.band_list[i].end;
+	}
+
+	return 0;
+}
+
+/**
+ * wbrf_supported_producer - Determine if the device can report frequencies
+ *
+ * @dev: device pointer
+ *
+ * WBRF is used to mitigate devices that cause harmonic interference.
+ * This function will determine if this device needs to report such frequencies.
+ */
+bool wbrf_supported_producer(struct device *dev)
+{
+	return true;
+}
+EXPORT_SYMBOL_GPL(wbrf_supported_producer);
+
+/**
+ * wbrf_add_exclusion - Add frequency ranges to the exclusion list
+ *
+ * @dev: device pointer
+ * @in: input structure containing the frequency ranges to be added
+ *
+ * Add frequencies into the exclusion list for supported consumers
+ * to react to.
+ */
+int wbrf_add_exclusion(struct device *dev,
+		       struct wbrf_ranges_in *in)
+{
+	int r;
+
+	mutex_lock(&wbrf_mutex);
+
+	r = _wbrf_add_exclusion_ranges(in);
+
+	mutex_unlock(&wbrf_mutex);
+	if (r)
+		return r;
+
+	blocking_notifier_call_chain(&wbrf_chain_head, WBRF_CHANGED, NULL);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(wbrf_add_exclusion);
+
+/**
+ * wbrf_remove_exclusion - Remove frequency ranges from the exclusion list
+ *
+ * @dev: device pointer
+ * @in: input structure containing the frequency ranges to be removed
+ *
+ * Remove frequencies from the exclusion list for supported consumers
+ * to react to.
+ */
+int wbrf_remove_exclusion(struct device *dev,
+			  struct wbrf_ranges_in *in)
+{
+	int r;
+
+	mutex_lock(&wbrf_mutex);
+
+	r = _wbrf_remove_exclusion_ranges(in);
+
+	mutex_unlock(&wbrf_mutex);
+	if (r)
+		return r;
+
+	blocking_notifier_call_chain(&wbrf_chain_head, WBRF_CHANGED, NULL);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(wbrf_remove_exclusion);
+
+/**
+ * wbrf_supported_consumer - Determine if the device can react to frequencies
+ *
+ * @dev: device pointer
+ *
+ * WBRF is used to mitigate devices that cause harmonic interference.
+ * This function will determine if this device needs to react to reports from
+ * other devices for such frequencies.
+ */
+bool wbrf_supported_consumer(struct device *dev)
+{
+	return true;
+}
+EXPORT_SYMBOL_GPL(wbrf_supported_consumer);
+
+/**
+ * wbrf_register_notifier - Register for notifications of frequency changes
+ *
+ * @nb: driver notifier block
+ *
+ * WBRF is used to mitigate devices that cause harmonic interference.
+ * This function will allow consumers to register for frequency notifications.
+ */
+int wbrf_register_notifier(struct notifier_block *nb)
+{
+	return blocking_notifier_chain_register(&wbrf_chain_head, nb);
+}
+EXPORT_SYMBOL_GPL(wbrf_register_notifier);
+
+/**
+ * wbrf_unregister_notifier - Unregister for notifications of frequency changes
+ *
+ * @nb: driver notifier block
+ *
+ * WBRF is used to mitigate devices that cause harmonic interference.
+ * This function will allow consumers to unregister for frequency notifications.
+ */
+int wbrf_unregister_notifier(struct notifier_block *nb)
+{
+	return blocking_notifier_chain_unregister(&wbrf_chain_head, nb);
+}
+EXPORT_SYMBOL_GPL(wbrf_unregister_notifier);
+
+/**
+ * wbrf_retrieve_exclusions - Retrieve the exclusion list
+ *
+ * @dev: device pointer
+ * @out: output structure containing the frequency ranges to be excluded
+ *
+ * Retrieve the current exclusion list
+ */
+int wbrf_retrieve_exclusions(struct device *dev,
+			     struct wbrf_ranges_out *out)
+{
+	int r;
+
+	mutex_lock(&wbrf_mutex);
+
+	r = _wbrf_retrieve_exclusion_ranges(out);
+
+	mutex_unlock(&wbrf_mutex);
+
+	return r;
+}
+EXPORT_SYMBOL_GPL(wbrf_retrieve_exclusions);
include/linux/wbrf.h new file +54 -0
new file mode 100644
index 000000000000..3ca95786cef5
@@ -0,0 +1,65 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Wifi Band Exclusion Interface
+ * Copyright (C) 2023 Advanced Micro Devices
+ */
+
+#ifndef _LINUX_WBRF_H
+#define _LINUX_WBRF_H
+
+#include <linux/device.h>
+
+/* Maximum number of wbrf ranges */
+#define MAX_NUM_OF_WBRF_RANGES		11
+
+struct exclusion_range {
+	/* start and end point of the frequency range in Hz */
+	uint64_t	start;
+	uint64_t	end;
+};
+
+struct exclusion_range_pool {
+	struct exclusion_range	band_list[MAX_NUM_OF_WBRF_RANGES];
+	uint64_t		ref_counter[MAX_NUM_OF_WBRF_RANGES];
+};
+
+struct wbrf_ranges_in {
+	/* valid entry: `start` and `end` filled with non-zero values */
+	struct exclusion_range	band_list[MAX_NUM_OF_WBRF_RANGES];
+};
+
+struct wbrf_ranges_out {
+	uint32_t		num_of_ranges;
+	struct exclusion_range	band_list[MAX_NUM_OF_WBRF_RANGES];
+} __packed;
+
+enum wbrf_notifier_actions {
+	WBRF_CHANGED,
+};
+
+#ifdef CONFIG_WBRF
+bool wbrf_supported_producer(struct device *dev);
+int wbrf_add_exclusion(struct device *adev,
+		       struct wbrf_ranges_in *in);
+int wbrf_remove_exclusion(struct device *dev,
+			  struct wbrf_ranges_in *in);
+int wbrf_retrieve_exclusions(struct device *dev,
+			     struct wbrf_ranges_out *out);
+bool wbrf_supported_consumer(struct device *dev);
+
+int wbrf_register_notifier(struct notifier_block *nb);
+int wbrf_unregister_notifier(struct notifier_block *nb);
+#else
+static inline bool wbrf_supported_producer(struct device *dev) { return false; }
+static inline int wbrf_add_exclusion(struct device *adev,

include/linux/wbrf.h line 64

Quoted 10 lines
include/linux/wbrf.h new file +10 -0
+				     struct wbrf_ranges_in *in) { return -ENODEV; }
+static inline int wbrf_remove_exclusion(struct device *dev,
+					struct wbrf_ranges_in *in) { return -ENODEV; }
+static inline int wbrf_retrieve_exclusions(struct device *dev,
+					   struct wbrf_ranges_out *out) { return -ENODEV; }
+static inline bool wbrf_supported_consumer(struct device *dev) { return false; }
+static inline int wbrf_register_notifier(struct notifier_block *nb) { return -ENODEV; }
+static inline int wbrf_unregister_notifier(struct notifier_block *nb) { return -ENODEV; }
+#endif
+

Right now there are stubs for non CONFIG_WBRF as well as other patches are using #ifdef CONFIG_WBRF or having their own stubs. Like mac80211 patch looks for #ifdef CONFIG_WBRF.

I think we should pick one or the other.

Having other subsystems #ifdef CONFIG_WBRF will make the series easier to land through multiple trees; so I have a slight leaning in that direction.

Quoted 1 line
include/linux/wbrf.h new file +1 -0
+#endif /* _LINUX_WBRF_H */
#5 lore raw

Re: [PATCH V5 1/9] drivers core: Add support for Wifi band RF mitigations

Quoted 8 lines

Right now there are stubs for non CONFIG_WBRF as well as other patches are using #ifdef CONFIG_WBRF or having their own stubs. Like mac80211 patch looks for #ifdef CONFIG_WBRF.

I think we should pick one or the other.

Having other subsystems #ifdef CONFIG_WBRF will make the series easier to land through multiple trees; so I have a slight leaning in that direction.

#ifdef in C files is generally not liked because it makes build testing harder. There are more permutations to build. It is better to use

if (IS_ENABLED(CONFIG_WBTR)) {
}

so that the code is compiled, and them throw away because IS_ENABLED(CONFIG_WBTR) evaluates to false.

However, if the stubs are done correctly, the driver should not care. I doubt this is used in any sort of hot path where every instruction counts.

Andrew

author
#6 lore raw

RE: [PATCH V5 1/9] drivers core: Add support for Wifi band RF mitigations

[AMD Official Use Only - General]

Quoted 32 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Saturday, July 1, 2023 8:25 AM
To: Limonciello, Mario <[email protected]>
Cc: Quan, Evan <[email protected]>; [email protected]; [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Lazar, Lijo <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; amd- [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH V5 1/9] drivers core: Add support for Wifi band RF mitigations

Quoted 8 lines

Right now there are stubs for non CONFIG_WBRF as well as other patches are using #ifdef CONFIG_WBRF or having their own stubs. Like mac80211 patch looks for #ifdef CONFIG_WBRF.

I think we should pick one or the other.

Having other subsystems #ifdef CONFIG_WBRF will make the series easier to land through multiple trees; so I have a slight leaning in that direction.

#ifdef in C files is generally not liked because it makes build testing harder. There are more permutations to build. It is better to use

Quoted 8 lines

if (IS_ENABLED(CONFIG_WBTR)) {
}

so that the code is compiled, and them throw away because IS_ENABLED(CONFIG_WBTR) evaluates to false.

However, if the stubs are done correctly, the driver should not care. I doubt this is used in any sort of hot path where every instruction counts.

OK, will update as suggested.

Evan

Quoted 2 lines

Andrew

author
#7 lore raw

RE: [PATCH V5 1/9] drivers core: Add support for Wifi band RF mitigations

In reply to Limonciello, Mario

[AMD Official Use Only - General]

Quoted 416 lines

-----Original Message-----
From: Limonciello, Mario <[email protected]>
Sent: Saturday, July 1, 2023 12:41 AM
To: Quan, Evan <[email protected]>; [email protected]; [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Lazar, Lijo <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; amd- [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH V5 1/9] drivers core: Add support for Wifi band RF mitigations

Quoted 9 lines · Evan Quan

Due to electrical and mechanical constraints in certain platform designs there may be likely interference of relatively high-powered harmonics of the (G-)DDR memory clocks with local radio module frequency bands used by Wifi 6/6e/7.

To mitigate this, AMD has introduced a mechanism that devices can use to notify active use of particular frequencies so that other devices can make relative internal adjustments as necessary to avoid this resonance.

Quoted 6 lines

In order for a device to support this, the expected flow for device driver or subsystems:

Drivers/subsystems contributing frequencies:

1) During probe, check wbrf_supported_producer to see if WBRF

supported

Quoted 9 lines

for the device.
2) If adding frequencies, then call wbrf_add_exclusion with the start and end ranges of the frequencies.
3) If removing frequencies, then call wbrf_remove_exclusion with start and end ranges of the frequencies.

Drivers/subsystems responding to frequencies:

1) During probe, check wbrf_supported_consumer to see if WBRF is

supported

Quoted 15 lines

for the device.
2) Call the wbrf_retrieve_exclusions to retrieve the current exclusions on receiving an ACPI notification for a new frequency change.

--
v4->v5:
- promote this to be a more generic solution with input argument taking struct device and provide better scalability to support non-ACPI scenarios(Andrew)
- update the APIs naming and some other minor fixes(Rafael)

Quoted 4 lines
---
  drivers/base/Kconfig  |   8 ++
  drivers/base/Makefile |   1 +
  drivers/base/wbrf.c   | 227

++++++++++++++++++++++++++++++++++++++++++

drivers/base/Kconfig config FW_DEVLINK_SYNC_STATE_TIMEOUT · line 242

Quoted 11 lines
  include/linux/wbrf.h  |  65 ++++++++++++
  4 files changed, 301 insertions(+)

create mode 100644 drivers/base/wbrf.c
create mode 100644 include/linux/wbrf.h

drivers/base/Kconfig index renamed from drivers/base/Kconfig +0 -0

2b8fd6bb7da0..5b441017b225 100644

drivers/base/Kconfig +0 -0
@@ -242,4 +242,12 @@ config FW_DEVLINK_SYNC_STATE_TIMEOUT
      command line option on every system/board your kernel is expected

to

Quoted 120 lines
drivers/base/Kconfig +8 -0
      work on.
 
+config WBRF
+   bool "Wifi band RF mitigation mechanism"
+   default n
+   help
+     Wifi band RF mitigation mechanism allows multiple drivers from
+     different domains to notify the frequencies in use so that hardware
+     can be reconfigured to avoid harmonic conflicts.
+
  endmenu
drivers/base/Makefile index renamed from drivers/base/Makefile +0 -0

3079bfe53d04..c844f68a6830 100644

drivers/base/Makefile +1 -0
@@ -26,6 +26,7 @@ obj-$(CONFIG_GENERIC_MSI_IRQ) += platform-msi.o
  obj-$(CONFIG_GENERIC_ARCH_TOPOLOGY) += arch_topology.o
  obj-$(CONFIG_GENERIC_ARCH_NUMA) += arch_numa.o
  obj-$(CONFIG_ACPI) += physical_location.o
+obj-$(CONFIG_WBRF) += wbrf.o
 
  obj-y                     += test/
 
drivers/base/wbrf.c new file mode renamed from drivers/base/wbrf.c +0 -0

100644 index 000000000000..2163a8ec8a9a

drivers/base/wbrf.c new file +23 -0
@@ -0,0 +1,227 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Wifi Band Exclusion Interface
+ * Copyright (C) 2023 Advanced Micro Devices
+ *
+ */
+
+#include <linux/wbrf.h>
+
+static BLOCKING_NOTIFIER_HEAD(wbrf_chain_head);
+static DEFINE_MUTEX(wbrf_mutex);
+static struct exclusion_range_pool wbrf_pool;
+
+static int _wbrf_add_exclusion_ranges(struct wbrf_ranges_in *in) {
+   int i, j;
+
+   for (i = 0; i < ARRAY_SIZE(in->band_list); i++) {
+           if (!in->band_list[i].start &&
+               !in->band_list[i].end)
+                   continue;
+
+           for (j = 0; j < ARRAY_SIZE(wbrf_pool.band_list); j++) {
+                   if (wbrf_pool.band_list[j].start == in-

band_list[i].start &&

drivers/base/wbrf.c new file +12 -0
+                       wbrf_pool.band_list[j].end == in->band_list[i].end) {
+                           wbrf_pool.ref_counter[j]++;
+                           break;
+                   }
+           }
+           if (j < ARRAY_SIZE(wbrf_pool.band_list))
+                   continue;
+
+           for (j = 0; j < ARRAY_SIZE(wbrf_pool.band_list); j++) {
+                   if (!wbrf_pool.band_list[j].start &&
+                       !wbrf_pool.band_list[j].end) {
+                           wbrf_pool.band_list[j].start = in-

band_list[i].start;
+ wbrf_pool.band_list[j].end = in-
band_list[i].end;

drivers/base/wbrf.c new file +21 -0
+                           wbrf_pool.ref_counter[j] = 1;
+                           break;
+                   }
+           }
+           if (j >= ARRAY_SIZE(wbrf_pool.band_list))
+                   return -ENOSPC;
+   }
+
+   return 0;
+}
+
+static int _wbrf_remove_exclusion_ranges(struct wbrf_ranges_in *in) {
+   int i, j;
+
+   for (i = 0; i < ARRAY_SIZE(in->band_list); i++) {
+           if (!in->band_list[i].start &&
+               !in->band_list[i].end)
+                   continue;
+
+           for (j = 0; j < ARRAY_SIZE(wbrf_pool.band_list); j++) {
+                   if (wbrf_pool.band_list[j].start == in-

band_list[i].start &&

drivers/base/wbrf.c new file +31 -0
+                       wbrf_pool.band_list[j].end == in->band_list[i].end) {
+                           wbrf_pool.ref_counter[j]--;
+                           if (!wbrf_pool.ref_counter[j]) {
+                                   wbrf_pool.band_list[j].start = 0;
+                                   wbrf_pool.band_list[j].end = 0;
+                           }
+                           break;
+                   }
+           }
+   }
+
+   return 0;
+}
+
+static int _wbrf_retrieve_exclusion_ranges(struct wbrf_ranges_out
+*out) {
+   int out_idx = 0;
+   int i;
+
+   memset(out, 0, sizeof(*out));
+
+   for (i = 0; i < ARRAY_SIZE(wbrf_pool.band_list); i++) {
+           if (!wbrf_pool.band_list[i].start &&
+               !wbrf_pool.band_list[i].end)
+                   continue;
+
+           out->band_list[out_idx].start = wbrf_pool.band_list[i].start;
+           out->band_list[out_idx++].end = wbrf_pool.band_list[i].end;
+   }
+
+   return 0;

drivers/base/wbrf.c

Quoted 10 lines
drivers/base/wbrf.c new file +10 -0
+}
+
+/**
+ * wbrf_supported_producer - Determine if the device can report
+frequencies
+ *
+ * @dev: device pointer
+ *
+ * WBRF is used to mitigate devices that cause harmonic interference.
+ * This function will determine if this device needs to report such

frequencies.

Quoted 19 lines

+ */

drivers/base/wbrf.c new file +18 -0
+bool wbrf_supported_producer(struct device *dev) {
+   return true;
+}
+EXPORT_SYMBOL_GPL(wbrf_supported_producer);
+
+/**
+ * wbrf_add_exclusion - Add frequency ranges to the exclusion list
+ *
+ * @dev: device pointer
+ * @in: input structure containing the frequency ranges to be added
+ *
+ * Add frequencies into the exclusion list for supported consumers
+ * to react to.
+ */
+int wbrf_add_exclusion(struct device *dev,
+                  struct wbrf_ranges_in *in)
+{
+   int r;

drivers/base/wbrf.c

Quoted 10 lines
drivers/base/wbrf.c new file +10 -0
+
+   mutex_lock(&wbrf_mutex);
+
+   r = _wbrf_add_exclusion_ranges(in);
+
+   mutex_unlock(&wbrf_mutex);
+   if (r)
+           return r;
+
+   blocking_notifier_call_chain(&wbrf_chain_head, WBRF_CHANGED,

NULL);

Quoted 19 lines
drivers/base/wbrf.c new file +19 -0
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(wbrf_add_exclusion);
+
+/**
+ * wbrf_remove_exclusion - Remove frequency ranges from the exclusion
+list
+ *
+ * @dev: device pointer
+ * @in: input structure containing the frequency ranges to be removed
+ *
+ * Remove frequencies from the exclusion list for supported consumers
+ * to react to.
+ */
+int wbrf_remove_exclusion(struct device *dev,
+                     struct wbrf_ranges_in *in)
+{
+   int r;

drivers/base/wbrf.c

Quoted 10 lines
drivers/base/wbrf.c new file +10 -0
+
+   mutex_lock(&wbrf_mutex);
+
+   r = _wbrf_remove_exclusion_ranges(in);
+
+   mutex_unlock(&wbrf_mutex);
+   if (r)
+           return r;
+
+   blocking_notifier_call_chain(&wbrf_chain_head, WBRF_CHANGED,

NULL);

Quoted 32 lines
drivers/base/wbrf.c new file +32 -0
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(wbrf_remove_exclusion);
+
+/**
+ * wbrf_supported_consumer - Determine if the device can react to
+frequencies
+ *
+ * @dev: device pointer
+ *
+ * WBRF is used to mitigate devices that cause harmonic interference.
+ * This function will determine if this device needs to react to
+reports from
+ * other devices for such frequencies.
+ */
+bool wbrf_supported_consumer(struct device *dev) {
+   return true;
+}
+EXPORT_SYMBOL_GPL(wbrf_supported_consumer);
+
+/**
+ * wbrf_register_notifier - Register for notifications of frequency
+changes
+ *
+ * @nb: driver notifier block
+ *
+ * WBRF is used to mitigate devices that cause harmonic interference.
+ * This function will allow consumers to register for frequency notifications.
+ */
+int wbrf_register_notifier(struct notifier_block *nb) {
+   return blocking_notifier_chain_register(&wbrf_chain_head, nb); }

drivers/base/wbrf.c

Quoted 10 lines
drivers/base/wbrf.c new file +10 -0
+EXPORT_SYMBOL_GPL(wbrf_register_notifier);
+
+/**
+ * wbrf_unregister_notifier - Unregister for notifications of
+frequency changes
+ *
+ * @nb: driver notifier block
+ *
+ * WBRF is used to mitigate devices that cause harmonic interference.
+ * This function will allow consumers to unregister for frequency

notifications.

Quoted 44 lines

+ */

drivers/base/wbrf.c new file +26 -0
+int wbrf_unregister_notifier(struct notifier_block *nb) {
+   return blocking_notifier_chain_unregister(&wbrf_chain_head, nb); }
+EXPORT_SYMBOL_GPL(wbrf_unregister_notifier);
+
+/**
+ * wbrf_retrieve_exclusions - Retrieve the exclusion list
+ *
+ * @dev: device pointer
+ * @out: output structure containing the frequency ranges to be
+excluded
+ *
+ * Retrieve the current exclusion list  */ int
+wbrf_retrieve_exclusions(struct device *dev,
+                        struct wbrf_ranges_out *out)
+{
+   int r;
+
+   mutex_lock(&wbrf_mutex);
+
+   r = _wbrf_retrieve_exclusion_ranges(out);
+
+   mutex_unlock(&wbrf_mutex);
+
+   return r;
+}
+EXPORT_SYMBOL_GPL(wbrf_retrieve_exclusions);
include/linux/wbrf.h new file mode renamed from include/linux/wbrf.h +0 -0

100644 index 000000000000..3ca95786cef5

include/linux/wbrf.h new file +12 -0
@@ -0,0 +1,65 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Wifi Band Exclusion Interface
+ * Copyright (C) 2023 Advanced Micro Devices  */
+
+#ifndef _LINUX_WBRF_H
+#define _LINUX_WBRF_H
+
+#include <linux/device.h>
+
+/* Maximum number of wbrf ranges */
+#define MAX_NUM_OF_WBRF_RANGES             11

include/linux/wbrf.h line 22

Quoted 10 lines
include/linux/wbrf.h new file +10 -0
+
+struct exclusion_range {
+   /* start and end point of the frequency range in Hz */
+   uint64_t        start;
+   uint64_t        end;
+};
+
+struct exclusion_range_pool {
+   struct exclusion_range  band_list[MAX_NUM_OF_WBRF_RANGES];
+   uint64_t
      ref_counter[MAX_NUM_OF_WBRF_RANGES];
Quoted 21 lines
include/linux/wbrf.h new file +21 -0
+};
+
+struct wbrf_ranges_in {
+   /* valid entry: `start` and `end` filled with non-zero values */
+   struct exclusion_range  band_list[MAX_NUM_OF_WBRF_RANGES];
+};
+
+struct wbrf_ranges_out {
+   uint32_t                num_of_ranges;
+   struct exclusion_range  band_list[MAX_NUM_OF_WBRF_RANGES];
+} __packed;
+
+enum wbrf_notifier_actions {
+   WBRF_CHANGED,
+};
+
+#ifdef CONFIG_WBRF
+bool wbrf_supported_producer(struct device *dev); int
+wbrf_add_exclusion(struct device *adev,
+                  struct wbrf_ranges_in *in);
+int wbrf_remove_exclusion(struct device *dev,

include/linux/wbrf.h

Quoted 10 lines
include/linux/wbrf.h new file +10 -0
+                     struct wbrf_ranges_in *in);
+int wbrf_retrieve_exclusions(struct device *dev,
+                        struct wbrf_ranges_out *out); bool
+wbrf_supported_consumer(struct device *dev);
+
+int wbrf_register_notifier(struct notifier_block *nb); int
+wbrf_unregister_notifier(struct notifier_block *nb); #else static
+inline bool wbrf_supported_producer(struct device *dev) { return
+false; } static inline int wbrf_add_exclusion(struct device *adev,
+                                struct wbrf_ranges_in *in) { return -

ENODEV; } static inline

include/linux/wbrf.h line 55

Quoted 2 lines
include/linux/wbrf.h new file +2 -0
+int wbrf_remove_exclusion(struct device *dev,
+                                   struct wbrf_ranges_in *in) { return -

ENODEV; } static inline int

include/linux/wbrf.h line 57

Quoted 2 lines
include/linux/wbrf.h new file +2 -0
+wbrf_retrieve_exclusions(struct device *dev,
+                                      struct wbrf_ranges_out *out)

{ return -ENODEV; } static

include/linux/wbrf.h line 63

Quoted 6 lines
include/linux/wbrf.h new file +6 -0
+inline bool wbrf_supported_consumer(struct device *dev) { return
+false; } static inline int wbrf_register_notifier(struct
+notifier_block *nb) { return -ENODEV; } static inline int
+wbrf_unregister_notifier(struct notifier_block *nb) { return -ENODEV;
+} #endif
+

Right now there are stubs for non CONFIG_WBRF as well as other patches are using #ifdef CONFIG_WBRF or having their own stubs. Like mac80211 patch looks for #ifdef CONFIG_WBRF.

Quoted 1 line

I think we should pick one or the other.

Right..

Quoted 3 lines

Having other subsystems #ifdef CONFIG_WBRF will make the series easier to land through multiple trees; so I have a slight leaning in that direction.

I kind of expecting to use the other way. That is to make CONFIG_WBRF agnostic to other subsystems or drivers. They (other subsystems or drivers) can always assume those wbrf_xxxxx interfaces are available. What they need to care only are the return values of those interfaces.
How do you think?

Evan

Quoted 2 lines
Quoted 2 lines
include/linux/wbrf.h new file +1 -0
+#endif /* _LINUX_WBRF_H */
#8 lore raw

Re: [PATCH V5 1/9] drivers core: Add support for Wifi band RF mitigations

Quoted 419 lines · Evan

[AMD Official Use Only - General]

Quoted 416 lines

-----Original Message-----
From: Limonciello, Mario <[email protected]>
Sent: Saturday, July 1, 2023 12:41 AM
To: Quan, Evan <[email protected]>; [email protected]; [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Lazar, Lijo <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; amd- [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH V5 1/9] drivers core: Add support for Wifi band RF mitigations

Quoted 9 lines · Evan Quan

Due to electrical and mechanical constraints in certain platform designs there may be likely interference of relatively high-powered harmonics of the (G-)DDR memory clocks with local radio module frequency bands used by Wifi 6/6e/7.

To mitigate this, AMD has introduced a mechanism that devices can use to notify active use of particular frequencies so that other devices can make relative internal adjustments as necessary to avoid this resonance.

Quoted 6 lines

In order for a device to support this, the expected flow for device driver or subsystems:

Drivers/subsystems contributing frequencies:

1) During probe, check wbrf_supported_producer to see if WBRF

supported

Quoted 9 lines

for the device.
2) If adding frequencies, then call wbrf_add_exclusion with the start and end ranges of the frequencies.
3) If removing frequencies, then call wbrf_remove_exclusion with start and end ranges of the frequencies.

Drivers/subsystems responding to frequencies:

1) During probe, check wbrf_supported_consumer to see if WBRF is

supported

Quoted 15 lines

for the device.
2) Call the wbrf_retrieve_exclusions to retrieve the current exclusions on receiving an ACPI notification for a new frequency change.

--
v4->v5:
- promote this to be a more generic solution with input argument taking struct device and provide better scalability to support non-ACPI scenarios(Andrew)
- update the APIs naming and some other minor fixes(Rafael)

Quoted 4 lines
---
   drivers/base/Kconfig  |   8 ++
   drivers/base/Makefile |   1 +
   drivers/base/wbrf.c   | 227

++++++++++++++++++++++++++++++++++++++++++

drivers/base/Kconfig config FW_DEVLINK_SYNC_STATE_TIMEOUT · line 242

Quoted 11 lines
   include/linux/wbrf.h  |  65 ++++++++++++
   4 files changed, 301 insertions(+)

create mode 100644 drivers/base/wbrf.c
create mode 100644 include/linux/wbrf.h

drivers/base/Kconfig index renamed from drivers/base/Kconfig +0 -0

2b8fd6bb7da0..5b441017b225 100644

drivers/base/Kconfig +0 -0
@@ -242,4 +242,12 @@ config FW_DEVLINK_SYNC_STATE_TIMEOUT
       command line option on every system/board your kernel is expected

to

Quoted 120 lines
drivers/base/Kconfig +8 -0
       work on.
 
+config WBRF
+   bool "Wifi band RF mitigation mechanism"
+   default n
+   help
+     Wifi band RF mitigation mechanism allows multiple drivers from
+     different domains to notify the frequencies in use so that hardware
+     can be reconfigured to avoid harmonic conflicts.
+
   endmenu
drivers/base/Makefile index renamed from drivers/base/Makefile +0 -0

3079bfe53d04..c844f68a6830 100644

drivers/base/Makefile +1 -0
@@ -26,6 +26,7 @@ obj-$(CONFIG_GENERIC_MSI_IRQ) += platform-msi.o
   obj-$(CONFIG_GENERIC_ARCH_TOPOLOGY) += arch_topology.o
   obj-$(CONFIG_GENERIC_ARCH_NUMA) += arch_numa.o
   obj-$(CONFIG_ACPI) += physical_location.o
+obj-$(CONFIG_WBRF) += wbrf.o
 
   obj-y                     += test/
 
drivers/base/wbrf.c new file mode renamed from drivers/base/wbrf.c +0 -0

100644 index 000000000000..2163a8ec8a9a

drivers/base/wbrf.c new file +23 -0
@@ -0,0 +1,227 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Wifi Band Exclusion Interface
+ * Copyright (C) 2023 Advanced Micro Devices
+ *
+ */
+
+#include <linux/wbrf.h>
+
+static BLOCKING_NOTIFIER_HEAD(wbrf_chain_head);
+static DEFINE_MUTEX(wbrf_mutex);
+static struct exclusion_range_pool wbrf_pool;
+
+static int _wbrf_add_exclusion_ranges(struct wbrf_ranges_in *in) {
+   int i, j;
+
+   for (i = 0; i < ARRAY_SIZE(in->band_list); i++) {
+           if (!in->band_list[i].start &&
+               !in->band_list[i].end)
+                   continue;
+
+           for (j = 0; j < ARRAY_SIZE(wbrf_pool.band_list); j++) {
+                   if (wbrf_pool.band_list[j].start == in-

band_list[i].start &&

drivers/base/wbrf.c new file +12 -0
+                       wbrf_pool.band_list[j].end == in->band_list[i].end) {
+                           wbrf_pool.ref_counter[j]++;
+                           break;
+                   }
+           }
+           if (j < ARRAY_SIZE(wbrf_pool.band_list))
+                   continue;
+
+           for (j = 0; j < ARRAY_SIZE(wbrf_pool.band_list); j++) {
+                   if (!wbrf_pool.band_list[j].start &&
+                       !wbrf_pool.band_list[j].end) {
+                           wbrf_pool.band_list[j].start = in-

band_list[i].start;
+ wbrf_pool.band_list[j].end = in-
band_list[i].end;

drivers/base/wbrf.c new file +21 -0
+                           wbrf_pool.ref_counter[j] = 1;
+                           break;
+                   }
+           }
+           if (j >= ARRAY_SIZE(wbrf_pool.band_list))
+                   return -ENOSPC;
+   }
+
+   return 0;
+}
+
+static int _wbrf_remove_exclusion_ranges(struct wbrf_ranges_in *in) {
+   int i, j;
+
+   for (i = 0; i < ARRAY_SIZE(in->band_list); i++) {
+           if (!in->band_list[i].start &&
+               !in->band_list[i].end)
+                   continue;
+
+           for (j = 0; j < ARRAY_SIZE(wbrf_pool.band_list); j++) {
+                   if (wbrf_pool.band_list[j].start == in-

band_list[i].start &&

drivers/base/wbrf.c new file +31 -0
+                       wbrf_pool.band_list[j].end == in->band_list[i].end) {
+                           wbrf_pool.ref_counter[j]--;
+                           if (!wbrf_pool.ref_counter[j]) {
+                                   wbrf_pool.band_list[j].start = 0;
+                                   wbrf_pool.band_list[j].end = 0;
+                           }
+                           break;
+                   }
+           }
+   }
+
+   return 0;
+}
+
+static int _wbrf_retrieve_exclusion_ranges(struct wbrf_ranges_out
+*out) {
+   int out_idx = 0;
+   int i;
+
+   memset(out, 0, sizeof(*out));
+
+   for (i = 0; i < ARRAY_SIZE(wbrf_pool.band_list); i++) {
+           if (!wbrf_pool.band_list[i].start &&
+               !wbrf_pool.band_list[i].end)
+                   continue;
+
+           out->band_list[out_idx].start = wbrf_pool.band_list[i].start;
+           out->band_list[out_idx++].end = wbrf_pool.band_list[i].end;
+   }
+
+   return 0;

drivers/base/wbrf.c

Quoted 10 lines
drivers/base/wbrf.c new file +10 -0
+}
+
+/**
+ * wbrf_supported_producer - Determine if the device can report
+frequencies
+ *
+ * @dev: device pointer
+ *
+ * WBRF is used to mitigate devices that cause harmonic interference.
+ * This function will determine if this device needs to report such

frequencies.

Quoted 19 lines

+ */

drivers/base/wbrf.c new file +18 -0
+bool wbrf_supported_producer(struct device *dev) {
+   return true;
+}
+EXPORT_SYMBOL_GPL(wbrf_supported_producer);
+
+/**
+ * wbrf_add_exclusion - Add frequency ranges to the exclusion list
+ *
+ * @dev: device pointer
+ * @in: input structure containing the frequency ranges to be added
+ *
+ * Add frequencies into the exclusion list for supported consumers
+ * to react to.
+ */
+int wbrf_add_exclusion(struct device *dev,
+                  struct wbrf_ranges_in *in)
+{
+   int r;

drivers/base/wbrf.c

Quoted 10 lines
drivers/base/wbrf.c new file +10 -0
+
+   mutex_lock(&wbrf_mutex);
+
+   r = _wbrf_add_exclusion_ranges(in);
+
+   mutex_unlock(&wbrf_mutex);
+   if (r)
+           return r;
+
+   blocking_notifier_call_chain(&wbrf_chain_head, WBRF_CHANGED,

NULL);

Quoted 19 lines
drivers/base/wbrf.c new file +19 -0
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(wbrf_add_exclusion);
+
+/**
+ * wbrf_remove_exclusion - Remove frequency ranges from the exclusion
+list
+ *
+ * @dev: device pointer
+ * @in: input structure containing the frequency ranges to be removed
+ *
+ * Remove frequencies from the exclusion list for supported consumers
+ * to react to.
+ */
+int wbrf_remove_exclusion(struct device *dev,
+                     struct wbrf_ranges_in *in)
+{
+   int r;

drivers/base/wbrf.c

Quoted 10 lines
drivers/base/wbrf.c new file +10 -0
+
+   mutex_lock(&wbrf_mutex);
+
+   r = _wbrf_remove_exclusion_ranges(in);
+
+   mutex_unlock(&wbrf_mutex);
+   if (r)
+           return r;
+
+   blocking_notifier_call_chain(&wbrf_chain_head, WBRF_CHANGED,

NULL);

Quoted 32 lines
drivers/base/wbrf.c new file +32 -0
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(wbrf_remove_exclusion);
+
+/**
+ * wbrf_supported_consumer - Determine if the device can react to
+frequencies
+ *
+ * @dev: device pointer
+ *
+ * WBRF is used to mitigate devices that cause harmonic interference.
+ * This function will determine if this device needs to react to
+reports from
+ * other devices for such frequencies.
+ */
+bool wbrf_supported_consumer(struct device *dev) {
+   return true;
+}
+EXPORT_SYMBOL_GPL(wbrf_supported_consumer);
+
+/**
+ * wbrf_register_notifier - Register for notifications of frequency
+changes
+ *
+ * @nb: driver notifier block
+ *
+ * WBRF is used to mitigate devices that cause harmonic interference.
+ * This function will allow consumers to register for frequency notifications.
+ */
+int wbrf_register_notifier(struct notifier_block *nb) {
+   return blocking_notifier_chain_register(&wbrf_chain_head, nb); }

drivers/base/wbrf.c

Quoted 10 lines
drivers/base/wbrf.c new file +10 -0
+EXPORT_SYMBOL_GPL(wbrf_register_notifier);
+
+/**
+ * wbrf_unregister_notifier - Unregister for notifications of
+frequency changes
+ *
+ * @nb: driver notifier block
+ *
+ * WBRF is used to mitigate devices that cause harmonic interference.
+ * This function will allow consumers to unregister for frequency

notifications.

Quoted 44 lines

+ */

drivers/base/wbrf.c new file +26 -0
+int wbrf_unregister_notifier(struct notifier_block *nb) {
+   return blocking_notifier_chain_unregister(&wbrf_chain_head, nb); }
+EXPORT_SYMBOL_GPL(wbrf_unregister_notifier);
+
+/**
+ * wbrf_retrieve_exclusions - Retrieve the exclusion list
+ *
+ * @dev: device pointer
+ * @out: output structure containing the frequency ranges to be
+excluded
+ *
+ * Retrieve the current exclusion list  */ int
+wbrf_retrieve_exclusions(struct device *dev,
+                        struct wbrf_ranges_out *out)
+{
+   int r;
+
+   mutex_lock(&wbrf_mutex);
+
+   r = _wbrf_retrieve_exclusion_ranges(out);
+
+   mutex_unlock(&wbrf_mutex);
+
+   return r;
+}
+EXPORT_SYMBOL_GPL(wbrf_retrieve_exclusions);
include/linux/wbrf.h new file mode renamed from include/linux/wbrf.h +0 -0

100644 index 000000000000..3ca95786cef5

include/linux/wbrf.h new file +12 -0
@@ -0,0 +1,65 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Wifi Band Exclusion Interface
+ * Copyright (C) 2023 Advanced Micro Devices  */
+
+#ifndef _LINUX_WBRF_H
+#define _LINUX_WBRF_H
+
+#include <linux/device.h>
+
+/* Maximum number of wbrf ranges */
+#define MAX_NUM_OF_WBRF_RANGES             11

include/linux/wbrf.h line 22

Quoted 10 lines
include/linux/wbrf.h new file +10 -0
+
+struct exclusion_range {
+   /* start and end point of the frequency range in Hz */
+   uint64_t        start;
+   uint64_t        end;
+};
+
+struct exclusion_range_pool {
+   struct exclusion_range  band_list[MAX_NUM_OF_WBRF_RANGES];
+   uint64_t
       ref_counter[MAX_NUM_OF_WBRF_RANGES];
Quoted 21 lines
include/linux/wbrf.h new file +21 -0
+};
+
+struct wbrf_ranges_in {
+   /* valid entry: `start` and `end` filled with non-zero values */
+   struct exclusion_range  band_list[MAX_NUM_OF_WBRF_RANGES];
+};
+
+struct wbrf_ranges_out {
+   uint32_t                num_of_ranges;
+   struct exclusion_range  band_list[MAX_NUM_OF_WBRF_RANGES];
+} __packed;
+
+enum wbrf_notifier_actions {
+   WBRF_CHANGED,
+};
+
+#ifdef CONFIG_WBRF
+bool wbrf_supported_producer(struct device *dev); int
+wbrf_add_exclusion(struct device *adev,
+                  struct wbrf_ranges_in *in);
+int wbrf_remove_exclusion(struct device *dev,

include/linux/wbrf.h

Quoted 10 lines
include/linux/wbrf.h new file +10 -0
+                     struct wbrf_ranges_in *in);
+int wbrf_retrieve_exclusions(struct device *dev,
+                        struct wbrf_ranges_out *out); bool
+wbrf_supported_consumer(struct device *dev);
+
+int wbrf_register_notifier(struct notifier_block *nb); int
+wbrf_unregister_notifier(struct notifier_block *nb); #else static
+inline bool wbrf_supported_producer(struct device *dev) { return
+false; } static inline int wbrf_add_exclusion(struct device *adev,
+                                struct wbrf_ranges_in *in) { return -

ENODEV; } static inline

include/linux/wbrf.h line 55

Quoted 2 lines
include/linux/wbrf.h new file +2 -0
+int wbrf_remove_exclusion(struct device *dev,
+                                   struct wbrf_ranges_in *in) { return -

ENODEV; } static inline int

include/linux/wbrf.h line 57

Quoted 2 lines
include/linux/wbrf.h new file +2 -0
+wbrf_retrieve_exclusions(struct device *dev,
+                                      struct wbrf_ranges_out *out)

{ return -ENODEV; } static

include/linux/wbrf.h line 63

Quoted 6 lines
include/linux/wbrf.h new file +6 -0
+inline bool wbrf_supported_consumer(struct device *dev) { return
+false; } static inline int wbrf_register_notifier(struct
+notifier_block *nb) { return -ENODEV; } static inline int
+wbrf_unregister_notifier(struct notifier_block *nb) { return -ENODEV;
+} #endif
+

Right now there are stubs for non CONFIG_WBRF as well as other patches are using #ifdef CONFIG_WBRF or having their own stubs. Like mac80211 patch looks for #ifdef CONFIG_WBRF.

Quoted 1 line

I think we should pick one or the other.

Quoted 8 lines

Right..

Quoted 3 lines

Having other subsystems #ifdef CONFIG_WBRF will make the series easier to land through multiple trees; so I have a slight leaning in that direction.

I kind of expecting to use the other way. That is to make CONFIG_WBRF agnostic to other subsystems or drivers. They (other subsystems or drivers) can always assume those wbrf_xxxxx interfaces are available. What they need to care only are the return values of those interfaces.
How do you think?

That's fine, thanks.

Quoted 5 lines

Evan

Quoted 2 lines
Quoted 2 lines
include/linux/wbrf.h new file +1 -0
+#endif /* _LINUX_WBRF_H */
#9 lore raw

Re: [PATCH V5 1/9] drivers core: Add support for Wifi band RF mitigations

In reply to Evan Quan
Quoted 4 lines

Drivers/subsystems contributing frequencies:

1) During probe, check wbrf_supported_producer to see if WBRF supported for the device.

What is the purpose of this stage? Why would it not be supported for this device?

Quoted 8 lines
include/linux/wbrf.h new file +8 -0
+#ifdef CONFIG_WBRF
+bool wbrf_supported_producer(struct device *dev);
+int wbrf_add_exclusion(struct device *adev,
+		       struct wbrf_ranges_in *in);
+int wbrf_remove_exclusion(struct device *dev,
+			  struct wbrf_ranges_in *in);
+int wbrf_retrieve_exclusions(struct device *dev,
+			     struct wbrf_ranges_out *out);

include/linux/wbrf.h line 57

Quoted 10 lines
include/linux/wbrf.h new file +10 -0
+bool wbrf_supported_consumer(struct device *dev);
+
+int wbrf_register_notifier(struct notifier_block *nb);
+int wbrf_unregister_notifier(struct notifier_block *nb);
+#else
+static inline bool wbrf_supported_producer(struct device *dev) { return false; }
+static inline int wbrf_add_exclusion(struct device *adev,
+				     struct wbrf_ranges_in *in) { return -ENODEV; }
+static inline int wbrf_remove_exclusion(struct device *dev,
+					struct wbrf_ranges_in *in) { return -ENODEV; }

The normal aim of stubs is that so long as it is not expected to be fatal if the functionality is missing, the caller should not care if it is missing. So i would expect these to return 0, indicating everything worked as expected.

include/linux/wbrf.h line 59

Quoted 2 lines
include/linux/wbrf.h new file +2 -0
+static inline int wbrf_retrieve_exclusions(struct device *dev,
+					   struct wbrf_ranges_out *out) { return -ENODEV; }

This is more complex. Ideally you want to return an empty set, so there is nothing to do. So i think the stub probably wants to do a memset and then return 0.

include/linux/wbrf.h line 62

Quoted 3 lines
include/linux/wbrf.h new file +3 -0
+static inline bool wbrf_supported_consumer(struct device *dev) { return false; }
+static inline int wbrf_register_notifier(struct notifier_block *nb) { return -ENODEV; }
+static inline int wbrf_unregister_notifier(struct notifier_block *nb) { return -ENODEV; }

And these can just return 0.

Andrew

author
#10 lore raw

RE: [PATCH V5 1/9] drivers core: Add support for Wifi band RF mitigations

[AMD Official Use Only - General]

Quoted 21 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Saturday, July 1, 2023 8:20 AM
To: Quan, Evan <[email protected]>
Cc: [email protected]; [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Limonciello, Mario <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Lazar, Lijo <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; dri- [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH V5 1/9] drivers core: Add support for Wifi band RF mitigations

Quoted 8 lines
Quoted 3 lines

Drivers/subsystems contributing frequencies:

1) During probe, check wbrf_supported_producer to see if WBRF

supported

Quoted 1 line

for the device.

What is the purpose of this stage? Why would it not be supported for this device?

This is needed for wbrf support via ACPI mechanism. If BIOS(AML code) does not support the wbrf adding/removing for some device, it should speak that out so that the device can be aware of that.

Quoted 17 lines
Quoted 6 lines
(quoted diff) +5 -0
+#ifdef CONFIG_WBRF
+bool wbrf_supported_producer(struct device *dev); int
+wbrf_add_exclusion(struct device *adev,
+                  struct wbrf_ranges_in *in);
+int wbrf_remove_exclusion(struct device *dev,

Review

Quoted 10 lines
(quoted diff) +10 -0
+                     struct wbrf_ranges_in *in);
+int wbrf_retrieve_exclusions(struct device *dev,
+                        struct wbrf_ranges_out *out); bool
+wbrf_supported_consumer(struct device *dev);
+
+int wbrf_register_notifier(struct notifier_block *nb); int
+wbrf_unregister_notifier(struct notifier_block *nb); #else static
+inline bool wbrf_supported_producer(struct device *dev) { return
+false; } static inline int wbrf_add_exclusion(struct device *adev,
+                                struct wbrf_ranges_in *in) { return -

ENODEV; } static inline

Quoted 7 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+int wbrf_remove_exclusion(struct device *dev,
+                                   struct wbrf_ranges_in *in) { return -

ENODEV; }

The normal aim of stubs is that so long as it is not expected to be fatal if the functionality is missing, the caller should not care if it is missing. So i would expect these to return 0, indicating everything worked as expected.

Sure, that makes sense.

Quoted 8 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+static inline int wbrf_retrieve_exclusions(struct device *dev,
+                                      struct wbrf_ranges_out *out)

{ return -ENODEV; }

This is more complex. Ideally you want to return an empty set, so there is nothing to do. So i think the stub probably wants to do a memset and then return 0.

Right, will update it accordingly.

Quoted 8 lines

Review

Quoted 6 lines
(quoted diff) +5 -0
+static inline bool wbrf_supported_consumer(struct device *dev) {
+return false; } static inline int wbrf_register_notifier(struct
+notifier_block *nb) { return -ENODEV; } static inline int
+wbrf_unregister_notifier(struct notifier_block *nb) { return -ENODEV;
+}

And these can just return 0.

Will update it.

Evan

Quoted 2 lines

Andrew

#11 lore raw

Re: [PATCH V5 1/9] drivers core: Add support for Wifi band RF mitigations

Quoted 4 lines
Quoted 2 lines

What is the purpose of this stage? Why would it not be supported for this device?

This is needed for wbrf support via ACPI mechanism. If BIOS(AML code) does not support the wbrf adding/removing for some device, it should speak that out so that the device can be aware of that.

How much overhead is this adding? How deep do you need to go to find the BIOS does not support it? And how often is this called?

Where do we want to add complexity? In the generic API? Or maybe a little deeper in the ACPI specific code?

Andrew

author
#12 lore raw

RE: [PATCH V5 1/9] drivers core: Add support for Wifi band RF mitigations

[AMD Official Use Only - General]

Hi Andrew,

I discussed with Mario about your proposal/concerns here.
We believe some changes below might address your concerns.
- place/move the wbrf_supported_producer check inside acpi_amd_wbrf_add_exclusion and acpi_amd_wbrf_add_exclusion
- place the wbrf_supported_consumer check inside acpi_amd_wbrf_retrieve_exclusions
So that the wbrf_supported_producer and wbrf_supported_consumer can be dropped.
We made some prototypes and even performed some tests which showed technically it is absolutely practicable.

However, we found several issues with that.
- The overhead caused by the extra _producer/_consumer check on every calling of wbrf_add/remove/retrieve_ecxclusion.
Especially when you consider there might be multiple producers and consumers in the system at the same time. And some of
them might do in-use band/frequency switching frequently.
- Some extra costs caused by the "know it only at the last minute". For example, to support WBRF, amdgpu driver needs some preparations: install the notification hander, setup the delay workqueue(to handle possible events flooding) and even notify firmware engine to be ready. However, only on the 1st notification receiving,
it is realized(reported by wbrf_supported_consumer check) the WBRF feature is actually not supported. All those extra costs can be actually avoided if we can know the WBRF is not supported at first. This could happen to other consumers and producers too.

After a careful consideration, we think the changes do not benefit us much. It does not deserve us to spend extra efforts. Thus we would like to stick with original implementations. That is to have wbrf_supported_producer and wbrf_supported_consumer interfaces exposed. Then other drivers/subsystems can do necessary wbrf support check in advance and coordinate their actions accordingly. Please let us know your thoughts.

BR,
Evan

Quoted 34 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Tuesday, July 4, 2023 9:07 PM
To: Quan, Evan <[email protected]>
Cc: [email protected]; [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Limonciello, Mario <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Lazar, Lijo <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; dri- [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH V5 1/9] drivers core: Add support for Wifi band RF mitigations

Quoted 4 lines
Quoted 2 lines

What is the purpose of this stage? Why would it not be supported for this device?

This is needed for wbrf support via ACPI mechanism. If BIOS(AML code) does not support the wbrf adding/removing for some device, it should

speak that out so that the device can be aware of that.

How much overhead is this adding? How deep do you need to go to find the BIOS does not support it? And how often is this called?

Where do we want to add complexity? In the generic API? Or maybe a little deeper in the ACPI specific code?

Andrew

#13 lore raw

Re: [PATCH V5 1/9] drivers core: Add support for Wifi band RF mitigations

Quoted 11 lines · Evan

[AMD Official Use Only - General]

Hi Andrew,

I discussed with Mario about your proposal/concerns here.
We believe some changes below might address your concerns.
- place/move the wbrf_supported_producer check inside acpi_amd_wbrf_add_exclusion and acpi_amd_wbrf_add_exclusion
- place the wbrf_supported_consumer check inside acpi_amd_wbrf_retrieve_exclusions
So that the wbrf_supported_producer and wbrf_supported_consumer can be dropped.
We made some prototypes and even performed some tests which showed technically it is absolutely practicable.

Quoted 4 lines

However, we found several issues with that.
- The overhead caused by the extra _producer/_consumer check on every calling of wbrf_add/remove/retrieve_ecxclusion. Especially when you consider there might be multiple producers and consumers in the system at the same time. And some of them might do in-use band/frequency switching frequently.

One more piece of overhead that is in this same theme that Evan didn't mention is the case of a system "without" AMD's ACPI WBRF but the kernel was configured with it enabled. Think like a distro kernel.

Moving it into add/remove exclusion would mean that every single time frequency changed by a producer the _DSM would attempt to be evaluated and fail. To avoid that extra call overhead after the first time would mean needing to keep a variable somewhere, and at that point what did you save?

Quoted 47 lines

- Some extra costs caused by the "know it only at the last minute". For example, to support WBRF, amdgpu driver needs some preparations: install the notification hander, setup the delay workqueue(to handle possible events flooding) and even notify firmware engine to be ready. However, only on the 1st notification receiving,
it is realized(reported by wbrf_supported_consumer check) the WBRF feature is actually not supported. All those extra costs can be actually avoided if we can know the WBRF is not supported at first. This could happen to other consumers and producers too.

After a careful consideration, we think the changes do not benefit us much. It does not deserve us to spend extra efforts. Thus we would like to stick with original implementations. That is to have wbrf_supported_producer and wbrf_supported_consumer interfaces exposed. Then other drivers/subsystems can do necessary wbrf support check in advance and coordinate their actions accordingly. Please let us know your thoughts.

BR,
Evan

Quoted 34 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Tuesday, July 4, 2023 9:07 PM
To: Quan, Evan <[email protected]>
Cc: [email protected]; [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Limonciello, Mario <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Lazar, Lijo <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; dri- [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH V5 1/9] drivers core: Add support for Wifi band RF mitigations

Quoted 4 lines
Quoted 2 lines

What is the purpose of this stage? Why would it not be supported for this device?

This is needed for wbrf support via ACPI mechanism. If BIOS(AML code) does not support the wbrf adding/removing for some device, it should

speak that out so that the device can be aware of that.

How much overhead is this adding? How deep do you need to go to find the BIOS does not support it? And how often is this called?

Where do we want to add complexity? In the generic API? Or maybe a little deeper in the ACPI specific code?

Andrew

author
#14 lore raw

PATCH v5 2/9 driver core: add ACPI based WBRF mechanism introduced by AMD

In reply to Evan Quan

AMD has introduced an ACPI based mechanism to support WBRF for some platforms with AMD dGPU + WLAN. This needs support from BIOS equipped with necessary AML implementations and dGPU firmwares.

For those systems without the ACPI mechanism and developing solutions, user can use the generic WBRF solution for diagnosing potential interference issues.

--
v4->v5:
- promote this to be a more generic solution with input argument taking struct device and provide better scalability to support non-ACPI scenarios(Andrew)
- update the APIs naming and some other minor fixes(Rafael)

---
 drivers/acpi/Makefile         |   2 +
 drivers/acpi/amd_wbrf.c       | 236 ++++++++++++++++++++++++++++++++++
 drivers/base/Kconfig          |  29 +++++
 drivers/base/wbrf.c           |  35 ++++-
 include/linux/acpi_amd_wbrf.h |  38 ++++++
 include/linux/wbrf.h          |   2 +
 6 files changed, 336 insertions(+), 6 deletions(-)
 create mode 100644 drivers/acpi/amd_wbrf.c
 create mode 100644 include/linux/acpi_amd_wbrf.h
drivers/acpi/Makefile +2 -0
index feb36c0b9446..94b940ddbf88 100644
@@ -131,3 +131,5 @@ obj-y				+= dptf/
 obj-$(CONFIG_ARM64)		+= arm64/
 
 obj-$(CONFIG_ACPI_VIOT)		+= viot.o
+
+obj-$(CONFIG_WBRF_AMD_ACPI)	+= amd_wbrf.o
drivers/acpi/amd_wbrf.c new file +236 -0

236 lines not on this page · raw message

drivers/base/Kconfig +29 -0
index 5b441017b225..cbf0b2358c17 100644
@@ -250,4 +250,33 @@ config WBRF
 	  different domains to notify the frequencies in use so that hardware
 	  can be reconfigured to avoid harmonic conflicts.
 
+config WBRF_AMD_ACPI
+	bool "Use the ACPI mechanism introduced by AMD to support WBRF"
+	default n
+	depends on ACPI
+	select WBRF
+	help
+	  AMD has introduced an ACPI based mechanism to support WBRF for some
+	  platforms with AMD dGPU and WLAN. This needs support from BIOS equipped
+	  with necessary AML implementations and dGPU firmwares.
+
+	  Say Y to enable this ACPI based mechanism. It is suggested to confirm
+	  with the hardware designer/provider first whether your platform
+	  equipped with necessary BIOS and firmwares.
+
+config WBRF_GENERIC
+	bool "Use the generic WBRF solution"
+	default n
+	depends on !WBRF_AMD_ACPI
+	select WBRF
+	help
+	  Ideally it is the hardware designer/provider who should provide a
+	  solution for the possible RF interference issue. Since they know
+	  well whether there could be RF interference issue with their
+	  platforms.
+
+	  Say Y to enable this generic WBRF solution for diagnosing potential
+	  interference issues on systems without the ACPI mechanism and
+	  developing solutions.
+
 endmenu
drivers/base/wbrf.c +29 -6
index 2163a8ec8a9a..d9fab9f3045e 100644
@@ -6,9 +6,12 @@
  */
 
 #include <linux/wbrf.h>
+#include <linux/acpi_amd_wbrf.h>
 
 static BLOCKING_NOTIFIER_HEAD(wbrf_chain_head);
 static DEFINE_MUTEX(wbrf_mutex);
+
+#if defined(CONFIG_WBRF_GENERIC)
 static struct exclusion_range_pool wbrf_pool;
 
 static int _wbrf_add_exclusion_ranges(struct wbrf_ranges_in *in)
@@ -89,6 +92,7 @@ static int _wbrf_retrieve_exclusion_ranges(struct wbrf_ranges_out *out)
 
 	return 0;
 }
+#endif
 
 /**
  * wbrf_supported_producer - Determine if the device can report frequencies
@@ -100,7 +104,12 @@ static int _wbrf_retrieve_exclusion_ranges(struct wbrf_ranges_out *out)
  */
 bool wbrf_supported_producer(struct device *dev)
 {
+#ifdef CONFIG_WBRF_AMD_ACPI
+	return acpi_amd_wbrf_supported_producer(dev);
+#elif defined(CONFIG_WBRF_GENERIC)
 	return true;
+#endif
+	return false;
 }
 EXPORT_SYMBOL_GPL(wbrf_supported_producer);
 
@@ -116,12 +125,15 @@ EXPORT_SYMBOL_GPL(wbrf_supported_producer);
 int wbrf_add_exclusion(struct device *dev,
 		       struct wbrf_ranges_in *in)
 {
-	int r;
+	int r = -ENODEV;
 
 	mutex_lock(&wbrf_mutex);
 
+#ifdef CONFIG_WBRF_AMD_ACPI
+	r = acpi_amd_wbrf_add_exclusion(dev, in);
+#elif defined(CONFIG_WBRF_GENERIC)
 	r = _wbrf_add_exclusion_ranges(in);
-
+#endif
 	mutex_unlock(&wbrf_mutex);
 	if (r)
 		return r;
@@ -144,12 +156,15 @@ EXPORT_SYMBOL_GPL(wbrf_add_exclusion);
 int wbrf_remove_exclusion(struct device *dev,
 			  struct wbrf_ranges_in *in)
 {
-	int r;
+	int r = -ENODEV;
 
 	mutex_lock(&wbrf_mutex);
 
+#ifdef CONFIG_WBRF_AMD_ACPI
+	r  = acpi_amd_wbrf_remove_exclusion(dev, in);
+#elif defined(CONFIG_WBRF_GENERIC)
 	r = _wbrf_remove_exclusion_ranges(in);
-
+#endif
 	mutex_unlock(&wbrf_mutex);
 	if (r)
 		return r;
@@ -171,7 +186,12 @@ EXPORT_SYMBOL_GPL(wbrf_remove_exclusion);
  */
 bool wbrf_supported_consumer(struct device *dev)
 {
+#ifdef CONFIG_WBRF_AMD_ACPI
+	return acpi_amd_wbrf_supported_consumer(dev);
+#elif defined(CONFIG_WBRF_GENERIC)
 	return true;
+#endif
+	return false;
 }
 EXPORT_SYMBOL_GPL(wbrf_supported_consumer);
 
@@ -214,12 +234,15 @@ EXPORT_SYMBOL_GPL(wbrf_unregister_notifier);
 int wbrf_retrieve_exclusions(struct device *dev,
 			     struct wbrf_ranges_out *out)
 {
-	int r;
+	int r = -ENODEV;
 
 	mutex_lock(&wbrf_mutex);
 
+#ifdef CONFIG_WBRF_AMD_ACPI
+	r = acpi_amd_wbrf_retrieve_exclusions(dev, out);
+#elif defined(CONFIG_WBRF_GENERIC)
 	r = _wbrf_retrieve_exclusion_ranges(out);
-
+#endif
 	mutex_unlock(&wbrf_mutex);
 
 	return r;
include/linux/acpi_amd_wbrf.h new file +38 -0
new file mode 100644
index 000000000000..c274093972e3
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Wifi Band Exclusion Interface (AMD ACPI Implementation)
+ * Copyright (C) 2023 Advanced Micro Devices
+ *
+ */
+
+#ifndef _ACPI_AMD_WBRF_H
+#define _ACPI_AMD_WBRF_H
+
+#include <linux/wbrf.h>
+
+#ifdef CONFIG_WBRF_AMD_ACPI
+bool acpi_amd_wbrf_supported_consumer(struct device *dev);
+bool acpi_amd_wbrf_supported_producer(struct device *dev);
+int acpi_amd_wbrf_remove_exclusion(struct device *dev,
+				   struct wbrf_ranges_in *in);
+int acpi_amd_wbrf_add_exclusion(struct device *dev,
+				struct wbrf_ranges_in *in);
+int acpi_amd_wbrf_retrieve_exclusions(struct device *dev,
+				      struct wbrf_ranges_out *out);
+#else
+static inline bool
+acpi_amd_wbrf_supported_consumer(struct device *dev) { return false; }
+static inline bool
+acpi_amd_wbrf_supported_producer(struct device *dev) {return false; }
+static inline int
+acpi_amd_wbrf_remove_exclusion(struct device *dev,
+			       struct wbrf_ranges_in *in) { return -ENODEV; }
+static inline int
+acpi_amd_wbrf_add_exclusion(struct device *dev,
+			    struct wbrf_ranges_in *in) { return -ENODEV; }
+static inline int
+acpi_amd_wbrf_retrieve_exclusions(struct device *dev,
+				  struct wbrf_ranges_out *out) { return -ENODEV; }
+#endif
+
+#endif /* _ACPI_AMD_WBRF_H */
include/linux/wbrf.h +2 -0
index 3ca95786cef5..f71ac2343b29 100644
@@ -18,10 +18,12 @@ struct exclusion_range {
 	uint64_t	end;
 };
 
+#if defined(CONFIG_WBRF_GENERIC)
 struct exclusion_range_pool {
 	struct exclusion_range	band_list[MAX_NUM_OF_WBRF_RANGES];
 	uint64_t		ref_counter[MAX_NUM_OF_WBRF_RANGES];
 };
+#endif
 
 struct wbrf_ranges_in {
 	/* valid entry: `start` and `end` filled with non-zero values */
Signature · 1 line
2.34.1
#15 lore raw

Re: [PATCH V5 2/9] driver core: add ACPI based WBRF mechanism introduced by AMD

drivers/acpi/amd_wbrf.c line 83

Quoted 11 lines
drivers/acpi/amd_wbrf.c new file +11 -0
+	argv4 = kzalloc(sizeof(*argv4) * (2 * num_of_ranges + 2 + 1), GFP_KERNEL);
+	if (!argv4)
+		return -ENOMEM;
+
+	argv4[arg_idx].package.type = ACPI_TYPE_PACKAGE;
+	argv4[arg_idx].package.count = 2 + 2 * num_of_ranges;
+	argv4[arg_idx++].package.elements = &argv4[1];
+	argv4[arg_idx].integer.type = ACPI_TYPE_INTEGER;
+	argv4[arg_idx++].integer.value = num_of_ranges;
+	argv4[arg_idx].integer.type = ACPI_TYPE_INTEGER;
+	argv4[arg_idx++].integer.value = action;

There is a lot of magic numbers in that kzalloc. It is being used as an array, kcalloc() would be a good start to make it more readable. Can some #define's be used to explain what the other numbers mean?

drivers/acpi/amd_wbrf.c line 195

Quoted 4 lines
drivers/acpi/amd_wbrf.c new file +4 -0
+	/*
+	 * Bit 0 indicates whether there's support for any functions other than
+	 * function 0.
+	 */

Please make use of the BIT macro to give the different bits informative names.

Quoted 15 lines
drivers/acpi/amd_wbrf.c new file +14 -0
+	if ((mask & 0x1) && (mask & funcs) == funcs)
+		return true;
+
+	return false;
+}
+
 
+int acpi_amd_wbrf_retrieve_exclusions(struct device *dev,
+				      struct wbrf_ranges_out *out)
+{
+	struct acpi_device *adev = ACPI_COMPANION(dev);
+	union acpi_object *obj;
+
+	if (!adev)
+		return -ENODEV;

drivers/acpi/amd_wbrf.c line 231

Quoted 10 lines
drivers/acpi/amd_wbrf.c new file +10 -0
+
+	obj = acpi_evaluate_wbrf(adev->handle,
+				 WBRF_REVISION,
+				 WBRF_RETRIEVE);
+	if (!obj)
+		return -EINVAL;
+
+	WARN(obj->buffer.length != sizeof(*out),
+		"Unexpected buffer length");
+	memcpy(out, obj->buffer.pointer, obj->buffer.length);

You WARN, and then overwrite whatever i passed the end of out? Please at least use min(obj->buffer.length, sizeof(*out)), but better still:

   if (obj->buffer.length != sizeof(*out)) {
         dev_err(dev, "BIOS FUBAR, ignoring wrong sized WBRT information");
	 return -EINVAL;

}

drivers/base/wbrf.c static int _wbrf_retrieve_exclusion_ranges(struct wbrf_ranges_out *out) · line 95

Quoted 9 lines
drivers/base/wbrf.c +2 -0
+#if defined(CONFIG_WBRF_GENERIC)
 static struct exclusion_range_pool wbrf_pool;
 
 static int _wbrf_add_exclusion_ranges(struct wbrf_ranges_in *in)
@@ -89,6 +92,7 @@ static int _wbrf_retrieve_exclusion_ranges(struct wbrf_ranges_out *out)
 
 	return 0;
 }
+#endif

I was expecting you would keep these tables, and then call into the BIOS as well. Having this table in debugfs seems like a useful thing to have for debugging the BIOS.

Quoted 5 lines
include/linux/acpi_amd_wbrf.h new file +5 -0
+#ifdef CONFIG_WBRF_AMD_ACPI
+#else
+static inline bool
+acpi_amd_wbrf_supported_consumer(struct device *dev) { return false; }
+static inline bool

include/linux/acpi_amd_wbrf.h line 35

Quoted 10 lines
include/linux/acpi_amd_wbrf.h new file +10 -0
+acpi_amd_wbrf_supported_producer(struct device *dev) {return false; }
+static inline int
+acpi_amd_wbrf_remove_exclusion(struct device *dev,
+			       struct wbrf_ranges_in *in) { return -ENODEV; }
+static inline int
+acpi_amd_wbrf_add_exclusion(struct device *dev,
+			    struct wbrf_ranges_in *in) { return -ENODEV; }
+static inline int
+acpi_amd_wbrf_retrieve_exclusions(struct device *dev,
+				  struct wbrf_ranges_out *out) { return -ENODEV; }

Do you actually need these stub versions?

Andrew

author
#16 lore raw

RE: [PATCH V5 2/9] driver core: add ACPI based WBRF mechanism introduced by AMD

[AMD Official Use Only - General]

Quoted 34 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Saturday, July 1, 2023 8:51 AM
To: Quan, Evan <[email protected]>
Cc: [email protected]; [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Limonciello, Mario <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Lazar, Lijo <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; dri- [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH V5 2/9] driver core: add ACPI based WBRF mechanism introduced by AMD

Quoted 1 line

+ argv4 = kzalloc(sizeof(*argv4) * (2 * num_of_ranges + 2 + 1),

GFP_KERNEL);

drivers/acpi/amd_wbrf.c line 83

Quoted 10 lines
drivers/acpi/amd_wbrf.c new file +10 -0
+   if (!argv4)
+           return -ENOMEM;
+
+   argv4[arg_idx].package.type = ACPI_TYPE_PACKAGE;
+   argv4[arg_idx].package.count = 2 + 2 * num_of_ranges;
+   argv4[arg_idx++].package.elements = &argv4[1];
+   argv4[arg_idx].integer.type = ACPI_TYPE_INTEGER;
+   argv4[arg_idx++].integer.value = num_of_ranges;
+   argv4[arg_idx].integer.type = ACPI_TYPE_INTEGER;
+   argv4[arg_idx++].integer.value = action;
Quoted 3 lines

There is a lot of magic numbers in that kzalloc. It is being used as an array, kcalloc() would be a good start to make it more readable.
Can some #define's be used to explain what the other numbers mean?

Sure, will update accordingly.

Quoted 7 lines

drivers/acpi/amd_wbrf.c line 195

Quoted 5 lines
drivers/acpi/amd_wbrf.c new file +4 -0
+   /*
+    * Bit 0 indicates whether there's support for any functions other than
+    * function 0.
+    */

Please make use of the BIT macro to give the different bits informative names.

Sure.

Quoted 29 lines
Quoted 15 lines
drivers/acpi/amd_wbrf.c new file +13 -0
+   if ((mask & 0x1) && (mask & funcs) == funcs)
+           return true;
+
+   return false;
+}
+
 
+int acpi_amd_wbrf_retrieve_exclusions(struct device *dev,
+                                 struct wbrf_ranges_out *out) {
+   struct acpi_device *adev = ACPI_COMPANION(dev);
+   union acpi_object *obj;
+
+   if (!adev)
+           return -ENODEV;

drivers/acpi/amd_wbrf.c line 231

Quoted 10 lines
drivers/acpi/amd_wbrf.c new file +10 -0
+
+   obj = acpi_evaluate_wbrf(adev->handle,
+                            WBRF_REVISION,
+                            WBRF_RETRIEVE);
+   if (!obj)
+           return -EINVAL;
+
+   WARN(obj->buffer.length != sizeof(*out),
+           "Unexpected buffer length");
+   memcpy(out, obj->buffer.pointer, obj->buffer.length);

You WARN, and then overwrite whatever i passed the end of out? Please at least use min(obj->buffer.length, sizeof(*out)), but better still:

Quoted 4 lines
   if (obj->buffer.length != sizeof(*out)) {
         dev_err(dev, "BIOS FUBAR, ignoring wrong sized WBRT information");
       return -EINVAL;
   }

OK. Sounds reasonable. Will update as suggested.

Quoted 8 lines
Quoted 8 lines

+#if defined(CONFIG_WBRF_GENERIC)
static struct exclusion_range_pool wbrf_pool;

static int _wbrf_add_exclusion_ranges(struct wbrf_ranges_in *in) @@
-89,6 +92,7 @@ static int _wbrf_retrieve_exclusion_ranges(struct wbrf_ranges_out *out)

Quoted 7 lines
Quoted 3 lines
    return 0;

}
+#endif

I was expecting you would keep these tables, and then call into the BIOS as well. Having this table in debugfs seems like a useful thing to have for debugging the BIOS.

I'm not sure. Since these interfaces what we designed now kind of serve as a library. When and where the debugfs should be created will be quite tricky.

Quoted 10 lines

include/linux/acpi_amd_wbrf.h line 29

Quoted 9 lines
include/linux/acpi_amd_wbrf.h new file +8 -0
+#ifdef CONFIG_WBRF_AMD_ACPI
+#else
+static inline bool
+acpi_amd_wbrf_supported_consumer(struct device *dev) { return false;
+} static inline bool acpi_amd_wbrf_supported_producer(struct device
+*dev) {return false; } static inline int
+acpi_amd_wbrf_remove_exclusion(struct device *dev,
+                          struct wbrf_ranges_in *in) { return -ENODEV; }

static

Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+inline int acpi_amd_wbrf_add_exclusion(struct device *dev,
+                       struct wbrf_ranges_in *in) { return -ENODEV; } static

inline

Review

Quoted 2 lines
(quoted diff) +2 -0
+int acpi_amd_wbrf_retrieve_exclusions(struct device *dev,
+                             struct wbrf_ranges_out *out) { return -

ENODEV; }

Do you actually need these stub versions?

Yes, these can be dropped. Let me update accordingly.

Evan

Quoted 2 lines

Andrew

author
#17 lore raw

PATCH v5 3/9 cfg80211: expose nl80211_chan_width_to_mhz for wide sharing

In reply to Evan Quan

The newly added WBRF feature needs this interface for channel width calculation.

---
 include/net/cfg80211.h | 8 ++++++++
 net/wireless/chan.c    | 3 ++-
 2 files changed, 10 insertions(+), 1 deletion(-)
include/net/cfg80211.h +8 -0
index 9e04f69712b1..c6dc337eafce 100644
@@ -920,6 +920,14 @@ const struct cfg80211_chan_def *
 cfg80211_chandef_compatible(const struct cfg80211_chan_def *chandef1,
 			    const struct cfg80211_chan_def *chandef2);
 
+/**
+ * nl80211_chan_width_to_mhz - get the channel width in Mhz
+ * @chan_width: the channel width from &enum nl80211_chan_width
+ * Return: channel width in Mhz if the chan_width from &enum nl80211_chan_width
+ * is valid. -1 otherwise.
+ */
+int nl80211_chan_width_to_mhz(enum nl80211_chan_width chan_width);
+
 /**
  * cfg80211_chandef_valid - check if a channel definition is valid
  * @chandef: the channel definition to check
net/wireless/chan.c +2 -1
index 0b7e81db383d..227db04eac42 100644
@@ -141,7 +141,7 @@ static bool cfg80211_edmg_chandef_valid(const struct cfg80211_chan_def *chandef)
 	return true;
 }
 
-static int nl80211_chan_width_to_mhz(enum nl80211_chan_width chan_width)
+int nl80211_chan_width_to_mhz(enum nl80211_chan_width chan_width)
 {
 	int mhz;
 
@@ -190,6 +190,7 @@ static int nl80211_chan_width_to_mhz(enum nl80211_chan_width chan_width)
 	}
 	return mhz;
 }
+EXPORT_SYMBOL(nl80211_chan_width_to_mhz);
 
 static int cfg80211_chandef_get_width(const struct cfg80211_chan_def *c)
 {
Signature · 1 line
2.34.1
author
#18 lore raw

PATCH v5 4/9 wifi: mac80211: Add support for ACPI WBRF

In reply to Evan Quan

To support AMD's WBRF interference mitigation mechanism, Wifi adapters utilized in the system must register the frequencies in use(or unregister those frequencies no longer used) via the dedicated APCI calls. So that, other drivers responding to the frequencies can take proper actions to mitigate possible interference.

--
v1->v2:
- place the new added member(wbrf_supported) in

    ieee80211_local(Johannes)

- handle chandefs change scenario properly(Johannes)
- some minor fixes around code sharing and possible invalid input checks(Johannes)
v2->v3:
- drop unnecessary input checks and intermediate APIs(Mario)
- Separate some mac80211 common code(Mario, Johannes)
v3->v4:
- some minor fixes around return values(Johannes)

---
 include/linux/ieee80211.h  |   1 +
 net/mac80211/Makefile      |   2 +
 net/mac80211/chan.c        |   9 ++++
 net/mac80211/ieee80211_i.h |  19 +++++++
 net/mac80211/main.c        |   2 +
 net/mac80211/wbrf.c        | 103 +++++++++++++++++++++++++++++++++++++
 6 files changed, 136 insertions(+)
 create mode 100644 net/mac80211/wbrf.c
include/linux/ieee80211.h +1 -0
index c4cf296e7eaf..0703921547f5 100644
@@ -4319,6 +4319,7 @@ static inline int ieee80211_get_tdls_action(struct sk_buff *skb, u32 hdr_size)
 /* convert frequencies */
 #define MHZ_TO_KHZ(freq) ((freq) * 1000)
 #define KHZ_TO_MHZ(freq) ((freq) / 1000)
+#define KHZ_TO_HZ(freq)  ((freq) * 1000)
 #define PR_KHZ(f) KHZ_TO_MHZ(f), f % 1000
 #define KHZ_F "%d.%03d"
 
net/mac80211/Makefile +2 -0
index b8de44da1fb8..8f8ac567e7c8 100644
@@ -65,4 +65,6 @@ rc80211_minstrel-$(CONFIG_MAC80211_DEBUGFS) += \
 
 mac80211-$(CONFIG_MAC80211_RC_MINSTREL) += $(rc80211_minstrel-y)
 
+mac80211-$(CONFIG_WBRF) += wbrf.o
+
 ccflags-y += -DDEBUG
net/mac80211/chan.c +9 -0
index 77c90ed8f5d7..9887471028dc 100644
@@ -506,11 +506,16 @@ static void _ieee80211_change_chanctx(struct ieee80211_local *local,
 
 	WARN_ON(!cfg80211_chandef_compatible(&ctx->conf.def, chandef));
 
+	ieee80211_remove_wbrf(local, &ctx->conf.def);
+
 	ctx->conf.def = *chandef;
 
 	/* check if min chanctx also changed */
 	changed = IEEE80211_CHANCTX_CHANGE_WIDTH |
 		  _ieee80211_recalc_chanctx_min_def(local, ctx, rsvd_for);
+
+	ieee80211_add_wbrf(local, &ctx->conf.def);
+
 	drv_change_chanctx(local, ctx, changed);
 
 	if (!local->use_chanctx) {
@@ -668,6 +673,8 @@ static int ieee80211_add_chanctx(struct ieee80211_local *local,
 	lockdep_assert_held(&local->mtx);
 	lockdep_assert_held(&local->chanctx_mtx);
 
+	ieee80211_add_wbrf(local, &ctx->conf.def);
+
 	if (!local->use_chanctx)
 		local->hw.conf.radar_enabled = ctx->conf.radar_enabled;
 
@@ -748,6 +755,8 @@ static void ieee80211_del_chanctx(struct ieee80211_local *local,
 	}
 
 	ieee80211_recalc_idle(local);
+
+	ieee80211_remove_wbrf(local, &ctx->conf.def);
 }
 
 static void ieee80211_free_chanctx(struct ieee80211_local *local,
net/mac80211/ieee80211_i.h +19 -0
index 4159fb65038b..ffe00c55304e 100644
@@ -1591,6 +1591,10 @@ struct ieee80211_local {
 
 	/* extended capabilities provided by mac80211 */
 	u8 ext_capa[8];
+
+#ifdef CONFIG_WBRF
+	bool wbrf_supported;
+#endif
 };
 
 static inline struct ieee80211_sub_if_data *
@@ -2615,4 +2619,19 @@ ieee80211_eht_cap_ie_to_sta_eht_cap(struct ieee80211_sub_if_data *sdata,
 				    const struct ieee80211_eht_cap_elem *eht_cap_ie_elem,
 				    u8 eht_cap_len,
 				    struct link_sta_info *link_sta);
+
+#ifdef CONFIG_WBRF
+void ieee80211_check_wbrf_support(struct ieee80211_local *local);
+void ieee80211_add_wbrf(struct ieee80211_local *local,
+			struct cfg80211_chan_def *chandef);
+void ieee80211_remove_wbrf(struct ieee80211_local *local,
+			   struct cfg80211_chan_def *chandef);
+#else
+static inline void ieee80211_check_wbrf_support(struct ieee80211_local *local) { }
+static inline void ieee80211_add_wbrf(struct ieee80211_local *local,
+				      struct cfg80211_chan_def *chandef) { return 0; }
+static inline void ieee80211_remove_wbrf(struct ieee80211_local *local,
+					 struct cfg80211_chan_def *chandef) { }
+#endif /* CONFIG_WBRF */
+
 #endif /* IEEE80211_I_H */
net/mac80211/main.c +2 -0
index 55cdfaef0f5d..0a55626b1546 100644
@@ -1395,6 +1395,8 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
 	debugfs_hw_add(local);
 	rate_control_add_debugfs(local);
 
+	ieee80211_check_wbrf_support(local);
+
 	rtnl_lock();
 	wiphy_lock(hw->wiphy);
 
net/mac80211/wbrf.c new file +103 -0

103 lines not on this page · raw message

Signature · 1 line
2.34.1
#19 lore raw

Re: [PATCH V5 4/9] wifi: mac80211: Add support for ACPI WBRF

kernel test robot noticed the following build errors:

Hi Evan,

kernel test robot noticed the following build errors:

[auto build test ERROR on wireless-next/main]
[also build test ERROR on wireless/main linus/master v6.4] [cannot apply to drm-misc/drm-misc-next next-20230630]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Evan-Quan/drivers-core-Add-support-for-Wifi-band-RF-mitigations/20230630-183633
base:   https://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless-next.git main
patch link:    https://lore.kernel.org/r/20230630103240.1557100-5-evan.quan%40amd.com
patch subject: [PATCH V5 4/9] wifi: mac80211: Add support for ACPI WBRF
config: powerpc-randconfig-r025-20230630 (https://download.01.org/0day-ci/archive/20230630/[email protected]/config)
compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project.git 4a5ac14ee968ff0ad5d2cc1ffa0299048db4c88a)
reproduce: (https://download.01.org/0day-ci/archive/20230630/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

         |                 ^~~~~~~~~~~~~~
   <scratch space>:87:1: note: expanded from here
      87 | __do_insw
         | ^
   arch/powerpc/include/asm/io.h:615:56: note: expanded from macro '__do_insw'
     615 | #define __do_insw(p, b, n)      readsw((PCI_IO_ADDR)_IO_BASE+(p), (b), (n))
         |                                        ~~~~~~~~~~~~~~~~~~~~~^
   In file included from net/mac80211/rx.c:15:
   In file included from include/linux/skbuff.h:17:
   In file included from include/linux/bvec.h:10:
   In file included from include/linux/highmem.h:12:
   In file included from include/linux/hardirq.h:11:
   In file included from arch/powerpc/include/asm/hardirq.h:6:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:677:
   arch/powerpc/include/asm/io-defs.h:47:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
      47 | DEF_PCI_AC_NORET(insl, (unsigned long p, void *b, unsigned long c),
         | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      48 |                  (p, b, c), pio, p)
         |                  ~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:674:3: note: expanded from macro 'DEF_PCI_AC_NORET'
     674 |                 __do_##name al;                                 \
         |                 ^~~~~~~~~~~~~~
   <scratch space>:89:1: note: expanded from here
      89 | __do_insl
         | ^
   arch/powerpc/include/asm/io.h:616:56: note: expanded from macro '__do_insl'
     616 | #define __do_insl(p, b, n)      readsl((PCI_IO_ADDR)_IO_BASE+(p), (b), (n))
         |                                        ~~~~~~~~~~~~~~~~~~~~~^
   In file included from net/mac80211/rx.c:15:
   In file included from include/linux/skbuff.h:17:
   In file included from include/linux/bvec.h:10:
   In file included from include/linux/highmem.h:12:
   In file included from include/linux/hardirq.h:11:
   In file included from arch/powerpc/include/asm/hardirq.h:6:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:677:
   arch/powerpc/include/asm/io-defs.h:49:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
      49 | DEF_PCI_AC_NORET(outsb, (unsigned long p, const void *b, unsigned long c),
         | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      50 |                  (p, b, c), pio, p)
         |                  ~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:674:3: note: expanded from macro 'DEF_PCI_AC_NORET'
     674 |                 __do_##name al;                                 \
         |                 ^~~~~~~~~~~~~~
   <scratch space>:91:1: note: expanded from here
      91 | __do_outsb
         | ^
   arch/powerpc/include/asm/io.h:617:58: note: expanded from macro '__do_outsb'
     617 | #define __do_outsb(p, b, n)     writesb((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
         |                                         ~~~~~~~~~~~~~~~~~~~~~^
   In file included from net/mac80211/rx.c:15:
   In file included from include/linux/skbuff.h:17:
   In file included from include/linux/bvec.h:10:
   In file included from include/linux/highmem.h:12:
   In file included from include/linux/hardirq.h:11:
   In file included from arch/powerpc/include/asm/hardirq.h:6:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:677:
   arch/powerpc/include/asm/io-defs.h:51:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
      51 | DEF_PCI_AC_NORET(outsw, (unsigned long p, const void *b, unsigned long c),
         | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      52 |                  (p, b, c), pio, p)
         |                  ~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:674:3: note: expanded from macro 'DEF_PCI_AC_NORET'
     674 |                 __do_##name al;                                 \
         |                 ^~~~~~~~~~~~~~
   <scratch space>:93:1: note: expanded from here
      93 | __do_outsw
         | ^
   arch/powerpc/include/asm/io.h:618:58: note: expanded from macro '__do_outsw'
     618 | #define __do_outsw(p, b, n)     writesw((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
         |                                         ~~~~~~~~~~~~~~~~~~~~~^
   In file included from net/mac80211/rx.c:15:
   In file included from include/linux/skbuff.h:17:
   In file included from include/linux/bvec.h:10:
   In file included from include/linux/highmem.h:12:
   In file included from include/linux/hardirq.h:11:
   In file included from arch/powerpc/include/asm/hardirq.h:6:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:677:
   arch/powerpc/include/asm/io-defs.h:53:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
      53 | DEF_PCI_AC_NORET(outsl, (unsigned long p, const void *b, unsigned long c),
         | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      54 |                  (p, b, c), pio, p)
         |                  ~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:674:3: note: expanded from macro 'DEF_PCI_AC_NORET'
     674 |                 __do_##name al;                                 \
         |                 ^~~~~~~~~~~~~~
   <scratch space>:95:1: note: expanded from here
      95 | __do_outsl
         | ^
   arch/powerpc/include/asm/io.h:619:58: note: expanded from macro '__do_outsl'
     619 | #define __do_outsl(p, b, n)     writesl((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
         |                                         ~~~~~~~~~~~~~~~~~~~~~^
   In file included from net/mac80211/rx.c:26:
>> net/mac80211/ieee80211_i.h:2655:48: error: void function 'ieee80211_add_wbrf' should not return a value [-Wreturn-type]

2655 | struct cfg80211_chan_def *chandef) { return 0; }
| ^ ~
6 warnings and 1 error generated.
--
In file included from include/net/net_namespace.h:43:
In file included from include/linux/skbuff.h:17:
In file included from include/linux/bvec.h:10:
In file included from include/linux/highmem.h:12:
In file included from include/linux/hardirq.h:11:
In file included from arch/powerpc/include/asm/hardirq.h:6:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/powerpc/include/asm/io.h:677:
arch/powerpc/include/asm/io-defs.h:47:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]

      47 | DEF_PCI_AC_NORET(insl, (unsigned long p, void *b, unsigned long c),
         | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      48 |                  (p, b, c), pio, p)
         |                  ~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:674:3: note: expanded from macro 'DEF_PCI_AC_NORET'
     674 |                 __do_##name al;                                 \
         |                 ^~~~~~~~~~~~~~
   <scratch space>:87:1: note: expanded from here
      87 | __do_insl
         | ^
   arch/powerpc/include/asm/io.h:616:56: note: expanded from macro '__do_insl'
     616 | #define __do_insl(p, b, n)      readsl((PCI_IO_ADDR)_IO_BASE+(p), (b), (n))
         |                                        ~~~~~~~~~~~~~~~~~~~~~^
   In file included from net/mac80211/rc80211_minstrel_ht.c:6:
   In file included from include/linux/netdevice.h:38:
   In file included from include/net/net_namespace.h:43:
   In file included from include/linux/skbuff.h:17:
   In file included from include/linux/bvec.h:10:
   In file included from include/linux/highmem.h:12:
   In file included from include/linux/hardirq.h:11:
   In file included from arch/powerpc/include/asm/hardirq.h:6:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:677:
   arch/powerpc/include/asm/io-defs.h:49:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
      49 | DEF_PCI_AC_NORET(outsb, (unsigned long p, const void *b, unsigned long c),
         | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      50 |                  (p, b, c), pio, p)
         |                  ~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:674:3: note: expanded from macro 'DEF_PCI_AC_NORET'
     674 |                 __do_##name al;                                 \
         |                 ^~~~~~~~~~~~~~
   <scratch space>:89:1: note: expanded from here
      89 | __do_outsb
         | ^
   arch/powerpc/include/asm/io.h:617:58: note: expanded from macro '__do_outsb'
     617 | #define __do_outsb(p, b, n)     writesb((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
         |                                         ~~~~~~~~~~~~~~~~~~~~~^
   In file included from net/mac80211/rc80211_minstrel_ht.c:6:
   In file included from include/linux/netdevice.h:38:
   In file included from include/net/net_namespace.h:43:
   In file included from include/linux/skbuff.h:17:
   In file included from include/linux/bvec.h:10:
   In file included from include/linux/highmem.h:12:
   In file included from include/linux/hardirq.h:11:
   In file included from arch/powerpc/include/asm/hardirq.h:6:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:677:
   arch/powerpc/include/asm/io-defs.h:51:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
      51 | DEF_PCI_AC_NORET(outsw, (unsigned long p, const void *b, unsigned long c),
         | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      52 |                  (p, b, c), pio, p)
         |                  ~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:674:3: note: expanded from macro 'DEF_PCI_AC_NORET'
     674 |                 __do_##name al;                                 \
         |                 ^~~~~~~~~~~~~~
   <scratch space>:91:1: note: expanded from here
      91 | __do_outsw
         | ^
   arch/powerpc/include/asm/io.h:618:58: note: expanded from macro '__do_outsw'
     618 | #define __do_outsw(p, b, n)     writesw((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
         |                                         ~~~~~~~~~~~~~~~~~~~~~^
   In file included from net/mac80211/rc80211_minstrel_ht.c:6:
   In file included from include/linux/netdevice.h:38:
   In file included from include/net/net_namespace.h:43:
   In file included from include/linux/skbuff.h:17:
   In file included from include/linux/bvec.h:10:
   In file included from include/linux/highmem.h:12:
   In file included from include/linux/hardirq.h:11:
   In file included from arch/powerpc/include/asm/hardirq.h:6:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:677:
   arch/powerpc/include/asm/io-defs.h:53:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
      53 | DEF_PCI_AC_NORET(outsl, (unsigned long p, const void *b, unsigned long c),
         | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      54 |                  (p, b, c), pio, p)
         |                  ~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:674:3: note: expanded from macro 'DEF_PCI_AC_NORET'
     674 |                 __do_##name al;                                 \
         |                 ^~~~~~~~~~~~~~
   <scratch space>:93:1: note: expanded from here
      93 | __do_outsl
         | ^
   arch/powerpc/include/asm/io.h:619:58: note: expanded from macro '__do_outsl'
     619 | #define __do_outsl(p, b, n)     writesl((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
         |                                         ~~~~~~~~~~~~~~~~~~~~~^
   In file included from net/mac80211/rc80211_minstrel_ht.c:15:
   In file included from net/mac80211/rate.h:16:
>> net/mac80211/ieee80211_i.h:2655:48: error: void function 'ieee80211_add_wbrf' should not return a value [-Wreturn-type]

2655 | struct cfg80211_chan_def *chandef) { return 0; }
| ^ ~
6 warnings and 1 error generated.
--
In file included from include/linux/ieee80211.h:19:
In file included from include/linux/if_ether.h:19:
In file included from include/linux/skbuff.h:17:
In file included from include/linux/bvec.h:10:
In file included from include/linux/highmem.h:12:
In file included from include/linux/hardirq.h:11:
In file included from arch/powerpc/include/asm/hardirq.h:6:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/powerpc/include/asm/io.h:677:
arch/powerpc/include/asm/io-defs.h:47:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]

      47 | DEF_PCI_AC_NORET(insl, (unsigned long p, void *b, unsigned long c),
         | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      48 |                  (p, b, c), pio, p)
         |                  ~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:674:3: note: expanded from macro 'DEF_PCI_AC_NORET'
     674 |                 __do_##name al;                                 \
         |                 ^~~~~~~~~~~~~~
   <scratch space>:126:1: note: expanded from here
     126 | __do_insl
         | ^
   arch/powerpc/include/asm/io.h:616:56: note: expanded from macro '__do_insl'
     616 | #define __do_insl(p, b, n)      readsl((PCI_IO_ADDR)_IO_BASE+(p), (b), (n))
         |                                        ~~~~~~~~~~~~~~~~~~~~~^
   In file included from net/mac80211/ht.c:15:
   In file included from include/linux/ieee80211.h:19:
   In file included from include/linux/if_ether.h:19:
   In file included from include/linux/skbuff.h:17:
   In file included from include/linux/bvec.h:10:
   In file included from include/linux/highmem.h:12:
   In file included from include/linux/hardirq.h:11:
   In file included from arch/powerpc/include/asm/hardirq.h:6:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:677:
   arch/powerpc/include/asm/io-defs.h:49:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
      49 | DEF_PCI_AC_NORET(outsb, (unsigned long p, const void *b, unsigned long c),
         | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      50 |                  (p, b, c), pio, p)
         |                  ~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:674:3: note: expanded from macro 'DEF_PCI_AC_NORET'
     674 |                 __do_##name al;                                 \
         |                 ^~~~~~~~~~~~~~
   <scratch space>:128:1: note: expanded from here
     128 | __do_outsb
         | ^
   arch/powerpc/include/asm/io.h:617:58: note: expanded from macro '__do_outsb'
     617 | #define __do_outsb(p, b, n)     writesb((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
         |                                         ~~~~~~~~~~~~~~~~~~~~~^
   In file included from net/mac80211/ht.c:15:
   In file included from include/linux/ieee80211.h:19:
   In file included from include/linux/if_ether.h:19:
   In file included from include/linux/skbuff.h:17:
   In file included from include/linux/bvec.h:10:
   In file included from include/linux/highmem.h:12:
   In file included from include/linux/hardirq.h:11:
   In file included from arch/powerpc/include/asm/hardirq.h:6:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:677:
   arch/powerpc/include/asm/io-defs.h:51:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
      51 | DEF_PCI_AC_NORET(outsw, (unsigned long p, const void *b, unsigned long c),
         | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      52 |                  (p, b, c), pio, p)
         |                  ~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:674:3: note: expanded from macro 'DEF_PCI_AC_NORET'
     674 |                 __do_##name al;                                 \
         |                 ^~~~~~~~~~~~~~
   <scratch space>:130:1: note: expanded from here
     130 | __do_outsw
         | ^
   arch/powerpc/include/asm/io.h:618:58: note: expanded from macro '__do_outsw'
     618 | #define __do_outsw(p, b, n)     writesw((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
         |                                         ~~~~~~~~~~~~~~~~~~~~~^
   In file included from net/mac80211/ht.c:15:
   In file included from include/linux/ieee80211.h:19:
   In file included from include/linux/if_ether.h:19:
   In file included from include/linux/skbuff.h:17:
   In file included from include/linux/bvec.h:10:
   In file included from include/linux/highmem.h:12:
   In file included from include/linux/hardirq.h:11:
   In file included from arch/powerpc/include/asm/hardirq.h:6:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:677:
   arch/powerpc/include/asm/io-defs.h:53:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
      53 | DEF_PCI_AC_NORET(outsl, (unsigned long p, const void *b, unsigned long c),
         | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      54 |                  (p, b, c), pio, p)
         |                  ~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:674:3: note: expanded from macro 'DEF_PCI_AC_NORET'
     674 |                 __do_##name al;                                 \
         |                 ^~~~~~~~~~~~~~
   <scratch space>:132:1: note: expanded from here
     132 | __do_outsl
         | ^
   arch/powerpc/include/asm/io.h:619:58: note: expanded from macro '__do_outsl'
     619 | #define __do_outsl(p, b, n)     writesl((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
         |                                         ~~~~~~~~~~~~~~~~~~~~~^
   In file included from net/mac80211/ht.c:18:
>> net/mac80211/ieee80211_i.h:2655:48: error: void function 'ieee80211_add_wbrf' should not return a value [-Wreturn-type]

2655 | struct cfg80211_chan_def *chandef) { return 0; }
| ^ ~
6 warnings and 1 error generated.
..

vim +/ieee80211_add_wbrf +2655 net/mac80211/ieee80211_i.h

2630
2631 u8 ieee80211_ie_len_eht_cap(struct ieee80211_sub_if_data *sdata, u8 iftype);
2632 u8 *ieee80211_ie_build_eht_cap(u8 *pos,

  2633				       const struct ieee80211_sta_he_cap *he_cap,
  2634				       const struct ieee80211_sta_eht_cap *eht_cap,
  2635				       u8 *end,
  2636				       bool for_ap);
  2637	
  2638	void
  2639	ieee80211_eht_cap_ie_to_sta_eht_cap(struct ieee80211_sub_if_data *sdata,
  2640					    struct ieee80211_supported_band *sband,
  2641					    const u8 *he_cap_ie, u8 he_cap_len,
  2642					    const struct ieee80211_eht_cap_elem *eht_cap_ie_elem,
  2643					    u8 eht_cap_len,
  2644					    struct link_sta_info *link_sta);
  2645	
  2646	#ifdef CONFIG_WBRF
  2647	void ieee80211_check_wbrf_support(struct ieee80211_local *local);
  2648	void ieee80211_add_wbrf(struct ieee80211_local *local,
  2649				struct cfg80211_chan_def *chandef);
  2650	void ieee80211_remove_wbrf(struct ieee80211_local *local,
  2651				   struct cfg80211_chan_def *chandef);
  2652	#else
  2653	static inline void ieee80211_check_wbrf_support(struct ieee80211_local *local) { }
  2654	static inline void ieee80211_add_wbrf(struct ieee80211_local *local,
> 2655					      struct cfg80211_chan_def *chandef) { return 0; }

2656 static inline void ieee80211_remove_wbrf(struct ieee80211_local *local,
2657 struct cfg80211_chan_def *chandef) { }
2658 #endif /* CONFIG_WBRF */
2659

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#20 lore raw

Re: [PATCH V5 4/9] wifi: mac80211: Add support for ACPI WBRF

In reply to Evan Quan
Quoted 5 lines
net/mac80211/wbrf.c new file +5 -0
+static void get_chan_freq_boundary(u32 center_freq,
+				   u32 bandwidth,
+				   u64 *start,
+				   u64 *end)
+{

net/mac80211/wbrf.c line 43

Quoted 10 lines
net/mac80211/wbrf.c new file +10 -0
+	bandwidth = MHZ_TO_KHZ(bandwidth);
+	center_freq = MHZ_TO_KHZ(center_freq);
+
+	*start = center_freq - bandwidth / 2;
+	*end = center_freq + bandwidth / 2;
+
+	/* Frequency in HZ is expected */
+	*start = KHZ_TO_HZ(*start);
+	*end = KHZ_TO_HZ(*end);
+}

This seems pretty generic, so maybe it should be moved into the shared code? It can then become a NOP when the functionality if disabled.

Andrew

author
#21 lore raw

RE: [PATCH V5 4/9] wifi: mac80211: Add support for ACPI WBRF

[AMD Official Use Only - General]

Hi Andrew,

Quoted 30 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Saturday, July 1, 2023 9:02 AM
To: Quan, Evan <[email protected]>
Cc: [email protected]; [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Limonciello, Mario <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Lazar, Lijo <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; dri- [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH V5 4/9] wifi: mac80211: Add support for ACPI WBRF

Quoted 10 lines
net/mac80211/wbrf.c new file +10 -0
+static void get_chan_freq_boundary(u32 center_freq,
+                              u32 bandwidth,
+                              u64 *start,
+                              u64 *end)
+{
+   bandwidth = MHZ_TO_KHZ(bandwidth);
+   center_freq = MHZ_TO_KHZ(center_freq);
+
+   *start = center_freq - bandwidth / 2;
+   *end = center_freq + bandwidth / 2;
Quoted 8 lines

net/mac80211/wbrf.c line 43

Quoted 5 lines
net/mac80211/wbrf.c new file +5 -0
+
+   /* Frequency in HZ is expected */
+   *start = KHZ_TO_HZ(*start);
+   *end = KHZ_TO_HZ(*end);
+}

This seems pretty generic, so maybe it should be moved into the shared code? It can then become a NOP when the functionality if disabled.

The shared code you mean is some place around mac80211?
Actually, there are two similar variants existed already: cfg80211_get_start_freq and cfg80211_get_end_freq. The outputs of them are really what most mac80211 logics care.
The new API here is unlikely to be shared by other mac80211 part.
So, I suppose placing it here(only in wbrf.c) seems proper.
How do you think?

Evan

Quoted 2 lines

Andrew

author
#22 lore raw

PATCH v5 5/9 drm/amd/pm: update driver_if and ppsmc headers for coming wbrf feature

In reply to Evan Quan

Add those data structures to support Wifi RFI mitigation feature.

---
 .../pm/swsmu/inc/pmfw_if/smu13_driver_if_v13_0_0.h | 14 +++++++++++++-
 .../pm/swsmu/inc/pmfw_if/smu13_driver_if_v13_0_7.h | 14 +++++++++++++-
 .../amd/pm/swsmu/inc/pmfw_if/smu_v13_0_0_ppsmc.h   |  3 ++-
 .../amd/pm/swsmu/inc/pmfw_if/smu_v13_0_7_ppsmc.h   |  3 ++-
 4 files changed, 30 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu13_driver_if_v13_0_0.h +13 -1
index b686fb68a6e7..d64188fb5839 100644
@@ -388,6 +388,17 @@ typedef struct {
   EccInfo_t  EccInfo[24];
 } EccInfoTable_t;
 
+typedef struct {
+  uint16_t     LowFreq;
+  uint16_t     HighFreq;
+} WifiOneBand_t;
+
+typedef struct {
+  uint32_t         WifiBandEntryNum;
+  WifiOneBand_t    WifiBandEntry[11];
+  uint32_t         MmHubPadding[8];
+} WifiBandEntryTable_t;
+
 //D3HOT sequences
 typedef enum {
   BACO_SEQUENCE,
@@ -1592,7 +1603,8 @@ typedef struct {
 #define TABLE_I2C_COMMANDS            9
 #define TABLE_DRIVER_INFO             10
 #define TABLE_ECCINFO                 11
-#define TABLE_COUNT                   12
+#define TABLE_WIFIBAND                12
+#define TABLE_COUNT                   13
 
 //IH Interupt ID
 #define IH_INTERRUPT_ID_TO_DRIVER                   0xFE
drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu13_driver_if_v13_0_7.h +13 -1
index 4c46a0392451..77483e8485e7 100644
@@ -392,6 +392,17 @@ typedef struct {
   EccInfo_t  EccInfo[24];
 } EccInfoTable_t;
 
+typedef struct {
+  uint16_t     LowFreq;
+  uint16_t     HighFreq;
+} WifiOneBand_t;
+
+typedef struct {
+  uint32_t         WifiBandEntryNum;
+  WifiOneBand_t    WifiBandEntry[11];
+  uint32_t         MmHubPadding[8];
+} WifiBandEntryTable_t;
+
 //D3HOT sequences
 typedef enum {
   BACO_SEQUENCE,
@@ -1624,7 +1635,8 @@ typedef struct {
 #define TABLE_I2C_COMMANDS            9
 #define TABLE_DRIVER_INFO             10
 #define TABLE_ECCINFO                 11
-#define TABLE_COUNT                   12
+#define TABLE_WIFIBAND                12
+#define TABLE_COUNT                   13
 
 //IH Interupt ID
 #define IH_INTERRUPT_ID_TO_DRIVER                   0xFE
drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v13_0_0_ppsmc.h +2 -1
index 10cff75b44d5..c98cc32d11bd 100644
@@ -138,7 +138,8 @@
 #define PPSMC_MSG_SetBadMemoryPagesRetiredFlagsPerChannel 0x4A
 #define PPSMC_MSG_SetPriorityDeltaGain           0x4B
 #define PPSMC_MSG_AllowIHHostInterrupt           0x4C
-#define PPSMC_Message_Count                      0x4D
+#define PPSMC_MSG_EnableUCLKShadow               0x51
+#define PPSMC_Message_Count                      0x52
 
 //Debug Dump Message
 #define DEBUGSMC_MSG_TestMessage                    0x1
drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v13_0_7_ppsmc.h +2 -1
index 6aaefca9b595..a6bf9cdd130e 100644
@@ -134,6 +134,7 @@
 #define PPSMC_MSG_SetBadMemoryPagesRetiredFlagsPerChannel 0x4A
 #define PPSMC_MSG_SetPriorityDeltaGain           0x4B
 #define PPSMC_MSG_AllowIHHostInterrupt           0x4C
-#define PPSMC_Message_Count                      0x4D
+#define PPSMC_MSG_EnableUCLKShadow               0x51
+#define PPSMC_Message_Count                      0x52
 
 #endif
Signature · 1 line
2.34.1
author
#23 lore raw

PATCH v5 6/9 drm/amd/pm: setup the framework to support Wifi RFI mitigation feature

In reply to Evan Quan

With WBRF feature supported, as a driver responding to the frequencies, amdgpu driver is able to do shadow pstate switching to mitigate possible interference(between its (G-)DDR memory clocks and local radio module frequency bands used by Wifi 6/6e/7).

--
v1->v2:
- update the prompt for feature support(Lijo)

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h           |   1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |  19 ++
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     | 194 ++++++++++++++++++
 drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h |  23 +++
 drivers/gpu/drm/amd/pm/swsmu/smu_internal.h   |   3 +
 5 files changed, 240 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index 02b827785e39..785d9b43f0c4 100644
@@ -241,6 +241,7 @@ extern int amdgpu_num_kcq;
 #define AMDGPU_VCNFW_LOG_SIZE (32 * 1024)
 extern int amdgpu_vcnfw_log;
 extern int amdgpu_sg_display;
+extern int amdgpu_wbrf;
 
 #define AMDGPU_VM_MAX_NUM_CTX			4096
 #define AMDGPU_SG_THRESHOLD			(256*1024*1024)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +19 -0
index 393b6fb7a71d..6c08a0cf8381 100644
@@ -191,6 +191,7 @@ int amdgpu_smartshift_bias;
 int amdgpu_use_xgmi_p2p = 1;
 int amdgpu_vcnfw_log;
 int amdgpu_sg_display = -1; /* auto */
+int amdgpu_wbrf = -1;
 
 static void amdgpu_drv_delayed_reset_work_handler(struct work_struct *work);
 
@@ -948,6 +949,24 @@ MODULE_PARM_DESC(smu_pptable_id,
 	"specify pptable id to be used (-1 = auto(default) value, 0 = use pptable from vbios, > 0 = soft pptable id)");
 module_param_named(smu_pptable_id, amdgpu_smu_pptable_id, int, 0444);
 
+#ifdef CONFIG_WBRF
+/**
+ * DOC: wbrf (int)
+ * Enable Wifi RFI interference mitigation feature.
+ * Due to electrical and mechanical constraints there may be likely interference of
+ * relatively high-powered harmonics of the (G-)DDR memory clocks with local radio
+ * module frequency bands used by Wifi 6/6e/7. To mitigate the possible RFI interference,
+ * with this feature enabled, PMFW will use either “shadowed P-State” or “P-State” based
+ * on active list of frequencies in-use (to be avoided) as part of initial setting or
+ * P-state transition. However, there may be potential performance impact with this
+ * feature enabled.
+ * (0 = disabled, 1 = enabled, -1 = auto (default setting, will be enabled if supported))
+ */
+MODULE_PARM_DESC(wbrf,
+	"Enable Wifi RFI interference mitigation (0 = disabled, 1 = enabled, -1 = auto(default)");
+module_param_named(wbrf, amdgpu_wbrf, int, 0444);
+#endif
+
 /* These devices are not supported by amdgpu.
  * They are supported by the mach64, r128, radeon drivers
  */
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +194 -0

224 lines not on this page · raw message

drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h +23 -0
index 09469c750a96..5b2343cfc69b 100644
@@ -22,6 +22,8 @@
 #ifndef __AMDGPU_SMU_H__
 #define __AMDGPU_SMU_H__
 
+#include <linux/wbrf.h>
+
 #include "amdgpu.h"
 #include "kgd_pp_interface.h"
 #include "dm_pp_interface.h"
@@ -573,6 +575,10 @@ struct smu_context
 	u32 debug_param_reg;
 	u32 debug_msg_reg;
 	u32 debug_resp_reg;
+
+	/* data structures for wbrf feature support */
+	bool				wbrf_supported;
+	struct notifier_block		wbrf_notifier;
 };
 
 struct i2c_adapter;
@@ -1354,6 +1360,23 @@ struct pptable_funcs {
 	 * @init_pptable_microcode: Prepare the pptable microcode to upload via PSP
 	 */
 	int (*init_pptable_microcode)(struct smu_context *smu);
+
+	/**
+	 * @is_asic_wbrf_supported: check whether PMFW supports the wbrf feature
+	 */
+	bool (*is_asic_wbrf_supported)(struct smu_context *smu);
+
+	/**
+	 * @enable_uclk_shadow: Enable the uclk shadow feature on wbrf supported
+	 */
+	int (*enable_uclk_shadow)(struct smu_context *smu,
+				  bool enablement);
+
+	/**
+	 * @set_wbrf_exclusion_ranges: notify SMU the wifi bands occupied
+	 */
+	int (*set_wbrf_exclusion_ranges)(struct smu_context *smu,
+					 struct exclusion_range *exclusion_ranges);
 };
 
 typedef enum {
drivers/gpu/drm/amd/pm/swsmu/smu_internal.h +3 -0
index ceb13c838067..67d7495ab49e 100644
@@ -97,6 +97,9 @@
 #define smu_get_default_config_table_settings(smu, config_table)	smu_ppt_funcs(get_default_config_table_settings, -EOPNOTSUPP, smu, config_table)
 #define smu_set_config_table(smu, config_table)				smu_ppt_funcs(set_config_table, -EOPNOTSUPP, smu, config_table)
 #define smu_init_pptable_microcode(smu)					smu_ppt_funcs(init_pptable_microcode, 0, smu)
+#define smu_is_asic_wbrf_supported(smu)					smu_ppt_funcs(is_asic_wbrf_supported, false, smu)
+#define smu_enable_uclk_shadow(smu, enablement)				smu_ppt_funcs(enable_uclk_shadow, 0, smu, enablement)
+#define smu_set_wbrf_exclusion_ranges(smu, exclusion_ranges)		smu_ppt_funcs(set_wbrf_exclusion_ranges, -EOPNOTSUPP, smu, exclusion_ranges)
 
 #endif
 #endif
Signature · 1 line
2.34.1
author
#24 lore raw

PATCH v5 7/9 drm/amd/pm: add flood detection for wbrf events

In reply to Evan Quan

To protect PMFW from being overloaded.

---
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     | 30 +++++++++++++++----
 drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h |  7 +++++
 2 files changed, 32 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +25 -5
index 83d428e890df..a4cfaf8a6f59 100644
@@ -1278,7 +1278,8 @@ static int smu_wbrf_event_handler(struct notifier_block *nb,
 
 	switch (action) {
 	case WBRF_CHANGED:
-		smu_wbrf_handle_exclusion_ranges(smu);
+		schedule_delayed_work(&smu->wbrf_delayed_work,
+				      msecs_to_jiffies(SMU_WBRF_EVENT_HANDLING_PACE));
 		break;
 	default:
 		return NOTIFY_DONE;
@@ -1287,6 +1288,21 @@ static int smu_wbrf_event_handler(struct notifier_block *nb,
 	return NOTIFY_OK;
 }
 
+/**
+ * smu_wbrf_delayed_work_handler - callback on delayed work timer expired
+ *
+ * @work: struct work_struct pointer
+ *
+ * Flood is over and driver will consume the latest exclusion ranges.
+ */
+static void smu_wbrf_delayed_work_handler(struct work_struct *work)
+{
+	struct smu_context *smu =
+		container_of(work, struct smu_context, wbrf_delayed_work.work);
+
+	smu_wbrf_handle_exclusion_ranges(smu);
+}
+
 /**
  * smu_wbrf_support_check - check wbrf support
  *
@@ -1323,6 +1339,9 @@ static int smu_wbrf_init(struct smu_context *smu)
 	if (!smu->wbrf_supported)
 		return 0;
 
+	INIT_DELAYED_WORK(&smu->wbrf_delayed_work,
+			  smu_wbrf_delayed_work_handler);
+
 	smu->wbrf_notifier.notifier_call = smu_wbrf_event_handler;
 	ret = wbrf_register_notifier(&smu->wbrf_notifier);
 	if (ret)
@@ -1333,11 +1352,10 @@ static int smu_wbrf_init(struct smu_context *smu)
 	 * before our driver loaded. To make sure our driver
 	 * is awared of those exclusion ranges.
 	 */
-	ret = smu_wbrf_handle_exclusion_ranges(smu);
-	if (ret)
-		dev_err(adev->dev, "Failed to handle wbrf exclusion ranges\n");
+	schedule_delayed_work(&smu->wbrf_delayed_work,
+			      msecs_to_jiffies(SMU_WBRF_EVENT_HANDLING_PACE));
 
-	return ret;
+	return 0;
 }
 
 /**
@@ -1353,6 +1371,8 @@ static void smu_wbrf_fini(struct smu_context *smu)
 		return;
 
 	wbrf_unregister_notifier(&smu->wbrf_notifier);
+
+	cancel_delayed_work_sync(&smu->wbrf_delayed_work);
 }
 
 static int smu_smc_hw_setup(struct smu_context *smu)
drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h +7 -0
index 5b2343cfc69b..5df28d4a8c30 100644
@@ -480,6 +480,12 @@ struct stb_context {
 
 #define WORKLOAD_POLICY_MAX 7
 
+/*
+ * Configure wbrf event handling pace as there can be only one
+ * event processed every SMU_WBRF_EVENT_HANDLING_PACE ms.
+ */
+#define SMU_WBRF_EVENT_HANDLING_PACE	10
+
 struct smu_context
 {
 	struct amdgpu_device            *adev;
@@ -579,6 +585,7 @@ struct smu_context
 	/* data structures for wbrf feature support */
 	bool				wbrf_supported;
 	struct notifier_block		wbrf_notifier;
+	struct delayed_work		wbrf_delayed_work;
 };
 
 struct i2c_adapter;
Signature · 1 line
2.34.1
#25 lore raw

Re: [PATCH V5 7/9] drm/amd/pm: add flood detection for wbrf events

kernel test robot noticed the following build warnings:

Hi Evan,

kernel test robot noticed the following build warnings:

[auto build test WARNING on wireless-next/main]
[also build test WARNING on wireless/main v6.4]
[cannot apply to drm-misc/drm-misc-next linus/master next-20230630] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Evan-Quan/drivers-core-Add-support-for-Wifi-band-RF-mitigations/20230630-183633
base:   https://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless-next.git main
patch link:    https://lore.kernel.org/r/20230630103240.1557100-8-evan.quan%40amd.com
patch subject: [PATCH V5 7/9] drm/amd/pm: add flood detection for wbrf events
config: x86_64-buildonly-randconfig-r003-20230630 (https://download.01.org/0day-ci/archive/20230630/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce: (https://download.01.org/0day-ci/archive/20230630/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

drivers/gpu/drm/amd/amdgpu/../pm/swsmu/amdgpu_smu.c: In function 'smu_wbrf_init':

>> drivers/gpu/drm/amd/amdgpu/../pm/swsmu/amdgpu_smu.c:1336:31: warning: unused variable 'adev' [-Wunused-variable]
    1336 |         struct amdgpu_device *adev = smu->adev;
         |                               ^~~~

vim +/adev +1336 drivers/gpu/drm/amd/amdgpu/../pm/swsmu/amdgpu_smu.c

19fbe240b2627a Evan Quan 2023-06-30  1324  
19fbe240b2627a Evan Quan 2023-06-30  1325  /**
19fbe240b2627a Evan Quan 2023-06-30  1326   * smu_wbrf_init - init driver wbrf support
19fbe240b2627a Evan Quan 2023-06-30  1327   *
19fbe240b2627a Evan Quan 2023-06-30  1328   * @smu: smu_context pointer
19fbe240b2627a Evan Quan 2023-06-30  1329   *
19fbe240b2627a Evan Quan 2023-06-30  1330   * Verifies the AMD ACPI interfaces and registers with the wbrf
19fbe240b2627a Evan Quan 2023-06-30  1331   * notifier chain if wbrf feature is supported.
19fbe240b2627a Evan Quan 2023-06-30  1332   * Returns 0 on success, error on failure.
19fbe240b2627a Evan Quan 2023-06-30  1333   */
19fbe240b2627a Evan Quan 2023-06-30  1334  static int smu_wbrf_init(struct smu_context *smu)
19fbe240b2627a Evan Quan 2023-06-30  1335  {
19fbe240b2627a Evan Quan 2023-06-30 @1336  	struct amdgpu_device *adev = smu->adev;
19fbe240b2627a Evan Quan 2023-06-30  1337  	int ret;
19fbe240b2627a Evan Quan 2023-06-30  1338  
19fbe240b2627a Evan Quan 2023-06-30  1339  	if (!smu->wbrf_supported)
19fbe240b2627a Evan Quan 2023-06-30  1340  		return 0;
19fbe240b2627a Evan Quan 2023-06-30  1341  
0b8224d2686865 Evan Quan 2023-06-30  1342  	INIT_DELAYED_WORK(&smu->wbrf_delayed_work,
0b8224d2686865 Evan Quan 2023-06-30  1343  			  smu_wbrf_delayed_work_handler);
0b8224d2686865 Evan Quan 2023-06-30  1344  
19fbe240b2627a Evan Quan 2023-06-30  1345  	smu->wbrf_notifier.notifier_call = smu_wbrf_event_handler;
19fbe240b2627a Evan Quan 2023-06-30  1346  	ret = wbrf_register_notifier(&smu->wbrf_notifier);
19fbe240b2627a Evan Quan 2023-06-30  1347  	if (ret)
19fbe240b2627a Evan Quan 2023-06-30  1348  		return ret;
19fbe240b2627a Evan Quan 2023-06-30  1349  
19fbe240b2627a Evan Quan 2023-06-30  1350  	/*
19fbe240b2627a Evan Quan 2023-06-30  1351  	 * Some wifiband exclusion ranges may be already there
19fbe240b2627a Evan Quan 2023-06-30  1352  	 * before our driver loaded. To make sure our driver
19fbe240b2627a Evan Quan 2023-06-30  1353  	 * is awared of those exclusion ranges.
19fbe240b2627a Evan Quan 2023-06-30  1354  	 */
0b8224d2686865 Evan Quan 2023-06-30  1355  	schedule_delayed_work(&smu->wbrf_delayed_work,
0b8224d2686865 Evan Quan 2023-06-30  1356  			      msecs_to_jiffies(SMU_WBRF_EVENT_HANDLING_PACE));
19fbe240b2627a Evan Quan 2023-06-30  1357  
0b8224d2686865 Evan Quan 2023-06-30  1358  	return 0;
19fbe240b2627a Evan Quan 2023-06-30  1359  }
19fbe240b2627a Evan Quan 2023-06-30  1360  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author
#26 lore raw

PATCH v5 8/9 drm/amd/pm: enable Wifi RFI mitigation feature support for SMU13.0.0

In reply to Evan Quan

Fulfill the SMU13.0.0 support for Wifi RFI mitigation feature.

---
 drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h |  3 +
 drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h  |  3 +-
 drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h  |  3 +
 .../gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c    |  9 +++
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c  | 60 +++++++++++++++++++
 5 files changed, 77 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h +3 -0
index 5df28d4a8c30..32764c509ba8 100644
@@ -325,6 +325,7 @@ enum smu_table_id
 	SMU_TABLE_PACE,
 	SMU_TABLE_ECCINFO,
 	SMU_TABLE_COMBO_PPTABLE,
+	SMU_TABLE_WIFIBAND,
 	SMU_TABLE_COUNT,
 };
 
@@ -1499,6 +1500,8 @@ enum smu_baco_seq {
 			 __dst_size);					   \
 })
 
+#define HZ_IN_MHZ		1000000U
+
 #if !defined(SWSMU_CODE_LAYER_L2) && !defined(SWSMU_CODE_LAYER_L3) && !defined(SWSMU_CODE_LAYER_L4)
 int smu_get_power_limit(void *handle,
 			uint32_t *limit,
drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h +2 -1
index 297b70b9388f..5bbb60289a79 100644
@@ -245,7 +245,8 @@
 	__SMU_DUMMY_MAP(AllowGpo),	\
 	__SMU_DUMMY_MAP(Mode2Reset),	\
 	__SMU_DUMMY_MAP(RequestI2cTransaction), \
-	__SMU_DUMMY_MAP(GetMetricsTable),
+	__SMU_DUMMY_MAP(GetMetricsTable), \
+	__SMU_DUMMY_MAP(EnableUCLKShadow),
 
 #undef __SMU_DUMMY_MAP
 #define __SMU_DUMMY_MAP(type)	SMU_MSG_##type
drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h +3 -0
index df3baaab0037..b6fae9b92303 100644
@@ -303,5 +303,8 @@ int smu_v13_0_get_pptable_from_firmware(struct smu_context *smu,
 					uint32_t *size,
 					uint32_t pptable_id);
 
+int smu_v13_0_enable_uclk_shadow(struct smu_context *smu,
+				 bool enablement);
+
 #endif
 #endif
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c +9 -0
index ca379181081c..7cb24c862720 100644
@@ -2453,3 +2453,12 @@ int smu_v13_0_mode1_reset(struct smu_context *smu)
 
 	return ret;
 }
+
+int smu_v13_0_enable_uclk_shadow(struct smu_context *smu,
+				 bool enablement)
+{
+	return smu_cmn_send_smc_msg_with_param(smu,
+					       SMU_MSG_EnableUCLKShadow,
+					       enablement,
+					       NULL);
+}
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +60 -0

90 lines not on this page · raw message

Signature · 1 line
2.34.1
author
#27 lore raw

PATCH v5 9/9 drm/amd/pm: enable Wifi RFI mitigation feature support for SMU13.0.7

In reply to Evan Quan

Fulfill the SMU13.0.7 support for Wifi RFI mitigation feature.

---
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c  | 59 +++++++++++++++++++
 1 file changed, 59 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +59 -0
index bba621615abf..4a680756208b 100644
@@ -126,6 +126,7 @@ static struct cmn2asic_msg_mapping smu_v13_0_7_message_map[SMU_MSG_MAX_COUNT] =
 	MSG_MAP(AllowGpo,			PPSMC_MSG_SetGpoAllow,           0),
 	MSG_MAP(GetPptLimit,			PPSMC_MSG_GetPptLimit,                 0),
 	MSG_MAP(NotifyPowerSource,		PPSMC_MSG_NotifyPowerSource,           0),
+	MSG_MAP(EnableUCLKShadow,		PPSMC_MSG_EnableUCLKShadow,            0),
 };
 
 static struct cmn2asic_mapping smu_v13_0_7_clk_map[SMU_CLK_COUNT] = {
@@ -206,6 +207,7 @@ static struct cmn2asic_mapping smu_v13_0_7_table_map[SMU_TABLE_COUNT] = {
 	TAB_MAP(DRIVER_SMU_CONFIG),
 	TAB_MAP(ACTIVITY_MONITOR_COEFF),
 	[SMU_TABLE_COMBO_PPTABLE] = {1, TABLE_COMBO_PPTABLE},
+	TAB_MAP(WIFIBAND),
 };
 
 static struct cmn2asic_mapping smu_v13_0_7_pwr_src_map[SMU_POWER_SOURCE_COUNT] = {
@@ -488,6 +490,9 @@ static int smu_v13_0_7_tables_init(struct smu_context *smu)
 	               AMDGPU_GEM_DOMAIN_VRAM);
 	SMU_TABLE_INIT(tables, SMU_TABLE_COMBO_PPTABLE, MP0_MP1_DATA_REGION_SIZE_COMBOPPTABLE,
 			PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
+	SMU_TABLE_INIT(tables, SMU_TABLE_WIFIBAND,
+		       sizeof(WifiBandEntryTable_t), PAGE_SIZE,
+		       AMDGPU_GEM_DOMAIN_VRAM);
 
 	smu_table->metrics_table = kzalloc(sizeof(SmuMetricsExternal_t), GFP_KERNEL);
 	if (!smu_table->metrics_table)
@@ -1722,6 +1727,57 @@ static int smu_v13_0_7_set_df_cstate(struct smu_context *smu,
 					       NULL);
 }
 
+static bool smu_v13_0_7_wbrf_support_check(struct smu_context *smu)
+{
+	return smu->smc_fw_version > 0x00524600;
+}
+
+static int smu_v13_0_7_set_wbrf_exclusion_ranges(struct smu_context *smu,
+						 struct exclusion_range *exclusion_ranges)
+{
+	WifiBandEntryTable_t wifi_bands;
+	int valid_entries = 0;
+	int ret, i;
+
+	memset(&wifi_bands, 0, sizeof(wifi_bands));
+	for (i = 0; i < ARRAY_SIZE(wifi_bands.WifiBandEntry); i++) {
+		if (!exclusion_ranges[i].start &&
+		    !exclusion_ranges[i].end)
+			break;
+
+		/* PMFW expects the inputs to be in Mhz unit */
+		wifi_bands.WifiBandEntry[valid_entries].LowFreq =
+			DIV_ROUND_DOWN_ULL(exclusion_ranges[i].start, HZ_IN_MHZ);
+		wifi_bands.WifiBandEntry[valid_entries++].HighFreq =
+			DIV_ROUND_UP_ULL(exclusion_ranges[i].end, HZ_IN_MHZ);
+	}
+	wifi_bands.WifiBandEntryNum = valid_entries;
+
+	/*
+	 * Per confirm with PMFW team, WifiBandEntryNum = 0 is a valid setting.
+	 * Considering the scenarios below:
+	 * - At first the wifi device adds an exclusion range e.g. (2400,2500) to
+	 *   BIOS and our driver gets notified. We will set WifiBandEntryNum = 1
+	 *   and pass the WifiBandEntry (2400, 2500) to PMFW.
+	 *
+	 * - Later the wifi device removes the wifiband list added above and
+	 *   our driver gets notified again. At this time, driver will set
+	 *   WifiBandEntryNum = 0 and pass an empty WifiBandEntry list to PMFW.
+	 *   - PMFW may still need to do some uclk shadow update(e.g. switching
+	 *     from shadow clock back to primary clock) on receiving this.
+	 */
+
+	ret = smu_cmn_update_table(smu,
+				   SMU_TABLE_WIFIBAND,
+				   0,
+				   (void *)(&wifi_bands),
+				   true);
+	if (ret)
+		dev_err(smu->adev->dev, "Failed to set wifiband!");
+
+	return ret;
+}
+
 static const struct pptable_funcs smu_v13_0_7_ppt_funcs = {
 	.get_allowed_feature_mask = smu_v13_0_7_get_allowed_feature_mask,
 	.set_default_dpm_table = smu_v13_0_7_set_default_dpm_table,
@@ -1787,6 +1843,9 @@ static const struct pptable_funcs smu_v13_0_7_ppt_funcs = {
 	.set_mp1_state = smu_v13_0_7_set_mp1_state,
 	.set_df_cstate = smu_v13_0_7_set_df_cstate,
 	.gpo_control = smu_v13_0_gpo_control,
+	.is_asic_wbrf_supported = smu_v13_0_7_wbrf_support_check,
+	.enable_uclk_shadow = smu_v13_0_enable_uclk_shadow,
+	.set_wbrf_exclusion_ranges = smu_v13_0_7_set_wbrf_exclusion_ranges,
 };
 
 void smu_v13_0_7_set_ppt_funcs(struct smu_context *smu)
Signature · 1 line
2.34.1