From: Bitterblue Smith <rtl8821cerfe2@gmail.com>
To: Kalle Valo <kvalo@kernel.org>, Ping-Ke Shih <pkshih@realtek.com>
Cc: "linux-wireless@vger.kernel.org" <linux-wireless@vger.kernel.org>
Subject: Re: [PATCH 03/20] wifi: rtw88: Allow different C2H RA report sizes
Date: Thu, 22 Aug 2024 17:04:30 +0300 [thread overview]
Message-ID: <2df8a217-b65b-473e-b69b-1b99c597a3f0@gmail.com> (raw)
In-Reply-To: <875xrtgi2f.fsf@kernel.org>
On 22/08/2024 09:58, Kalle Valo wrote:
> Ping-Ke Shih <pkshih@realtek.com> writes:
>
>> Bitterblue Smith <rtl8821cerfe2@gmail.com> wrote:
>>
>>> On 21/08/2024 03:31, Ping-Ke Shih wrote:
>>>> Bitterblue Smith <rtl8821cerfe2@gmail.com> wrote:
>>>>> On 20/08/2024 04:10, Ping-Ke Shih wrote:
>>>>>> Bitterblue Smith <rtl8821cerfe2@gmail.com> wrote:
>>>>>>> On 15/08/2024 09:14, Ping-Ke Shih wrote:
>>>>>>>> Bitterblue Smith <rtl8821cerfe2@gmail.com> wrote:
>>>>>>>>> The RTL8821AU and RTL8812AU have smaller RA report size, only 4 bytes.
>>>>>>>>> Avoid the "invalid ra report c2h length" error.
>>>>>>>>>
>>>>>>>>> Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
>>>>>>>>> ---
>>>>>>>>> drivers/net/wireless/realtek/rtw88/fw.c | 8 ++++++--
>>>>>>>>> drivers/net/wireless/realtek/rtw88/main.h | 1 +
>>>>>>>>> drivers/net/wireless/realtek/rtw88/rtw8703b.c | 1 +
>>>>>>>>> drivers/net/wireless/realtek/rtw88/rtw8723d.c | 1 +
>>>>>>>>> drivers/net/wireless/realtek/rtw88/rtw8821c.c | 1 +
>>>>>>>>> drivers/net/wireless/realtek/rtw88/rtw8822b.c | 1 +
>>>>>>>>> drivers/net/wireless/realtek/rtw88/rtw8822c.c | 1 +
>>>>>>>>> 7 files changed, 12 insertions(+), 2 deletions(-)
>>>>>>>>>
>>>>>>>>> diff --git a/drivers/net/wireless/realtek/rtw88/fw.c b/drivers/net/wireless/realtek/rtw88/fw.c
>>>>>>>>> index 782f3776e0a0..ac53e3e30af0 100644
>>>>>>>>> --- a/drivers/net/wireless/realtek/rtw88/fw.c
>>>>>>>>> +++ b/drivers/net/wireless/realtek/rtw88/fw.c
>>>>>>>>> @@ -157,7 +157,10 @@ static void rtw_fw_ra_report_iter(void *data, struct ieee80211_sta *sta)
>>>>>>>>>
>>>>>>>>> rate = GET_RA_REPORT_RATE(ra_data->payload);
>>>>>>>>> sgi = GET_RA_REPORT_SGI(ra_data->payload);
>>>>>>>>> - bw = GET_RA_REPORT_BW(ra_data->payload);
>>>>>>>>> + if (si->rtwdev->chip->c2h_ra_report_size < 7)
>>>>>>>>
>>>>>>>> Explicitly specify '== 4' for the case of RTL8821AU and RTL8812AU.
>>>>>>>>
>>>>>>>>> + bw = si->bw_mode;
>>>>>>>>> + else
>>>>>>>>> + bw = GET_RA_REPORT_BW(ra_data->payload);
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>> Would that make sense? I check for less than 7 because the size
>>>>>>> has to be at least 7 in order to access payload[6] (GET_RA_REPORT_BW).
>>>>>>
>>>>>> As you did "WARN(length < rtwdev->chip->c2h_ra_report_size)", I assume you
>>>>>> expect "< 7" cases is only for coming chips RTL8821AU and RTL8812AU.
>>>>>>
>>>>>> Maybe explicitly specifying chips ID would be easier to understand:
>>>>>> if (chip == RTL8821A || chip == RTL8812A)
>>>>>> bw = si->bw_mode;
>>>>>> else
>>>>>> bw = GET_RA_REPORT_BW(ra_data->payload);
>>>>>>
>>>>>> That's why I want "== 4". (but it seems implicitly not explicitly though.)
>>>>>>
>>>>>
>>>>> I just checked, the RA report size of RTL8814AU is 6.
>>>>
>>>> Could you also check if the report format is compatible?
>>>> I mean definition of first 4 bytes are the same for all chips? and
>>>> definition of first 6 bytes are the same for RTL8814AU and current
>>>> exiting chips?
>>>>
>>>> By the way, I think we should struct with w0, w1, ... fields instead.
>>>> struct rtw_ra_report {
>>>> __le32 w0;
>>>> __le32 w1;
>>>> __le32 w2;
>>>> __le32 w3;
>>>> __le32 w4;
>>>> __le32 w5;
>>>> __le32 w6;
>>>> } __packed;
>>>>
>>>> Then, we can be easier to avoid accessing out of range. GET_RA_REPORT_BW()
>>>> hides something, no help to read the code.
>>>>
>>>
>>> The report format looks compatible.
>>>
>>> I'm not sure how a struct with __le32 members would help here.
>>> I agree that the current macros hide things. We could access payload
>>> directly. The variable names already make it clear what each byte is:
>>>
>>> mac_id = ra_data->payload[1];
>>> if (si->mac_id != mac_id)
>>> return;
>>>
>>> si->ra_report.txrate.flags = 0;
>>>
>>> rate = u8_get_bits(ra_data->payload[0], GENMASK(6, 0));
>>> sgi = u8_get_bits(ra_data->payload[0], BIT(7));
>>> if (si->rtwdev->chip->c2h_ra_report_size >= 7)
>>> bw = ra_data->payload[6];
>>> else
>>> bw = si->bw_mode;
>>
>> Yes, this is also clear to me to avoid accessing out of range.
>> Another advantage of a struct is to explicitly tell us the total size of a
>> C2H event.
>
> Yeah, please avoid that payload[6] stuff for parsing firmware commands
> and events. It just makes the code harder to read and more fragile.
>
Okay, I will use a struct. This is similar to the solution
already accepted in rtl8xxxu:
struct rtw_c2h_ra_rpt {
u8 rate_sgi;
u8 mac_id;
u8 byte2;
u8 status;
u8 byte4;
u8 ra_ratio;
u8 bw;
u8 txcls_rate;
} __packed;
#define RTW_C2H_RA_RPT_RATE GENMASK(6, 0)
#define RTW_C2H_RA_RPT_SGI BIT(7)
mac_id = ra_rpt->mac_id;
if (si->mac_id != mac_id)
return;
si->ra_report.txrate.flags = 0;
rate = u8_get_bits(ra_rpt->rate_sgi, RTW_C2H_RA_RPT_RATE);
sgi = u8_get_bits(ra_rpt->rate_sgi, RTW_C2H_RA_RPT_SGI);
if (ra_data->length >= offsetofend(typeof(*ra_rpt), bw))
bw = ra_rpt->bw;
else
bw = si->bw_mode;
next prev parent reply other threads:[~2024-08-22 14:04 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-11 20:53 [PATCH 00/20] wifi: rtw88: Add support for RTL8821AU and RTL8812AU Bitterblue Smith
2024-08-11 20:54 ` [PATCH 01/20] wifi: rtw88: Add some definitions for RTL8821AU/RTL8812AU Bitterblue Smith
2024-08-15 6:34 ` Ping-Ke Shih
2024-08-11 20:54 ` [PATCH 02/20] wifi: rtw88: Dump the HW features only for some chips Bitterblue Smith
2024-08-15 6:10 ` Ping-Ke Shih
2024-08-19 17:51 ` Bitterblue Smith
2024-08-11 20:55 ` [PATCH 03/20] wifi: rtw88: Allow different C2H RA report sizes Bitterblue Smith
2024-08-15 6:14 ` Ping-Ke Shih
2024-08-19 17:52 ` Bitterblue Smith
2024-08-20 1:10 ` Ping-Ke Shih
2024-08-20 21:44 ` Bitterblue Smith
2024-08-21 0:31 ` Ping-Ke Shih
2024-08-21 11:13 ` Bitterblue Smith
2024-08-22 0:33 ` Ping-Ke Shih
2024-08-22 6:58 ` Kalle Valo
2024-08-22 14:04 ` Bitterblue Smith [this message]
2024-08-11 20:55 ` [PATCH 04/20] wifi: rtw88: Extend the init table parsing for RTL8812AU Bitterblue Smith
2024-08-15 6:27 ` Ping-Ke Shih
2024-08-11 20:57 ` [PATCH 05/20] wifi: rtw88: Allow rtw_chip_info.ltecoex_addr to be NULL Bitterblue Smith
2024-08-15 6:33 ` Ping-Ke Shih
2024-08-19 17:53 ` Bitterblue Smith
2024-08-20 1:15 ` Ping-Ke Shih
2024-08-11 20:57 ` [PATCH 06/20] wifi: rtw88: Let each driver control the power on/off process Bitterblue Smith
2024-08-11 20:59 ` [PATCH 07/20] wifi: rtw88: Enable data rate fallback for older chips Bitterblue Smith
2024-08-15 6:46 ` Ping-Ke Shih
2024-08-11 21:00 ` [PATCH 08/20] wifi: rtw88: Make txagc_remnant_ofdm an array Bitterblue Smith
2024-08-15 6:50 ` Ping-Ke Shih
2024-08-11 21:00 ` [PATCH 09/20] wifi: rtw88: Support TX page sizes bigger than 128 Bitterblue Smith
2024-08-15 6:52 ` Ping-Ke Shih
2024-08-11 21:01 ` [PATCH 10/20] wifi: rtw88: Move pwr_track_tbl to struct rtw_rfe_def Bitterblue Smith
2024-08-15 7:00 ` Ping-Ke Shih
2024-08-11 21:02 ` [PATCH 11/20] wifi: rtw88: usb: Set pkt_info.ls for the reserved page Bitterblue Smith
2024-08-15 7:07 ` Ping-Ke Shih
2024-08-11 21:02 ` [PATCH 12/20] wifi: rtw88: Detect beacon loss with chips other than 8822c Bitterblue Smith
2024-08-15 7:16 ` Ping-Ke Shih
2024-08-11 21:03 ` [PATCH 13/20] wifi: rtw88: coex: Support chips without a scoreboard Bitterblue Smith
2024-08-15 7:19 ` Ping-Ke Shih
2024-08-11 21:04 ` [PATCH 14/20] wifi: rtw88: 8821a: Regularly ask for BT info updates Bitterblue Smith
2024-08-15 7:26 ` Ping-Ke Shih
2024-08-11 21:05 ` [PATCH 15/20] wifi: rtw88: 8812a: Mitigate beacon loss Bitterblue Smith
2024-08-15 7:31 ` Ping-Ke Shih
2024-08-11 21:06 ` [PATCH 16/20] wifi: rtw88: Add rtw8812a_table.{c,h} Bitterblue Smith
2024-08-15 7:53 ` Ping-Ke Shih
2024-08-16 1:19 ` Ping-Ke Shih
2024-08-11 21:06 ` [PATCH 17/20] wifi: rtw88: Add rtw8821a_table.{c,h} Bitterblue Smith
2024-08-15 7:55 ` Ping-Ke Shih
2024-08-11 21:07 ` [PATCH 18/20] wifi: rtw88: Add rtw8821a.{c,h} Bitterblue Smith
2024-08-16 6:06 ` Ping-Ke Shih
2024-08-27 17:52 ` Bitterblue Smith
2024-09-10 2:30 ` Ping-Ke Shih
2024-09-12 15:59 ` Bitterblue Smith
2024-09-13 1:50 ` Ping-Ke Shih
2024-09-21 22:47 ` Bitterblue Smith
2024-09-23 5:47 ` Ping-Ke Shih
2024-09-23 5:58 ` Ping-Ke Shih
2024-09-24 21:19 ` Bitterblue Smith
2024-09-25 1:25 ` Ping-Ke Shih
2024-09-25 11:28 ` Bitterblue Smith
2024-09-26 2:27 ` Ping-Ke Shih
2024-09-26 16:41 ` Bitterblue Smith
2024-08-11 21:08 ` [PATCH 19/20] wifi: rtw88: Add rtw8821au.c and rtw8812au.c Bitterblue Smith
2024-08-15 7:58 ` Ping-Ke Shih
2024-08-11 21:11 ` [PATCH 20/20] wifi: rtw88: Enable the new RTL8821AU/RTL8812AU drivers Bitterblue Smith
2024-08-15 8:01 ` Ping-Ke Shih
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2df8a217-b65b-473e-b69b-1b99c597a3f0@gmail.com \
--to=rtl8821cerfe2@gmail.com \
--cc=kvalo@kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=pkshih@realtek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).