信息搜集

中断

# ifconfig
eth0      Link encap:Ethernet  HWaddr 02:81:E6:56:D9:1F
          inet addr:192.168.31.32  Bcast:192.168.31.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:11666519 errors:0 dropped:5150 overruns:0 frame:0
          TX packets:5860150 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:255370485 (243.5 MiB)  TX bytes:514635051 (490.7 MiB)
          Interrupt:46

# cat /proc/interrupts | grep eth
 46:   11835604          0          0          0     GICv2 114 Level     eth0

逻辑中断号:46,物理中断号:114

H3_interrupt_Source

dts

		emac: ethernet@1c30000 {
			compatible = "allwinner,sun8i-h3-emac";
			syscon = <&syscon>;
			reg = <0x01c30000 0x10000>;
			interrupts = <GIC_SPI 82 IRQ_TYPE_LEVEL_HIGH>; // 114 -32 = 82
			interrupt-names = "macirq";
			resets = <&ccu RST_BUS_EMAC>;
			reset-names = "stmmaceth";
			clocks = <&ccu CLK_BUS_EMAC>;
			clock-names = "stmmaceth";
			status = "disabled";

			mdio: mdio {
				#address-cells = <1>;
				#size-cells = <0>;
				compatible = "snps,dwmac-mdio";
			};

			mdio-mux {
				compatible = "allwinner,sun8i-h3-mdio-mux";
				#address-cells = <1>;
				#size-cells = <0>;

				mdio-parent-bus = <&mdio>;
				/* Only one MDIO is usable at the time */
				internal_mdio: mdio@1 {
					compatible = "allwinner,sun8i-h3-mdio-internal";
					reg = <1>;
					#address-cells = <1>;
					#size-cells = <0>;

					int_mii_phy: ethernet-phy@1 {
						compatible = "ethernet-phy-ieee802.3-c22";
						reg = <1>;
						clocks = <&ccu CLK_BUS_EPHY>;
						resets = <&ccu RST_BUS_EPHY>;
					};
				};

				external_mdio: mdio@2 {
					reg = <2>;
					#address-cells = <1>;
					#size-cells = <0>;
				};
			};
		};

寄存器

H3_EMAC_register

# cat /proc/iomem | grep eth
01c30000-01c3ffff : 1c30000.ethernet ethernet@1c30000

寄存器详情

# devmem 0x01c30000 32
0x0000000D // 1101 0000 :100Mbps,全双工

H3_EMAC_Ctrl_0_reg

EPHY

手册中没有相关寄存器介绍 ?? 不过记得前 15 个寄存器是通用的

问题是:如何通过 MDIO 读取呢?

方法:/home/liyongjun/project/board/buildroot/override/OrangePiPC/mdio/mdio.c

# ./mdio.out eth0 0 0
read --- value : 0x3100
# ./mdio.out eth0 0 1
read --- value : 0x79ed

PHY寄存器

uboot 网络不通问题解决一例1 uboot 下读取 PHY 寄存器

=> mii read 1 0
1000
=> mii read 1 1
1000
=> mii dump 1 0
0.     (1000)                 -- PHY control register --
  (8000:0000) 0.15    =     0     reset
  (4000:0000) 0.14    =     0     loopback
  (2040:0000) 0. 6,13 =   b00    speed selection = 10 Mbps
  (1000:1000) 0.12    =     1     A/N enable
  (0800:0000) 0.11    =     0     power-down
  (0400:0000) 0.10    =     0     isolate
  (0200:0000) 0. 9    =     0     restart A/N
  (0100:0000) 0. 8    =     0     duplex = half
  (0080:0000) 0. 7    =     0     collision test enable
  (003f:0000) 0. 5- 0 =     0     (reserved)


=> mii dump 1 1
1.     (1000)                 -- PHY status register --
  (8000:0000) 1.15    =     0     100BASE-T4 able
  (4000:0000) 1.14    =     0     100BASE-X  full duplex able
  (2000:0000) 1.13    =     0     100BASE-X  half duplex able
  (1000:1000) 1.12    =     1     10 Mbps    full duplex able
  (0800:0000) 1.11    =     0     10 Mbps    half duplex able
  (0400:0000) 1.10    =     0     100BASE-T2 full duplex able
  (0200:0000) 1. 9    =     0     100BASE-T2 half duplex able
  (0100:0000) 1. 8    =     0     extended status
  (0080:0000) 1. 7    =     0     (reserved)
  (0040:0000) 1. 6    =     0     MF preamble suppression
  (0020:0000) 1. 5    =     0     A/N complete
  (0010:0000) 1. 4    =     0     remote fault
  (0008:0000) 1. 3    =     0     A/N able
  (0004:0000) 1. 2    =     0     link status
  (0002:0000) 1. 1    =     0     jabber detect
  (0001:0000) 1. 0    =     0     extended capabilities

ethtool

如何使用 ethtool 命令管理以太网卡

# ethtool eth0
Settings for eth0:
        Supported ports: [ TP    MII ] // MII
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full // 支持的速率
        Supported pause frame use: Symmetric Receive-only
        Supports auto-negotiation: Yes // 支持自动协商
        Supported FEC modes: Not reported
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
        Advertised pause frame use: Symmetric Receive-only
        Advertised auto-negotiation: Yes
        Advertised FEC modes: Not reported
        Link partner advertised link modes:  10baseT/Half 10baseT/Full
                                             100baseT/Half 100baseT/Full
        Link partner advertised pause frame use: Symmetric
        Link partner advertised auto-negotiation: Yes
        Link partner advertised FEC modes: Not reported
        Speed: 100Mb/s	// 速率
        Duplex: Full	// 全双工
        Auto-negotiation: on	// 自动协商:开
        Port: MII				// 接口:MII
        PHYAD: 1				// PHY 地址:1
        Transceiver: external
        Supports Wake-on: d		// 支持唤醒
        Wake-on: d
        Current message level: 0x0000003f (63)
                               drv probe link timer ifdown ifup
        Link detected: yes		// 连接状态