linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] wifi: mt76: mt7915: add chip id condition in mt7915_check_eeprom()
@ 2022-12-08 16:01 Shayne Chen
  2022-12-08 23:14 ` Julian Calaby
  0 siblings, 1 reply; 3+ messages in thread
From: Shayne Chen @ 2022-12-08 16:01 UTC (permalink / raw)
  To: Felix Fietkau
  Cc: linux-wireless, Lorenzo Bianconi, Ryder Lee, Evelyn Tsai,
	linux-mediatek, 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().

Reported-by: Cheng-Ji Li <cheng-ji.li@mediatek.com>
Signed-off-by: Shayne Chen <shayne.chen@mediatek.com>
---
 drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c b/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c
index 59069fb86414..e21aa03c85b1 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c
@@ -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)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] wifi: mt76: mt7915: add chip id condition in mt7915_check_eeprom()
  2022-12-08 16:01 [PATCH] wifi: mt76: mt7915: add chip id condition in mt7915_check_eeprom() Shayne Chen
@ 2022-12-08 23:14 ` Julian Calaby
  2022-12-16  3:43   ` shayne.chen
  0 siblings, 1 reply; 3+ messages in thread
From: Julian Calaby @ 2022-12-08 23:14 UTC (permalink / raw)
  To: Shayne Chen
  Cc: Felix Fietkau, linux-wireless, Lorenzo Bianconi, Ryder Lee,
	Evelyn Tsai, linux-mediatek

Hi Shayne,

On Fri, Dec 9, 2022 at 3:06 AM Shayne Chen <shayne.chen@mediatek.com> wrote:
>
> 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().
>
> Reported-by: Cheng-Ji Li <cheng-ji.li@mediatek.com>
> Signed-off-by: Shayne Chen <shayne.chen@mediatek.com>
> ---
>  drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c b/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c
> index 59069fb86414..e21aa03c85b1 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c
> @@ -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;

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

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

Thanks,

-- 
Julian Calaby

Email: julian.calaby@gmail.com
Profile: http://www.google.com/profiles/julian.calaby/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] wifi: mt76: mt7915: add chip id condition in mt7915_check_eeprom()
  2022-12-08 23:14 ` Julian Calaby
@ 2022-12-16  3:43   ` shayne.chen
  0 siblings, 0 replies; 3+ messages in thread
From: shayne.chen @ 2022-12-16  3:43 UTC (permalink / raw)
  To: julian.calaby
  Cc: linux-wireless, linux-mediatek, nbd,
	Evelyn Tsai (蔡珊鈺),
	lorenzo, Ryder Lee

On Fri, 2022-12-09 at 10:14 +1100, Julian Calaby wrote:
> Hi Shayne,
> 
> On Fri, Dec 9, 2022 at 3:06 AM Shayne Chen <shayne.chen@mediatek.com>
> wrote:
> > 
> > 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().
> > 
> > Reported-by: Cheng-Ji Li <cheng-ji.li@mediatek.com>
> > Signed-off-by: Shayne Chen <shayne.chen@mediatek.com>
> > ---
> >  drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c | 12 +++++-----
> > --
> >  1 file changed, 5 insertions(+), 7 deletions(-)
> > 
> > diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c
> > b/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c
> > index 59069fb86414..e21aa03c85b1 100644
> > --- a/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c
> > +++ b/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c
> > @@ -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;
> 
> If this returned a bool, you could write this as:
> 
> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-12-16  3:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-08 16:01 [PATCH] wifi: mt76: mt7915: add chip id condition in mt7915_check_eeprom() Shayne Chen
2022-12-08 23:14 ` Julian Calaby
2022-12-16  3:43   ` shayne.chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).