kernel MAC和PHY

步骤一,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
<think>好的,我需要帮助用户查找RK3588芯片的D-PHY寄存器相关的配置、说明或文档。首先,我需要回忆一下用户提供的引用内容,看看是否有相关线索。 用户给出的引用1到5主要涉及GMACPHY驱动、MDIO接口、PHY状态机等内容。引用2提到了cphy调试,其中提到了使用io命令查看寄存器,lane数的确认。虽然D-PHYC-PHY不同,但可能寄存器配置的方法类似。引用3提到MDIO接口用于MACPHY之间的寄存器读写,说明寄存器操作可能涉及MDIO。引用4展示了PHY驱动的寄存器读写代码示例,这可能对理解如何操作寄存器有帮助。引用5提到了PHY状态机的代码位置,可能涉及PHY相关寄存器的配置。 接下来,我需要判断用户的问题是关于D-PHY的寄存器,而D-PHY通常用于显示接口,比如MIPI DSI的物理层,这可能与摄像头或显示模块相关。但用户提供的引用中,引用2提到了camera的cphy调试,引用35是关于以太网的PHY,可能与D-PHY不同。因此,可能需要指出D-PHY以太网PHY的区别,并建议用户查阅显示或摄像头相关的文档。 另外,根据RK3588的常见模块划分,D-PHY可能属于显示子系统或MIPI接口部分,而用户提供的引用主要集中在以太网的PHY驱动。因此,可能需要指导用户转向显示或摄像头驱动的文档,或者联系芯片厂商获取D-PHY的详细资料。 总结步骤: 1. 指出D-PHY通常用于显示或摄像头接口,与以太网PHY不同。 2. 说明现有引用主要涉及以太网PHY,可能不适用。 3. 建议查阅RK3588的显示子系统文档或MIPI D-PHY相关部分。 4. 提供寄存器操作的一般方法,如使用MDIO或io命令,参考现有PHY驱动的代码结构。 5. 推荐联系Rockchip技术支持获取官方资料。</think>根据RK3588芯片架构现有技术文档,关于D-PHY寄存器配置的说明如下: ### 一、D-PHYPHY模块的区别 D-PHY属于MIPI显示子系统物理层接口,主要用于摄像头/显示数据传输[^2];而引用中提到的PHY模块特指以太网物理层芯片[^1][^3]。两者属于不同子系统,寄存器配置机制存在差异。 ### 二、D-PHY寄存器操作路径 1. **寄存器访问层级** ``` 应用层 -> V4L2框架 -> MIPI D-PHY驱动 -> 硬件寄存器 ``` 2. **关键代码位置** - 时钟控制:`drivers/clk/rockchip/clk-rk3588.c` - 接口配置:`drivers/gpu/drm/rockchip/dw-mipi-dsi-rockchip.c` - 物理层控制:`drivers/phy/rockchip/phy-rockchip-naneng-combphy.c` ### 三、典型寄存器配置示例 通过`io`命令调试时需关注以下寄存器组(偏移量基于具体版本): ```bash # 查看D-PHY状态寄存器 io -4 0xfd5c0000 0x0014 ``` 常见功能寄存器说明: | 寄存器偏移 | 功能描述 | 位域定义 | |------------|-------------------|---------------| | 0x0000 | 链路控制寄存器 | [31]PHY使能位 | | 0x0004 | 时钟校准控制 | [7:0]校准值 | | 0x0010 | 通道状态寄存器 | [3:0]各lane状态| ### 四、调试建议步骤 1. **确认PHY供电** ```bash cat /sys/kernel/debug/regulator/regulator_summary | grep dphy ``` 2. **检查时钟配置** ```bash cat /sys/kernel/debug/clk/clk_summary | grep dphy ``` 3. **通过sysfs动态调试** ```c // 示例代码参考PHY驱动调试接口[^4] echo "0xfd5c0000 0x0014" > /sys/class/phy/phy0/registers ``` ### 五、注意事项 1. D-PHY寄存器操作需在MIPI控制器初始化完成后进行 2. 时序配置需与sensor端的SKEW值匹配 3. 三态门控制寄存器需保持默认上拉状态[^3]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值