Skip to content

Commit f2027ef

Browse files
Ming Yen Hsiehnbd168
authored andcommitted
wifi: mt76: mt7925: load the appropriate CLC data based on hardware type
Read the EEPROM to determine the hardware type and uses this to load the correct CLC data. Signed-off-by: Ming Yen Hsieh <mingyen.hsieh@mediatek.com> Link: https://patch.msgid.link/20250304113649.867387-1-mingyen.hsieh@mediatek.com Signed-off-by: Felix Fietkau <nbd@nbd.name>
1 parent 276a568 commit f2027ef

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

drivers/net/wireless/mediatek/mt76/mt7925/mcu.c

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,54 @@ int mt7925_mcu_uni_rx_ba(struct mt792x_dev *dev,
627627
enable, false);
628628
}
629629

630+
static int mt7925_mcu_read_eeprom(struct mt792x_dev *dev, u32 offset, u8 *val)
631+
{
632+
struct {
633+
u8 rsv[4];
634+
635+
__le16 tag;
636+
__le16 len;
637+
638+
__le32 addr;
639+
__le32 valid;
640+
u8 data[MT7925_EEPROM_BLOCK_SIZE];
641+
} __packed req = {
642+
.tag = cpu_to_le16(1),
643+
.len = cpu_to_le16(sizeof(req) - 4),
644+
.addr = cpu_to_le32(round_down(offset,
645+
MT7925_EEPROM_BLOCK_SIZE)),
646+
};
647+
struct evt {
648+
u8 rsv[4];
649+
650+
__le16 tag;
651+
__le16 len;
652+
653+
__le32 ver;
654+
__le32 addr;
655+
__le32 valid;
656+
__le32 size;
657+
__le32 magic_num;
658+
__le32 type;
659+
__le32 rsv1[4];
660+
u8 data[32];
661+
} __packed *res;
662+
struct sk_buff *skb;
663+
int ret;
664+
665+
ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_WM_UNI_CMD_QUERY(EFUSE_CTRL),
666+
&req, sizeof(req), true, &skb);
667+
if (ret)
668+
return ret;
669+
670+
res = (struct evt *)skb->data;
671+
*val = res->data[offset % MT7925_EEPROM_BLOCK_SIZE];
672+
673+
dev_kfree_skb(skb);
674+
675+
return 0;
676+
}
677+
630678
static int mt7925_load_clc(struct mt792x_dev *dev, const char *fw_name)
631679
{
632680
const struct mt76_connac2_fw_trailer *hdr;
@@ -635,13 +683,20 @@ static int mt7925_load_clc(struct mt792x_dev *dev, const char *fw_name)
635683
struct mt76_dev *mdev = &dev->mt76;
636684
struct mt792x_phy *phy = &dev->phy;
637685
const struct firmware *fw;
686+
u8 *clc_base = NULL, hw_encap = 0;
638687
int ret, i, len, offset = 0;
639-
u8 *clc_base = NULL;
640688

641689
if (mt7925_disable_clc ||
642690
mt76_is_usb(&dev->mt76))
643691
return 0;
644692

693+
if (mt76_is_mmio(&dev->mt76)) {
694+
ret = mt7925_mcu_read_eeprom(dev, MT_EE_HW_TYPE, &hw_encap);
695+
if (ret)
696+
return ret;
697+
hw_encap = u8_get_bits(hw_encap, MT_EE_HW_TYPE_ENCAP);
698+
}
699+
645700
ret = request_firmware(&fw, fw_name, mdev->dev);
646701
if (ret)
647702
return ret;
@@ -686,6 +741,10 @@ static int mt7925_load_clc(struct mt792x_dev *dev, const char *fw_name)
686741
if (phy->clc[clc->idx])
687742
continue;
688743

744+
/* header content sanity */
745+
if (u8_get_bits(clc->type, MT_EE_HW_TYPE_ENCAP) != hw_encap)
746+
continue;
747+
689748
phy->clc[clc->idx] = devm_kmemdup(mdev->dev, clc,
690749
le32_to_cpu(clc->len),
691750
GFP_KERNEL);

drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,12 @@ enum mt7925_eeprom_field {
167167
MT_EE_CHIP_ID = 0x000,
168168
MT_EE_VERSION = 0x002,
169169
MT_EE_MAC_ADDR = 0x004,
170+
MT_EE_HW_TYPE = 0xa71,
170171
__MT_EE_MAX = 0x9ff
171172
};
172173

174+
#define MT_EE_HW_TYPE_ENCAP GENMASK(1, 0)
175+
173176
enum {
174177
TXPWR_USER,
175178
TXPWR_EEPROM,

0 commit comments

Comments
 (0)