Skip to content

Commit a046d6f

Browse files
dangowrtPaolo Abeni
authored andcommitted
net: dsa: mxl-gsw1xx: validate chip ID
No check for actually present hardware is being performed in the probe function of the mxl-gsw1xx switch driver. So even if the switch isn't present at the configured MDIO bus address the driver wrongly tells the user that a "GSWIP version 0 mod 0" was found, outputting errors about PHY capabilities not matching. Read and validate the chip MANU_ID and PNUM_ID registers and output information while probing, but return an error and abort probing in case the hardware is not actually present. Signed-off-by: Daniel Golle <daniel@makrotopia.org> Link: https://patch.msgid.link/3194d3d3bb0b51f08755d392e1fdf7bb6dc49608.1769916962.git.daniel@makrotopia.org Reviewed-by: Vladimir Oltean <olteanv@gmail.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent ffd034a commit a046d6f

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

drivers/net/dsa/lantiq/mxl-gsw1xx.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,9 @@ static int gsw1xx_probe(struct mdio_device *mdiodev)
688688
{
689689
struct device *dev = &mdiodev->dev;
690690
struct gsw1xx_priv *priv;
691-
u32 version;
691+
u32 version, val;
692+
u8 shellver;
693+
u16 pnum;
692694
int ret;
693695

694696
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
@@ -736,6 +738,27 @@ static int gsw1xx_probe(struct mdio_device *mdiodev)
736738
if (IS_ERR(priv->shell))
737739
return PTR_ERR(priv->shell);
738740

741+
ret = regmap_read(priv->shell, GSW1XX_SHELL_MANU_ID, &val);
742+
if (ret < 0)
743+
return ret;
744+
745+
/* validate chip ID */
746+
if (FIELD_GET(GSW1XX_SHELL_MANU_ID_FIX1, val) != 1)
747+
return -ENODEV;
748+
749+
if (FIELD_GET(GSW1XX_SHELL_MANU_ID_MANID, val) !=
750+
GSW1XX_SHELL_MANU_ID_MANID_VAL)
751+
return -ENODEV;
752+
753+
pnum = FIELD_GET(GSW1XX_SHELL_MANU_ID_PNUML, val);
754+
755+
ret = regmap_read(priv->shell, GSW1XX_SHELL_PNUM_ID, &val);
756+
if (ret < 0)
757+
return ret;
758+
759+
pnum |= FIELD_GET(GSW1XX_SHELL_PNUM_ID_PNUMM, val) << 4;
760+
shellver = FIELD_GET(GSW1XX_SHELL_PNUM_ID_VER, val);
761+
739762
ret = gsw1xx_serdes_pcs_init(priv);
740763
if (ret < 0)
741764
return ret;
@@ -756,6 +779,8 @@ static int gsw1xx_probe(struct mdio_device *mdiodev)
756779
if (ret)
757780
return ret;
758781

782+
dev_info(dev, "standalone switch part number 0x%x v1.%u\n", pnum, shellver);
783+
759784
dev_set_drvdata(dev, &priv->gswip);
760785

761786
return 0;

drivers/net/dsa/lantiq/mxl-gsw1xx.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@
110110
#define GSW1XX_SHELL_BASE 0xfa00
111111
#define GSW1XX_SHELL_RST_REQ 0x01
112112
#define GSW1XX_RST_REQ_SGMII_SHELL BIT(5)
113+
#define GSW1XX_SHELL_MANU_ID 0x10
114+
#define GSW1XX_SHELL_MANU_ID_PNUML GENMASK(15, 12)
115+
#define GSW1XX_SHELL_MANU_ID_MANID GENMASK(11, 1)
116+
#define GSW1XX_SHELL_MANU_ID_MANID_VAL 0x389
117+
#define GSW1XX_SHELL_MANU_ID_FIX1 BIT(0)
118+
#define GSW1XX_SHELL_PNUM_ID 0x11
119+
#define GSW1XX_SHELL_PNUM_ID_VER GENMASK(15, 12)
120+
#define GSW1XX_SHELL_PNUM_ID_PNUMM GENMASK(11, 0)
121+
113122
/* RGMII PAD Slew Control Register */
114123
#define GSW1XX_SHELL_RGMII_SLEW_CFG 0x78
115124
#define RGMII_SLEW_CFG_DRV_TXC BIT(2)

0 commit comments

Comments
 (0)