diff mbox series

mt76: mt7921: reset msta->airtime_ac while clearing up hw value

Message ID fd716a393e20d5db89f4f9d705d6dbbfde7260a6.1661400412.git.objelf@gmail.com
State New
Headers show
Series mt76: mt7921: reset msta->airtime_ac while clearing up hw value | expand

Commit Message

Sean Wang Aug. 25, 2022, 4:09 a.m. UTC
From: Sean Wang <sean.wang@mediatek.com>

We should reset mstat->airtime_ac along with clear up the entries in the
hardware WLAN table for the Rx and Rx accumulative airtime. Otherwsie, the
value msta->airtime_ac - [tx, rx]_last may be a negative and that is not
the actual airtime the device took in the last run.

Reported-by: YN Chen <YN.Chen@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
---
 drivers/net/wireless/mediatek/mt76/mt7921/mac.c   | 15 ++++++++++-----
 drivers/net/wireless/mediatek/mt76/mt7921/main.c  |  9 +++------
 .../net/wireless/mediatek/mt76/mt7921/mt7921.h    |  2 ++
 3 files changed, 15 insertions(+), 11 deletions(-)

Comments

Lorenzo Bianconi Aug. 25, 2022, 8:41 a.m. UTC | #1
> From: Sean Wang <sean.wang@mediatek.com>
> 
> We should reset mstat->airtime_ac along with clear up the entries in the
> hardware WLAN table for the Rx and Rx accumulative airtime. Otherwsie, the
> value msta->airtime_ac - [tx, rx]_last may be a negative and that is not
> the actual airtime the device took in the last run.

the only point where we need it is mt7921_mac_sta_assoc() since in
mt7921_mac_sta_add() airtime_ac array is supposed to be already 0 and in
mt7921_mac_sta_remove() we are removing the sta. Is my understanding correct?
If so, is it better to just add a memset(, 0, ..) in mt7921_mac_sta_assoc()?

Regards,
Lorenzo

