Merge "[Bugfix][T106BUG-522]The value of reading the cable status VCT is 0 when the cable is normally connected"
diff --git a/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/net/ethernet/zte/zx29_gmac.c b/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/net/ethernet/zte/zx29_gmac.c
index 5d3f1d4..556f9c4 100644
--- a/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/net/ethernet/zte/zx29_gmac.c
+++ b/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/net/ethernet/zte/zx29_gmac.c
@@ -1392,17 +1392,30 @@
/*jb.qi add for gamc power down on 20231116 end */
/*zw.wang add for switching the primary/secondary mode of gmac on 20240118 start*/
-int mode_type = -1;
+static int mode_type = -1;
+static int enter_only_one = 0;
ssize_t gmac_master_or_slave_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct net_device *ndev = platform_get_drvdata(pdev);
- struct zx29_gmac_dev *priv = (struct zx29_gmac_dev *)netdev_priv(ndev);
int mmd = 0;
int reg = 0;
int val = 0;
int ret;
+ struct platform_device *pdev = to_platform_device(dev);
+ if(!pdev){
+ printk(KERN_ERR "%s : %s pdev : %x \n", __func__, __LINE__, pdev);
+ return -1;
+ }
+ struct net_device *ndev = platform_get_drvdata(pdev);
+ if(!ndev){
+ printk(KERN_ERR "%s : %s ndev : %x \n", __func__, __LINE__, ndev);
+ return -1;
+ }
+ struct zx29_gmac_dev *priv = (struct zx29_gmac_dev *)netdev_priv(ndev);
+ if(!priv){
+ printk(KERN_ERR "%s : %s priv : %x \n", __func__, __LINE__, priv);
+ return -1;
+ }
///read mode_type
ret = sscanf(buf, "%d", &mode_type);
@@ -1456,14 +1469,33 @@
ssize_t gmac_master_or_slave_show(struct device *dev, struct device_attribute *attr, char *buf)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct net_device *ndev = platform_get_drvdata(pdev);
- struct zx29_gmac_dev *priv = (struct zx29_gmac_dev *)netdev_priv(ndev);
int mmd = 0;
int reg = 0;
int val = 0;
int len = 0;
int ret;
+ struct platform_device *pdev = to_platform_device(dev);
+ if(!pdev){
+ printk(KERN_ERR "%s : %s pdev : %x \n", __func__, __LINE__, pdev);
+ return -1;
+ }
+ struct net_device *ndev = platform_get_drvdata(pdev);
+ if(!ndev){
+ printk(KERN_ERR "%s : %s ndev : %x \n", __func__, __LINE__, ndev);
+ return -1;
+ }
+ struct zx29_gmac_dev *priv = (struct zx29_gmac_dev *)netdev_priv(ndev);
+ if(!priv){
+ printk(KERN_ERR "%s : %s priv : %x \n", __func__, __LINE__, priv);
+ return -1;
+ }
+
+ ///Reentrant prevention
+ if(enter_only_one == 1)
+ {
+ return 0;
+ }
+ enter_only_one = 1;
///Read the network master/slave
if (mode_type == 0 || mode_type == 1) {
@@ -1503,7 +1535,7 @@
mdiobus_write(priv->phydev->mdio.bus, priv->phydev->mdio.addr, 0x0e, reg);
mdiobus_write(priv->phydev->mdio.bus, priv->phydev->mdio.addr, 0x0d, 0x4000 | mmd);
mdiobus_write(priv->phydev->mdio.bus, priv->phydev->mdio.addr, 0x0e, BIT(14) | BIT(12));
-
+ msleep(10);
///--Read VCT
mmd = 0x1;
reg = 0x8B02;
@@ -1512,9 +1544,9 @@
mdiobus_write(priv->phydev->mdio.bus, priv->phydev->mdio.addr, 0x0d, 0x4000 | mmd);
val = mdiobus_read(priv->phydev->mdio.bus, priv->phydev->mdio.addr, 0x0e);
printk(KERN_DEBUG "Open status: %s - Short status: %s\n",
- (val & BIT(0)) ? "Open" : "Normal", (val & BIT(1)) ? "Short" : "Normal");
+ (val & BIT(1)) ? "Open" : "Normal", (val & BIT(0)) ? "Short" : "Normal");
sprintf(buf, "Open status: %s\nShort status: %s\n",
- (val & BIT(0)) ? "Open" : "Normal", (val & BIT(1)) ? "Short" : "Normal");
+ (val & BIT(1)) ? "Open" : "Normal", (val & BIT(0)) ? "Short" : "Normal");
reg = 0x8B01;
mdiobus_write(priv->phydev->mdio.bus, priv->phydev->mdio.addr, 0x0d, mmd);
mdiobus_write(priv->phydev->mdio.bus, priv->phydev->mdio.addr, 0x0e, reg);
@@ -1547,6 +1579,7 @@
"3: Set the VCT value view mode \n"
"After the mode is set, the corresponding value can be obtained\n");
}
+ enter_only_one = 0;
return strlen(buf);
}