RK3568 以太网驱动

RTL8201F

Posted by LXG on April 8, 2024

MDIO 协议

MDIO(Media Independent Interface)是一种广泛应用于以太网物理层芯片(PHY)与MAC控制器之间通信的接口标准,主要用于管理和配置PHY芯片的各种参数,例如工作模式(10M/100M/1000M)、双工模式(半双工/全双工)以及自协商等功能

MDIO接口通常包含两根信号线:MDIO(主设备数据输入输出线)和MDC(管理数据时钟线)。通过MDC提供的时钟信号,MAC控制器可以在MDIO线上按特定协议格式与PHY进行数据交换,实现对PHY的配置和状态查询。

RTL8201F

在以太网设备中,MAC(Media Access Control)控制器负责处理高层协议数据包的收发,而PHY则负责将这些数据包转换为电信号并在物理媒介上传输。MDIO接口允许MAC控制器读写PHY内部寄存器,以便控制和监控PHY的工作状态。

rtl8201f_diagram

rtl8201f_block_diagram

rk3568 硬件设计

rk3568_rtl8201f

rk3568_rtl8201f_2

CLK_REF

rtl8201f_clk_ref

rtl8201f_clk_ref_2

rk3568-pinctrl.dtsi

RMII只需要接10根线,对应如下:


        gmac1 {
                /omit-if-no-ref/
                gmac1m1_miim: gmac1m1-miim {
                        rockchip,pins =
                                /* gmac1_mdcm1 */
                                <4 RK_PB6 3 &pcfg_pull_none>,
                                /* gmac1_mdiom1 */
                                <4 RK_PB7 3 &pcfg_pull_none>;
                };

                /omit-if-no-ref/
                gmac1m1_rx_er: gmac1m1-rx-er {
                        rockchip,pins =
                                /* gmac1_rxerm1 */
                                <4 RK_PB2 3 &pcfg_pull_none>;
                };

                /omit-if-no-ref/
                gmac1m1_rx_bus2: gmac1m1-rx-bus2 {
                        rockchip,pins =
                                /* gmac1_rxd0m1 */
                                <4 RK_PA7 3 &pcfg_pull_none>,
                                /* gmac1_rxd1m1 */
                                <4 RK_PB0 3 &pcfg_pull_none>,
                                /* gmac1_rxdvcrsm1 */
                                <4 RK_PB1 3 &pcfg_pull_none>;
                };

                /omit-if-no-ref/
                gmac1m1_tx_bus2: gmac1m1-tx-bus2 {
                        rockchip,pins =
                                /* gmac1_txd0m1 */
                                <4 RK_PA4 3 &pcfg_pull_none_drv_level_2>,
                                /* gmac1_txd1m1 */
                                <4 RK_PA5 3 &pcfg_pull_none_drv_level_2>,
                                /* gmac1_txenm1 */
                                <4 RK_PA6 3 &pcfg_pull_none>;
                };

                /omit-if-no-ref/
                gmac1m1_clkinout: gmac1m1-clkinout {
                        rockchip,pins =
                                /* gmac1_mclkinoutm1 */
                                <4 RK_PC1 3 &pcfg_pull_none>;
                };
        };

GMAC1_RSTn 复位引脚

Set low to reset the chip. For a complete reset, this pin must be asserted low for at least 10ms.

rtl8201f_rst

驱动配置

瑞芯微官方文档: Rockchip_Developer_Guide_Linux_GMAC_Mode_Configuration_CN.pdf

rk3568_rtl8201f_dts

RJ45

rj45

rj45_led

以太网不通日志分析

异常时网卡状态


eth0      Link encap:Ethernet  HWaddr 4e:ec:04:ce:b0:7f  Driver rk_gmac-dwmac // 以太网控制器的驱动程序
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0 
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 
          collisions:0 txqueuelen:1000 
          RX bytes:0 TX bytes:0 //目前通过此接口接收(RX)和发送(TX)的字节数均为零,表示尚未通过此接口传输任何数据。
          Interrupt:39 

异常日志


