wifi: ath11k: Introduce and use ath11k_sta_to_arsta()
authorJeff Johnson <quic_jjohnson@quicinc.com>
Mon, 9 Oct 2023 16:39:42 +0000 (09:39 -0700)
committerKalle Valo <quic_kvalo@quicinc.com>
Thu, 12 Oct 2023 16:08:22 +0000 (19:08 +0300)
Currently, the logic to return an ath11k_sta pointer, given a
ieee80211_sta pointer, uses typecasting throughout the driver. In
general, conversion functions are preferable to typecasting since
using a conversion function allows the compiler to validate the types
of both the input and output parameters.

ath11k already defines a conversion function ath11k_vif_to_arvif() for
a similar conversion. So introduce ath11k_sta_to_arsta() for this use
case, and convert all of the existing typecasting to use this
function.

No functional changes, compile tested only.

Signed-off-by: Jeff Johnson <quic_jjohnson@quicinc.com>
Signed-off-by: Kalle Valo <quic_kvalo@quicinc.com>
Link: https://lore.kernel.org/r/20231009-ath11k_sta_to_arsta-v1-1-1563e3a307e8@quicinc.com
drivers/net/wireless/ath/ath11k/core.h
drivers/net/wireless/ath/ath11k/debugfs.c
drivers/net/wireless/ath/ath11k/debugfs_sta.c
drivers/net/wireless/ath/ath11k/dp_rx.c
drivers/net/wireless/ath/ath11k/dp_tx.c
drivers/net/wireless/ath/ath11k/mac.c
drivers/net/wireless/ath/ath11k/peer.c
drivers/net/wireless/ath/ath11k/wmi.c

index 650972f9d146a9c17f010a5e91d64cc9dc66924e..489c863215a45ac0ca9ec5aadfee474f6f329aac 100644 (file)
@@ -1223,6 +1223,11 @@ static inline struct ath11k_vif *ath11k_vif_to_arvif(struct ieee80211_vif *vif)
        return (struct ath11k_vif *)vif->drv_priv;
 }
 
