Skip to contentSkip to conversation

wifi: mt76: mt7915: add chip id condition in mt7915_check_eeprom()

PATCH Superseded Shayne Chen 2 participants 3 messages Dec 8, 2022 – Dec 16, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Shayne Chen

author reviewer
#0 lore raw

PATCH 1/1 wifi: mt76: mt7915: add chip id condition in mt7915_check_eeprom()

When flash mode is enabled, and the eeprom data in the flash is not for the current chipset, it'll still be checked valid, and the default eeprom bin won't be loaded.
(e.g., mt7915 NIC inserted with mt7916 eeprom data in the flash.)

Fix this kind of case by adding chip id into consideration in mt7915_check_eeprom().

---
 drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c +5 -7
index 59069fb86414..e21aa03c85b1 100644
@@ -33,14 +33,12 @@ static int mt7915_check_eeprom(struct mt7915_dev *dev)
 	u8 *eeprom = dev->mt76.eeprom.data;
 	u16 val = get_unaligned_le16(eeprom);
 
-	switch (val) {
-	case 0x7915:
-	case 0x7916:
-	case 0x7986:
+	if ((is_mt7915(&dev->mt76) && val == 0x7915) ||
+	    (is_mt7916(&dev->mt76) && val == 0x7916) ||
+	    (is_mt7986(&dev->mt76) && val == 0x7986))
 		return 0;
-	default:
-		return -EINVAL;
-	}
+
+	return -EINVAL;
 }
 
 static char *mt7915_eeprom_name(struct mt7915_dev *dev)
Signature · 1 line
2.25.1
#1 lore raw

Hi Shayne,

Quoted 26 lines · Shayne Chen

When flash mode is enabled, and the eeprom data in the flash is not for the current chipset, it'll still be checked valid, and the default eeprom bin won't be loaded.
(e.g., mt7915 NIC inserted with mt7916 eeprom data in the flash.)

Fix this kind of case by adding chip id into consideration in mt7915_check_eeprom().

---
 drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c +0 -3
index 59069fb86414..e21aa03c85b1 100644
@@ -33,14 +33,12 @@ static int mt7915_check_eeprom(struct mt7915_dev *dev)
        u8 *eeprom = dev->mt76.eeprom.data;
        u16 val = get_unaligned_le16(eeprom);
 
-       switch (val) {
-       case 0x7915:
-       case 0x7916:

drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c static int mt7915_check_eeprom(struct mt7915_dev *dev) · line 41

Quoted 10 lines
drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c +5 -4
-       case 0x7986:
+       if ((is_mt7915(&dev->mt76) && val == 0x7915) ||
+           (is_mt7916(&dev->mt76) && val == 0x7916) ||
+           (is_mt7986(&dev->mt76) && val == 0x7986))
                return 0;
-       default:
-               return -EINVAL;
-       }
+
+       return -EINVAL;

If this returned a bool, you could write this as:

switch (val) {
        case 0x7915:
                return is_mt7915(&dev->mt76);
}

Thanks,

Signature · 4 lines
Julian Calaby

Email: [email protected]
Profile: http://www.google.com/profiles/julian.calaby/
author reviewer
#2 lore raw
Quoted 47 lines · Julian Calaby

Hi Shayne,

Quoted 30 lines · Shayne Chen

When flash mode is enabled, and the eeprom data in the flash is not for
the current chipset, it'll still be checked valid, and the default eeprom bin won't be loaded.
(e.g., mt7915 NIC inserted with mt7916 eeprom data in the flash.)

Fix this kind of case by adding chip id into consideration in mt7915_check_eeprom().

---
 drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c | 12 +++++-----
--
 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c +0 -3
index 59069fb86414..e21aa03c85b1 100644
@@ -33,14 +33,12 @@ static int mt7915_check_eeprom(struct
 mt7915_dev *dev)
        u8 *eeprom = dev->mt76.eeprom.data;
        u16 val = get_unaligned_le16(eeprom);
 
-       switch (val) {
-       case 0x7915:
-       case 0x7916:

drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c static int mt7915_check_eeprom(struct · line 42

Quoted 10 lines
drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c +5 -4
-       case 0x7986:
+       if ((is_mt7915(&dev->mt76) && val == 0x7915) ||
+           (is_mt7916(&dev->mt76) && val == 0x7916) ||
+           (is_mt7986(&dev->mt76) && val == 0x7986))
                return 0;
-       default:
-               return -EINVAL;
-       }
+
+       return -EINVAL;

If this returned a bool, you could write this as:

Quoted 7 lines
switch (val) {
        case 0x7915:
                return is_mt7915(&dev->mt76);
}

Thanks,

Hi Julian,

Thanks for your comment.
This function returns 0 on success and -EINVAL on fail, so I'll add a macro to convert the return value in v2.

Regards,
Shayne