Skip to contentSkip to conversation

wifi: ath12k: order hw group devices by WSI index

PATCH In review Benoit Masson 3 participants 4 messages Sep 27 – Sep 28

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wifi: ath12k: order hw group devices by WSI index

On multi-chip (WSI/MLO) platforms the devices of a hardware group are added to ag->ab[] in PCI probe completion order (ab->device_id = ag->num_probed++). PCI probe is asynchronous, so the order in which the chips complete firmware bring-up is not stable across boots.

ath12k_mac_allocate() builds the wiphy radio array directly from ag->ab[], and takes the wiphy device from the first entry. As a result both the wiphy sysfs path and the mapping of radio indices to bands change from boot to boot on boards such as the TP-Link Archer BE800, which has three single-band QCN9274/QCN9224 radios in one group. A persisted hostapd configuration that pins radio0 to a band then attaches to a random band.

Order the devices used to build pdev_map[] by ab->wsi_info.index, which is derived deterministically from the device tree WSI ring and the qcom,wsi-controller node. ath12k already uses wsi_info.index as the canonical per-device index for the firmware link IDs in ath12k_host_cap_hw_link_id_init().

Note that ag->ab[] itself is left untouched: the unassign path indexes it by ab->device_id, which is the probe-order id.

Fixes 6f245ea0ec6c ("wifi: ath12k: introduce device group abstraction")
---
 drivers/net/wireless/ath/ath12k/mac.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/net/wireless/ath/ath12k/mac.c +18 -2
