wifi: rtw89: adjust code to fit coming field_prep()
Ping-Ke Shih
maintainercover wifi: rtw89: adjust code to fit coming field_prep()
As Geert mentioned [1], two more tricky cases are pointed out by implementation of field_prep(). Change the code to resolve the tricks.
Ping-Ke Shih (2):
wifi: rtw89: 8852a: correct field mask of reset DAC/ADC FIFO
wifi: rtw89: avoid to use not consecutive mask in __write_ctrl()
drivers/net/wireless/realtek/rtw89/mac.h | 20 ++++++++++++++ drivers/net/wireless/realtek/rtw89/rtw8851b.c | 26 +++++-------------- .../net/wireless/realtek/rtw89/rtw8852a_rfk.c | 8 +++--- drivers/net/wireless/realtek/rtw89/rtw8852b.c | 26 +++++-------------- drivers/net/wireless/realtek/rtw89/rtw8852c.c | 26 +++++-------------- 5 files changed, 45 insertions(+), 61 deletions(-)
Signature · 1 line
2.25.1
Ping-Ke Shih
maintainerPATCH 1/2 wifi: rtw89: 8852a: correct field mask of reset DAC/ADC FIFO
The field mask should be bits 16-31, but suddenly use wrong bits 24-31, rarely causing a little performance degraded if DAC/DAC FIFO stays on an unexpected state.
Found this by Geert who works on bit field functions.
--- drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c +4 -4
@@ -756,8 +756,8 @@ static void _iqk_rxk_setting(struct rtw89_dev *rtwdev, u8 path)rtw89_phy_write32_mask (rtwdev,R_ANAPAR ,B_ANAPAR_FLTRST ,0x1 );rtw89_phy_write32_mask (rtwdev,R_ANAPAR_PW15 ,B_ANAPAR_PW15_H2 ,0x0 );udelay (1 ); -rtw89_phy_write32_mask (rtwdev,R_ADC_FIFO ,B_ADC_FIFO_RST ,0x0303 ); -rtw89_phy_write32_mask (rtwdev,R_ADC_FIFO ,B_ADC_FIFO_RST ,0x0000 ); +rtw89_phy_write32_mask (rtwdev,R_ADC_FIFO ,B_ADC_FIFO_RXK ,0x0303 ); +rtw89_phy_write32_mask (rtwdev,R_ADC_FIFO ,B_ADC_FIFO_RXK ,0x0000 );switch (iqk_info->iqk_band[path]) {case RTW89_BAND_2G :
@@ -1239,8 +1239,8 @@ static void _iqk_txk_setting(struct rtw89_dev *rtwdev, u8 path)udelay (1 );rtw89_phy_write32_mask (rtwdev,R_ANAPAR ,B_ANAPAR_15 ,0x0041 );udelay (1 ); -rtw89_phy_write32_mask (rtwdev,R_ADC_FIFO ,B_ADC_FIFO_RST ,0x0303 ); -rtw89_phy_write32_mask (rtwdev,R_ADC_FIFO ,B_ADC_FIFO_RST ,0x0000 ); +rtw89_phy_write32_mask (rtwdev,R_ADC_FIFO ,B_ADC_FIFO_RXK ,0x0303 ); +rtw89_phy_write32_mask (rtwdev,R_ADC_FIFO ,B_ADC_FIFO_RXK ,0x0000 );switch (iqk_info->iqk_band[path]) {case RTW89_BAND_2G :rtw89_write_rf (rtwdev, path,RR_XALNA2 ,RR_XALNA2_SW ,0x00 );
Signature · 1 line
2.25.1
Re: [PATCH rtw-next 1/2] wifi: rtw89: 8852a: correct field mask of reset DAC/ADC FIFO
Quoted 8 lines · Ping-Ke Shih
The field mask should be bits 16-31, but suddenly use wrong bits 24-31, rarely causing a little performance degraded if DAC/DAC FIFO stays on an unexpected state.
Found this by Geert who works on bit field functions.
Cc Geert Uytterhoeven <[email protected]>Signed-off-by Ping-Ke Shih <[email protected]>
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Ping-Ke Shih
maintainerRE: [PATCH rtw-next 1/2] wifi: rtw89: 8852a: correct field mask of reset DAC/ADC FIFO
Quoted 5 lines · Geert Uytterhoeven
Quoted 4 lines · Ping-Ke Shih
The field mask should be bits 16-31, but suddenly use wrong bits 24-31, rarely causing a little performance degraded if DAC/DAC FIFO stays on an unexpected state.
Quoted 7 lines
Quoted 4 lines
Found this by Geert who works on bit field functions.
Cc Geert Uytterhoeven <[email protected]>Signed-off-by Ping-Ke Shih <[email protected]>Reported-by Geert Uytterhoeven <[email protected]>
I suppose you meant Reviewed-by, but you also the reporter. I will add these tags by v2.
Re: [PATCH rtw-next 1/2] wifi: rtw89: 8852a: correct field mask of reset DAC/ADC FIFO
Hi Ping-Ke,
Quoted 8 lines · Ping-Ke Shih
Quoted 7 lines · Geert Uytterhoeven
Quoted 6 lines · Ping-Ke Shih
The field mask should be bits 16-31, but suddenly use wrong bits 24-31, rarely causing a little performance degraded if DAC/DAC FIFO stays on an unexpected state.
Found this by Geert who works on bit field functions.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Cc Geert Uytterhoeven <[email protected]>Signed-off-by Ping-Ke Shih <[email protected]>Reported-by Geert Uytterhoeven <[email protected]>I suppose you meant Reviewed-by, but you also the reporter. I will add these tags by v2.
I did mean Reported-by.
I cannot review the actual values, as I do not have hardware documentation.
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Ping-Ke Shih
maintainerPATCH 2/2 wifi: rtw89: avoid to use not consecutive mask in __write_ctrl()
In reply to Ping-Ke ShihThe power value and enable bit fields can be not consecutive mask, but normally we expect mask argument of rtw89_mac_txpwr_write32_mask() is consecutive bit mask. Therefore, change the code accordingly.
--- drivers/net/wireless/realtek/rtw89/mac.h | 20 ++++++++++++++ drivers/net/wireless/realtek/rtw89/rtw8851b.c | 26 +++++-------------- drivers/net/wireless/realtek/rtw89/rtw8852b.c | 26 +++++-------------- drivers/net/wireless/realtek/rtw89/rtw8852c.c | 26 +++++-------------- 4 files changed, 41 insertions(+), 57 deletions(-)
drivers/net/wireless/realtek/rtw89/mac.h +20 -0
@@ -1456,6 +1456,26 @@ static inline int rtw89_mac_txpwr_write32_mask(struct rtw89_dev *rtwdev,return 0 ; } +static inline +void rtw89_mac_write_txpwr_ctrl (struct rtw89_dev *rtwdev,u32 reg,u32 mask,u32 val, +u32 mask_en,bool cond) +{ +u32 wrt =u32_encode_bits (val, mask); +u32 val32; +int ret; + +if (cond) + wrt |= mask_en; + + ret =rtw89_mac_txpwr_read32 (rtwdev,RTW89_PHY_0 , reg, &val32); +if (ret) +return ; + + val32 &= ~(mask | mask_en); + val32 |= wrt; +rtw89_mac_txpwr_write32 (rtwdev,RTW89_PHY_0 , reg, val32); +} +static inline void rtw89_mac_ctrl_hci_dma_tx (struct rtw89_dev *rtwdev,bool enable) {
drivers/net/wireless/realtek/rtw89/rtw8851b.c +7 -19
@@ -2291,18 +2291,6 @@ rtw8851b_btc_set_wl_txpwr_ctrl(struct rtw89_dev *rtwdev, u32 txpwr_val)union rtw8851b_btc_wl_txpwr_ctrl arg = { .txpwr_val = txpwr_val };s32 val; -#define __write_ctrl (_reg, _msk, _val, _en, _cond) \ -do { \ - u32 _wrt = FIELD_PREP(_msk, _val); \ - BUILD_BUG_ON(!!(_msk & _en)); \ - if (_cond) \ - _wrt |= _en; \ - else \ - _wrt &= ~_en; \ - rtw89_mac_txpwr_write32_mask(rtwdev, RTW89_PHY_0, _reg, \ - _msk | _en, _wrt); \ -} while (0) -switch (arg.ctrl_all_time) {case 0xffff : val =0 ;
@@ -2312,9 +2300,10 @@ do { \break ; } -__write_ctrl (R_AX_PWR_RATE_CTRL ,B_AX_FORCE_PWR_BY_RATE_VALUE_MASK , - val,B_AX_FORCE_PWR_BY_RATE_EN , - arg.ctrl_all_time !=0xffff ); +rtw89_mac_write_txpwr_ctrl (rtwdev,R_AX_PWR_RATE_CTRL , +B_AX_FORCE_PWR_BY_RATE_VALUE_MASK , + val,B_AX_FORCE_PWR_BY_RATE_EN , + arg.ctrl_all_time !=0xffff );switch (arg.ctrl_gnt_bt) {case 0xffff :
@@ -2325,10 +2314,9 @@ do { \break ; } -__write_ctrl (R_AX_PWR_COEXT_CTRL ,B_AX_TXAGC_BT_MASK , val, -B_AX_TXAGC_BT_EN , arg.ctrl_gnt_bt !=0xffff ); - -#undef __write_ctrl +rtw89_mac_write_txpwr_ctrl (rtwdev,R_AX_PWR_COEXT_CTRL , +B_AX_TXAGC_BT_MASK , val, +B_AX_TXAGC_BT_EN , arg.ctrl_gnt_bt !=0xffff ); } static
drivers/net/wireless/realtek/rtw89/rtw8852b.c +7 -19
@@ -761,18 +761,6 @@ rtw8852b_btc_set_wl_txpwr_ctrl(struct rtw89_dev *rtwdev, u32 txpwr_val)union rtw8852b_btc_wl_txpwr_ctrl arg = { .txpwr_val = txpwr_val };s32 val; -#define __write_ctrl (_reg, _msk, _val, _en, _cond) \ -do { \ - u32 _wrt = FIELD_PREP(_msk, _val); \ - BUILD_BUG_ON(!!(_msk & _en)); \ - if (_cond) \ - _wrt |= _en; \ - else \ - _wrt &= ~_en; \ - rtw89_mac_txpwr_write32_mask(rtwdev, RTW89_PHY_0, _reg, \ - _msk | _en, _wrt); \ -} while (0) -switch (arg.ctrl_all_time) {case 0xffff : val =0 ;
@@ -782,9 +770,10 @@ do { \break ; } -__write_ctrl (R_AX_PWR_RATE_CTRL ,B_AX_FORCE_PWR_BY_RATE_VALUE_MASK , - val,B_AX_FORCE_PWR_BY_RATE_EN , - arg.ctrl_all_time !=0xffff ); +rtw89_mac_write_txpwr_ctrl (rtwdev,R_AX_PWR_RATE_CTRL , +B_AX_FORCE_PWR_BY_RATE_VALUE_MASK , + val,B_AX_FORCE_PWR_BY_RATE_EN , + arg.ctrl_all_time !=0xffff );switch (arg.ctrl_gnt_bt) {case 0xffff :
@@ -795,10 +784,9 @@ do { \break ; } -__write_ctrl (R_AX_PWR_COEXT_CTRL ,B_AX_TXAGC_BT_MASK , val, -B_AX_TXAGC_BT_EN , arg.ctrl_gnt_bt !=0xffff ); - -#undef __write_ctrl +rtw89_mac_write_txpwr_ctrl (rtwdev,R_AX_PWR_COEXT_CTRL , +B_AX_TXAGC_BT_MASK , val, +B_AX_TXAGC_BT_EN , arg.ctrl_gnt_bt !=0xffff ); }static const struct rtw89_chip_ops rtw8852b_chip_ops = {
drivers/net/wireless/realtek/rtw89/rtw8852c.c +7 -19
@@ -2760,18 +2760,6 @@ rtw8852c_btc_set_wl_txpwr_ctrl(struct rtw89_dev *rtwdev, u32 txpwr_val)union rtw8852c_btc_wl_txpwr_ctrl arg = { .txpwr_val = txpwr_val };s32 val; -#define __write_ctrl (_reg, _msk, _val, _en, _cond) \ -do { \ - u32 _wrt = FIELD_PREP(_msk, _val); \ - BUILD_BUG_ON((_msk & _en) != 0); \ - if (_cond) \ - _wrt |= _en; \ - else \ - _wrt &= ~_en; \ - rtw89_mac_txpwr_write32_mask(rtwdev, RTW89_PHY_0, _reg, \ - _msk | _en, _wrt); \ -} while (0) -switch (arg.ctrl_all_time) {case 0xffff : val =0 ;
@@ -2781,9 +2769,10 @@ do { \break ; } -__write_ctrl (R_AX_PWR_RATE_CTRL ,B_AX_FORCE_PWR_BY_RATE_VALUE_MASK , - val,B_AX_FORCE_PWR_BY_RATE_EN , - arg.ctrl_all_time !=0xffff ); +rtw89_mac_write_txpwr_ctrl (rtwdev,R_AX_PWR_RATE_CTRL , +B_AX_FORCE_PWR_BY_RATE_VALUE_MASK , + val,B_AX_FORCE_PWR_BY_RATE_EN , + arg.ctrl_all_time !=0xffff );switch (arg.ctrl_gnt_bt) {case 0xffff :
@@ -2794,10 +2783,9 @@ do { \break ; } -__write_ctrl (R_AX_PWR_COEXT_CTRL ,B_AX_TXAGC_BT_MASK , val, -B_AX_TXAGC_BT_EN , arg.ctrl_gnt_bt !=0xffff ); - -#undef __write_ctrl +rtw89_mac_write_txpwr_ctrl (rtwdev,R_AX_PWR_COEXT_CTRL , +B_AX_TXAGC_BT_MASK , val, +B_AX_TXAGC_BT_EN , arg.ctrl_gnt_bt !=0xffff ); } static
Signature · 1 line
2.25.1
Re: [PATCH rtw-next 2/2] wifi: rtw89: avoid to use not consecutive mask in __write_ctrl()
Hi Ping-Ke,
Quoted 6 lines · Ping-Ke Shih
The power value and enable bit fields can be not consecutive mask, but normally we expect mask argument of
rtw89_mac_txpwr_write32_mask()is consecutive bit mask. Therefore, change the code accordingly.Cc Geert Uytterhoeven <[email protected]>Signed-off-by Ping-Ke Shih <[email protected]>
Thanks for your patch!
drivers/net/wireless/realtek/rtw89/mac.h static inline int rtw89_mac_txpwr_write32_mask(struct rtw89_dev *rtwdev, · line 1463
Quoted 11 lines
drivers/net/wireless/realtek/rtw89/mac.h +5
-0@@ -1456,6 +1456,26 @@ static inline int rtw89_mac_txpwr_write32_mask(struct rtw89_dev *rtwdev,return 0 ; } +static inline +void rtw89_mac_write_txpwr_ctrl (struct rtw89_dev *rtwdev,u32 reg,u32 mask,u32 val, +u32 mask_en,bool cond) +{ +u32 wrt =u32_encode_bits (val, mask);
Nit: you could do without this variable...
drivers/net/wireless/realtek/rtw89/mac.h static inline int rtw89_mac_txpwr_write32_mask(struct rtw89_dev *rtwdev, · line 1475
Quoted 12 lines
drivers/net/wireless/realtek/rtw89/mac.h +12
-0+u32 val32; +int ret; + +if (cond) + wrt |= mask_en; + + ret =rtw89_mac_txpwr_read32 (rtwdev,RTW89_PHY_0 , reg, &val32); +if (ret) +return ; + + val32 &= ~(mask | mask_en); + val32 |= wrt;
val32 |= u32_encode_bits(val, mask);
if (cond)
cal32 |= mask_en;
drivers/net/wireless/realtek/rtw89/mac.h static inline int rtw89_mac_txpwr_write32_mask(struct rtw89_dev *rtwdev, · line 1476
Quoted 1 line
drivers/net/wireless/realtek/rtw89/mac.h +1
-0+rtw89_mac_txpwr_write32 (rtwdev,RTW89_PHY_0 , reg, val32);
As this calls mac->get_txpwr_cr() a second time, perhaps it is better to open-code rtw89_mac_txpwr_read32() and rtw89_mac_txpwr_write32() in this function?
drivers/net/wireless/realtek/rtw89/mac.h static inline int rtw89_mac_txpwr_write32_mask(struct rtw89_dev *rtwdev, · line 1481
Quoted 5 lines
drivers/net/wireless/realtek/rtw89/mac.h +2
-0+} +static inline void rtw89_mac_ctrl_hci_dma_tx (struct rtw89_dev *rtwdev,bool enable) {
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Ping-Ke Shih
maintainerRE: [PATCH rtw-next 2/2] wifi: rtw89: avoid to use not consecutive mask in __write_ctrl()
Quoted 43 lines · Geert Uytterhoeven
Hi Ping-Ke,
Quoted 6 lines · Ping-Ke Shih
The power value and enable bit fields can be not consecutive mask, but normally we expect mask argument of
rtw89_mac_txpwr_write32_mask()is consecutive bit mask. Therefore, change the code accordingly.Cc Geert Uytterhoeven <[email protected]>Signed-off-by Ping-Ke Shih <[email protected]>Thanks for your patch!
Reviewed-by Geert Uytterhoeven <[email protected]>drivers/net/wireless/realtek/rtw89/mac.h static inline int rtw89_mac_txpwr_write32_mask(struct rtw89_dev *rtwdev, · line 1463
Quoted 11 lines
drivers/net/wireless/realtek/rtw89/mac.h +5
-0@@ -1456,6 +1456,26 @@ static inline int rtw89_mac_txpwr_write32_mask(struct rtw89_dev *rtwdev,return 0 ; } +static inline +void rtw89_mac_write_txpwr_ctrl (struct rtw89_dev *rtwdev,u32 reg,u32 mask,u32 val, +u32 mask_en,bool cond) +{ +u32 wrt =u32_encode_bits (val, mask);Nit: you could do without this variable...
drivers/net/wireless/realtek/rtw89/mac.h static inline int rtw89_mac_txpwr_write32_mask(struct rtw89_dev *rtwdev, · line 1475
Quoted 12 lines
drivers/net/wireless/realtek/rtw89/mac.h +12
-0+u32 val32; +int ret; + +if (cond) + wrt |= mask_en; + + ret =rtw89_mac_txpwr_read32 (rtwdev,RTW89_PHY_0 , reg, &val32); +if (ret) +return ; + + val32 &= ~(mask | mask_en); + val32 |= wrt;val32 |=
u32_encode_bits(val, mask);
if (cond)
Quoted 1 line
cal32 |= mask_en;
With this change, ARCH arm is failed to build (x86 is well):
In file included from /build/rtw89/core.h:9,
from /build/rtw89/coex.h:8,
from /build/rtw89/rtw8851b.c:5:
In function 'field_multiplier',
inlined from 'field_mask' at ./include/linux/bitfield.h:170:17,
inlined from 'u32_encode_bits' at ./include/linux/bitfield.h:200:1,
inlined from 'rtw89_mac_write_txpwr_ctrl' at /build/rtw89/mac.h:1468:11:
./include/linux/bitfield.h:165:17: error: call to '__bad_mask' declared with attribute error: bad bitfield mask
165 | __bad_mask();
| ^~~~~~~~~~~~In function 'field_multiplier',
Quoted 6 lines
drivers/net/wireless/realtek/rtw89/mac.h static inline int rtw89_mac_txpwr_write32_mask(struct rtw89_dev *rtwdev, · line 1476
Quoted 2 lines
drivers/net/wireless/realtek/rtw89/mac.h +1
-0+rtw89_mac_txpwr_write32 (rtwdev,RTW89_PHY_0 , reg, val32);As this calls
mac->get_txpwr_cr()a second time, perhaps it is better to open-codertw89_mac_txpwr_read32()andrtw89_mac_txpwr_write32()in this function?
This function isn't in hot path, and using rtw89_mac_txpwr_read32() and rtw89_mac_txpwr_write32() is clearer than open-code, so I'd keep it as was.
Then I don't plan to send v2.
Re: [PATCH rtw-next 2/2] wifi: rtw89: avoid to use not consecutive mask in __write_ctrl()
Hi Ping-Ke,
Quoted 56 lines · Ping-Ke Shih
Quoted 41 lines · Geert Uytterhoeven
Quoted 6 lines · Ping-Ke Shih
The power value and enable bit fields can be not consecutive mask, but normally we expect mask argument of
rtw89_mac_txpwr_write32_mask()is consecutive bit mask. Therefore, change the code accordingly.Cc Geert Uytterhoeven <[email protected]>Signed-off-by Ping-Ke Shih <[email protected]>Thanks for your patch!
Reviewed-by Geert Uytterhoeven <[email protected]>drivers/net/wireless/realtek/rtw89/mac.h static inline int rtw89_mac_txpwr_write32_mask(struct rtw89_dev *rtwdev, · line 1463
Quoted 11 lines
drivers/net/wireless/realtek/rtw89/mac.h +5
-0@@ -1456,6 +1456,26 @@ static inline int rtw89_mac_txpwr_write32_mask(struct rtw89_dev *rtwdev,return 0 ; } +static inline +void rtw89_mac_write_txpwr_ctrl (struct rtw89_dev *rtwdev,u32 reg,u32 mask,u32 val, +u32 mask_en,bool cond) +{ +u32 wrt =u32_encode_bits (val, mask);Nit: you could do without this variable...
drivers/net/wireless/realtek/rtw89/mac.h static inline int rtw89_mac_txpwr_write32_mask(struct rtw89_dev *rtwdev, · line 1475
Quoted 12 lines
drivers/net/wireless/realtek/rtw89/mac.h +12
-0+u32 val32; +int ret; + +if (cond) + wrt |= mask_en; + + ret =rtw89_mac_txpwr_read32 (rtwdev,RTW89_PHY_0 , reg, &val32); +if (ret) +return ; + + val32 &= ~(mask | mask_en); + val32 |= wrt;val32 |=
u32_encode_bits(val, mask);
if (cond)Quoted 1 line
cal32 |= mask_en;With this change, ARCH arm is failed to build (x86 is well):
In file included from /build/rtw89/core.h:9,
from /build/rtw89/coex.h:8, from /build/rtw89/rtw8851b.c:5: In function 'field_multiplier', inlined from 'field_mask' at ./include/linux/bitfield.h:170:17, inlined from 'u32_encode_bits' at ./include/linux/bitfield.h:200:1, inlined from 'rtw89_mac_write_txpwr_ctrl' at /build/rtw89/mac.h:1468:11: ./include/linux/bitfield.h:165:17: error: call to '__bad_mask' declared with attribute error: bad bitfield mask 165 | __bad_mask(); | ^~~~~~~~~~~~
Quoted 1 line
In function '
field_multiplier',
Hmm...
Note that u32_encode_bits() really requires a constant mask, just like FIELD_PREP(). So probably the compiler can no longer deduce it is called with a constant after restructuring the code...
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Ping-Ke Shih
maintainerRE: [PATCH rtw-next 2/2] wifi: rtw89: avoid to use not consecutive mask in __write_ctrl()
Quoted 62 lines · Geert Uytterhoeven
Hi Ping-Ke,
Quoted 46 lines · Ping-Ke Shih
Quoted 41 lines · Geert Uytterhoeven
Quoted 6 lines · Ping-Ke Shih
The power value and enable bit fields can be not consecutive mask, but normally we expect mask argument of
rtw89_mac_txpwr_write32_mask()is consecutive bit mask. Therefore, change the code accordingly.Cc Geert Uytterhoeven <[email protected]>Signed-off-by Ping-Ke Shih <[email protected]>Thanks for your patch!
Reviewed-by Geert Uytterhoeven <[email protected]>drivers/net/wireless/realtek/rtw89/mac.h static inline int rtw89_mac_txpwr_write32_mask(struct rtw89_dev *rtwdev, · line 1463
Quoted 11 lines
drivers/net/wireless/realtek/rtw89/mac.h +5
-0@@ -1456,6 +1456,26 @@ static inline int rtw89_mac_txpwr_write32_mask(struct rtw89_dev *rtwdev,return 0 ; } +static inline +void rtw89_mac_write_txpwr_ctrl (struct rtw89_dev *rtwdev,u32 reg,u32 mask,u32 val, +u32 mask_en,bool cond) +{ +u32 wrt =u32_encode_bits (val, mask);Nit: you could do without this variable...
drivers/net/wireless/realtek/rtw89/mac.h static inline int rtw89_mac_txpwr_write32_mask(struct rtw89_dev *rtwdev, · line 1475
Quoted 12 lines
drivers/net/wireless/realtek/rtw89/mac.h +12
-0+u32 val32; +int ret; + +if (cond) + wrt |= mask_en; + + ret =rtw89_mac_txpwr_read32 (rtwdev,RTW89_PHY_0 , reg, &val32); +if (ret) +return ; + + val32 &= ~(mask | mask_en); + val32 |= wrt;val32 |=
u32_encode_bits(val, mask);
if (cond)Quoted 1 line
cal32 |= mask_en;With this change, ARCH arm is failed to build (x86 is well):
Quoted 8 lines
In file included from /build/rtw89/core.h:9,
from /build/rtw89/coex.h:8, from /build/rtw89/rtw8851b.c:5: In function 'field_multiplier', inlined from 'field_mask' at ./include/linux/bitfield.h:170:17, inlined from 'u32_encode_bits' at ./include/linux/bitfield.h:200:1, inlined from 'rtw89_mac_write_txpwr_ctrl' at /build/rtw89/mac.h:1468:11:
./include/linux/bitfield.h:165:17: error: call to '__bad_mask' declared with attribute error: badbitfield mask
Quoted 3 lines
165 | __bad_mask(); | ^~~~~~~~~~~~In function '
field_multiplier',
Quoted 5 lines
Hmm...
Note that
u32_encode_bits()really requires a constant mask, just likeFIELD_PREP(). So probably the compiler can no longer deduce it is called with a constant after restructuring the code...
Do you think I need to add a macro to generate mask with u32_encode_bits() and then call this inline function?
Or, compiler can always deduce it in the inline function, and current version is okay?
Ping-Ke Shih
maintainerRE: [PATCH rtw-next 2/2] wifi: rtw89: avoid to use not consecutive mask in __write_ctrl()
Hi Geert,
Quoted 23 lines · Ping-Ke Shih
Quoted 22 lines · Geert Uytterhoeven
Hi Ping-Ke,
Quoted 19 lines · Ping-Ke Shih
Quoted 18 lines · Geert Uytterhoeven
Quoted 6 lines · Ping-Ke Shih
The power value and enable bit fields can be not consecutive mask, but normally we expect mask argument of
rtw89_mac_txpwr_write32_mask()is consecutive bit mask. Therefore, change the code accordingly.Cc Geert Uytterhoeven <[email protected]>Signed-off-by Ping-Ke Shih <[email protected]>Thanks for your patch!
Reviewed-by Geert Uytterhoeven <[email protected]>Quoted 6 lines
drivers/net/wireless/realtek/rtw89/mac.h +0
-0@@ -1456,6 +1456,26 @@ static inline int rtw89_mac_txpwr_write32_mask(struct rtw89_dev *rtwdev,return 0 ; }
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/net/wireless/realtek/rtw89/mac.h static inline int rtw89_mac_txpwr_write32_mask(struct rtw89_dev *rtwdev, · line 1463
Quoted 5 lines
drivers/net/wireless/realtek/rtw89/mac.h +5
-0+static inline +void rtw89_mac_write_txpwr_ctrl (struct rtw89_dev *rtwdev,u32 reg,u32 mask,u32 val, +u32 mask_en,bool cond) +{ +u32 wrt =u32_encode_bits (val, mask);Nit: you could do without this variable...
Can you change u32_encode_bits() to field_prep() you are going to add? And take this patch (v1) with your suggestion into your patchset. Then the code looks better and thing can be smooth.
I will drop my v2 that looks not good.
Quoted 45 lines
Quoted 33 lines
Quoted 20 lines
Quoted 16 lines
drivers/net/wireless/realtek/rtw89/mac.h static inline int rtw89_mac_txpwr_write32_mask(struct rtw89_dev *rtwdev, · line 1475
Quoted 13 lines
drivers/net/wireless/realtek/rtw89/mac.h +12
-0+u32 val32; +int ret; + +if (cond) + wrt |= mask_en; + + ret =rtw89_mac_txpwr_read32 (rtwdev,RTW89_PHY_0 , reg, &val32); +if (ret) +return ; + + val32 &= ~(mask | mask_en); + val32 |= wrt;val32 |=
u32_encode_bits(val, mask);
if (cond)Quoted 1 line
cal32 |= mask_en;With this change, ARCH arm is failed to build (x86 is well):
Quoted 8 lines
In file included from /build/rtw89/core.h:9,
from /build/rtw89/coex.h:8, from /build/rtw89/rtw8851b.c:5: In function 'field_multiplier', inlined from 'field_mask' at ./include/linux/bitfield.h:170:17, inlined from 'u32_encode_bits' at ./include/linux/bitfield.h:200:1, inlined from 'rtw89_mac_write_txpwr_ctrl' at /build/rtw89/mac.h:1468:11:
./include/linux/bitfield.h:165:17: error: call to '__bad_mask' declared with attribute error: badbitfield mask
Quoted 3 lines
165 | __bad_mask(); | ^~~~~~~~~~~~In function '
field_multiplier',Quoted 5 lines
Hmm...
Note that
u32_encode_bits()really requires a constant mask, just likeFIELD_PREP(). So probably the compiler can no longer deduce it is called with a constant after restructuring the code...Do you think I need to add a macro to generate mask with
u32_encode_bits()and then call this inline function?Or, compiler can always deduce it in the inline function, and current version is okay?