diff mbox series

[RFC,07/14] wifi: rtl8xxxu: Add parameter macid to update_rate_mask

Message ID 20230322171905.492855-8-martin.kaistra@linutronix.de
State Superseded
Headers show
Series wifi: rtl8xxxu: Add AP mode support for 8188f | expand

Commit Message

Martin Kaistra March 22, 2023, 5:18 p.m. UTC
The HW maintains a rate_mask for each connection, referenced by the
macid. Add a parameter to update_rate_mask and add the macid to the
h2c call in the gen2 implementation.

Also extend refresh_rate_mask to generate the macid in AP mode from
sta->aid.

Signed-off-by: Martin Kaistra <martin.kaistra@linutronix.de>
---
 .../net/wireless/realtek/rtl8xxxu/rtl8xxxu.h    |  7 ++++---
 .../wireless/realtek/rtl8xxxu/rtl8xxxu_8188e.c  |  3 ++-
 .../wireless/realtek/rtl8xxxu/rtl8xxxu_core.c   | 17 +++++++++++++----
 3 files changed, 19 insertions(+), 8 deletions(-)

Comments

Ping-Ke Shih March 27, 2023, 1:48 a.m. UTC | #1
> -----Original Message-----
> From: Martin Kaistra <martin.kaistra@linutronix.de>
> Sent: Thursday, March 23, 2023 1:19 AM
> To: linux-wireless@vger.kernel.org
> Cc: Jes Sorensen <Jes.Sorensen@gmail.com>; Kalle Valo <kvalo@kernel.org>; Ping-Ke Shih
> <pkshih@realtek.com>; Bitterblue Smith <rtl8821cerfe2@gmail.com>; Sebastian Andrzej Siewior
> <bigeasy@linutronix.de>
> Subject: [RFC PATCH 07/14] wifi: rtl8xxxu: Add parameter macid to update_rate_mask
> 
> The HW maintains a rate_mask for each connection, referenced by the
> macid. Add a parameter to update_rate_mask and add the macid to the
> h2c call in the gen2 implementation.
> 
> Also extend refresh_rate_mask to generate the macid in AP mode from
> sta->aid.

Firmware can support 32 mac_id (station instance) at most, so it will be a
problem if hostapd assigns aid more than 32. Though I'm not clear how
hostpad assigns the aid, it would be always safe that rtl8xxxu maintains
mac_id by a bitmap in driver.