> 
> Reported-by: YN Chen <YN.Chen@mediatek.com>
> Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> ---
>  drivers/net/wireless/mediatek/mt76/mt7921/mac.c   | 15 ++++++++++-----
>  drivers/net/wireless/mediatek/mt76/mt7921/main.c  |  9 +++------
>  .../net/wireless/mediatek/mt76/mt7921/mt7921.h    |  2 ++
>  3 files changed, 15 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c
> index 47f0aa81ab02..87dd0babff7a 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c
> @@ -46,6 +46,14 @@ bool mt7921_mac_wtbl_update(struct mt7921_dev *dev, int idx, u32 mask)
>  			 0, 5000);
>  }
>  
> +void mt7921_mac_sta_airtime_clear(struct mt7921_dev *dev,
> +				  struct mt7921_sta *msta)
> +{
> +	mt7921_mac_wtbl_update(dev, msta->wcid.idx,
> +			       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
> +	memset(msta->airtime_ac, 0, sizeof(msta->airtime_ac));
> +}
> +
>  void mt7921_mac_sta_poll(struct mt7921_dev *dev)
>  {
>  	static const u8 ac_to_tid[] = {
> @@ -100,11 +108,8 @@ void mt7921_mac_sta_poll(struct mt7921_dev *dev)
>  			addr += 8;
>  		}
>  
> -		if (clear) {
> -			mt7921_mac_wtbl_update(dev, idx,
> -					       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
> -			memset(msta->airtime_ac, 0, sizeof(msta->airtime_ac));
> -		}
> +		if (clear)
> +			mt7921_mac_sta_airtime_clear(dev, msta);
>  
>  		if (!msta->wcid.sta)
>  			continue;
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/main.c b/drivers/net/wireless/mediatek/mt76/mt7921/main.c
> index 1438a9f8d1fd..9d70884e24af 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7921/main.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7921/main.c
> @@ -723,8 +723,7 @@ int mt7921_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
>  	if (vif->type == NL80211_IFTYPE_STATION)
>  		mvif->wep_sta = msta;
>  
> -	mt7921_mac_wtbl_update(dev, idx,
> -			       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
> +	mt7921_mac_sta_airtime_clear(dev, msta);
>  
>  	ret = mt7921_mcu_sta_update(dev, sta, vif, true,
>  				    MT76_STA_INFO_STATE_NONE);
> @@ -750,8 +749,7 @@ void mt7921_mac_sta_assoc(struct mt76_dev *mdev, struct ieee80211_vif *vif,
>  		mt76_connac_mcu_uni_add_bss(&dev->mphy, vif, &mvif->sta.wcid,
>  					    true);
>  
> -	mt7921_mac_wtbl_update(dev, msta->wcid.idx,
> -			       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
> +	mt7921_mac_sta_airtime_clear(dev, msta);
>  
>  	mt7921_mcu_sta_update(dev, sta, vif, true, MT76_STA_INFO_STATE_ASSOC);
>  
> @@ -769,8 +767,7 @@ void mt7921_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
>  	mt76_connac_pm_wake(&dev->mphy, &dev->pm);
>  
>  	mt7921_mcu_sta_update(dev, sta, vif, false, MT76_STA_INFO_STATE_NONE);
> -	mt7921_mac_wtbl_update(dev, msta->wcid.idx,
> -			       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
> +	mt7921_mac_sta_airtime_clear(dev, msta);
>  
>  	if (vif->type == NL80211_IFTYPE_STATION) {
>  		struct mt7921_vif *mvif = (struct mt7921_vif *)vif->drv_priv;
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h b/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h
> index c161031ac62a..8b704d08509d 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h
> +++ b/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h
> @@ -362,6 +362,8 @@ void mt7921_stop(struct ieee80211_hw *hw);
>  int mt7921_mac_init(struct mt7921_dev *dev);
>  bool mt7921_mac_wtbl_update(struct mt7921_dev *dev, int idx, u32 mask);
>  void mt7921_mac_reset_counters(struct mt7921_phy *phy);
> +void mt7921_mac_sta_airtime_clear(struct mt7921_dev *dev,
> +				  struct mt7921_sta *msta);
>  void mt7921_mac_set_timing(struct mt7921_phy *phy);
>  int mt7921_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
>  		       struct ieee80211_sta *sta);
> -- 
> 2.25.1
>
sean wang Aug. 26, 2022, 5:13 a.m. UTC | #2
Hi Lorenzo,

On Thu, Aug 25, 2022 at 1:41 AM Lorenzo Bianconi <lorenzo@kernel.org> wrote:
>
> > From: Sean Wang <sean.wang@mediatek.com>
> >
> > We should reset mstat->airtime_ac along with clear up the entries in the
> > hardware WLAN table for the Rx and Rx accumulative airtime. Otherwsie, the
> > value msta->airtime_ac - [tx, rx]_last may be a negative and that is not
> > the actual airtime the device took in the last run.
>
> the only point where we need it is mt7921_mac_sta_assoc() since in
> mt7921_mac_sta_add() airtime_ac array is supposed to be already 0 and in
> mt7921_mac_sta_remove() we are removing the sta. Is my understanding correct?
> If so, is it better to just add a memset(, 0, ..) in mt7921_mac_sta_assoc()?
>

The way looks good to me. I'll add in the v2. thanks!

    Sean

> Regards,
> Lorenzo
>
> >
> > Reported-by: YN Chen <YN.Chen@mediatek.com>
> > Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> > ---
> >  drivers/net/wireless/mediatek/mt76/mt7921/mac.c   | 15 ++++++++++-----
> >  drivers/net/wireless/mediatek/mt76/mt7921/main.c  |  9 +++------
> >  .../net/wireless/mediatek/mt76/mt7921/mt7921.h    |  2 ++
> >  3 files changed, 15 insertions(+), 11 deletions(-)
> >
> > diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c
> > index 47f0aa81ab02..87dd0babff7a 100644
> > --- a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c
> > +++ b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c
> > @@ -46,6 +46,14 @@ bool mt7921_mac_wtbl_update(struct mt7921_dev *dev, int idx, u32 mask)
> >                        0, 5000);
> >  }
> >
> > +void mt7921_mac_sta_airtime_clear(struct mt7921_dev *dev,
> > +                               struct mt7921_sta *msta)
> > +{
> > +     mt7921_mac_wtbl_update(dev, msta->wcid.idx,
> > +                            MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
> > +     memset(msta->airtime_ac, 0, sizeof(msta->airtime_ac));
> > +}
> > +
> >  void mt7921_mac_sta_poll(struct mt7921_dev *dev)
> >  {
> >       static const u8 ac_to_tid[] = {
> > @@ -100,11 +108,8 @@ void mt7921_mac_sta_poll(struct mt7921_dev *dev)
> >                       addr += 8;
> >               }
> >
> > -             if (clear) {
> > -                     mt7921_mac_wtbl_update(dev, idx,
> > -                                            MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
> > -                     memset(msta->airtime_ac, 0, sizeof(msta->airtime_ac));
> > -             }
> > +             if (clear)
> > +                     mt7921_mac_sta_airtime_clear(dev, msta);
> >
> >               if (!msta->wcid.sta)
> >                       continue;
> > diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/main.c b/drivers/net/wireless/mediatek/mt76/mt7921/main.c
> > index 1438a9f8d1fd..9d70884e24af 100644
> > --- a/drivers/net/wireless/mediatek/mt76/mt7921/main.c
> > +++ b/drivers/net/wireless/mediatek/mt76/mt7921/main.c
> > @@ -723,8 +723,7 @@ int mt7921_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
> >       if (vif->type == NL80211_IFTYPE_STATION)
> >               mvif->wep_sta = msta;
> >
> > -     mt7921_mac_wtbl_update(dev, idx,
> > -                            MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
> > +     mt7921_mac_sta_airtime_clear(dev, msta);
> >
> >       ret = mt7921_mcu_sta_update(dev, sta, vif, true,
> >                                   MT76_STA_INFO_STATE_NONE);
> > @@ -750,8 +749,7 @@ void mt7921_mac_sta_assoc(struct mt76_dev *mdev, struct ieee80211_vif *vif,
> >               mt76_connac_mcu_uni_add_bss(&dev->mphy, vif, &mvif->sta.wcid,
> >                                           true);
> >
> > -     mt7921_mac_wtbl_update(dev, msta->wcid.idx,
> > -                            MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
> > +     mt7921_mac_sta_airtime_clear(dev, msta);
> >
> >       mt7921_mcu_sta_update(dev, sta, vif, true, MT76_STA_INFO_STATE_ASSOC);
> >
> > @@ -769,8 +767,7 @@ void mt7921_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
> >       mt76_connac_pm_wake(&dev->mphy, &dev->pm);
> >
> >       mt7921_mcu_sta_update(dev, sta, vif, false, MT76_STA_INFO_STATE_NONE);
> > -     mt7921_mac_wtbl_update(dev, msta->wcid.idx,
> > -                            MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
> > +     mt7921_mac_sta_airtime_clear(dev, msta);
> >
> >       if (vif->type == NL80211_IFTYPE_STATION) {
> >               struct mt7921_vif *mvif = (struct mt7921_vif *)vif->drv_priv;
> > diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h b/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h
> > index c161031ac62a..8b704d08509d 100644
> > --- a/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h
> > +++ b/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h
> > @@ -362,6 +362,8 @@ void mt7921_stop(struct ieee80211_hw *hw);
> >  int mt7921_mac_init(struct mt7921_dev *dev);
> >  bool mt7921_mac_wtbl_update(struct mt7921_dev *dev, int idx, u32 mask);
> >  void mt7921_mac_reset_counters(struct mt7921_phy *phy);
> > +void mt7921_mac_sta_airtime_clear(struct mt7921_dev *dev,
> > +                               struct mt7921_sta *msta);
> >  void mt7921_mac_set_timing(struct mt7921_phy *phy);
> >  int mt7921_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
> >                      struct ieee80211_sta *sta);
> > --
> > 2.25.1
> >
diff mbox series

Patch

diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c
index 47f0aa81ab02..87dd0babff7a 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c
@@ -46,6 +46,14 @@  bool mt7921_mac_wtbl_update(struct mt7921_dev *dev, int idx, u32 mask)
 			 0, 5000);
 }
 
+void mt7921_mac_sta_airtime_clear(struct mt7921_dev *dev,
+				  struct mt7921_sta *msta)
+{
+	mt7921_mac_wtbl_update(dev, msta->wcid.idx,
+			       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
+	memset(msta->airtime_ac, 0, sizeof(msta->airtime_ac));
+}
+
 void mt7921_mac_sta_poll(struct mt7921_dev *dev)
 {
 	static const u8 ac_to_tid[] = {
@@ -100,11 +108,8 @@  void mt7921_mac_sta_poll(struct mt7921_dev *dev)
 			addr += 8;
 		}
 
-		if (clear) {
-			mt7921_mac_wtbl_update(dev, idx,
-					       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
-			memset(msta->airtime_ac, 0, sizeof(msta->airtime_ac));
-		}
+		if (clear)
+			mt7921_mac_sta_airtime_clear(dev, msta);
 
 		if (!msta->wcid.sta)
 			continue;
diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/main.c b/drivers/net/wireless/mediatek/mt76/mt7921/main.c
index 1438a9f8d1fd..9d70884e24af 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/main.c
@@ -723,8 +723,7 @@  int mt7921_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
 	if (vif->type == NL80211_IFTYPE_STATION)
 		mvif->wep_sta = msta;
 
-	mt7921_mac_wtbl_update(dev, idx,
-			       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
+	mt7921_mac_sta_airtime_clear(dev, msta);
 
 	ret = mt7921_mcu_sta_update(dev, sta, vif, true,
 				    MT76_STA_INFO_STATE_NONE);
@@ -750,8 +749,7 @@  void mt7921_mac_sta_assoc(struct mt76_dev *mdev, struct ieee80211_vif *vif,
 		mt76_connac_mcu_uni_add_bss(&dev->mphy, vif, &mvif->sta.wcid,
 					    true);
 
-	mt7921_mac_wtbl_update(dev, msta->wcid.idx,
-			       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
+	mt7921_mac_sta_airtime_clear(dev, msta);
 
 	mt7921_mcu_sta_update(dev, sta, vif, true, MT76_STA_INFO_STATE_ASSOC);
 
@@ -769,8 +767,7 @@  void mt7921_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
 	mt76_connac_pm_wake(&dev->mphy, &dev->pm);
 
 	mt7921_mcu_sta_update(dev, sta, vif, false, MT76_STA_INFO_STATE_NONE);
-	mt7921_mac_wtbl_update(dev, msta->wcid.idx,
-			       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
+	mt7921_mac_sta_airtime_clear(dev, msta);
 
 	if (vif->type == NL80211_IFTYPE_STATION) {
 		struct mt7921_vif *mvif = (struct mt7921_vif *)vif->drv_priv;
diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h b/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h
index c161031ac62a..8b704d08509d 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h
@@ -362,6 +362,8 @@  void mt7921_stop(struct ieee80211_hw *hw);
 int mt7921_mac_init(struct mt7921_dev *dev);
 bool mt7921_mac_wtbl_update(struct mt7921_dev *dev, int idx, u32 mask);
 void mt7921_mac_reset_counters(struct mt7921_phy *phy);
+void mt7921_mac_sta_airtime_clear(struct mt7921_dev *dev,
+				  struct mt7921_sta *msta);
 void mt7921_mac_set_timing(struct mt7921_phy *phy);
 int mt7921_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
 		       struct ieee80211_sta *sta);