+static inline struct ath11k_sta *ath11k_sta_to_arsta(struct ieee80211_sta *sta)
+{
+       return (struct ath11k_sta *)sta->drv_priv;
+}
+
 static inline struct ath11k *ath11k_ab_to_ar(struct ath11k_base *ab,
                                             int mac_id)
 {
index 6f89e24cb6125d35442521dd62124e97b41f3d65..be76e7d1c4366e99cbd345a4b8386a9c05ca7857 100644 (file)
@@ -1459,7 +1459,7 @@ static void ath11k_reset_peer_ps_duration(void *data,
                                          struct ieee80211_sta *sta)
 {
        struct ath11k *ar = data;
-       struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
+       struct ath11k_sta *arsta = ath11k_sta_to_arsta(sta);
 
        spin_lock_bh(&ar->data_lock);
        arsta->ps_total_duration = 0;
@@ -1510,7 +1510,7 @@ static void ath11k_peer_ps_state_disable(void *data,
                                         struct ieee80211_sta *sta)
 {
        struct ath11k *ar = data;
-       struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
+       struct ath11k_sta *arsta = ath11k_sta_to_arsta(sta);
 
        spin_lock_bh(&ar->data_lock);
        arsta->peer_ps_state = WMI_PEER_PS_STATE_DISABLED;
index 9cc4ef28e7519bab4d9886b3e7df0f39360ada07..8c177fba6f145a01bc29411cf8c46ad2d627360e 100644 (file)
@@ -136,7 +136,7 @@ static ssize_t ath11k_dbg_sta_dump_tx_stats(struct file *file,
                                            size_t count, loff_t *ppos)
 {
        struct ieee80211_sta *sta = file->private_data;
-       struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
+       struct ath11k_sta *arsta = ath11k_sta_to_arsta(sta);
        struct ath11k *ar = arsta->arvif->ar;
        struct ath11k_htt_data_stats *stats;
        static const char *str_name[ATH11K_STATS_TYPE_MAX] = {"succ", "fail",
@@ -243,7 +243,7 @@ static ssize_t ath11k_dbg_sta_dump_rx_stats(struct file *file,
                                            size_t count, loff_t *ppos)
 {
        struct ieee80211_sta *sta = file->private_data;
-       struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
+       struct ath11k_sta *arsta = ath11k_sta_to_arsta(sta);
        struct ath11k *ar = arsta->arvif->ar;
        struct ath11k_rx_peer_stats *rx_stats = arsta->rx_stats;
        int len = 0, i, retval = 0;
@@ -340,7 +340,7 @@ static int
 ath11k_dbg_sta_open_htt_peer_stats(struct inode *inode, struct file *file)
 {
        struct ieee80211_sta *sta = inode->i_private;
-       struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
+       struct ath11k_sta *arsta = ath11k_sta_to_arsta(sta);
        struct ath11k *ar = arsta->arvif->ar;
        struct debug_htt_stats_req *stats_req;
        int type = ar->debug.htt_stats.type;
@@ -376,7 +376,7 @@ static int
 ath11k_dbg_sta_release_htt_peer_stats(struct inode *inode, struct file *file)
 {
        struct ieee80211_sta *sta = inode->i_private;
-       struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
+       struct ath11k_sta *arsta = ath11k_sta_to_arsta(sta);
        struct ath11k *ar = arsta->arvif->ar;
 
        mutex_lock(&ar->conf_mutex);
@@ -413,7 +413,7 @@ static ssize_t ath11k_dbg_sta_write_peer_pktlog(struct file *file,
                                                size_t count, loff_t *ppos)
 {
        struct ieee80211_sta *sta = file->private_data;
-       struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
+       struct ath11k_sta *arsta = ath11k_sta_to_arsta(sta);
        struct ath11k *ar = arsta->arvif->ar;
        int ret, enable;
 
@@ -453,7 +453,7 @@ static ssize_t ath11k_dbg_sta_read_peer_pktlog(struct file *file,
                                               size_t count, loff_t *ppos)
 {
        struct ieee80211_sta *sta = file->private_data;
-       struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
+       struct ath11k_sta *arsta = ath11k_sta_to_arsta(sta);
        struct ath11k *ar = arsta->arvif->ar;
        char buf[32] = {0};
        int len;
@@ -480,7 +480,7 @@ static ssize_t ath11k_dbg_sta_write_delba(struct file *file,
                                          size_t count, loff_t *ppos)
 {
        struct ieee80211_sta *sta = file->private_data;
-       struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
+       struct ath11k_sta *arsta = ath11k_sta_to_arsta(sta);
        struct ath11k *ar = arsta->arvif->ar;
        u32 tid, initiator, reason;
        int ret;
@@ -531,7 +531,7 @@ static ssize_t ath11k_dbg_sta_write_addba_resp(struct file *file,
                                               size_t count, loff_t *ppos)
 {
        struct ieee80211_sta *sta = file->private_data;
-       struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
+       struct ath11k_sta *arsta = ath11k_sta_to_arsta(sta);
        struct ath11k *ar = arsta->arvif->ar;
        u32 tid, status;
        int ret;
@@ -581,7 +581,7 @@ static ssize_t ath11k_dbg_sta_write_addba(struct file *file,
                                          size_t count, loff_t *ppos)
 {
        struct ieee80211_sta *sta = file->private_data;
-       struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
+       struct ath11k_sta *arsta = ath11k_sta_to_arsta(sta);
        struct ath11k *ar = arsta->arvif->ar;
        u32 tid, buf_size;
        int ret;
@@ -632,7 +632,7 @@ static ssize_t ath11k_dbg_sta_read_aggr_mode(struct file *file,
                                             size_t count, loff_t *ppos)
 {
        struct ieee80211_sta *sta = file->private_data;
-       struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
+       struct ath11k_sta *arsta = ath11k_sta_to_arsta(sta);
        struct ath11k *ar = arsta->arvif->ar;
        char buf[64];
        int len = 0;
@@ -652,7 +652,7 @@ static ssize_t ath11k_dbg_sta_write_aggr_mode(struct file *file,
                                              size_t count, loff_t *ppos)
 {
        struct ieee80211_sta *sta = file->private_data;
-       struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
+       struct ath11k_sta *arsta = ath11k_sta_to_arsta(sta);
        struct ath11k *ar = arsta->arvif->ar;
        u32 aggr_mode;
        int ret;
@@ -697,7 +697,7 @@ ath11k_write_htt_peer_stats_reset(struct file *file,
                                  size_t count, loff_t *ppos)
 {
        struct ieee80211_sta *sta = file->private_data;
-       struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
+       struct ath11k_sta *arsta = ath11k_sta_to_arsta(sta);
        struct ath11k *ar = arsta->arvif->ar;
        struct htt_ext_stats_cfg_params cfg_params = { 0 };
        int ret;
@@ -756,7 +756,7 @@ static ssize_t ath11k_dbg_sta_read_peer_ps_state(struct file *file,
                                                 size_t count, loff_t *ppos)
 {
        struct ieee80211_sta *sta = file->private_data;
-       struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
+       struct ath11k_sta *arsta = ath11k_sta_to_arsta(sta);
        struct ath11k *ar = arsta->arvif->ar;
        char buf[20];
        int len;
@@ -783,7 +783,7 @@ static ssize_t ath11k_dbg_sta_read_current_ps_duration(struct file *file,
                                                       loff_t *ppos)
 {
        struct ieee80211_sta *sta = file->private_data;
-       struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
+       struct ath11k_sta *arsta = ath11k_sta_to_arsta(sta);
        struct ath11k *ar = arsta->arvif->ar;
        u64 time_since_station_in_power_save;
        char buf[20];
@@ -817,7 +817,7 @@ static ssize_t ath11k_dbg_sta_read_total_ps_duration(struct file *file,
                                                     size_t count, loff_t *ppos)
 {
        struct ieee80211_sta *sta = file->private_data;
-       struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
+       struct ath11k_sta *arsta = ath11k_sta_to_arsta(sta);
        struct ath11k *ar = arsta->arvif->ar;
        char buf[20];
        u64 power_save_duration;
index 9de849f096209873460f2f07abda7ac45f0290aa..96a60bfd1b163ce3c0d5d673ab7302de6e8f9752 100644 (file)
@@ -1099,7 +1099,7 @@ int ath11k_dp_rx_ampdu_start(struct ath11k *ar,
                             struct ieee80211_ampdu_params *params)
 {
        struct ath11k_base *ab = ar->ab;
-       struct ath11k_sta *arsta = (void *)params->sta->drv_priv;
+       struct ath11k_sta *arsta = ath11k_sta_to_arsta(params->sta);
        int vdev_id = arsta->arvif->vdev_id;
        int ret;
 
@@ -1117,7 +1117,7 @@ int ath11k_dp_rx_ampdu_stop(struct ath11k *ar,
 {
        struct ath11k_base *ab = ar->ab;
        struct ath11k_peer *peer;
-       struct ath11k_sta *arsta = (void *)params->sta->drv_priv;
+       struct ath11k_sta *arsta = ath11k_sta_to_arsta(params->sta);
        int vdev_id = arsta->arvif->vdev_id;
        dma_addr_t paddr;
        bool active;
@@ -1456,7 +1456,7 @@ ath11k_update_per_peer_tx_stats(struct ath11k *ar,
        }
 
        sta = peer->sta;
-       arsta = (struct ath11k_sta *)sta->drv_priv;
+       arsta = ath11k_sta_to_arsta(sta);
 
        memset(&arsta->txrate, 0, sizeof(arsta->txrate));
 
@@ -5242,7 +5242,7 @@ int ath11k_dp_rx_process_mon_status(struct ath11k_base *ab, int mac_id,
                        goto next_skb;
                }
 
-               arsta = (struct ath11k_sta *)peer->sta->drv_priv;
+               arsta = ath11k_sta_to_arsta(peer->sta);
                ath11k_dp_rx_update_peer_stats(arsta, ppdu_info);
 
                if (ath11k_debugfs_is_pktlog_peer_valid(ar, peer->addr))
index 0dda76f7a4b50d4701721d8e8a9fdf5a4409fe09..a5fa08bc623b8580ec1d2fd296966173764cb4e5 100644 (file)
@@ -467,7 +467,7 @@ void ath11k_dp_tx_update_txcompl(struct ath11k *ar, struct hal_tx_status *ts)
        }
 
        sta = peer->sta;
-       arsta = (struct ath11k_sta *)sta->drv_priv;
+       arsta = ath11k_sta_to_arsta(sta);
 
        memset(&arsta->txrate, 0, sizeof(arsta->txrate));
        pkt_type = FIELD_GET(HAL_TX_RATE_STATS_INFO0_PKT_TYPE,
@@ -627,7 +627,7 @@ static void ath11k_dp_tx_complete_msdu(struct ath11k *ar,
                ieee80211_free_txskb(ar->hw, msdu);
                return;
        }
-       arsta = (struct ath11k_sta *)peer->sta->drv_priv;
+       arsta = ath11k_sta_to_arsta(peer->sta);
        status.sta = peer->sta;
        status.skb = msdu;
        status.info = info;
index 98a2ac885c544816214cd3b924a06475aaf6eb41..ec46e2ee6ddffaea597b6b95fb6c57e449a8f142 100644 (file)
@@ -2832,7 +2832,7 @@ static void ath11k_peer_assoc_prepare(struct ath11k *ar,
 
        lockdep_assert_held(&ar->conf_mutex);
 
-       arsta = (struct ath11k_sta *)sta->drv_priv;
+       arsta = ath11k_sta_to_arsta(sta);
 
        memset(arg, 0, sizeof(*arg));
 
@@ -4313,7 +4313,7 @@ static int ath11k_mac_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
                ath11k_warn(ab, "peer %pM disappeared!\n", peer_addr);
 
        if (sta) {
-               arsta = (struct ath11k_sta *)sta->drv_priv;
+               arsta = ath11k_sta_to_arsta(sta);
 
                switch (key->cipher) {
                case WLAN_CIPHER_SUITE_TKIP:
@@ -4904,7 +4904,7 @@ static int ath11k_mac_station_add(struct ath11k *ar,
 {
        struct ath11k_base *ab = ar->ab;
        struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
-       struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
+       struct ath11k_sta *arsta = ath11k_sta_to_arsta(sta);
        struct peer_create_params peer_param;
        int ret;
 
@@ -5028,7 +5028,7 @@ static int ath11k_mac_op_sta_state(struct ieee80211_hw *hw,
 {
        struct ath11k *ar = hw->priv;
        struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
-       struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
+       struct ath11k_sta *arsta = ath11k_sta_to_arsta(sta);
        struct ath11k_peer *peer;
        int ret = 0;
 
@@ -5194,7 +5194,7 @@ static void ath11k_mac_op_sta_set_4addr(struct ieee80211_hw *hw,
                                        struct ieee80211_sta *sta, bool enabled)
 {
        struct ath11k *ar = hw->priv;
-       struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
+       struct ath11k_sta *arsta = ath11k_sta_to_arsta(sta);
 
        if (enabled && !arsta->use_4addr_set) {
                ieee80211_queue_work(ar->hw, &arsta->set_4addr_wk);
@@ -5208,7 +5208,7 @@ static void ath11k_mac_op_sta_rc_update(struct ieee80211_hw *hw,
                                        u32 changed)
 {
        struct ath11k *ar = hw->priv;
-       struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
+       struct ath11k_sta *arsta = ath11k_sta_to_arsta(sta);
        struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
        struct ath11k_peer *peer;
        u32 bw, smps;
@@ -6201,7 +6201,7 @@ static void ath11k_mac_op_tx(struct ieee80211_hw *hw,
        }
 
        if (control->sta)
-               arsta = (struct ath11k_sta *)control->sta->drv_priv;
+               arsta = ath11k_sta_to_arsta(control->sta);
 
        ret = ath11k_dp_tx(ar, arvif, arsta, skb);
        if (unlikely(ret)) {
@@ -8233,7 +8233,7 @@ static void ath11k_mac_set_bitrate_mask_iter(void *data,
                                             struct ieee80211_sta *sta)
 {
        struct ath11k_vif *arvif = data;
-       struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
+       struct ath11k_sta *arsta = ath11k_sta_to_arsta(sta);
        struct ath11k *ar = arvif->ar;
 
        spin_lock_bh(&ar->data_lock);
@@ -8637,7 +8637,7 @@ static void ath11k_mac_op_sta_statistics(struct ieee80211_hw *hw,
                                         struct ieee80211_sta *sta,
                                         struct station_info *sinfo)
 {
-       struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
+       struct ath11k_sta *arsta = ath11k_sta_to_arsta(sta);
        struct ath11k *ar = arsta->arvif->ar;
        s8 signal;
        bool db2dbm = test_bit(WMI_TLV_SERVICE_HW_DB2DBM_CONVERSION_SUPPORT,
index 114aa3a9a3397b3a868cb5b7f1e557ae203b6ca3..1c79a932d17f3bf8537361a42fe16667e880cf4e 100644 (file)
@@ -446,7 +446,7 @@ int ath11k_peer_create(struct ath11k *ar, struct ath11k_vif *arvif,
        peer->sec_type_grp = HAL_ENCRYPT_TYPE_OPEN;
 
        if (sta) {
-               arsta = (struct ath11k_sta *)sta->drv_priv;
+               arsta = ath11k_sta_to_arsta(sta);
                arsta->tcl_metadata |= FIELD_PREP(HTT_TCL_META_DATA_TYPE, 0) |
                                       FIELD_PREP(HTT_TCL_META_DATA_PEER_ID,
                                                  peer->peer_id);
index 8ecf67bf9b43b3326c4311178888fb7b517dd47e..26d416aa9c1f13c5bb5368670f54e02ff45bd8af 100644 (file)
@@ -6453,7 +6453,7 @@ static int ath11k_wmi_tlv_rssi_chain_parse(struct ath11k_base *ab,
                goto exit;
        }
 
-       arsta = (struct ath11k_sta *)sta->drv_priv;
+       arsta = ath11k_sta_to_arsta(sta);
 
        BUILD_BUG_ON(ARRAY_SIZE(arsta->chain_signal) >
                     ARRAY_SIZE(stats_rssi->rssi_avg_beacon));
@@ -6541,7 +6541,7 @@ static int ath11k_wmi_tlv_fw_stats_data_parse(struct ath11k_base *ab,
                                                           arvif->bssid,
                                                           NULL);
                        if (sta) {
-                               arsta = (struct ath11k_sta *)sta->drv_priv;
+                               arsta = ath11k_sta_to_arsta(sta);
                                arsta->rssi_beacon = src->beacon_snr;
                                ath11k_dbg(ab, ATH11K_DBG_WMI,
                                           "stats vdev id %d snr %d\n",
@@ -7468,7 +7468,7 @@ static void ath11k_wmi_event_peer_sta_ps_state_chg(struct ath11k_base *ab,
                goto exit;
        }
 
-       arsta = (struct ath11k_sta *)sta->drv_priv;
+       arsta = ath11k_sta_to_arsta(sta);
 
        spin_lock_bh(&ar->data_lock);