index 99bf5cf..6505255 100644
@@ -15444,6 +15444,7 @@ static void ath12k_mac_set_device_defaults(struct ath12k_base *ab)
 int ath12k_mac_allocate(struct ath12k_hw_group *ag)
 {
 	struct ath12k_pdev_map pdev_map[ATH12K_GROUP_MAX_RADIO];
+	struct ath12k_base *ab_order[ATH12K_MAX_DEVICES] = {};
 	int mac_id, device_id, total_radio, num_hw;
 	struct ath12k_base *ab;
 	struct ath12k_hw *ah;
@@ -15467,6 +15468,21 @@ int ath12k_mac_allocate(struct ath12k_hw_group *ag)
 	if (WARN_ON(total_radio > ATH12K_GROUP_MAX_RADIO))
 		return -ENOSPC;
 
+	/*
+	 * Order the devices deterministically by WSI index instead of PCI
+	 * probe completion order, so that the wiphy and the radio index to
+	 * band mapping do not change from boot to boot.
+	 */
+	for (i = 0; i < ag->num_devices; i++) {
+		ab = ag->ab[i];
+		if (!ab)
+			continue;
+		if (WARN_ON(ab->wsi_info.index >= ATH12K_MAX_DEVICES))
+			return -EINVAL;
+
+		ab_order[ab->wsi_info.index] = ab;
+	}
+
 	/* All pdev get combined and register as single wiphy based on
 	 * hardware group which participate in multi-link operation else
 	 * each pdev get register separately.
@@ -15483,12 +15499,12 @@ int ath12k_mac_allocate(struct ath12k_hw_group *ag)
 	mac_id = 0;
 	for (i = 0; i < num_hw; i++) {
 		for (j = 0; j < radio_per_hw; j++) {
-			if (device_id >= ag->num_devices || !ag->ab[device_id]) {
+			if (device_id >= ag->num_devices || !ab_order[device_id]) {
 				ret = -ENOSPC;
 				goto err;
 			}
 
-			ab = ag->ab[device_id];
+			ab = ab_order[device_id];
 
 			/*
 			 * the assumption is all devices within an ah
Signature · 1 line
2.54.0 (Apple Git-157)
#1 lore raw
Quoted 48 lines · Benoit Masson

On multi-chip (WSI/MLO) platforms the devices of a hardware group are added to ag->ab[] in PCI probe completion order (ab->device_id = ag->num_probed++). PCI probe is asynchronous, so the order in which the chips complete firmware bring-up is not stable across boots.

ath12k_mac_allocate() builds the wiphy radio array directly from ag->ab[], and takes the wiphy device from the first entry. As a result both the wiphy sysfs path and the mapping of radio indices to bands change from boot to boot on boards such as the TP-Link Archer BE800, which has three single-band QCN9274/QCN9224 radios in one group. A persisted hostapd configuration that pins radio0 to a band then attaches to a random band.

Order the devices used to build pdev_map[] by ab->wsi_info.index, which is derived deterministically from the device tree WSI ring and the qcom,wsi-controller node. ath12k already uses wsi_info.index as the canonical per-device index for the firmware link IDs in ath12k_host_cap_hw_link_id_init().

Note that ag->ab[] itself is left untouched: the unassign path indexes it by ab->device_id, which is the probe-order id.

Fixes 6f245ea0ec6c ("wifi: ath12k: introduce device group abstraction")
---
  drivers/net/wireless/ath/ath12k/mac.c | 20 ++++++++++++++++++--
  1 file changed, 18 insertions(+), 2 deletions(-)
drivers/net/wireless/ath/ath12k/mac.c +4 -0
index 99bf5cf..6505255 100644
@@ -15444,6 +15444,7 @@ static void ath12k_mac_set_device_defaults(struct ath12k_base *ab)
  int ath12k_mac_allocate(struct ath12k_hw_group *ag)
  {
  	struct ath12k_pdev_map pdev_map[ATH12K_GROUP_MAX_RADIO];
+	struct ath12k_base *ab_order[ATH12K_MAX_DEVICES] = {};
  	int mac_id, device_id, total_radio, num_hw;
  	struct ath12k_base *ab;
  	struct ath12k_hw *ah;
@@ -15467,6 +15468,21 @@ int ath12k_mac_allocate(struct ath12k_hw_group *ag)
  	if (WARN_ON(total_radio > ATH12K_GROUP_MAX_RADIO))
  		return -ENOSPC;
 
+	/*
+	 * Order the devices deterministically by WSI index instead of PCI
+	 * probe completion order, so that the wiphy and the radio index to

drivers/net/wireless/ath/ath12k/mac.c int ath12k_mac_allocate(struct ath12k_hw_group *ag) · line 15483

Quoted 10 lines
drivers/net/wireless/ath/ath12k/mac.c +10 -0
+	 * band mapping do not change from boot to boot.
+	 */
+	for (i = 0; i < ag->num_devices; i++) {
+		ab = ag->ab[i];
+		if (!ab)
+			continue;
+		if (WARN_ON(ab->wsi_info.index >= ATH12K_MAX_DEVICES))
+			return -EINVAL;
+
+		ab_order[ab->wsi_info.index] = ab;

Maintaining the ab/ar ordering in ah based on the WSI index feels like the wrong layer. The WSI index is a property of a device's position in the group (ag) based on DT.

Did we consider placing ab into ag->ab[] deterministically based on wsi_info.index? Do you foresee any issues with that?

something like below in ath12k_core_hw_group_assign(),

-       ab->device_id = ag->num_probed++;
+       ag->num_probed++;
+       ab->device_id = wsi->index;
        ag->ab[ab->device_id] = ab;

If that works, ath12k_mac_allocate() wouldn't need the new ab_order[] array at all. It could simply iterate over ag->ab[i] directly.

Quoted 20 lines
drivers/net/wireless/ath/ath12k/mac.c +4 -2
+	}
+
  	/* All pdev get combined and register as single wiphy based on
  	 * hardware group which participate in multi-link operation else
  	 * each pdev get register separately.
@@ -15483,12 +15499,12 @@ int ath12k_mac_allocate(struct ath12k_hw_group *ag)
  	mac_id = 0;
  	for (i = 0; i < num_hw; i++) {
  		for (j = 0; j < radio_per_hw; j++) {
-			if (device_id >= ag->num_devices || !ag->ab[device_id]) {
+			if (device_id >= ag->num_devices || !ab_order[device_id]) {
  				ret = -ENOSPC;
  				goto err;
  			}
 
-			ab = ag->ab[device_id];
+			ab = ab_order[device_id];
 
  			/*
  			 * the assumption is all devices within an ah
Signature · 1 line
Ramesh
#2 lore raw

PATCH 1/1 wifi: ath12k: assign device id from the WSI index

Devices of a hardware group are added to ag->ab[] in PCI probe completion order (ab->device_id = ag->num_probed++). The wiphy radio array is built from ag->ab[] and the wiphy device is taken from its first entry, so the wiphy path and the radio index to band mapping change on every boot.

Store each ab in ag->ab[] at its wsi_info.index, which is derived from the device tree WSI ring. The group order is then deterministic. ag->num_probed remains the group device counter. The unassign path is unchanged, it already indexes ag->ab[] by ab->device_id.

Verified on TP-Link Archer BE800 (three single-band radios in one group): the wiphy path and the radio index to band mapping are identical across cold boots.

Fixes 6f245ea0ec6c ("wifi: ath12k: introduce device group abstraction")

---
Changes in v2:
- Set ab->device_id from wsi_info.index in ath12k_core_hw_group_assign() instead of reordering pdev_map[] in ath12k_mac_allocate(), as suggested by Rameshkumar. mac.c is no longer modified.

---
 drivers/net/wireless/ath/ath12k/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/wireless/ath/ath12k/core.c +2 -1
index 262a204..f43319f 100644
@@ -2029,7 +2029,8 @@ exit:
 		goto invalid_group;
 	}
 
-	ab->device_id = ag->num_probed++;
+	ag->num_probed++;
+	ab->device_id = wsi->index;
 	ag->ab[ab->device_id] = ab;
 	ab->ag = ag;
 
Signature · 1 line
2.54.0 (Apple Git-157)
#3 lore raw

Re: [PATCH] wifi: ath12k: assign device id from the WSI index

Quoted 5 lines · Benoit Masson

Devices of a hardware group are added to ag->ab[] in PCI probe completion order (ab->device_id = ag->num_probed++). The wiphy radio array is built from ag->ab[] and the wiphy device is taken from its first entry, so the wiphy path and the radio index to band mapping change on every boot.

you don't describe why this is is a problem, and hence why it should be considered for backporting to stable kernels.

Quoted 6 lines

Store each ab in ag->ab[] at its wsi_info.index, which is derived from the device tree WSI ring. The group order is then deterministic. ag->num_probed remains the group device counter. The unassign path is unchanged, it already indexes ag->ab[] by ab->device_id.

Quoted 7 lines

Verified on TP-Link Archer BE800 (three single-band radios in one group): the wiphy path and the radio index to band mapping are identical across cold boots.

Fixes 6f245ea0ec6c ("wifi: ath12k: introduce device group abstraction")

SOB doesn't match your From address. So you either need to change your SOB, update your From address in your e-mail agent, or add a From: tag to you patch so that From == SOB

Quoted 5 lines

---
Changes in v2:
- Set ab->device_id from wsi_info.index in ath12k_core_hw_group_assign() instead of reordering pdev_map[] in ath12k_mac_allocate(), as suggested by Rameshkumar. mac.c is no longer modified.

your e-mail subject doesn't reflect that this is a v2, and it was threaded instead of being sent as a separate e-mail thread.

when you send a v3 that addresses the above please make sure to use a properly versioned subject and send as a separate thread.

Thanks
/jeff