wifi: ath12k: provide MAC address list for single-radio wiphys
PATCH v2 1/1 wifi: ath12k: provide MAC address list for single-radio wiphys
From: Vitor Soares <[email protected]>
ath12k supports creating vdevs with addresses provided by mac80211. Userspace can already make concurrent interfaces work by explicitly assigning different locally administered addresses.
However, ath12k does not advertise an address list, so when a second interface is created without an explicit address, mac80211 has nothing to pick from and falls back to the permanent address. If the first interface is already running with that address, bringing up the second one fails with -ENOTUNIQ.
As in ath11k, provide a list of usable addresses so ieee80211_assign_perm_addr() can hand each new interface an unused one. Keep the first entry as the radio's own MAC address. Generate the remaining entries as locally administered variants by changing only the upper nibble of the first octet, which naturally limits the pool to 16 unique addresses.
The wiphy->addresses semantics are hardware-specific in ath12k: some platforms use it as an interface MAC address pool, while others use it for firmware-provided per-radio addresses. Gate host-generated addresses behind host_alloc_iface_mac and enable it for WCN7850.
Handle only single-radio WCN7850 wiphys. Wiphys with more than one radio and other hardware families behave exactly as before.
Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c7-00108-QCAHMTSWPL_V1.0_V2.0_SILICONZ_UPSTREAM-3
---
v2:
- Gate generated interface MAC address list behind hw_params host_alloc_iface_mac, as suggested by Kang Yang.
- Enable it only for WCN7850, the only part available for testing here.
- Add Assisted-by: tag.
- Link for v1: https://lore.kernel.org/all/[email protected]/
--- drivers/net/wireless/ath/ath12k/hw.h | 1 + drivers/net/wireless/ath/ath12k/mac.c | 52 ++++++++++++++++++++++ drivers/net/wireless/ath/ath12k/wifi7/hw.c | 6 +++ 3 files changed, 59 insertions(+)
drivers/net/wireless/ath/ath12k/hw.h +1 -0
@@ -238,6 +238,7 @@ struct ath12k_hw_params { } client;bool host_alloc_ml_id; +bool host_alloc_iface_mac; };struct ath12k_hw_ops {
drivers/net/wireless/ath/ath12k/mac.c +52 -0
76 lines not on this page · raw message
drivers/net/wireless/ath/ath12k/wifi7/hw.c +6 -0
@@ -445,6 +445,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { }, .host_alloc_ml_id = true, + .host_alloc_iface_mac = false, }, { .name = "wcn7850 hw2.0",
@@ -539,6 +540,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { }, .host_alloc_ml_id = false, + .host_alloc_iface_mac = true, }, { .name = "qcn9274 hw2.0",
@@ -629,6 +631,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { }, .host_alloc_ml_id = true, + .host_alloc_iface_mac = false, }, { .name = "ipq5332 hw1.0",
@@ -713,6 +716,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { }, .host_alloc_ml_id = true, + .host_alloc_iface_mac = false, }, { .name = "qcc2072 hw1.0",
@@ -808,6 +812,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { }, .host_alloc_ml_id = false, + .host_alloc_iface_mac = false, }, { .name = "ipq5424 hw1.0",
@@ -895,6 +900,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { }, .host_alloc_ml_id = true, + .host_alloc_iface_mac = false, }, };
Signature · 1 line
2.55.0
Quoted 68 lines · Vitor Soares
From: Vitor Soares <[email protected]>
ath12k supports creating vdevs with addresses provided by mac80211. Userspace can already make concurrent interfaces work by explicitly assigning different locally administered addresses.
However, ath12k does not advertise an address list, so when a second interface is created without an explicit address, mac80211 has nothing to pick from and falls back to the permanent address. If the first interface is already running with that address, bringing up the second one fails with
-ENOTUNIQ.As in ath11k, provide a list of usable addresses so
ieee80211_assign_perm_addr()can hand each new interface an unused one. Keep the first entry as the radio's own MAC address. Generate the remaining entries as locally administered variants by changing only the upper nibble of the first octet, which naturally limits the pool to 16 unique addresses.The
wiphy->addressessemantics are hardware-specific in ath12k: some platforms use it as an interface MAC address pool, while others use it for firmware-provided per-radio addresses. Gate host-generated addresses behindhost_alloc_iface_macand enable it for WCN7850.Handle only single-radio WCN7850 wiphys. Wiphys with more than one radio and other hardware families behave exactly as before.
Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c7-00108-QCAHMTSWPL_V1.0_V2.0_SILICONZ_UPSTREAM-3
Assisted-by LLMSigned-off-by Vitor Soares <[email protected]>---
v2:
- Gate generated interface MAC address list behindhw_paramshost_alloc_iface_mac, as suggested by Kang Yang.
- Enable it only for WCN7850, the only part available for testing here.
- Add Assisted-by: tag.
- Link for v1: https://lore.kernel.org/all/[email protected]/--- drivers/net/wireless/ath/ath12k/hw.h | 1 + drivers/net/wireless/ath/ath12k/mac.c | 52 ++++++++++++++++++++++ drivers/net/wireless/ath/ath12k/wifi7/hw.c | 6 +++ 3 files changed, 59 insertions(+)drivers/net/wireless/ath/ath12k/hw.h +1
-0@@ -238,6 +238,7 @@ struct ath12k_hw_params { } client;bool host_alloc_ml_id; +bool host_alloc_iface_mac; };struct ath12k_hw_ops {drivers/net/wireless/ath/ath12k/mac.c +4
-0@@ -14743,6 +14743,54 @@ static void ath12k_mac_cleanup_unregister(struct ath12k *ar)kfree (ar->mac.sbands[NL80211_BAND_6GHZ ].channels); } +static void ath12k_mac_cleanup_mac_address_list (struct ath12k_hw *ah) +{ +kfree (ah->hw->wiphy->addresses); +}
drivers/net/wireless/ath/ath12k/mac.c static void ath12k_mac_cleanup_unregister(struct ath12k *ar) · line 14759
Quoted 10 lines
drivers/net/wireless/ath/ath12k/mac.c +10
-0+ +static void ath12k_mac_setup_mac_address_list (struct ath12k_hw *ah, +const u8 *mac_addr) +{ +struct mac_address *addresses; +struct ath12k *ar; +u16 n_addresses; +int i; + +/* The pool is derived from one base address, so it can describe only a
networking code prefers that the first line of a comment contains only '/*':
/* * comment starts from this line */
drivers/net/wireless/ath/ath12k/mac.c static void ath12k_mac_cleanup_unregister(struct ath12k *ar) · line 14770
Quoted 11 lines
drivers/net/wireless/ath/ath12k/mac.c +11
-0+* single-radio wiphy: with more radios each radio has its own base +* address, possibly from a different ath12k_base. +*/ +if (ah->num_radio !=1 ) +return ; + + ar =ath12k_ah_to_ar (ah,0 ); +if (!ar->ab->hw_params->host_alloc_iface_mac) +return ; + +/* Only the upper nibble of the first octet is varied, so at most 16
ditto
Quoted 88 lines
drivers/net/wireless/ath/ath12k/mac.c +27
-0+* addresses can be derived from one base. +*/ + n_addresses =min_t (u16,TARGET_NUM_VDEVS (ar->ab),16 ); +if (n_addresses <=1 ) +return ; + + addresses =kzalloc_objs (*addresses, n_addresses); +if (!addresses) +return ; + +ether_addr_copy (addresses[0 ].addr, mac_addr); +for (i =1 ; i < n_addresses; i++) { +ether_addr_copy (addresses[i].addr, mac_addr); +/* set Local Administered Address bit */ + addresses[i].addr[0 ] |=0x2 ; + + addresses[i].addr[0 ] += i <<4 ; + } + + ah->hw->wiphy->addresses = addresses; + ah->hw->wiphy->n_addresses = n_addresses; +} +static void ath12k_mac_hw_unregister (struct ath12k_hw *ah) {struct ieee80211_hw *hw = ah->hw;@@ -14762,6 +14810,7 @@ static void ath12k_mac_hw_unregister(struct ath12k_hw *ah)ath12k_mac_cleanup_unregister (ar);ath12k_mac_cleanup_iface_combinations (ah); +ath12k_mac_cleanup_mac_address_list (ah);SET_IEEE80211_DEV (hw,NULL ); }@@ -14878,6 +14927,7 @@ static int ath12k_mac_hw_register(struct ath12k_hw *ah) wiphy->available_antennas_tx = antennas_tx;SET_IEEE80211_PERM_ADDR (hw, mac_addr); +ath12k_mac_setup_mac_address_list (ah, mac_addr);SET_IEEE80211_DEV (hw, ab->dev); ret =ath12k_mac_setup_iface_combinations (ah);@@ -15120,6 +15170,8 @@ static int ath12k_mac_hw_register(struct ath12k_hw *ah)ath12k_mac_cleanup_unregister (ar); } +ath12k_mac_cleanup_mac_address_list (ah); +SET_IEEE80211_DEV (hw,NULL );return ret;drivers/net/wireless/ath/ath12k/wifi7/hw.c +4
-0@@ -445,6 +445,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { }, .host_alloc_ml_id = true, + .host_alloc_iface_mac = false, }, { .name = "wcn7850 hw2.0",@@ -539,6 +540,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { }, .host_alloc_ml_id = false, + .host_alloc_iface_mac = true, }, { .name = "qcn9274 hw2.0",@@ -629,6 +631,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { }, .host_alloc_ml_id = true, + .host_alloc_iface_mac = false, }, { .name = "ipq5332 hw1.0",@@ -713,6 +716,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { }, .host_alloc_ml_id = true, + .host_alloc_iface_mac = false, }, { .name = "qcc2072 hw1.0",
drivers/net/wireless/ath/ath12k/wifi7/hw.c static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { · line 815
Quoted 4 lines
drivers/net/wireless/ath/ath12k/wifi7/hw.c +1
-0@@ -808,6 +812,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { }, .host_alloc_ml_id = false, + .host_alloc_iface_mac = false,
QCC2072 behaves like WCN7850, so we should enable it as well
Quoted 12 lines · Vitor Soares
From: Vitor Soares <[email protected]>
ath12k supports creating vdevs with addresses provided by mac80211. Userspace can already make concurrent interfaces work by explicitly assigning different locally administered addresses.
However, ath12k does not advertise an address list, so when a second interface is created without an explicit address, mac80211 has nothing to pick from and falls back to the permanent address. If the first interface is already running with that address, bringing up the second one fails with
-ENOTUNIQ.
Quoted 8 lines
As in ath11k, provide a list of usable addresses so
ieee80211_assign_perm_addr()can hand each new interface an unused one. Keep the first entry as the radio's own MAC address. Generate the remaining entries as locally administered variants by changing only the upper nibble of the first octet, which naturally limits the pool to 16 unique addresses.The
wiphy->addressessemantics are hardware-specific in ath12k: some
@n_addresses: number of addresses in @addresses.
@addresses: If the device has more than one address, set this pointer to a list of addresses (6 bytes each). The first one will be used by default for perm_addr. In this case, the mask should be set to all-zeroes. In this case it is assumed that the device can handle the same number of arbitrary MAC addresses.
The cfg80211 definition of wiphy->addresses does not specify where the addresses must come from. As a result, different ath12k platforms have historically used it in different ways (interface MAC pool vs. firmware-provided per-radio MAC addresses). That's why we suggest gating this behavior with a hw capability flag, so existing platform behavior remains unchanged.
Quoted 29 lines
platforms use it as an interface MAC address pool, while others use it for firmware-provided per-radio addresses. Gate host-generated addresses behind
host_alloc_iface_macand enable it for WCN7850.Handle only single-radio WCN7850 wiphys. Wiphys with more than one radio and other hardware families behave exactly as before.
Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c7-00108-QCAHMTSWPL_V1.0_V2.0_SILICONZ_UPSTREAM-3
Assisted-by LLMSigned-off-by Vitor Soares <[email protected]>---
v2:
- Gate generated interface MAC address list behindhw_paramshost_alloc_iface_mac, as suggested by Kang Yang.
- Enable it only for WCN7850, the only part available for testing here.
- Add Assisted-by: tag.
- Link for v1: https://lore.kernel.org/all/[email protected]/--- drivers/net/wireless/ath/ath12k/hw.h | 1 + drivers/net/wireless/ath/ath12k/mac.c | 52 ++++++++++++++++++++++ drivers/net/wireless/ath/ath12k/wifi7/hw.c | 6 +++ 3 files changed, 59 insertions(+)drivers/net/wireless/ath/ath12k/hw.h +0
-0
drivers/net/wireless/ath/ath12k/hw.h struct ath12k_hw_params { · line 241
Quoted 4 lines
drivers/net/wireless/ath/ath12k/hw.h +1
-0@@ -238,6 +238,7 @@ struct ath12k_hw_params { } client;bool host_alloc_ml_id; +bool host_alloc_iface_mac;
Please notice that, ath12k only reports address pool, and the allocation is done by mac80211, so advertise_iface_mac_pool maybe better.
Quoted 8 lines
drivers/net/wireless/ath/ath12k/hw.h +0
-0};struct ath12k_hw_ops {drivers/net/wireless/ath/ath12k/mac.c +0
-0
drivers/net/wireless/ath/ath12k/mac.c static void ath12k_mac_cleanup_unregister(struct ath12k *ar) · line 14748
Quoted 6 lines
drivers/net/wireless/ath/ath12k/mac.c +3
-0@@ -14743,6 +14743,54 @@ static void ath12k_mac_cleanup_unregister(struct ath12k *ar)kfree (ar->mac.sbands[NL80211_BAND_6GHZ ].channels); } +static void ath12k_mac_cleanup_mac_address_list (struct ath12k_hw *ah) +{ +kfree (ah->hw->wiphy->addresses);
wiphy->addresses = NULL;
wiphy->n_addresses = 0;
Quoted 7 lines
drivers/net/wireless/ath/ath12k/mac.c +7
-0+} + +static void ath12k_mac_setup_mac_address_list (struct ath12k_hw *ah, +const u8 *mac_addr) +{ +struct mac_address *addresses; +struct ath12k *ar;
drivers/net/wireless/ath/ath12k/mac.c static void ath12k_mac_cleanup_unregister(struct ath12k *ar) · line 14765
Quoted 10 lines
drivers/net/wireless/ath/ath12k/mac.c +10
-0+u16 n_addresses; +int i; + +/* The pool is derived from one base address, so it can describe only a +* single-radio wiphy: with more radios each radio has its own base +* address, possibly from a different ath12k_base. +*/ +if (ah->num_radio !=1 ) +return ; +
Delete this num_radio check, please use hw_params check only. We cannot make sure other chips won't have one radio products in the future(Maybe they already have).
Quoted 93 lines
drivers/net/wireless/ath/ath12k/mac.c +32
-0+ ar =ath12k_ah_to_ar (ah,0 ); +if (!ar->ab->hw_params->host_alloc_iface_mac) +return ; + +/* Only the upper nibble of the first octet is varied, so at most 16 +* addresses can be derived from one base. +*/ + n_addresses =min_t (u16,TARGET_NUM_VDEVS (ar->ab),16 ); +if (n_addresses <=1 ) +return ; + + addresses =kzalloc_objs (*addresses, n_addresses); +if (!addresses) +return ; + +ether_addr_copy (addresses[0 ].addr, mac_addr); +for (i =1 ; i < n_addresses; i++) { +ether_addr_copy (addresses[i].addr, mac_addr); +/* set Local Administered Address bit */ + addresses[i].addr[0 ] |=0x2 ; + + addresses[i].addr[0 ] += i <<4 ; + } + + ah->hw->wiphy->addresses = addresses; + ah->hw->wiphy->n_addresses = n_addresses; +} +static void ath12k_mac_hw_unregister (struct ath12k_hw *ah) {struct ieee80211_hw *hw = ah->hw;@@ -14762,6 +14810,7 @@ static void ath12k_mac_hw_unregister(struct ath12k_hw *ah)ath12k_mac_cleanup_unregister (ar);ath12k_mac_cleanup_iface_combinations (ah); +ath12k_mac_cleanup_mac_address_list (ah);SET_IEEE80211_DEV (hw,NULL ); }@@ -14878,6 +14927,7 @@ static int ath12k_mac_hw_register(struct ath12k_hw *ah) wiphy->available_antennas_tx = antennas_tx;SET_IEEE80211_PERM_ADDR (hw, mac_addr); +ath12k_mac_setup_mac_address_list (ah, mac_addr);SET_IEEE80211_DEV (hw, ab->dev); ret =ath12k_mac_setup_iface_combinations (ah);@@ -15120,6 +15170,8 @@ static int ath12k_mac_hw_register(struct ath12k_hw *ah)ath12k_mac_cleanup_unregister (ar); } +ath12k_mac_cleanup_mac_address_list (ah); +SET_IEEE80211_DEV (hw,NULL );return ret;drivers/net/wireless/ath/ath12k/wifi7/hw.c +4
-0@@ -445,6 +445,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { }, .host_alloc_ml_id = true, + .host_alloc_iface_mac = false, }, { .name = "wcn7850 hw2.0",@@ -539,6 +540,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { }, .host_alloc_ml_id = false, + .host_alloc_iface_mac = true, }, { .name = "qcn9274 hw2.0",@@ -629,6 +631,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { }, .host_alloc_ml_id = true, + .host_alloc_iface_mac = false, }, { .name = "ipq5332 hw1.0",@@ -713,6 +716,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { }, .host_alloc_ml_id = true, + .host_alloc_iface_mac = false, }, { .name = "qcc2072 hw1.0",
drivers/net/wireless/ath/ath12k/wifi7/hw.c static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { · line 816
Quoted 5 lines
drivers/net/wireless/ath/ath12k/wifi7/hw.c +1
-0@@ -808,6 +812,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { }, .host_alloc_ml_id = false, + .host_alloc_iface_mac = false, },
For QCC2072, i suggest true. And you can mention in commit message for WCN7850/QCC2072.
Quoted 10 lines
drivers/net/wireless/ath/ath12k/wifi7/hw.c +1
-0{ .name = "ipq5424 hw1.0",@@ -895,6 +900,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { }, .host_alloc_ml_id = true, + .host_alloc_iface_mac = false, }, };