Since the mt7981 group pre-calibration size follows the vendor flash layout, mt7915_mcu_apply_group_cal() sends 144 units of 1024 bytes on mt7981. The group store of the mt7981 firmware holds 94 units, as on mt7986. Its handler checks neither the index nor the length of a chunk. The units with index 94 to 143 thus overwrite 50 KiB of firmware memory behind the store. This happens at each probe of a board with group pre-calibration data. Send only the units that the firmware stores. Keep the trailer and the DPD data at their offsets of the flash layout. Fixes: 2b660ee10a0c ("wifi: mt76: mt7915: fix mt7981 pre-calibration") Signed-off-by: Felix Fietkau --- .../wireless/mediatek/mt76/mt7915/eeprom.h | 2 ++ .../net/wireless/mediatek/mt76/mt7915/mcu.c | 28 ++++++++++--------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.h b/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.h index 1dc285c72991..bfba4fce3f6d 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.h @@ -51,6 +51,8 @@ enum mt7915_eeprom_field { #define MT_EE_CAL_GROUP_SIZE_7976 (94 * MT_EE_CAL_UNIT + 16) #define MT_EE_CAL_GROUP_SIZE_7916_6G (94 * MT_EE_CAL_UNIT + 16) #define MT_EE_CAL_GROUP_SIZE_7981 (144 * MT_EE_CAL_UNIT + 16) +/* the mt7981 firmware stores fewer group units than its flash layout holds */ +#define MT_EE_CAL_GROUP_FW_UNITS_7981 94 #define MT_EE_CAL_DPD_SIZE_V1 (54 * MT_EE_CAL_UNIT) #define MT_EE_CAL_DPD_SIZE_V2 (300 * MT_EE_CAL_UNIT) diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c index 02426feb6182..e9a10606c6aa 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c @@ -3105,33 +3105,35 @@ static int mt7915_mcu_set_pre_cal(struct mt7915_dev *dev, u8 idx, int mt7915_mcu_apply_group_cal(struct mt7915_dev *dev) { - u8 idx = 0, *cal = dev->cal, *eep = dev->mt76.eeprom.data; - u32 total = mt7915_get_cal_group_size(dev); + u8 idx, units, *cal = dev->cal, *eep = dev->mt76.eeprom.data; + u32 size = mt7915_get_cal_group_size(dev); u32 offs = is_mt7915(&dev->mt76) ? MT_EE_DO_PRE_CAL : MT_EE_DO_PRE_CAL_V2; + u32 trailer = size % MT_EE_CAL_UNIT; + int ret; if (!(eep[offs] & MT_EE_WIFI_CAL_GROUP)) return 0; + units = size / MT_EE_CAL_UNIT; + if (is_mt7981(&dev->mt76)) + units = MT_EE_CAL_GROUP_FW_UNITS_7981; + /* * Items: Rx DCOC, RSSI DCOC, Tx TSSI DCOC, Tx LPFG * Tx FDIQ, Tx DCIQ, Rx FDIQ, Rx FIIQ, ADCDCOC */ - while (total > 0) { - int ret, len; - - len = min_t(u32, total, MT_EE_CAL_UNIT); - - ret = mt7915_mcu_set_pre_cal(dev, idx, cal, len, + for (idx = 0; idx < units; idx++) { + ret = mt7915_mcu_set_pre_cal(dev, idx, + cal + idx * MT_EE_CAL_UNIT, + MT_EE_CAL_UNIT, MCU_EXT_CMD(GROUP_PRE_CAL_INFO)); if (ret) return ret; - - total -= len; - cal += len; - idx++; } - return 0; + /* the trailer follows all units of the flash layout */ + return mt7915_mcu_set_pre_cal(dev, idx, cal + size - trailer, trailer, + MCU_EXT_CMD(GROUP_PRE_CAL_INFO)); } static int mt7915_find_freq_idx(const u16 *freqs, int n_freqs, u16 cur) -- 2.47.3