一、确认硬件接口
phy1:

phy2:

PHY 地址设置:

以上三管脚要接上拉电阻时候,需接到 DVDD_RGMII 电压上;
二、软件配置
覆盖规则:板级配置文件board.dts会覆盖sun55iw3p1.dtsi
1、设备树:
bsp/configs/linux-5.15/sun55iw3p1.dtsi
                gmac0: gmac0@4500000 {
                        compatible = "allwinner,sunxi-gmac";
                        reg = <0x0 0x04500000 0x0 0x10000>,
                              <0x0 0x03000030 0x0 0x4>;
                        interrupts = <GIC_SPI 46 IRQ_TYPE_LEVEL_HIGH>;
                        interrupt-names = "gmacirq";
                        clocks = <&ccu CLK_GMAC0>, <&ccu CLK_GMAC0_25M>;
                        clock-names = "gmac", "phy25m";
                        resets = <&ccu RST_BUS_GMAC0>;
                        phy-handle = <&gmac0_phy0>;
                        status = "disabled";
                };
                gmac1: ethernet@4510000 {
                        compatible = "allwinner,sunxi-gmac-200", "snps,dwmac-4.20a";
                        reg = <0x0 0x04510000 0x0 0x10000>,
                              <0x0 0x03000034 0x0 0x4>;
                        interrupts = <GIC_SPI 47 IRQ_TYPE_LEVEL_HIGH>;
                        interrupt-names = "macirq";
                        clocks = <&ccu CLK_GMAC1>, <&ccu CLK_GMAC1_MBUS_GATE>, <&ccu CLK_GMAC1_25M>;
                        clock-names = "stmmaceth", "pclk", "phy25m";
                        resets = <&ccu RST_BUS_GMAC1>;
                        reset-names = "stmmaceth";
                        phy-handle = <&gmac1_phy0>;
                        power-domains = <&pd1 A523_PCK_VO1>;
                        status = "disabled";
                        snps,fixed-burst;
                        snps,axi-config = <&gmac1_stmmac_axi_setup>;
                        snps,mtl-rx-config = <&gmac1_mtl_rx_setup>;
                        snps,mtl-tx-config = <&gmac1_mtl_tx_setup>;
                        gmac1_stmmac_axi_setup: stmmac-axi-config {
                                snps,wr_osr_lmt = <0xf>;
                                snps,rd_osr_lmt = <0xf>;
                                snps,blen = <256 128 64 32 16 8 4>;
                        };
                        gmac1_mtl_rx_setup: rx-queues-config {
                                snps,rx-queues-to-use = <1>;
                                queue0 {};
                        };
                        gmac1_mtl_tx_setup: tx_queues-config {
                                snps,tx-queues-to-use = <1>;
                                queue0 {};
                        };
                        mdio1: mdio1@1 {
                                compatible = "snps,dwmac-mdio";
                                #address-cells = <1>;
                                #size-cells = <0>;
                                gmac1_phy0: ethernet-phy@1 {
                                        compatible = "ethernet-phy-ieee802.3-c22";
                                        reg = <1>;
                                        max-speed = <1000>;  /* Max speed capability */
                                        reset-gpios = <&pio PJ 27 GPIO_ACTIVE_LOW>;
                                        /* PHY datasheet rst time */
                                        reset-assert-us = <10000>;
                                        reset-deassert-us = <150000>;
                                };
                        };
                };
device/config/chips/t527/configs/demo_linux_car/linux-5.15/board.dts
&gmac0 {
        phy-mode = "rgmii";
        pinctrl-names = "default", "sleep";
        pinctrl-0 = <&gmac0_pins_default>;
        pinctrl-1 = <&gmac0_pins_sleep>;
        sunxi,phy-clk-type = <0>;//使用内部时钟还是外部时钟
        tx-delay = <3>;
        rx-delay = <4>;
        gmac3v3-supply = <®_cldo3>;
        status = "okay";
};
&gmac1 {
        phy-mode = "rgmii";
        pinctrl-names = "default", "sleep";
        pinctrl-0 = <&gmac1_pins_default>;
        pinctrl-1 = <&gmac1_pins_sleep>;
        aw,soc-phy25m;//有这个属性表示使用soc提供的内部25M
        tx-delay = <3>;
        rx-delay = <4>;
        dwmac3v3-supply = <®_cldo3>;
        status = "okay";
        mdio1: mdio1@1 {
                gmac1_phy0: ethernet-phy@1 {
                        reset-gpios = <&pio PJ 18  GPIO_ACTIVE_LOW>;
                };
        };
};
2、引脚信息:

