文章目录
步骤一,ifconfig -a 查询网卡
能识别到网卡
ifconfig -a
——————————————————————
eth0 Link encap:Ethernet HWaddr 96:6f:9c:8b:a6:12
......
lo Link encap:Local Loopback
......
步骤二,重启网卡
目的是走一遍网卡驱动流程。报错了
ifconfig eth0 down
ifconfig eth0 up
——————————————————————
[ 21.772399] Generic PHY stmmac-0:00: attached PHY driver [Generic PHY] (mii_bus:phy_addr=stmmac-0:00, irq=POLL)
[ 21.896404] rk_gmac-dwmac fe2a0000.ethernet: Failed to reset the dma
[ 21.896452] rk_gmac-dwmac fe2a0000.ethernet eth0: stmmac_hw_setup: DMA engine initialization failed
[ 21.896464] rk_gmac-dwmac fe2a0000.ethernet eth0: stmmac_open: Hw setup failed
SIOCSIFFLAGS: Device or resource busy
说明phy初始化是成功的,MAC网卡初始化失败。
步骤三,对比南瑞自己的板子,因为他的网卡驱动正常
使用南瑞自己的内核+设备树和根文件系统,启动系统后有如下打印
[ 11.278840] rk_gmac-dwmac fe2a0000.ethernet: Looking up phy-supply from device tree
[ 11.278872] rk_gmac-dwmac fe2a0000.ethernet: Looking up phy-supply property in node /ethernet@fe2a0000 failed
[ 11.278907] rk_gmac-dwmac fe2a0000.ethernet: no regulator found
[ 11.279020] rk_gmac-dwmac fe2a0000.ethernet: clock input or output? (output).
[ 11.279053] rk_gmac-dwmac fe2a0000.ethernet: TX delay(0x3c).
[ 11.279082] rk_gmac-dwmac fe2a0000.ethernet: RX delay(0x2f).
[ 11.279115] rk_gmac-dwmac fe2a0000.ethernet: integrated PHY? (no).
[ 11.284221] rk_gmac-dwmac fe2a0000.ethernet: init for RGMII
[ 11.284564] rk_gmac-dwmac fe2a0000.ethernet: User ID: 0x30, Synopsys ID: 0x51
[ 11.284636] rk_gmac-dwmac fe2a0000.ethernet: DWMAC4/5
[ 11.284664] rk_gmac-dwmac fe2a0000.ethernet: DMA HW capability register supported
[ 11.284689] rk_gmac-dwmac fe2a0000.ethernet: RX Checksum Offload Engine supported
[ 11.284712] rk_gmac-dwmac fe2a0000.ethernet: TX Checksum insertion supported
[ 11.284735] rk_gmac-dwmac fe2a0000.ethernet: Wake-Up On Lan supported
[ 11.284758] rk_gmac-dwmac fe2a0000.ethernet: TSO supported
[ 11.284781] rk_gmac-dwmac fe2a0000.ethernet: Enable RX Mitigation via HW Watchdog Timer
[ 11.284806] rk_gmac-dwmac fe2a0000.ethernet: TSO feature enabled
[ 11.815111] rk_gmac-dwmac fe2a0000.ethernet ethdbg: renamed from eth1
[ 11.874706] rk_gmac-dwmac fe2a0000.ethernet ethdbg: No Safety Features support found
[ 11.874742] rk_gmac-dwmac fe2a0000.ethernet ethdbg: IEEE 1588-2008 Advanced Timestamp supported
[ 11.875069] rk_gmac-dwmac fe2a0000.ethernet ethdbg: registered PTP clock
[ 14.920473] rk_gmac-dwmac fe2a0000.ethernet ethdbg: Link is Up - 100Mbps/Full - flow control rx/tx
[ 11.285552] libphy: stmmac: probed
正常可以使用,但关闭后无法重启
ifconfig ethdbg down
ifconfig ethdbg up # 无法重启网卡,同样的错误
——————————————————————
SIOCSIFFLAGS: Device or resource busy
步骤四,尝试读写phy寄存器
查阅rk官方文档,可知系统启动后可以读写phy的寄存器,如下
根据返回值,说明可以正常读到phy的寄存器值,并且寄存器值基本正常,所以phy芯片的驱动是正常的,网卡无法使用可以确定是MAC驱动错误。
root@rk3568:~# cat /sys/bus/mdio_bus/devices/stmmac-0\:00/phy_registers
0: 0x1940
1: 0x7949
2: 0x937c
3: 0x4032
4: 0x1e1
5: 0x0
6: 0x6
7: 0x2001
8: 0x0
9: 0x200
10: 0x0
11: 0x0
12: 0x0
13: 0x0
14: 0x0
15: 0x2000
16: 0x0
17: 0x0
18: 0x0
19: 0x0
20: 0xc090
21: 0x7c13
22: 0x489b
23: 0x0
24: 0x8000
25: 0x0
26: 0x0
27: 0x2f
28: 0x0
29: 0x1101
30: 0x0
31: 0x0
步骤四,尝试将复位引脚注释掉
将几个snps属性注释掉
&gmac0 {
phy-mode = "rgmii";
clock_in_out = "output";
assigned-clocks = <&cru SCLK_GMAC0_RX_TX>, <&cru SCLK_GMAC0>;
assigned-clock-parents = <&cru SCLK_GMAC0_RGMII_SPEED>;
assigned-clock-rates = <0>, <125000000>;
// snps,reset-gpio = <&gpio0 RK_PB7 GPIO_ACTIVE_LOW>;
// snps,reset-active-low;
// /* Reset time is 20ms, 100ms for rtl8211f */
// snps,reset-delays-us = <0 20000 100000>;
pinctrl-names = "default";
pinctrl-0 = <&gmac0_miim
&gmac0_tx_bus2
&gmac0_rx_bus2
&gmac0_rgmii_clk
&gmac0_rgmii_bus>;
tx_delay = <0x3c>;
rx_delay = <0x2f>;
phy-handle = <&rgmii_phy0>;
status = "okay";
};
烧录之后重启,在uboot命令行下使用网卡后,比如ping命令,启动内核时网卡会有以下打印,说明正常(后续查明这个正常的原因是内核继承了uboot初始化网卡的硬件条件,导致内核可以使用网卡)。但是重启网卡时同样报错。
[ 9.330236] Generic PHY stmmac-0:00: attached PHY driver [Generic PHY] (mii_bus:phy_addr=stmmac-0:00, irq=POLL)
[ 9.352653] dwmac4: Master AXI performs any burst length
[ 9.352717] rk_gmac-dwmac fe2a0000.ethernet eth0: No Safety Features support found
[ 9.352755] rk_gmac-dwmac fe2a0000.ethernet eth0: IEEE 1588-2008 Advanced Timestamp supported
[ 9.366724] rk_gmac-dwmac fe2a0000.ethernet eth0: registered PTP clock
[ 9.367518] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
[ 10.380895] rk_gmac-dwmac fe2a0000.ethernet eth0: Link is Up - 100Mbps/Full - flow control rx/tx
[ 10.380988] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
而且在上电后直接启动内核而不使用uboot网卡功能时,直接报错。
说明注释调复位引脚不能解决问题
步骤五,将错误log复制到kernel源码中搜索
得到以下函数调用
module_platform_driver(rk_gmac_dwmac_driver);
——rk_gmac_dwmac_driver.probe = rk_gmac_probe()
————stmmac_dvr_probe()
——————stmmac_hw_init()
————————stmmac_hwif_init()
——————————entry = &stmmac_hw[i]; // stmmac_hw[] = { {.dma = &dwmac410_dma_ops,.....} } const struct stmmac_dma_ops dwmac410_dma_ops = { .reset = dwmac4_dma_reset,..... }
——————————mac->dma = mac->dma ? : entry->dma;
——————ndev->netdev_ops = &stmmac_netdev_ops
————————stmmac_netdev_ops.ndo_open = stmmac_open()
——————————stmmac_init_phy()
——————————stmmac_hw_setup()
——————————stmmac_init_dma_engine()
————————————stmmac_reset()
——————————————dwmac4_dma_reset()
————————————————if (limit < 0) return -EBUSY; //#define EBUSY 16 /* Device or resource busy */
———————————— [ 12.608163] CXY ################# stmmac_reset():ret[-16]
———————————— "Failed to reset the dma"
—————————— "DMA engine initialization failed"
————————"Hw setup failed"
步骤六,取消DMA_RESET
drivers/net/ethernet/stmicro/stmmac/dwmac4_lib.c,在writel之前return 0,直接取消这个复位操作,修改之后如下
int dwmac4_dma_reset(void __iomem *ioaddr)
{
u32 value = readl(ioaddr + DMA_BUS_MODE);
int limit;
/* DMA SW reset */
value |= DMA_BUS_MODE_SFT_RESET;
return 0;
writel(value, ioaddr + DMA_BUS_MODE);
limit = 10;
while (limit--) {
if (!(readl(ioaddr + DMA_BUS_MODE) & DMA_BUS_MODE_SFT_RESET))
break;
mdelay(10);
}
if (limit < 0)
return -EBUSY;
return 0;
}
步骤七,测试
启动内核,得到内核启动日志
驱动正常了
[ 0.661549] rk_gmac-dwmac fe2a0000.ethernet: Looking up phy-supply from device tree
[ 0.661566] rk_gmac-dwmac fe2a0000.ethernet: Looking up phy-supply property in node /ethernet@fe2a0000 failed
[ 0.661593] rk_gmac-dwmac fe2a0000.ethernet: no regulator found
[ 0.661618] rk_gmac-dwmac fe2a0000.ethernet: clock input or output? (output).
[ 0.661636] rk_gmac-dwmac fe2a0000.ethernet: TX delay(0x3c).
[ 0.661651] rk_gmac-dwmac fe2a0000.ethernet: RX delay(0x2f).
[ 0.661672] rk_gmac-dwmac fe2a0000.ethernet: integrated PHY? (no).
[ 0.666730] rk_gmac-dwmac fe2a0000.ethernet: init for RGMII
[ 0.667036] rk_gmac-dwmac fe2a0000.ethernet: User ID: 0x30, Synopsys ID: 0x51
[ 0.667064] rk_gmac-dwmac fe2a0000.ethernet: DWMAC4/5
[ 0.667083] rk_gmac-dwmac fe2a0000.ethernet: DMA HW capability register supported
[ 0.667098] rk_gmac-dwmac fe2a0000.ethernet: RX Checksum Offload Engine supported
[ 0.667110] rk_gmac-dwmac fe2a0000.ethernet: TX Checksum insertion supported
[ 0.667122] rk_gmac-dwmac fe2a0000.ethernet: Wake-Up On Lan supported
[ 0.667165] rk_gmac-dwmac fe2a0000.ethernet: TSO supported
[ 0.667180] rk_gmac-dwmac fe2a0000.ethernet: Enable RX Mitigation via HW Watchdog Timer
[ 0.667196] rk_gmac-dwmac fe2a0000.ethernet: TSO feature enabled
[ 23.613091] rk_gmac-dwmac fe2a0000.ethernet eth0: No Safety Features support found
[ 23.613129] rk_gmac-dwmac fe2a0000.ethernet eth0: IEEE 1588-2008 Advanced Timestamp supported
[ 23.618581] rk_gmac-dwmac fe2a0000.ethernet eth0: registered PTP clock
[ 27.686915] rk_gmac-dwmac fe2a0000.ethernet eth0: Link is Up - 100Mbps/Full - flow control rx/tx
ifconfig # 网卡也出来了
步骤八,测试ping命令
ifconfig eth0 192.168.11
ping 192.168.1.10
————————————————————
ping: sendmsg: Operation not permitted
出现Operation not permitted错误
tftp -g -r uboot.img 192.168.1.10
tftp: sendto: Operation not permitted
同样出现Operation not permitted错误
步骤九,关闭iptables
使用一下命令关闭防火墙,网络功能就都可以使用了
iptables -P OUTPUT ACCEPT
iptables -P INPUT ACCEPT