[    0.000000] psci: probing for conduit method from DT.
[    0.262433] rk_gmac-dwmac fe010000.ethernet: no regulator found
[    0.262459] rk_gmac-dwmac fe010000.ethernet: clock input or output? (output).
[    0.262469] rk_gmac-dwmac fe010000.ethernet: Can not read property: tx_delay.
[    0.262477] rk_gmac-dwmac fe010000.ethernet: set tx_delay to 0xffffffff
[    0.262485] rk_gmac-dwmac fe010000.ethernet: Can not read property: rx_delay.
[    0.262492] rk_gmac-dwmac fe010000.ethernet: set rx_delay to 0xffffffff
[    0.262503] rk_gmac-dwmac fe010000.ethernet: integrated PHY? (no).
[    0.262540] rk_gmac-dwmac fe010000.ethernet: cannot get clock clk_mac_ref
[    0.267576] rk_gmac-dwmac fe010000.ethernet: init for RMII
[    0.267592] rk_gmac-dwmac fe010000.ethernet: ======================init for RMII================
[    0.267639] rk_gmac-dwmac fe010000.ethernet: [stmmac_dvr_probe-4362]led_status_value = 0x6940
[    0.267830] rk_gmac-dwmac fe010000.ethernet: User ID: 0x30, Synopsys ID: 0x51
[    0.267849] rk_gmac-dwmac fe010000.ethernet: 	DWMAC4/5
[    0.267860] rk_gmac-dwmac fe010000.ethernet: DMA HW capability register supported
[    0.267867] rk_gmac-dwmac fe010000.ethernet: RX Checksum Offload Engine supported
[    0.267884] rk_gmac-dwmac fe010000.ethernet: TX Checksum insertion supported
[    0.267897] rk_gmac-dwmac fe010000.ethernet: Wake-Up On Lan supported
[    0.267932] rk_gmac-dwmac fe010000.ethernet: TSO supported
[    0.267946] rk_gmac-dwmac fe010000.ethernet: Enable RX Mitigation via HW Watchdog Timer
[    0.267960] rk_gmac-dwmac fe010000.ethernet: TSO feature enabled
[   14.235831] using random self ethernet address
[   14.235920] using random host ethernet address
[   23.816446] rk_gmac-dwmac fe010000.ethernet eth0: No Safety Features support found
[   23.816544] rk_gmac-dwmac fe010000.ethernet eth0: IEEE 1588-2008 Advanced Timestamp supported
[   23.817213] rk_gmac-dwmac fe010000.ethernet eth0: registered PTP clock
[   23.818058] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready

rk3566 RGMII正常日志


[    0.210105] rk_gmac-dwmac fe010000.ethernet: no regulator found
[    0.210117] rk_gmac-dwmac fe010000.ethernet: clock input or output? (output).
[    0.210126] rk_gmac-dwmac fe010000.ethernet: TX delay(0x3d).
[    0.210132] rk_gmac-dwmac fe010000.ethernet: RX delay(0x27).
[    0.210142] rk_gmac-dwmac fe010000.ethernet: integrated PHY? (no).
[    0.215178] rk_gmac-dwmac fe010000.ethernet: init for RGMII
[    0.215464] rk_gmac-dwmac fe010000.ethernet: User ID: 0x30, Synopsys ID: 0x51
[    0.215475] rk_gmac-dwmac fe010000.ethernet:         DWMAC4/5
[    0.215483] rk_gmac-dwmac fe010000.ethernet: DMA HW capability register supported
[    0.215489] rk_gmac-dwmac fe010000.ethernet: RX Checksum Offload Engine supported
[    0.215495] rk_gmac-dwmac fe010000.ethernet: TX Checksum insertion supported
[    0.215500] rk_gmac-dwmac fe010000.ethernet: Wake-Up On Lan supported
[    0.215532] rk_gmac-dwmac fe010000.ethernet: TSO supported
[    0.215539] rk_gmac-dwmac fe010000.ethernet: Enable RX Mitigation via HW Watchdog Timer
[    0.215546] rk_gmac-dwmac fe010000.ethernet: TSO feature enabled
[    6.559585] using random self ethernet address
[    6.559604] using random host ethernet address
[   19.376067] rk_gmac-dwmac fe010000.ethernet: rk_get_eth_addr: mac address: 28:54:ea:e5:92:e3
[   19.376091] rk_gmac-dwmac fe010000.ethernet: device MAC address 28:54:ea:e5:92:e3
[   19.395969] rk_gmac-dwmac fe010000.ethernet eth0: No Safety Features support found
[   19.395990] rk_gmac-dwmac fe010000.ethernet eth0: IEEE 1588-2008 Advanced Timestamp supported
[   19.400685] rk_gmac-dwmac fe010000.ethernet eth0: registered PTP clock
[   19.401369] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
[   19.457347] rk_gmac-dwmac fe010000.ethernet: RGMII TX&RX delay fixup for YT8511
[   22.454963] rk_gmac-dwmac fe010000.ethernet eth0: Link is Up - 1Gbps/Full - flow control rx/tx
[   22.455042] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready

PHY 寄存器读写测试

驱动提供了读写寄存器的接口,目前在不同内核版本上面有两套接口。 路径: /sys/bus/mdio_bus/devices/stmmac-0:00,其中 stmmac-0:00 表示 PHY 地址是 0。


rk3568_r:/ $ cat sys/bus/mdio_bus/devices/stmmac-1\:00/phy_registers
 0: 0xffff
 1: 0xffff
 2: 0xffff
 3: 0xffff
 4: 0xffff
 5: 0xffff
 6: 0xffff
 7: 0xffff
 8: 0xffff
 9: 0xffff
10: 0xffff
11: 0xffff
12: 0xffff
13: 0xffff
14: 0xffff
15: 0xffff
16: 0xffff
17: 0xffff
18: 0xffff
19: 0xffff
20: 0xffff
21: 0xffff
22: 0xffff
23: 0xffff
24: 0xffff
25: 0xffff
26: 0xffff
27: 0xffff
28: 0xffff
29: 0xffff
30: 0xffff
31: 0xffff