> 
> Signed-off-by: Martin Kaistra <martin.kaistra@linutronix.de>
> ---
>  .../net/wireless/realtek/rtl8xxxu/rtl8xxxu.h    |  7 ++++---
>  .../wireless/realtek/rtl8xxxu/rtl8xxxu_8188e.c  |  3 ++-
>  .../wireless/realtek/rtl8xxxu/rtl8xxxu_core.c   | 17 +++++++++++++----
>  3 files changed, 19 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h
> b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h
> index cac985271628c..c06ad33645974 100644
> --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h
> +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h
> @@ -1905,7 +1905,8 @@ struct rtl8xxxu_fileops {
>         void (*set_tx_power) (struct rtl8xxxu_priv *priv, int channel,
>                               bool ht40);
>         void (*update_rate_mask) (struct rtl8xxxu_priv *priv,
> -                                 u32 ramask, u8 rateid, int sgi, int txbw_40mhz);
> +                                 u32 ramask, u8 rateid, int sgi, int txbw_40mhz,
> +                                 u8 macid);
>         void (*report_connect) (struct rtl8xxxu_priv *priv,
>                                 u8 macid, bool connect);
>         void (*report_rssi) (struct rtl8xxxu_priv *priv, u8 macid, u8 rssi);
> @@ -2007,9 +2008,9 @@ void rtl8xxxu_gen2_config_channel(struct ieee80211_hw *hw);
>  void rtl8xxxu_gen1_usb_quirks(struct rtl8xxxu_priv *priv);
>  void rtl8xxxu_gen2_usb_quirks(struct rtl8xxxu_priv *priv);
>  void rtl8xxxu_update_rate_mask(struct rtl8xxxu_priv *priv,
> -                              u32 ramask, u8 rateid, int sgi, int txbw_40mhz);
> +                              u32 ramask, u8 rateid, int sgi, int txbw_40mhz, u8 macid);
>  void rtl8xxxu_gen2_update_rate_mask(struct rtl8xxxu_priv *priv,
> -                                   u32 ramask, u8 rateid, int sgi, int txbw_40mhz);
> +                                   u32 ramask, u8 rateid, int sgi, int txbw_40mhz, u8 macid);
>  void rtl8xxxu_gen1_report_connect(struct rtl8xxxu_priv *priv,
>                                   u8 macid, bool connect);
>  void rtl8xxxu_gen2_report_connect(struct rtl8xxxu_priv *priv,
> diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188e.c
> b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188e.c
> index 6a82ec47568ee..c3dc5130c9f37 100644
> --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188e.c
> +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188e.c
> @@ -1798,7 +1798,8 @@ static void rtl8188e_arfb_refresh(struct rtl8xxxu_ra_info *ra)
> 
>  static void
>  rtl8188e_update_rate_mask(struct rtl8xxxu_priv *priv,
> -                         u32 ramask, u8 rateid, int sgi, int txbw_40mhz)
> +                         u32 ramask, u8 rateid, int sgi, int txbw_40mhz,
> +                         u8 macid)
>  {
>         struct rtl8xxxu_ra_info *ra = &priv->ra_info;
> 
> diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
> b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
> index b20ff8bc40870..b5cb15e472f1c 100644
> --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
> +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
> @@ -4471,7 +4471,8 @@ static void rtl8xxxu_sw_scan_complete(struct ieee80211_hw *hw,
>  }
> 
>  void rtl8xxxu_update_rate_mask(struct rtl8xxxu_priv *priv,
> -                              u32 ramask, u8 rateid, int sgi, int txbw_40mhz)
> +                              u32 ramask, u8 rateid, int sgi, int txbw_40mhz,
> +                              u8 macid)
>  {
>         struct h2c_cmd h2c;
> 
> @@ -4491,7 +4492,8 @@ void rtl8xxxu_update_rate_mask(struct rtl8xxxu_priv *priv,
>  }
> 
>  void rtl8xxxu_gen2_update_rate_mask(struct rtl8xxxu_priv *priv,
> -                                   u32 ramask, u8 rateid, int sgi, int txbw_40mhz)
> +                                   u32 ramask, u8 rateid, int sgi, int txbw_40mhz,
> +                                   u8 macid)
>  {
>         struct h2c_cmd h2c;
>         u8 bw;
> @@ -4508,6 +4510,7 @@ void rtl8xxxu_gen2_update_rate_mask(struct rtl8xxxu_priv *priv,
>         h2c.b_macid_cfg.ramask1 = (ramask >> 8) & 0xff;
>         h2c.b_macid_cfg.ramask2 = (ramask >> 16) & 0xff;
>         h2c.b_macid_cfg.ramask3 = (ramask >> 24) & 0xff;
> +       h2c.b_macid_cfg.macid = macid;
> 
>         h2c.b_macid_cfg.data1 = rateid;
>         if (sgi)
> @@ -4870,7 +4873,8 @@ rtl8xxxu_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
>                         priv->vif = vif;
>                         priv->rssi_level = RTL8XXXU_RATR_STA_INIT;
> 
> -                       priv->fops->update_rate_mask(priv, ramask, 0, sgi, bw == RATE_INFO_BW_40);
> +                       priv->fops->update_rate_mask(priv, ramask, 0, sgi,
> +                                                    bw == RATE_INFO_BW_40, 0);
> 
>                         rtl8xxxu_write8(priv, REG_BCN_MAX_ERR, 0xff);
> 
> @@ -6772,6 +6776,7 @@ static void rtl8xxxu_refresh_rate_mask(struct rtl8xxxu_priv *priv,
>         u8 txbw_40mhz;
>         u8 snr, snr_thresh_high, snr_thresh_low;
>         u8 go_up_gap = 5;
> +       u8 macid = 0;
> 
>         rssi_level = priv->rssi_level;
>         snr = rtl8xxxu_signal_to_snr(signal);
> @@ -6891,7 +6896,11 @@ static void rtl8xxxu_refresh_rate_mask(struct rtl8xxxu_priv *priv,
>                 }
> 
>                 priv->rssi_level = rssi_level;
> -               priv->fops->update_rate_mask(priv, rate_bitmap, ratr_idx, sgi, txbw_40mhz);
> +
> +               if (priv->vif->type == NL80211_IFTYPE_AP)
> +                       macid = sta->aid + 1;

We should reserve a special mac_id for broadcast packets, because rate adaptive 
algorithm in firmware also uses mac_id as instance ID of rate selection.

> +
> +               priv->fops->update_rate_mask(priv, rate_bitmap, ratr_idx, sgi, txbw_40mhz, macid);
>         }
>  }
> 
> --
> 2.30.2
Kalle Valo March 27, 2023, 8:41 a.m. UTC | #2
Ping-Ke Shih <pkshih@realtek.com> writes:

>> -----Original Message-----
>> From: Martin Kaistra <martin.kaistra@linutronix.de>
>> Sent: Thursday, March 23, 2023 1:19 AM
>> To: linux-wireless@vger.kernel.org
>> Cc: Jes Sorensen <Jes.Sorensen@gmail.com>; Kalle Valo <kvalo@kernel.org>; Ping-Ke Shih
>> <pkshih@realtek.com>; Bitterblue Smith <rtl8821cerfe2@gmail.com>; Sebastian Andrzej Siewior
>> <bigeasy@linutronix.de>
>> Subject: [RFC PATCH 07/14] wifi: rtl8xxxu: Add parameter macid to update_rate_mask
>> 
>> The HW maintains a rate_mask for each connection, referenced by the
>> macid. Add a parameter to update_rate_mask and add the macid to the
>> h2c call in the gen2 implementation.
>> 
>> Also extend refresh_rate_mask to generate the macid in AP mode from
>> sta->aid.
>
> Firmware can support 32 mac_id (station instance) at most, so it will be a
> problem if hostapd assigns aid more than 32. Though I'm not clear how
> hostpad assigns the aid, it would be always safe that rtl8xxxu maintains
> mac_id by a bitmap in driver.

Does rtlw8xxxu set struct wiphy::max_ap_assoc_sta? It would be good to
advertise the user space the maximum number of stations.
Ping-Ke Shih March 27, 2023, 9:19 a.m. UTC | #3
> -----Original Message-----
> From: Kalle Valo <kvalo@kernel.org>
> Sent: Monday, March 27, 2023 4:42 PM
> To: Ping-Ke Shih <pkshih@realtek.com>
> Cc: Martin Kaistra <martin.kaistra@linutronix.de>; linux-wireless@vger.kernel.org; Jes Sorensen
> <Jes.Sorensen@gmail.com>; Bitterblue Smith <rtl8821cerfe2@gmail.com>; Sebastian Andrzej Siewior
> <bigeasy@linutronix.de>
> Subject: Re: [RFC PATCH 07/14] wifi: rtl8xxxu: Add parameter macid to update_rate_mask
> 
> Ping-Ke Shih <pkshih@realtek.com> writes:
> 
> >> -----Original Message-----
> >> From: Martin Kaistra <martin.kaistra@linutronix.de>
> >> Sent: Thursday, March 23, 2023 1:19 AM
> >> To: linux-wireless@vger.kernel.org
> >> Cc: Jes Sorensen <Jes.Sorensen@gmail.com>; Kalle Valo <kvalo@kernel.org>; Ping-Ke Shih
> >> <pkshih@realtek.com>; Bitterblue Smith <rtl8821cerfe2@gmail.com>; Sebastian Andrzej Siewior
> >> <bigeasy@linutronix.de>
> >> Subject: [RFC PATCH 07/14] wifi: rtl8xxxu: Add parameter macid to update_rate_mask
> >>
> >> The HW maintains a rate_mask for each connection, referenced by the
> >> macid. Add a parameter to update_rate_mask and add the macid to the
> >> h2c call in the gen2 implementation.
> >>
> >> Also extend refresh_rate_mask to generate the macid in AP mode from
> >> sta->aid.
> >
> > Firmware can support 32 mac_id (station instance) at most, so it will be a
> > problem if hostapd assigns aid more than 32. Though I'm not clear how
> > hostpad assigns the aid, it would be always safe that rtl8xxxu maintains
> > mac_id by a bitmap in driver.
> 
> Does rtlw8xxxu set struct wiphy::max_ap_assoc_sta? It would be good to
> advertise the user space the maximum number of stations.
> 

Thanks for this information, Kalle.

Martin, please add this. I think we can preserve at least one mac_id for
broadcast/multicast frames. In fact, I'm not absolutely sure we can
support up to 32 mac_id, so set wiphy::max_ap_assoc_sta = 16 -1 or -2
would be safer.

Ping-Ke
Bitterblue Smith March 27, 2023, 1:12 p.m. UTC | #4
On 27/03/2023 12:19, Ping-Ke Shih wrote:
> 
> 
>> -----Original Message-----
>> From: Kalle Valo <kvalo@kernel.org>
>> Sent: Monday, March 27, 2023 4:42 PM
>> To: Ping-Ke Shih <pkshih@realtek.com>
>> Cc: Martin Kaistra <martin.kaistra@linutronix.de>; linux-wireless@vger.kernel.org; Jes Sorensen
>> <Jes.Sorensen@gmail.com>; Bitterblue Smith <rtl8821cerfe2@gmail.com>; Sebastian Andrzej Siewior
>> <bigeasy@linutronix.de>
>> Subject: Re: [RFC PATCH 07/14] wifi: rtl8xxxu: Add parameter macid to update_rate_mask
>>
>> Ping-Ke Shih <pkshih@realtek.com> writes:
>>
>>>> -----Original Message-----
>>>> From: Martin Kaistra <martin.kaistra@linutronix.de>
>>>> Sent: Thursday, March 23, 2023 1:19 AM
>>>> To: linux-wireless@vger.kernel.org
>>>> Cc: Jes Sorensen <Jes.Sorensen@gmail.com>; Kalle Valo <kvalo@kernel.org>; Ping-Ke Shih
>>>> <pkshih@realtek.com>; Bitterblue Smith <rtl8821cerfe2@gmail.com>; Sebastian Andrzej Siewior
>>>> <bigeasy@linutronix.de>
>>>> Subject: [RFC PATCH 07/14] wifi: rtl8xxxu: Add parameter macid to update_rate_mask
>>>>
>>>> The HW maintains a rate_mask for each connection, referenced by the
>>>> macid. Add a parameter to update_rate_mask and add the macid to the
>>>> h2c call in the gen2 implementation.
>>>>
>>>> Also extend refresh_rate_mask to generate the macid in AP mode from
>>>> sta->aid.
>>>
>>> Firmware can support 32 mac_id (station instance) at most, so it will be a
>>> problem if hostapd assigns aid more than 32. Though I'm not clear how
>>> hostpad assigns the aid, it would be always safe that rtl8xxxu maintains
>>> mac_id by a bitmap in driver.
>>
>> Does rtlw8xxxu set struct wiphy::max_ap_assoc_sta? It would be good to
>> advertise the user space the maximum number of stations.
>>
> 
> Thanks for this information, Kalle.
> 
> Martin, please add this. I think we can preserve at least one mac_id for
> broadcast/multicast frames. In fact, I'm not absolutely sure we can
> support up to 32 mac_id, so set wiphy::max_ap_assoc_sta = 16 -1 or -2
> would be safer.
> 
> Ping-Ke
> 
> 
Indeed, the RTL8188FU driver has hal_spec->macid_num = 16. I think that's
the maximum for this chip.

RTL8710BU: 16
RTL8188EU: 64
RTL8192EU: 128
RTL8723BU: 128
diff mbox series

Patch

diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h
index cac985271628c..c06ad33645974 100644
--- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h
+++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h
@@ -1905,7 +1905,8 @@  struct rtl8xxxu_fileops {
 	void (*set_tx_power) (struct rtl8xxxu_priv *priv, int channel,
 			      bool ht40);
 	void (*update_rate_mask) (struct rtl8xxxu_priv *priv,
-				  u32 ramask, u8 rateid, int sgi, int txbw_40mhz);
+				  u32 ramask, u8 rateid, int sgi, int txbw_40mhz,
+				  u8 macid);
 	void (*report_connect) (struct rtl8xxxu_priv *priv,
 				u8 macid, bool connect);
 	void (*report_rssi) (struct rtl8xxxu_priv *priv, u8 macid, u8 rssi);
@@ -2007,9 +2008,9 @@  void rtl8xxxu_gen2_config_channel(struct ieee80211_hw *hw);
 void rtl8xxxu_gen1_usb_quirks(struct rtl8xxxu_priv *priv);
 void rtl8xxxu_gen2_usb_quirks(struct rtl8xxxu_priv *priv);
 void rtl8xxxu_update_rate_mask(struct rtl8xxxu_priv *priv,
-			       u32 ramask, u8 rateid, int sgi, int txbw_40mhz);
+			       u32 ramask, u8 rateid, int sgi, int txbw_40mhz, u8 macid);
 void rtl8xxxu_gen2_update_rate_mask(struct rtl8xxxu_priv *priv,
-				    u32 ramask, u8 rateid, int sgi, int txbw_40mhz);
+				    u32 ramask, u8 rateid, int sgi, int txbw_40mhz, u8 macid);
 void rtl8xxxu_gen1_report_connect(struct rtl8xxxu_priv *priv,
 				  u8 macid, bool connect);
 void rtl8xxxu_gen2_report_connect(struct rtl8xxxu_priv *priv,
diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188e.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188e.c
index 6a82ec47568ee..c3dc5130c9f37 100644
--- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188e.c
+++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188e.c
@@ -1798,7 +1798,8 @@  static void rtl8188e_arfb_refresh(struct rtl8xxxu_ra_info *ra)
 
 static void
 rtl8188e_update_rate_mask(struct rtl8xxxu_priv *priv,
-			  u32 ramask, u8 rateid, int sgi, int txbw_40mhz)
+			  u32 ramask, u8 rateid, int sgi, int txbw_40mhz,
+			  u8 macid)
 {
 	struct rtl8xxxu_ra_info *ra = &priv->ra_info;
 
diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
index b20ff8bc40870..b5cb15e472f1c 100644
--- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
+++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
@@ -4471,7 +4471,8 @@  static void rtl8xxxu_sw_scan_complete(struct ieee80211_hw *hw,
 }
 
 void rtl8xxxu_update_rate_mask(struct rtl8xxxu_priv *priv,
-			       u32 ramask, u8 rateid, int sgi, int txbw_40mhz)
+			       u32 ramask, u8 rateid, int sgi, int txbw_40mhz,
+			       u8 macid)
 {
 	struct h2c_cmd h2c;
 
@@ -4491,7 +4492,8 @@  void rtl8xxxu_update_rate_mask(struct rtl8xxxu_priv *priv,
 }
 
 void rtl8xxxu_gen2_update_rate_mask(struct rtl8xxxu_priv *priv,
-				    u32 ramask, u8 rateid, int sgi, int txbw_40mhz)
+				    u32 ramask, u8 rateid, int sgi, int txbw_40mhz,
+				    u8 macid)
 {
 	struct h2c_cmd h2c;
 	u8 bw;
@@ -4508,6 +4510,7 @@  void rtl8xxxu_gen2_update_rate_mask(struct rtl8xxxu_priv *priv,
 	h2c.b_macid_cfg.ramask1 = (ramask >> 8) & 0xff;
 	h2c.b_macid_cfg.ramask2 = (ramask >> 16) & 0xff;
 	h2c.b_macid_cfg.ramask3 = (ramask >> 24) & 0xff;
+	h2c.b_macid_cfg.macid = macid;
 
 	h2c.b_macid_cfg.data1 = rateid;
 	if (sgi)
@@ -4870,7 +4873,8 @@  rtl8xxxu_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 			priv->vif = vif;
 			priv->rssi_level = RTL8XXXU_RATR_STA_INIT;
 
-			priv->fops->update_rate_mask(priv, ramask, 0, sgi, bw == RATE_INFO_BW_40);
+			priv->fops->update_rate_mask(priv, ramask, 0, sgi,
+						     bw == RATE_INFO_BW_40, 0);
 
 			rtl8xxxu_write8(priv, REG_BCN_MAX_ERR, 0xff);
 
@@ -6772,6 +6776,7 @@  static void rtl8xxxu_refresh_rate_mask(struct rtl8xxxu_priv *priv,
 	u8 txbw_40mhz;
 	u8 snr, snr_thresh_high, snr_thresh_low;
 	u8 go_up_gap = 5;
+	u8 macid = 0;
 
 	rssi_level = priv->rssi_level;
 	snr = rtl8xxxu_signal_to_snr(signal);
@@ -6891,7 +6896,11 @@  static void rtl8xxxu_refresh_rate_mask(struct rtl8xxxu_priv *priv,
 		}
 
 		priv->rssi_level = rssi_level;
-		priv->fops->update_rate_mask(priv, rate_bitmap, ratr_idx, sgi, txbw_40mhz);
+
+		if (priv->vif->type == NL80211_IFTYPE_AP)
+			macid = sta->aid + 1;
+
+		priv->fops->update_rate_mask(priv, rate_bitmap, ratr_idx, sgi, txbw_40mhz, macid);
 	}
 }