[PATCH ath-next v2] wifi: ath12k: add hash table for peer lookup in struct ath12k_dp_hw

Rameshkumar Sundaram rameshkumar.sundaram at oss.qualcomm.com
Mon Nov 23 06:34:12 PST 2026


On 11/20/2026 12:39 PM, Aishwarya R wrote:
> Peer lookup by MAC address in struct ath12k_dp_hw is currently performed by
> walking the dp_peers_list, resulting in O(n) lookup complexity. As the
> driver supports up to 1536 clients, frequent lookups on critical paths
> such as TX/RX processing, peer management, control operations and
> debug/statistics handling can incur noticeable overhead in dense
> deployment scenarios.
> 
> Replace the peer list with a generic kernel hash table for MAC address
> based peer management and lookup, providing O(1) average-case lookup
> performance. The hash table is implemented using DECLARE_HASHTABLE()
> with 2048 buckets (2^11), derived from
> order_base_2(ATH12K_MAX_DEVICES * ATH12K_MAX_CLIENTS), and uses jhash()
> over the peer MAC address as the hash key.
> 
> The hash table is used both for address-based lookups and peer
> traversal operations, eliminating the need for maintaining a separate
> peer list.
> 
> The maximum single-radio client limit is defined as
> ATH12K_MAX_CLIENTS and reused by the memory profile and hardware
> params. This keeps the peer hash sizing aligned with the per-device
> client limit and the maximum number of devices in a hardware group.
> 
> Key changes:
> - Add peer_hash table to ath12k_dp_hw and initialize it during
>    hardware allocation.
> - Add hash_node to ath12k_dp_peer for hash table membership.
> - Introduce helper APIs for hash computation, insertion, deletion and
>    lookup.
> - Convert MAC-address-based peer searches from list traversal to
>    hash-table lookup.
> - Replace peer list traversal with hash table iteration.
> 
> Peer creation inserts the peer into the hash table, while deletion
> removes it from the hash table. Peer cleanup paths are updated to
> iterate over the hash table and safely free peer objects.
> 
> Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.6-01243-QCAHKSWPL_SILICONZ-1
> 
> Co-developed-by: Harsh Kumar Bijlani <harsh.bijlani at oss.qualcomm.com>
> Signed-off-by: Harsh Kumar Bijlani <harsh.bijlani at oss.qualcomm.com>
> Signed-off-by: Aishwarya R <aishwarya.r at oss.qualcomm.com>
> Reviewed-by: Baochen Qiang <baochen.qiang at oss.qualcomm.com>
> ---
> Changes in v2:
> - Rebased the changes
> ---
>   drivers/net/wireless/ath/ath12k/cmn_defs.h |  2 +
>   drivers/net/wireless/ath/ath12k/core.c     |  2 +-
>   drivers/net/wireless/ath/ath12k/dp_cmn.h   | 14 ++++++-
>   drivers/net/wireless/ath/ath12k/dp_peer.c  | 47 ++++++++++++++++++----
>   drivers/net/wireless/ath/ath12k/dp_peer.h  |  7 +++-
>   drivers/net/wireless/ath/ath12k/mac.c      | 20 ++++-----
>   drivers/net/wireless/ath/ath12k/wifi7/hw.c | 10 ++---
>   7 files changed, 76 insertions(+), 26 deletions(-)
> 
> diff --git a/drivers/net/wireless/ath/ath12k/cmn_defs.h b/drivers/net/wireless/ath/ath12k/cmn_defs.h
> index 20208ffea1c9..15c5e8d11afc 100644
> --- a/drivers/net/wireless/ath/ath12k/cmn_defs.h
> +++ b/drivers/net/wireless/ath/ath12k/cmn_defs.h
> @@ -10,6 +10,8 @@
>   
>   #define MAX_RADIOS 2
>   #define ATH12K_MAX_DEVICES 3
> +#define ATH12K_MAX_CLIENTS 512
> +
>   #define ATH12K_GROUP_MAX_RADIO (ATH12K_MAX_DEVICES * MAX_RADIOS)
>   
>   #define ATH12K_SCAN_MAX_LINKS	ATH12K_GROUP_MAX_RADIO
> diff --git a/drivers/net/wireless/ath/ath12k/core.c b/drivers/net/wireless/ath/ath12k/core.c
> index 719200759ca0..6e0bb1fecc09 100644
> --- a/drivers/net/wireless/ath/ath12k/core.c
> +++ b/drivers/net/wireless/ath/ath12k/core.c
> @@ -44,7 +44,7 @@ static const struct
>   ath12k_mem_profile_based_param ath12k_mem_profile_based_param[] = {
>   [ATH12K_QMI_MEMORY_MODE_DEFAULT] = {
>   		.num_vdevs = 17,
> -		.max_client_single = 512,
> +		.max_client_single = ATH12K_MAX_CLIENTS,
>   		.max_client_dbs = 128,
>   		.max_client_dbs_sbs = 128,
>   		.dp_params = {
> diff --git a/drivers/net/wireless/ath/ath12k/dp_cmn.h b/drivers/net/wireless/ath/ath12k/dp_cmn.h
> index 88abe90767eb..ff011fafc175 100644
> --- a/drivers/net/wireless/ath/ath12k/dp_cmn.h
> +++ b/drivers/net/wireless/ath/ath12k/dp_cmn.h
> @@ -6,6 +6,7 @@
>   #ifndef ATH12K_DP_CMN_H
>   #define ATH12K_DP_CMN_H
>   
> +#include <linux/hashtable.h>
>   #include "cmn_defs.h"
>   
>   struct ath12k_hw_group;
> @@ -18,12 +19,21 @@ struct ath12k_dp_link_peer;
>    */
>   #define MAX_DP_PEER_LIST_SIZE  16384
>   
> +/*
> + * The hash table supports ATH12K_MAX_DEVICES * ATH12K_MAX_CLIENTS clients;
> + * order_base_2() gives 2048 hash buckets.
> + */
> +#define ATH12K_DP_PEER_HASH_BITS \
> +	order_base_2(ATH12K_MAX_DEVICES * ATH12K_MAX_CLIENTS)
> +
>   struct ath12k_dp_hw {
>   	struct ath12k_dp_peer __rcu *dp_peers[MAX_DP_PEER_LIST_SIZE];
>   
> -	/* Lock for protection of dp_peer_list and peers */
> +	/* Lock for protection of dp_peers[] and peer_hash */
>   	spinlock_t peer_lock;
> -	struct list_head dp_peers_list;
> +
> +	/* Generic hash table for fast MAC address lookup */
> +	DECLARE_HASHTABLE(peer_hash, ATH12K_DP_PEER_HASH_BITS);
>   };
>   
>   struct ath12k_dp_hw_group {
> diff --git a/drivers/net/wireless/ath/ath12k/dp_peer.c b/drivers/net/wireless/ath/ath12k/dp_peer.c
> index 4e753e6abe3a..5dc7f08e6292 100644
> --- a/drivers/net/wireless/ath/ath12k/dp_peer.c
> +++ b/drivers/net/wireless/ath/ath12k/dp_peer.c
> @@ -4,6 +4,7 @@
>    * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
>    */
>   
> +#include <linux/jhash.h>
>   #include "core.h"
>   #include "dp_peer.h"
>   #include "debug.h"
> @@ -371,30 +372,58 @@ void ath12k_dp_link_peer_rhash_delete(struct ath12k_dp *dp,
>   			    peer->addr, peer->peer_id, ret);
>   }
>   
> +static u32 ath12k_dp_peer_addr_hash(const u8 *addr)
> +{
> +	return jhash(addr, ETH_ALEN, 0);
> +}
> +
>   struct ath12k_dp_peer *ath12k_dp_peer_find_by_addr(struct ath12k_dp_hw *dp_hw, u8 *addr)
>   {
> -	struct ath12k_dp_peer *peer;
> +	struct ath12k_dp_peer *dp_peer;
> +	u32 hash;
>   
>   	lockdep_assert_held(&dp_hw->peer_lock);
>   
> -	list_for_each_entry(peer, &dp_hw->dp_peers_list, list) {
> -		if (ether_addr_equal(peer->addr, addr))
> -			return peer;
> +	hash = ath12k_dp_peer_addr_hash(addr);
> +	hash_for_each_possible(dp_hw->peer_hash, dp_peer, hash_node, hash) {
> +		if (ether_addr_equal(dp_peer->addr, addr))
> +			return dp_peer;
>   	}
>   
>   	return NULL;
>   }
>   EXPORT_SYMBOL(ath12k_dp_peer_find_by_addr);
>   
> +static void ath12k_dp_peer_hash_table_add(struct ath12k_dp_hw *dp_hw,
> +					  struct ath12k_dp_peer *dp_peer)
> +{
> +	u32 hash;
> +
> +	lockdep_assert_held(&dp_hw->peer_lock);
> +
> +	hash = ath12k_dp_peer_addr_hash(dp_peer->addr);
> +	hash_add(dp_hw->peer_hash, &dp_peer->hash_node, hash);
> +}
> +
> +void ath12k_dp_peer_hash_table_delete(struct ath12k_dp_hw *dp_hw,
> +				      struct ath12k_dp_peer *dp_peer)
> +{
> +	lockdep_assert_held(&dp_hw->peer_lock);
> +
> +	hash_del(&dp_peer->hash_node);
> +}
> +
>   struct ath12k_dp_peer *ath12k_dp_peer_find_by_addr_and_sta(struct ath12k_dp_hw *dp_hw,
>   							   u8 *addr,
>   							   struct ieee80211_sta *sta)
>   {
>   	struct ath12k_dp_peer *dp_peer;
> +	u32 hash;
>   
>   	lockdep_assert_held(&dp_hw->peer_lock);
>   
> -	list_for_each_entry(dp_peer, &dp_hw->dp_peers_list, list) {
> +	hash = ath12k_dp_peer_addr_hash(addr);
> +	hash_for_each_possible(dp_hw->peer_hash, dp_peer, hash_node, hash) {
>   		if (ether_addr_equal(dp_peer->addr, addr) && (dp_peer->sta == sta))
>   			return dp_peer;
>   	}
> @@ -408,10 +437,12 @@ static struct ath12k_dp_peer *ath12k_dp_peer_create_find(struct ath12k_dp_hw *dp
>   							 bool mlo_peer)
>   {
>   	struct ath12k_dp_peer *dp_peer;
> +	u32 hash;
>   
>   	lockdep_assert_held(&dp_hw->peer_lock);
>   
> -	list_for_each_entry(dp_peer, &dp_hw->dp_peers_list, list) {
> +	hash = ath12k_dp_peer_addr_hash(addr);
> +	hash_for_each_possible(dp_hw->peer_hash, dp_peer, hash_node, hash) {
>   		if (ether_addr_equal(dp_peer->addr, addr)) {
>   			if (!sta || mlo_peer || dp_peer->is_mlo ||
>   			    dp_peer->sta == sta)
> @@ -517,7 +548,7 @@ int ath12k_dp_peer_create(struct ath12k_dp_hw *dp_hw, u8 *addr,
>   
>   	spin_lock_bh(&dp_hw->peer_lock);
>   
> -	list_add(&dp_peer->list, &dp_hw->dp_peers_list);
> +	ath12k_dp_peer_hash_table_add(dp_hw, dp_peer);
>   
>   	/*
>   	 * For an MLO client whose ML peer ID is allocated by the host, the
> @@ -555,7 +586,7 @@ void ath12k_dp_peer_delete(struct ath12k_dp_hw *dp_hw, u8 *addr,
>   	    dp_peer->peer_id != ATH12K_MLO_PEER_ID_PENDING)
>   		rcu_assign_pointer(dp_hw->dp_peers[dp_peer->peer_id], NULL);
>   
> -	list_del(&dp_peer->list);
> +	ath12k_dp_peer_hash_table_delete(dp_hw, dp_peer);
>   
>   	spin_unlock_bh(&dp_hw->peer_lock);
>   
> diff --git a/drivers/net/wireless/ath/ath12k/dp_peer.h b/drivers/net/wireless/ath/ath12k/dp_peer.h
> index 2ac4c6c6d535..0a2b9d1814a5 100644
> --- a/drivers/net/wireless/ath/ath12k/dp_peer.h
> +++ b/drivers/net/wireless/ath/ath12k/dp_peer.h
> @@ -127,7 +127,6 @@ void ath12k_dp_link_peer_extended_event(struct ath12k_base *ab, u8 vdev_id,
>   					u8 logical_link_id, u8 valid);
>   
>   struct ath12k_dp_peer {
> -	struct list_head list;
>   	bool is_mlo;
>   	bool dp_setup_done;
>   
> @@ -164,6 +163,9 @@ struct ath12k_dp_peer {
>   	struct ath12k_dp_rx_tid rx_tid[IEEE80211_NUM_TIDS + 1];
>   
>   	bool use_4addr;
> +
> +	/* Hash table node for MAC address lookup */
> +	struct hlist_node hash_node;
>   };
>   
>   struct ath12k_dp_link_peer *
> @@ -212,4 +214,7 @@ ath12k_dp_link_peer_get_sta(const struct ath12k_dp_link_peer *link_peer)
>   	return link_peer && link_peer->dp_peer ?
>   		link_peer->dp_peer->sta : NULL;
>   }
> +
> +void ath12k_dp_peer_hash_table_delete(struct ath12k_dp_hw *dp_hw,
> +				      struct ath12k_dp_peer *dp_peer);
>   #endif
> diff --git a/drivers/net/wireless/ath/ath12k/mac.c b/drivers/net/wireless/ath/ath12k/mac.c
> index a247dcf387de..51ee44e72abf 100644
> --- a/drivers/net/wireless/ath/ath12k/mac.c
> +++ b/drivers/net/wireless/ath/ath12k/mac.c
> @@ -1277,16 +1277,20 @@ void ath12k_mac_peer_cleanup_all(struct ath12k *ar)
>   
>   void ath12k_mac_dp_peer_cleanup(struct ath12k_hw *ah)
>   {
> -	struct list_head peers;
> -	struct ath12k_dp_peer *dp_peer, *tmp;
>   	struct ath12k_dp_hw *dp_hw = &ah->dp_hw;
> +	struct ath12k_dp_peer *dp_peer;
> +	struct hlist_head free_list;
> +	struct hlist_node *tmp;
> +	int bkt;
>   
>   	lockdep_assert_wiphy(ah->hw->wiphy);
>   
> -	INIT_LIST_HEAD(&peers);
> +	INIT_HLIST_HEAD(&free_list);
>   
>   	spin_lock_bh(&dp_hw->peer_lock);
> -	list_for_each_entry_safe(dp_peer, tmp, &dp_hw->dp_peers_list, list) {
> +	hash_for_each_safe(dp_hw->peer_hash, bkt, tmp, dp_peer, hash_node) {
> +		ath12k_dp_peer_hash_table_delete(dp_hw, dp_peer);
> +
>   		if (dp_peer->is_mlo) {
>   			if (dp_peer->peer_id != ATH12K_MLO_PEER_ID_PENDING)
>   				rcu_assign_pointer(dp_hw->dp_peers[dp_peer->peer_id],
> @@ -1294,17 +1298,15 @@ void ath12k_mac_dp_peer_cleanup(struct ath12k_hw *ah)
>   			ath12k_peer_ml_free(ah, ath12k_sta_to_ahsta(dp_peer->sta));
>   		}
>   
> -		list_move(&dp_peer->list, &peers);
> +		hlist_add_head(&dp_peer->hash_node, &free_list);
>   	}
>   
>   	spin_unlock_bh(&dp_hw->peer_lock);
>   
>   	synchronize_rcu();
>   
> -	list_for_each_entry_safe(dp_peer, tmp, &peers, list) {
> -		list_del(&dp_peer->list);
> +	hlist_for_each_entry_safe(dp_peer, tmp, &free_list, hash_node)
>   		kfree(dp_peer);
> -	}
>   }
>   
>   static int ath12k_mac_vdev_setup_sync(struct ath12k *ar)
> @@ -15530,7 +15532,7 @@ static struct ath12k_hw *ath12k_mac_hw_allocate(struct ath12k_hw_group *ag,
>   
>   	spin_lock_init(&ah->survey_lock);
>   	spin_lock_init(&ah->dp_hw.peer_lock);
> -	INIT_LIST_HEAD(&ah->dp_hw.dp_peers_list);
> +	hash_init(ah->dp_hw.peer_hash);
>   
>   	for (i = 0; i < num_pdev_map; i++) {
>   		ab = pdev_map[i].ab;
> diff --git a/drivers/net/wireless/ath/ath12k/wifi7/hw.c b/drivers/net/wireless/ath/ath12k/wifi7/hw.c
> index 48a2f6da16ef..9f2b1dddfdb4 100644
> --- a/drivers/net/wireless/ath/ath12k/wifi7/hw.c
> +++ b/drivers/net/wireless/ath/ath12k/wifi7/hw.c
> @@ -488,7 +488,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = {
>   
>   		.dp_primary_link_only = true,
>   		.client = {
> -			.max_client_single = 512,
> +			.max_client_single = ATH12K_MAX_CLIENTS,
>   			.max_client_dbs = 128,
>   			.max_client_dbs_sbs = 128,
>   		},
> @@ -587,7 +587,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = {
>   
>   		.dp_primary_link_only = false,
>   		.client = {
> -			.max_client_single = 512,
> +			.max_client_single = ATH12K_MAX_CLIENTS,
>   			.max_client_dbs = 128,
>   			.max_client_dbs_sbs = 128,
>   		},
> @@ -682,7 +682,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = {
>   
>   		.dp_primary_link_only = true,
>   		.client = {
> -			.max_client_single = 512,
> +			.max_client_single = ATH12K_MAX_CLIENTS,
>   			.max_client_dbs = 128,
>   			.max_client_dbs_sbs = 128,
>   		},
> @@ -871,7 +871,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = {
>   
>   		.dp_primary_link_only = false,
>   		.client = {
> -			.max_client_single = 512,
> +			.max_client_single = ATH12K_MAX_CLIENTS,
>   			.max_client_dbs = 128,
>   			.max_client_dbs_sbs = 128,
>   		},
> @@ -963,7 +963,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = {
>   
>   		.dp_primary_link_only = true,
>   		.client = {
> -			.max_client_single = 512,
> +			.max_client_single = ATH12K_MAX_CLIENTS,
>   			.max_client_dbs = 128,
>   			.max_client_dbs_sbs = 128,
>   		},
> 
> base-commit: 03b7c601b6e314115015a57061f5b377afe13190


Reviewed-by: Rameshkumar Sundaram <rameshkumar.sundaram at oss.qualcomm.com>



More information about the ath12k mailing list