ath11k: clean up in htt extd stats
PATCH 1/2 ath11k: clean up in htt extd stats
Removed pointer arithmetic and the magic numbers
Signed-off-by Venkateswara Naralasetty <[email protected]>
--- drivers/net/wireless/ath/ath11k/debug_htt_stats.c | 29 +++++++++++++---------- drivers/net/wireless/ath/ath11k/dp.h | 19 ++++++--------- 2 files changed, 24 insertions(+), 24 deletions(-)
drivers/net/wireless/ath/ath11k/debug_htt_stats.c +17 -12
@@ -16,7 +16,7 @@#define HTT_MAX_STRING_LEN 256#define HTT_MAX_PRINT_CHAR_PER_ELEM 15 -#define HTT_TLV_HDR_LEN HTT_T2H_EXT_STATS_CONF_TLV_HDR_SIZE +#define HTT_TLV_HDR_LEN 4#define ARRAY_TO_STRING (out, arr, len) \ do { \
@@ -4192,22 +4192,29 @@ static int ath11k_dbg_htt_ext_stats_parse(struct ath11k_base *ab,void ath11k_dbg_htt_ext_stats_handler (struct ath11k_base *ab,struct sk_buff *skb) { -u8 *data = (u8 *)skb->data; -u32 len; -u64 cookie; +struct ath11k_htt_extd_stats_msg *msg;struct debug_htt_stats_req *stats_req;struct ath11k *ar; +u32 len; +u64 cookie;int ret;u8 pdev_id; - data = data +4 ; - cookie = *(u64 *)data; + msg = (struct ath11k_htt_extd_stats_msg *)skb->data; + cookie = msg->cookie; stats_req = (struct debug_htt_stats_req *)(uintptr_t )cookie;if (!stats_req)return ; - pdev_id =DP_HW2SW_MACID (stats_req->pdev_id); - ar = ab->pdevs[pdev_id].ar; + pdev_id = stats_req->pdev_id; +rcu_read_lock (); + ar =ath11k_get_ar_by_pdev_id (ab, pdev_id); +rcu_read_unlock (); +if (!ar) { +ath11k_warn (ab,"failed to get ar for pdev_id %d\n" , pdev_id); +return ; + } +spin_lock_bh (&ar->debug.htt_stats.lock);if (stats_req->done) {spin_unlock_bh (&ar->debug.htt_stats.lock);
@@ -4216,10 +4223,8 @@ void ath11k_dbg_htt_ext_stats_handler(struct ath11k_base *ab, stats_req->done = true;spin_unlock_bh (&ar->debug.htt_stats.lock); - data = data +8 ; - len =FIELD_GET (HTT_T2H_EXT_STATS_CONF_TLV_LENGTH_M , *(u32 *)data); - data = data +4 ; - ret =ath11k_dp_htt_tlv_iter (ab, data, len, + len =FIELD_GET (HTT_T2H_EXT_STATS_INFO1_LENGTH , msg->info1); + ret =ath11k_dp_htt_tlv_iter (ab, msg->data, len, ath11k_dbg_htt_ext_stats_parse, (void *)stats_req);if (ret)
drivers/net/wireless/ath/ath11k/dp.h +7 -12
@@ -1463,20 +1463,15 @@ struct htt_ext_stats_cfg_params {* 4 bytes. */ -#define HTT_T2H_EXT_STATS_COOKIE_SIZE 8 +#define HTT_T2H_EXT_STATS_INFO1_LENGTH GENMASK(31, 16) -#define HTT_T2H_EXT_STATS_CONF_HDR_SIZE 4 - -#define HTT_T2H_EXT_STATS_CONF_TLV_HDR_SIZE 4 +struct ath11k_htt_extd_stats_msg { +u32 info0; +u64 cookie; +u32 info1; +u8 data[0 ]; +} __packed; -#define HTT_T2H_EXT_STATS_CONF_TLV_TYPE_M 0x000000ff -#define HTT_T2H_EXT_STATS_CONF_TLV_TYPE_S 0 -#define HTT_T2H_EXT_STATS_CONF_TLV_STATUS_M 0x00000700 -#define HTT_T2H_EXT_STATS_CONF_TLV_STATUS_S 8 -#define HTT_T2H_EXT_STATS_CONF_TLV_DONE_M 0x00000800 -#define HTT_T2H_EXT_STATS_CONF_TLV_DONE_S 11 -#define HTT_T2H_EXT_STATS_CONF_TLV_LENGTH_M GENMASK(31, 16) -#define HTT_T2H_EXT_STATS_CONF_TLV_LENGTH_S 16struct htt_mac_addr {u32 mac_addr_l32;
Signature · 7 lines
2.7.4 _______________________________________________ ath11k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath11k
PATCH 2/2 ath11k: fix invalid htt extd stats processing
Check for valid cookie before processing htt extd stats event, which prevents processing invalid htt extd stats event.
Signed-off-by Venkateswara Naralasetty <[email protected]>
--- drivers/net/wireless/ath/ath11k/core.h | 1 + drivers/net/wireless/ath/ath11k/debug.h | 6 ++---- drivers/net/wireless/ath/ath11k/debug_htt_stats.c | 26 +++++++++++++++-------- drivers/net/wireless/ath/ath11k/debug_htt_stats.h | 4 ++++ drivers/net/wireless/ath/ath11k/debugfs_sta.c | 5 ++++- 5 files changed, 28 insertions(+), 14 deletions(-)
drivers/net/wireless/ath/ath11k/core.h +1 -0
@@ -385,6 +385,7 @@ struct ath11k_fw_stats {struct ath11k_dbg_htt_stats {u8 type;u8 reset; +struct debug_htt_stats_req *stats_req;/* protects shared stats req buffer */ spinlock_t lock; };
drivers/net/wireless/ath/ath11k/debug.h +2 -4
@@ -141,8 +141,7 @@ void ath11k_debug_fw_stats_process(struct ath11k_base *ab, u8 *evt_buf, u32 len);void ath11k_debug_fw_stats_init (struct ath11k *ar); -int ath11k_dbg_htt_stats_req (struct ath11k *ar, -struct debug_htt_stats_req *stats_req); +int ath11k_dbg_htt_stats_req (struct ath11k *ar);static inline bool ath11k_debug_is_pktlog_lite_mode_enabled (struct ath11k *ar) {
@@ -216,8 +215,7 @@ static inline int ath11k_debug_is_extd_rx_stats_enabled(struct ath11k *ar)return 0 ; } -static inline int ath11k_dbg_htt_stats_req (struct ath11k *ar, -struct debug_htt_stats_req *stats_req) +static inline int ath11k_dbg_htt_stats_req (struct ath11k *ar) {return 0 ; }
drivers/net/wireless/ath/ath11k/debug_htt_stats.c +17 -9
@@ -4202,11 +4202,13 @@ void ath11k_dbg_htt_ext_stats_handler(struct ath11k_base *ab, msg = (struct ath11k_htt_extd_stats_msg *)skb->data; cookie = msg->cookie; - stats_req = (struct debug_htt_stats_req *)(uintptr_t )cookie; -if (!stats_req) + +if (FIELD_GET (HTT_STATS_COOKIE_MSB , cookie) !=HTT_STATS_MAGIC_VALUE ) { +ath11k_warn (ab,"received invalid htt ext stats event\n" );return ; + } - pdev_id = stats_req->pdev_id; + pdev_id =FIELD_GET (HTT_STATS_COOKIE_LSB , cookie);rcu_read_lock (); ar =ath11k_get_ar_by_pdev_id (ab, pdev_id);rcu_read_unlock ();
@@ -4215,6 +4217,10 @@ void ath11k_dbg_htt_ext_stats_handler(struct ath11k_base *ab,return ; } + stats_req = ar->debug.htt_stats.stats_req; +if (!stats_req) +return ; +spin_lock_bh (&ar->debug.htt_stats.lock);if (stats_req->done) {spin_unlock_bh (&ar->debug.htt_stats.lock);
@@ -4322,9 +4328,9 @@ static int ath11k_prep_htt_stats_cfg_params(struct ath11k *ar, u8 type,return 0 ; } -int ath11k_dbg_htt_stats_req (struct ath11k *ar, -struct debug_htt_stats_req *stats_req) +int ath11k_dbg_htt_stats_req (struct ath11k *ar) { +struct debug_htt_stats_req *stats_req = ar->debug.htt_stats.stats_req;u8 type = stats_req->type;u64 cookie =0 ;int ret, pdev_id = ar->pdev->pdev_id;
@@ -4335,7 +4341,8 @@ int ath11k_dbg_htt_stats_req(struct ath11k *ar, stats_req->done = false; stats_req->pdev_id = pdev_id; - cookie = (u64 )(uintptr_t )stats_req; + cookie =FIELD_PREP (HTT_STATS_COOKIE_MSB ,HTT_STATS_MAGIC_VALUE ) | +FIELD_PREP (HTT_STATS_COOKIE_LSB , pdev_id); ret =ath11k_prep_htt_stats_cfg_params (ar, type, stats_req->peer_addr, &cfg_params);
@@ -4344,14 +4351,12 @@ int ath11k_dbg_htt_stats_req(struct ath11k *ar,return ret; } -mutex_lock (&ar->conf_mutex); ret =ath11k_dp_tx_htt_h2t_ext_stats_req (ar, type, &cfg_params, cookie);if (ret) {ath11k_warn (ar->ab,"failed to send htt stats request: %d\n" , ret);mutex_unlock (&ar->conf_mutex);return ret; } -mutex_unlock (&ar->conf_mutex);while (!wait_for_completion_timeout (&stats_req->cmpln,3 *HZ )) {spin_lock_bh (&ar->debug.htt_stats.lock);
@@ -4381,8 +4386,11 @@ static int ath11k_open_htt_stats(struct inode *inode, struct file *file)if (!stats_req)return -ENOMEM ; +mutex_lock (&ar->conf_mutex); + ar->debug.htt_stats.stats_req = stats_req; stats_req->type = type; - ret =ath11k_dbg_htt_stats_req (ar, stats_req); + ret =ath11k_dbg_htt_stats_req (ar); +mutex_unlock (&ar->conf_mutex);if (ret <0 ) goto out;
drivers/net/wireless/ath/ath11k/debug_htt_stats.h +4 -0
@@ -6,6 +6,10 @@#ifndef DEBUG_HTT_STATS_H #define DEBUG_HTT_STATS_H +#define HTT_STATS_COOKIE_LSB GENMASK_ULL(31, 0) +#define HTT_STATS_COOKIE_MSB GENMASK_ULL(63, 32) +#define HTT_STATS_MAGIC_VALUE 0xF0F0F0F0 +enum htt_tlv_tag_t {HTT_STATS_TX_PDEV_CMN_TAG =0 , HTT_STATS_TX_PDEV_UNDERRUN_TAG = 1,
drivers/net/wireless/ath/ath11k/debugfs_sta.c +4 -1
@@ -415,9 +415,12 @@ ath11k_dbg_sta_open_htt_peer_stats(struct inode *inode, struct file *file)if (!stats_req)return -ENOMEM ; +mutex_lock (&ar->conf_mutex); + ar->debug.htt_stats.stats_req = stats_req; stats_req->type =ATH11K_DBG_HTT_EXT_STATS_PEER_INFO ;memcpy (stats_req->peer_addr, sta->addr,ETH_ALEN ); - ret =ath11k_dbg_htt_stats_req (ar, stats_req); + ret =ath11k_dbg_htt_stats_req (ar); +mutex_unlock (&ar->conf_mutex);if (ret <0 ) goto out;
Signature · 7 lines
2.7.4 _______________________________________________ ath11k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath11k
Quoted 4 lines · Venkateswara Naralasetty
Removed pointer arithmetic and the magic numbers
Signed-off-by Venkateswara Naralasetty <[email protected]>Signed-off-by Kalle Valo <[email protected]>
2 patches applied to ath11k-bringup branch of ath.git, thanks.
8c04d1c544fd ath11k: clean up in htt extd stats 049a795bb88e ath11k: fix invalid htt extd stats processing
Signature · 9 lines
https://patchwork.kernel.org/patch/11001373/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches _______________________________________________ ath11k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath11k