[ Linux RK3568 ] 创建节点手动更新已扫描的延时值

本章基于手动/自动调整延时值。但是在实际使用中遇到网络丢包或者获取IP不成功的情况,需要在开机的情况下使用一条命令实现更新已有的扫描值。
注:扫描时不可插网口,不然会出现段错误。

使用命令实现延时值替换
echo 1 > /sys/devices/platform/fe010000.ethernet/phy_rescan
echo 1 > /sys/devices/platform/fe2a0000.ethernet/phy_rescan

命令实现:
1、清除vendor分区里对应tx/rx延时值
2、启动重新扫描功能

内核更改实现功能

---
 .../net/ethernet/stmicro/stmmac/dwmac-rk-tool.c    | 54 ++++++++++++++++++++--
 1 file changed, 50 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk-tool.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk-tool.c
index 856714b..465d1b5 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk-tool.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk-tool.c
@@ -1416,6 +1416,44 @@ static ssize_t phy_lb_scan_store(struct device *dev,
 }
 static DEVICE_ATTR_WO(phy_lb_scan);
 
+static ssize_t phy_rescan_store(struct device *dev,
+				 struct device_attribute *attr,
+				 const char *buf, size_t count)
+{
+	struct net_device *ndev = dev_get_drvdata(dev);
+	struct stmmac_priv *priv = netdev_priv(ndev);
+	unsigned char delayline[2];
+	int vendor_id;
+	int ret =0;
+
+	if(!strcmp(priv->dev->name , "lan"))            
+		vendor_id = ETH0_DELAY_ID;
+	else if(!strcmp(priv->dev->name , "wan"))
+		vendor_id = ETH1_DELAY_ID;
+
+	memset(delayline, 0x0, sizeof(delayline));       
+	ret =rk_vendor_read(vendor_id, delayline, 2);   
+	delayline[0] = 0xff;
+	delayline[1] = 0xff;
+	if (rk_vendor_write(vendor_id, delayline, 2))  
+		pr_err("damac rk: write rgmii delayline to vendor failed\n");
+
+	priv->delayline_scanned = false;
+
+    if (!priv->delayline_scanned) {
+            if (dwmac_rk_get_rgmii_delayline_from_vendor(priv)){
+                    priv->delayline_scanned = true;
+                    schedule_delayed_work(&priv->scan_dwork, msecs_to_jiffies(8000));
+            }else{
+                priv->delayline_scanned = true;
+            }
+    }
+
+	return count;
+}
+static DEVICE_ATTR_WO(phy_rescan);
+
+
 int dwmac_rk_create_loopback_sysfs(struct device *device)
 {
 	int ret;
@@ -1436,6 +1474,10 @@ int dwmac_rk_create_loopback_sysfs(struct device *device)
 	if (ret)
 		goto remove_phy_lb;
 
+	ret = device_create_file(device, &dev_attr_phy_rescan);
+	if (ret)
+		goto remove_phy_rescan;
+
 	return 0;
 
 remove_rgmii_delayline:
@@ -1447,6 +1489,9 @@ int dwmac_rk_create_loopback_sysfs(struct device *device)
 remove_phy_lb:
 	device_remove_file(device, &dev_attr_phy_lb);
 
+remove_phy_rescan:
+	device_remove_file(device, &dev_attr_phy_rescan);
+
 	return ret;
 }
 
@@ -1456,6 +1501,7 @@ int dwmac_rk_remove_loopback_sysfs(struct device *device)
 	device_remove_file(device, &dev_attr_mac_lb);
 	device_remove_file(device, &dev_attr_phy_lb);
 	device_remove_file(device, &dev_attr_phy_lb_scan);
+	device_remove_file(device, &dev_attr_phy_rescan);
 
 	return 0;
 }

你可能感兴趣的:(驱动功能适配,linux,网络,运维,arm)