3、Kconfig:
路径:/drivers/net/phy/Kconfig
+config MOTORCOMM_PHY
tristate "Motorcomm PHYs"
---help---
Supports the YT8010, YT8510, YT8511, YT8512 PHYs.4、Makefile:
路径:/drivers/net/phy/Makefile
obj-$(CONFIG_XILINX_GMII2RGMII) += xilinx_gmii2rgmii.o
+obj-$(CONFIG_MOTORCOMM_PHY) += motorcomm.o5、menuconfig内核中勾选motorcomm

如果需要保存该.config 配置到相应的 defconfig 里面,可以到 Tina5.0 根目录下执行以下指令。
./build.sh saveconfig6、驱动
kernel/linux-5.15/drivers/net/phy/motorcomm.c三、测试
1、查看驱动:
ls /sys/bus/mdio_bus/drivers

移植驱动完成后有以下打印信息:
PHY ID 4f51e91b at 1 IRQ poll (4500048.mdio0-mii:01)
PHY [stmmac-0:01] driver [YT8531 Gigabit Ethernet] (irq=POLL)2、网卡查看:ifconfig -a

3、打开网卡
ifconfig eth0 up
ifconfig eth1 up4、关闭网卡
ifconfig eth0 down
ifconfig eth1 down5、设置静态IP:
ifconfig eth0 172.16.112.244

6、获取 IP 地址
udhcpc -i eth0
udhcpc -i eth17、设置速率:
ethtool -s eth0 speed 1000 duplex full autoneg on
ethtool -s eth speed 1000 duplex full autoneg off测试芯片外围,TX 和 RX 发现 tx clk 时钟 125M ,而 rx clk 是25M,phy 芯片 在 1000M 速率下 TX 和 RX 时钟都应为 125M

Ping百度出现bad address 'www.baidu.com'
解决方法:
1.设置IP
首先打开文 件 vi /etc/network/interfaces在
auto lo
iface lo inet loopback
加上
auto eth0
iface eth0 inet dhcp
2.配置DNS
打开文件vi /etc/resolv.conf
加入
nameserver 8.8.8.8
nameserver 8.8.4.4
2、重启
最后ping www.baidu.com结果如下
8、iperf3速率测试
iperf3 -s
iperf3 -c IP iperf3 -u -c 172.16.112.75 -i 1 -b 1000M -l 65507
route add default gw 172.16.112.1测试出现千兆速率不达标情况

四、问题分析
排查点1:
SOC会给PHY提供一个25M的时钟

和下方25M晶振重复,只能使用一个,去掉晶振
排查点2:
根据芯片手册:
发现引脚反了

更改引脚后,示波器测量TX RX的CLK均为125M
再次ping时出现丢包问题,排查解决丢包问题,是否丢包引起速率不达标现象
调整TX RX时延:
调试方法如下:请注意rx_delay和tx_delay的范围(tx_delay【0~7】;rx_delay【0~31】)
cd /sys/devices/platform/soc@3000000/4500000.gmac0
echo xx >  tx_delay
echo  xx > rx_delay
查看当前tx_delay/rx_delay数值的方法
cat tx_delay
cat rx_delay
cat /sys/devices/platform/soc@3000000/4500000.gmac0/tx_delay
echo  xx > /sys/devices/platform/soc@3000000/4500000.gmac0/tx_delay发现tx_delay的范围在:0~3 rx_delay的范围4~18 ,丢包率在0到4左右
修改后不丢包速率正常
排查点三:eth1
ifconfig eth1后不能link,偶尔会出现下述情况

用示波器测量外部供电,时钟,发现soc连接phy25M时钟为0
查看硬件

发现SOC的25M时钟未连接到phy

硬件连接好后,eth1能正常link

与PC端ping





![搞清楚[继承],易如反掌](https://i-blog.csdnimg.cn/direct/e092630e39854916992cb5ebea7f58de.png)
















