Skip to content

Commit d60e73e

Browse files
Ping-Ke ShihKalle Valo
authored andcommitted
wifi: rtw89: fw: load TX power track tables from fw_element
The TX power track tables are used to define compensation power reflected to thermal value. Currently, we have 16 (2 * 4 * 2) tables made by combinations of {negative/positive thermal value, 2GHz/2GHz-CCK/5GHz/6GHz, path A/B} Signed-off-by: Ping-Ke Shih <[email protected]> Signed-off-by: Kalle Valo <[email protected]> Link: https://msgid.link/[email protected]
1 parent f0dd488 commit d60e73e

File tree

4 files changed

+135
-2
lines changed

4 files changed

+135
-2
lines changed

drivers/net/wireless/realtek/rtw89/core.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct rtw89_pci_info;
1717
struct rtw89_mac_gen_def;
1818
struct rtw89_phy_gen_def;
1919
struct rtw89_efuse_block_cfg;
20+
struct rtw89_fw_txpwr_track_cfg;
2021

2122
extern const struct ieee80211_ops rtw89_ops;
2223

@@ -38,6 +39,8 @@ extern const struct ieee80211_ops rtw89_ops;
3839
#define RSSI_FACTOR 1
3940
#define RTW89_RSSI_RAW_TO_DBM(rssi) ((s8)((rssi) >> RSSI_FACTOR) - MAX_RSSI)
4041
#define RTW89_TX_DIV_RSSI_RAW_TH (2 << RSSI_FACTOR)
42+
#define DELTA_SWINGIDX_SIZE 30
43+
4144
#define RTW89_RADIOTAP_ROOM_HE sizeof(struct ieee80211_radiotap_he)
4245
#define RTW89_RADIOTAP_ROOM_EHT \
4346
(sizeof(struct ieee80211_radiotap_tlv) + \
@@ -3948,6 +3951,7 @@ struct rtw89_fw_elm_info {
39483951
struct rtw89_phy_table *bb_gain;
39493952
struct rtw89_phy_table *rf_radio[RF_PATH_MAX];
39503953
struct rtw89_phy_table *rf_nctl;
3954+
struct rtw89_fw_txpwr_track_cfg *txpwr_trk;
39513955
};
39523956

39533957
struct rtw89_fw_info {

drivers/net/wireless/realtek/rtw89/fw.c

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,72 @@ int rtw89_fw_recognize_txpwr_from_elm(struct rtw89_dev *rtwdev,
659659
return 0;
660660
}
661661

662+
static
663+
int rtw89_build_txpwr_trk_tbl_from_elm(struct rtw89_dev *rtwdev,
664+
const struct rtw89_fw_element_hdr *elm,
665+
const union rtw89_fw_element_arg arg)
666+
{
667+
struct rtw89_fw_elm_info *elm_info = &rtwdev->fw.elm_info;
668+
const struct rtw89_chip_info *chip = rtwdev->chip;
669+
u32 needed_bitmap = 0;
670+
u32 offset = 0;
671+
int subband;
672+
u32 bitmap;
673+
int type;
674+
675+
if (chip->support_bands & BIT(NL80211_BAND_6GHZ))
676+
needed_bitmap |= RTW89_DEFAULT_NEEDED_FW_TXPWR_TRK_6GHZ;
677+
if (chip->support_bands & BIT(NL80211_BAND_5GHZ))
678+
needed_bitmap |= RTW89_DEFAULT_NEEDED_FW_TXPWR_TRK_5GHZ;
679+
if (chip->support_bands & BIT(NL80211_BAND_2GHZ))
680+
needed_bitmap |= RTW89_DEFAULT_NEEDED_FW_TXPWR_TRK_2GHZ;
681+
682+
bitmap = le32_to_cpu(elm->u.txpwr_trk.bitmap);
683+
684+
if ((bitmap & needed_bitmap) != needed_bitmap) {
685+
rtw89_warn(rtwdev, "needed txpwr trk bitmap %08x but %0x8x\n",
686+
needed_bitmap, bitmap);
687+
return -ENOENT;
688+
}
689+
690+
elm_info->txpwr_trk = kzalloc(sizeof(*elm_info->txpwr_trk), GFP_KERNEL);
691+
if (!elm_info->txpwr_trk)
692+
return -ENOMEM;
693+
694+
for (type = 0; bitmap; type++, bitmap >>= 1) {
695+
if (!(bitmap & BIT(0)))
696+
continue;
697+
698+
if (type >= __RTW89_FW_TXPWR_TRK_TYPE_6GHZ_START &&
699+
type <= __RTW89_FW_TXPWR_TRK_TYPE_6GHZ_MAX)
700+
subband = 4;
701+
else if (type >= __RTW89_FW_TXPWR_TRK_TYPE_5GHZ_START &&
702+
type <= __RTW89_FW_TXPWR_TRK_TYPE_5GHZ_MAX)
703+
subband = 3;
704+
else if (type >= __RTW89_FW_TXPWR_TRK_TYPE_2GHZ_START &&
705+
type <= __RTW89_FW_TXPWR_TRK_TYPE_2GHZ_MAX)
706+
subband = 1;
707+
else
708+
break;
709+
710+
elm_info->txpwr_trk->delta[type] = &elm->u.txpwr_trk.contents[offset];
711+
712+
offset += subband;
713+
if (offset * DELTA_SWINGIDX_SIZE > le32_to_cpu(elm->size))
714+
goto err;
715+
}
716+
717+
return 0;
718+
719+
err:
720+
rtw89_warn(rtwdev, "unexpected txpwr trk offset %d over size %d\n",
721+
offset, le32_to_cpu(elm->size));
722+
kfree(elm_info->txpwr_trk);
723+
elm_info->txpwr_trk = NULL;
724+
725+
return -EFAULT;
726+
}
727+
662728
static const struct rtw89_fw_element_handler __fw_element_handlers[] = {
663729
[RTW89_FW_ELEMENT_ID_BBMCU0] = {__rtw89_fw_recognize_from_elm,
664730
{ .fw_type = RTW89_FW_BBMCU0 }, NULL},
@@ -711,6 +777,9 @@ static const struct rtw89_fw_element_handler __fw_element_handlers[] = {
711777
rtw89_fw_recognize_txpwr_from_elm,
712778
{ .offset = offsetof(struct rtw89_rfe_data, tx_shape_lmt_ru.conf) }, NULL,
713779
},
780+
[RTW89_FW_ELEMENT_ID_TXPWR_TRK] = {
781+
rtw89_build_txpwr_trk_tbl_from_elm, {}, "PWR_TRK",
782+
},
714783
};
715784

716785
int rtw89_fw_recognize_elements(struct rtw89_dev *rtwdev)
@@ -1144,6 +1213,8 @@ static void rtw89_unload_firmware_elements(struct rtw89_dev *rtwdev)
11441213
for (i = 0; i < ARRAY_SIZE(elm_info->rf_radio); i++)
11451214
rtw89_free_phy_tbl_from_elm(elm_info->rf_radio[i]);
11461215
rtw89_free_phy_tbl_from_elm(elm_info->rf_nctl);
1216+
1217+
kfree(elm_info->txpwr_trk);
11471218
}
11481219

11491220
void rtw89_unload_firmware(struct rtw89_dev *rtwdev)

drivers/net/wireless/realtek/rtw89/fw.h

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3426,6 +3426,7 @@ enum rtw89_fw_element_id {
34263426
RTW89_FW_ELEMENT_ID_TXPWR_LMT_RU_6GHZ = 15,
34273427
RTW89_FW_ELEMENT_ID_TX_SHAPE_LMT = 16,
34283428
RTW89_FW_ELEMENT_ID_TX_SHAPE_LMT_RU = 17,
3429+
RTW89_FW_ELEMENT_ID_TXPWR_TRK = 18,
34293430

34303431
RTW89_FW_ELEMENT_ID_NUM,
34313432
};
@@ -3446,6 +3447,7 @@ enum rtw89_fw_element_id {
34463447
BIT(RTW89_FW_ELEMENT_ID_RADIO_A) | \
34473448
BIT(RTW89_FW_ELEMENT_ID_RADIO_B) | \
34483449
BIT(RTW89_FW_ELEMENT_ID_RF_NCTL) | \
3450+
BIT(RTW89_FW_ELEMENT_ID_TXPWR_TRK) | \
34493451
BITS_OF_RTW89_TXPWR_FW_ELEMENTS)
34503452

34513453
struct __rtw89_fw_txpwr_element {
@@ -3457,6 +3459,59 @@ struct __rtw89_fw_txpwr_element {
34573459
u8 content[];
34583460
} __packed;
34593461

3462+
enum rtw89_fw_txpwr_trk_type {
3463+
__RTW89_FW_TXPWR_TRK_TYPE_6GHZ_START = 0,
3464+
RTW89_FW_TXPWR_TRK_TYPE_6GB_N = 0,
3465+
RTW89_FW_TXPWR_TRK_TYPE_6GB_P = 1,
3466+
RTW89_FW_TXPWR_TRK_TYPE_6GA_N = 2,
3467+
RTW89_FW_TXPWR_TRK_TYPE_6GA_P = 3,
3468+
__RTW89_FW_TXPWR_TRK_TYPE_6GHZ_MAX = 3,
3469+
3470+
__RTW89_FW_TXPWR_TRK_TYPE_5GHZ_START = 4,
3471+
RTW89_FW_TXPWR_TRK_TYPE_5GB_N = 4,
3472+
RTW89_FW_TXPWR_TRK_TYPE_5GB_P = 5,
3473+
RTW89_FW_TXPWR_TRK_TYPE_5GA_N = 6,
3474+
RTW89_FW_TXPWR_TRK_TYPE_5GA_P = 7,
3475+
__RTW89_FW_TXPWR_TRK_TYPE_5GHZ_MAX = 7,
3476+
3477+
__RTW89_FW_TXPWR_TRK_TYPE_2GHZ_START = 8,
3478+
RTW89_FW_TXPWR_TRK_TYPE_2GB_N = 8,
3479+
RTW89_FW_TXPWR_TRK_TYPE_2GB_P = 9,
3480+
RTW89_FW_TXPWR_TRK_TYPE_2GA_N = 10,
3481+
RTW89_FW_TXPWR_TRK_TYPE_2GA_P = 11,
3482+
RTW89_FW_TXPWR_TRK_TYPE_2G_CCK_B_N = 12,
3483+
RTW89_FW_TXPWR_TRK_TYPE_2G_CCK_B_P = 13,
3484+
RTW89_FW_TXPWR_TRK_TYPE_2G_CCK_A_N = 14,
3485+
RTW89_FW_TXPWR_TRK_TYPE_2G_CCK_A_P = 15,
3486+
__RTW89_FW_TXPWR_TRK_TYPE_2GHZ_MAX = 15,
3487+
3488+
RTW89_FW_TXPWR_TRK_TYPE_NR,
3489+
};
3490+
3491+
struct rtw89_fw_txpwr_track_cfg {
3492+
const s8 (*delta[RTW89_FW_TXPWR_TRK_TYPE_NR])[DELTA_SWINGIDX_SIZE];
3493+
};
3494+
3495+
#define RTW89_DEFAULT_NEEDED_FW_TXPWR_TRK_6GHZ \
3496+
(BIT(RTW89_FW_TXPWR_TRK_TYPE_6GB_N) | \
3497+
BIT(RTW89_FW_TXPWR_TRK_TYPE_6GB_P) | \
3498+
BIT(RTW89_FW_TXPWR_TRK_TYPE_6GA_N) | \
3499+
BIT(RTW89_FW_TXPWR_TRK_TYPE_6GA_P))
3500+
#define RTW89_DEFAULT_NEEDED_FW_TXPWR_TRK_5GHZ \
3501+
(BIT(RTW89_FW_TXPWR_TRK_TYPE_5GB_N) | \
3502+
BIT(RTW89_FW_TXPWR_TRK_TYPE_5GB_P) | \
3503+
BIT(RTW89_FW_TXPWR_TRK_TYPE_5GA_N) | \
3504+
BIT(RTW89_FW_TXPWR_TRK_TYPE_5GA_P))
3505+
#define RTW89_DEFAULT_NEEDED_FW_TXPWR_TRK_2GHZ \
3506+
(BIT(RTW89_FW_TXPWR_TRK_TYPE_2GB_N) | \
3507+
BIT(RTW89_FW_TXPWR_TRK_TYPE_2GB_P) | \
3508+
BIT(RTW89_FW_TXPWR_TRK_TYPE_2GA_N) | \
3509+
BIT(RTW89_FW_TXPWR_TRK_TYPE_2GA_P) | \
3510+
BIT(RTW89_FW_TXPWR_TRK_TYPE_2G_CCK_B_N) | \
3511+
BIT(RTW89_FW_TXPWR_TRK_TYPE_2G_CCK_B_P) | \
3512+
BIT(RTW89_FW_TXPWR_TRK_TYPE_2G_CCK_A_N) | \
3513+
BIT(RTW89_FW_TXPWR_TRK_TYPE_2G_CCK_A_P))
3514+
34603515
struct rtw89_fw_element_hdr {
34613516
__le32 id; /* enum rtw89_fw_element_id */
34623517
__le32 size; /* exclude header size */
@@ -3477,6 +3532,11 @@ struct rtw89_fw_element_hdr {
34773532
__le32 data;
34783533
} __packed regs[];
34793534
} __packed reg2;
3535+
struct {
3536+
__le32 bitmap; /* bitmap of enum rtw89_fw_txpwr_trk_type */
3537+
__le32 rsvd;
3538+
s8 contents[][DELTA_SWINGIDX_SIZE];
3539+
} __packed txpwr_trk;
34803540
struct __rtw89_fw_txpwr_element txpwr;
34813541
} __packed u;
34823542
} __packed;

drivers/net/wireless/realtek/rtw89/phy.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,6 @@ struct rtw89_txpwr_byrate_cfg {
291291
u32 data;
292292
};
293293

294-
#define DELTA_SWINGIDX_SIZE 30
295-
296294
struct rtw89_txpwr_track_cfg {
297295
const s8 (*delta_swingidx_6gb_n)[DELTA_SWINGIDX_SIZE];
298296
const s8 (*delta_swingidx_6gb_p)[DELTA_SWINGIDX_SIZE];

0 commit comments

Comments
 (0)