OpenNuvoton / NUC980-linux-5.10.y

NUC980 Linux Kernel 5.10.y
Other
11 stars 7 forks source link

emac0没有识别IP101GRI这个phy芯片 #6

Closed CodeMzc closed 1 year ago

CodeMzc commented 1 year ago

你好,我正在调试以太网驱动,公司使用的是IP101GRI这个phy芯片,5.10内核下有这个驱动,也已经打开并加载了,并没有报错但是网卡没有正确加载,手动添加ip后,eth0是有了,但是读不到phy的id,也ping不通网关。 但是在linux 4.4是正常的,需要解决Y2038问题所以得升级5.10版本。

因为我刚入门Linux所以技术不是很强,也调了很久了,在谷歌上实在是找不到解决方法。 麻烦各位大佬解答一下我的问题,感谢!

日志信息:

1122


# ifconfig -a
dummy0    Link encap:Ethernet  HWaddr D2:48:DD:93:39:1B  
          BROADCAST NOARP  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 (0.0 B)  TX bytes:0 (0.0 B)

eth0      Link encap:Ethernet  HWaddr 08:00:27:00:01:92  
          inet addr:192.168.1.10  Bcast:0.0.0.0  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe00:192/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:32 
          RX bytes:0 (0.0 B)  TX bytes:1216 (1.1 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:8 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:672 (672.0 B)  TX bytes:672 (672.0 B)

sit0      Link encap:IPv6-in-IPv4  
          NOARP  MTU:1480  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 (0.0 B)  TX bytes:0 (0.0 B)

# ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1): 56 data bytes
^C
--- 192.168.1.1 ping statistics ---
5 packets transmitted, 0 packets received, 100% packet loss
# ping 127.0.0.1
PING 127.0.0.1 (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: seq=0 ttl=64 time=0.608 ms
64 bytes from 127.0.0.1: seq=1 ttl=64 time=0.592 ms
64 bytes from 127.0.0.1: seq=2 ttl=64 time=0.609 ms
^C
--- 127.0.0.1 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.592/0.603/0.609 ms
# 

内核config已经打开了驱动:


CONFIG_ETHERNET=y
# CONFIG_NET_VENDOR_ALACRITECH is not set
# CONFIG_ALTERA_TSE is not set
# CONFIG_NET_VENDOR_AMAZON is not set
# CONFIG_NET_VENDOR_AQUANTIA is not set
# CONFIG_NET_VENDOR_ARC is not set
# CONFIG_NET_VENDOR_AURORA is not set
# CONFIG_NET_VENDOR_BROADCOM is not set
# CONFIG_NET_VENDOR_CADENCE is not set
# CONFIG_NET_VENDOR_CAVIUM is not set
# CONFIG_NET_VENDOR_CIRRUS is not set
# CONFIG_NET_VENDOR_CORTINA is not set
# CONFIG_DM9000 is not set
# CONFIG_DNET is not set
# CONFIG_NET_VENDOR_EZCHIP is not set
# CONFIG_NET_VENDOR_FARADAY is not set
# CONFIG_NET_VENDOR_GOOGLE is not set
# CONFIG_NET_VENDOR_HISILICON is not set
# CONFIG_NET_VENDOR_HUAWEI is not set
# CONFIG_NET_VENDOR_INTEL is not set
# CONFIG_NET_VENDOR_MARVELL is not set
# CONFIG_NET_VENDOR_MELLANOX is not set
# CONFIG_NET_VENDOR_MICREL is not set
# CONFIG_NET_VENDOR_MICROCHIP is not set
# CONFIG_NET_VENDOR_MICROSEMI is not set
# CONFIG_NET_VENDOR_NATSEMI is not set
# CONFIG_NET_VENDOR_NETRONOME is not set
# CONFIG_NET_VENDOR_NI is not set
CONFIG_NET_VENDOR_NUVOTON=y
CONFIG_NUC980_ETH0=y
# CONFIG_NUC980_ETH1 is not set
# CONFIG_ETHOC is not set
# CONFIG_NET_VENDOR_PENSANDO is not set
# CONFIG_NET_VENDOR_QUALCOMM is not set
# CONFIG_NET_VENDOR_RENESAS is not set
# CONFIG_NET_VENDOR_ROCKER is not set
# CONFIG_NET_VENDOR_SAMSUNG is not set
# CONFIG_NET_VENDOR_SEEQ is not set
# CONFIG_NET_VENDOR_SOLARFLARE is not set
# CONFIG_NET_VENDOR_SMSC is not set
# CONFIG_NET_VENDOR_SOCIONEXT is not set
# CONFIG_NET_VENDOR_STMICRO is not set
# CONFIG_NET_VENDOR_SYNOPSYS is not set
# CONFIG_NET_VENDOR_VIA is not set
# CONFIG_NET_VENDOR_WIZNET is not set
# CONFIG_NET_VENDOR_XILINX is not set
CONFIG_PHYLIB=y
CONFIG_SWPHY=y
CONFIG_FIXED_PHY=y

#
# MII PHY device drivers
#
# CONFIG_AMD_PHY is not set
# CONFIG_ADIN_PHY is not set
# CONFIG_AQUANTIA_PHY is not set
# CONFIG_AX88796B_PHY is not set
# CONFIG_BROADCOM_PHY is not set
# CONFIG_BCM54140_PHY is not set
# CONFIG_BCM7XXX_PHY is not set
# CONFIG_BCM84881_PHY is not set
# CONFIG_BCM87XX_PHY is not set
# CONFIG_CICADA_PHY is not set
# CONFIG_CORTINA_PHY is not set
# CONFIG_DAVICOM_PHY is not set
CONFIG_ICPLUS_PHY=y
# CONFIG_LXT_PHY is not set
# CONFIG_INTEL_XWAY_PHY is not set
# CONFIG_LSI_ET1011C_PHY is not set
# CONFIG_MARVELL_PHY is not set
# CONFIG_MARVELL_10G_PHY is not set
# CONFIG_MICREL_PHY is not set
# CONFIG_MICROCHIP_PHY is not set
# CONFIG_MICROCHIP_T1_PHY is not set
# CONFIG_MICROSEMI_PHY is not set
# CONFIG_NATIONAL_PHY is not set
# CONFIG_QSEMI_PHY is not set
# CONFIG_REALTEK_PHY is not set
# CONFIG_RENESAS_PHY is not set
# CONFIG_ROCKCHIP_PHY is not set
# CONFIG_SMSC_PHY is not set
# CONFIG_STE10XP is not set
# CONFIG_TERANETICS_PHY is not set
# CONFIG_DP83822_PHY is not set
# CONFIG_DP83TC811_PHY is not set
# CONFIG_DP83848_PHY is not set
# CONFIG_DP83867_PHY is not set
# CONFIG_DP83869_PHY is not set
# CONFIG_VITESSE_PHY is not set
# CONFIG_XILINX_GMII2RGMII is not set
# CONFIG_MICREL_KS8995MA is not set
CONFIG_MDIO_DEVICE=y
CONFIG_MDIO_BUS=y
CONFIG_OF_MDIO=y
CONFIG_MDIO_DEVRES=y
# CONFIG_MDIO_BITBANG is not set
# CONFIG_MDIO_BCM_UNIMAC is not set
# CONFIG_MDIO_HISI_FEMAC is not set
# CONFIG_MDIO_MVUSB is not set
# CONFIG_MDIO_MSCC_MIIM is not set
# CONFIG_MDIO_IPQ4019 is not set

设备树:

/*
 * Device Tree Source for NUC980 DEV board
 *
 * Copyright (C) 2018 Nuvoton Technology Corp.
 *
 * The code contained herein is licensed under the GNU General Public
 * License. You may obtain a copy of the GNU General Public License
 * Version 2 or later at the following locations:
 *
 * http://www.opensource.org/licenses/gpl-license.html
 * http://www.gnu.org/copyleft/gpl.html
 */
/dts-v1/;

#include "nuc980.dtsi"

/ {
    model = "Nuvoton NUC980 DEV V1.0";
    compatible = "nuvoton,nuc980-dev-v1.0", "nuvoton,nuc980";

    chosen {
        bootargs = "console=ttyS0,115200n8 noinitrd rootfstype=ext4 root=/dev/mmcblk0p2 rw rootwait mem=64M";
    };

    apb {
        uart1: serial@b0071000 {
            pinctrl-0 = <&pinctrl_uart1_PC>;
            status = "okay";
        };

        uart2: serial@b0072000 {
            status = "disabled";
        };

        uart3: serial@b0073000 {
            pinctrl-0 = <&pinctrl_uart3_PC>;
            status = "okay";
        };

        uart4: serial@b0074000 {
            status = "disabled";
        };

        uart5: serial@b0075000 {
            status = "disabled";
        };

        uart6: serial@b0076000 {
            pinctrl-0 = <&pinctrl_uart6_PA>;
            status = "okay";
        };

        uart7: serial@b0077000 {
            pinctrl-0 = <&pinctrl_uart7_PB>;
            status = "okay";
        };

        uart8: serial@b0078000 {
            pinctrl-0 = <&pinctrl_uart8_PA_PG>;
            status = "okay";
        };

        uart9: serial@b0079000 {
            pinctrl-0 = <&pinctrl_uart9_PB_PE>;
            status = "okay";
        };

        can0: can@b00a0000 {
            status = "disabled";
        };

        can1: can@b00a1000 {
            status = "disabled";
        };

        rtc: rtc@b0041000 {
            status = "okay";
        };

        nadc: nadc@b0043000 {
            status = "disabled";
        };

        pwm0: pwm@b0058000 {
            status = "disabled";
        };

        pwm1: pwm@b0059000 {
            status = "disabled";
        };

        etimer0: etimer0@b0050000 {
            status = "disabled";
        };

        etimer1: etimer1@b0050100 {
            status = "disabled";
        };

        etimer2: etimer2@b0051000 {
            status = "disabled";
        };

        etimer3: etimer3@b0051100 {
            status = "disabled";
        };

        i2c0: i2c0@b0080000 {
            status = "disabled";

            pinctrl-0 = <&pinctrl_i2c0_PA>;
            nau8822: nau8822@1a {
                compatible = "nuvoton,nau8822";
                reg = <0x1a> ;
            };
        };

        i2c1: i2c1@b0081000 {
            status = "disabled";
            pinctrl-0 = <&pinctrl_i2c1_PB>;
        };

        i2c2: i2c2@b0082000 {
            status = "okay";
            pinctrl-0 = <&pinctrl_i2c2_PB>;
        };

    };

    ahb {

        usbh_ehci@b0015000 {
            status = "okay";
        };
        usbh_ohci@b0017000{
            status = "okay";
        };

        usbdev@b0016000 {
            status = "okay";
        };

        fmi@b0019000 {
            pinctrl-0 = <&pinctrl_sd0>;
            status = "disabled";

        };

        sdh@b0018000 {
            status = "okay";
        };

        emac0@b0012000 {
            status = "okay";

            phy-mode = "rmii";
            phy-handle = <&ethphy>;
            mdio {
                compatible = "snps,dwmac-mdio";
                #address-cells = <1>;
                #size-cells = <0>;

                snps,reset-gpio = <&gpio 0x8c GPIO_ACTIVE_LOW>;
                snps,reset-active-low;
                snps,reset-delays-us = <0 100000 100000>;

                ethphy: ethernet-phy@0 {

                    compatible = "ethernet-phy-ieee802.3-c22";
                    reg = <0>;

                    /*
                    reset-assert-us = <10000>;
                    reset-deassert-us = <10000>;
                    reset-gpios = <&gpio 0x8c GPIO_ACTIVE_LOW>;
                    */

                    icplus,select-interrupt;

                };
            };

        };
        emac1@b0022000 {
            status = "disabled";
        };
        ccap0@b0024000 {
            status = "disabled";
        };
        i2c_gpio0: i2c-gpio-0 {
            status = "disabled";
        };
        ccap1@b0014000 {
            status = "disabled";
        };
        i2c_gpio1: i2c-gpio-1 {
            status = "disabled";
        };
        dma@b0008000 {
            status = "okay";
        };

        i2s: i2s@b0020000 {
            status = "disabled";
        };

        i2s_pcm: i2s_pcm {
            status = "disabled";
        };

        sound {
            compatible = "nuvoton,nuc980-audio";
            i2s-controller = <&i2s>;
            i2s-platform = <&i2s_pcm>;
            status = "disabled";
        };
        ebi: ebi@b0010000 {
            status = "disabled";
        };
    };
};
ychuang3 commented 1 year ago

compatible = "snps,dwmac-mdio" 這是從 MA35D1 抄過來的吧, MA35D1 ethernet GMAC 跟 NUC980 EMAC 是不同的設計

NUC980 Linux 5.10 BSP 不需要做任何修改,應該就可以 work 你在 device tree 添加了錯誤的 driver,才導致 MDIO failed

CodeMzc commented 1 year ago

感谢你的回复。

我根据 imx6ull 修改了device tree ,并调试了一下nuc980_ether0.c这个驱动文件,发现在nuc980_mii_setup这个函数中,if (ether->phy_dn)执行完后return 0结束掉了nuc980_mii_setup函数。 在注释掉return 0后,IP101GRI驱动就能加载了,可以在日志中看到,但是工作仍然不正常。报错 no of_node; not parsing pinctrl DT,似乎是需要在设备树里添加一些什么。

同时,我在官网找到了《NUC980 Ethernet Connection via NC-SI》这个文档,尝试使用NC-SI,根据文档操作后,依然报错。但是硬件本身没有问题,因为在Linux 4.4上一切正常

能否给一个设备树的示例,以便能在Linux 5.10上正常加载IP101GRI呢,再次感谢!

注释掉return 0后的日志信息:

[    0.547049] nuc980-pinctrl apb:pinctrl@b0000000: parse function(28): emac0
[    0.547099] nuc980-pinctrl apb:pinctrl@b0000000: group(0): emac0
[    0.547541] nuc980-pinctrl apb:pinctrl@b0000000: parse function(29): emac1
[    0.547591] nuc980-pinctrl apb:pinctrl@b0000000: group(0): emac1
[    3.536716] nuc980-pinctrl apb:pinctrl@b0000000: emac0: 10 0:64
[    3.536799] nuc980-pinctrl apb:pinctrl@b0000000: maps: function emac0 group emac0 num 11
[    3.537016] nuc980-pinctrl apb:pinctrl@b0000000: found group selector 82 for emac0
[    3.537558] nuc980-pinctrl apb:pinctrl@b0000000: request pin 64 (PE0) for b0012000.emac0
[    3.537608] nuc980-pinctrl apb:pinctrl@b0000000: request pin 65 (PE1) for b0012000.emac0
[    3.537649] nuc980-pinctrl apb:pinctrl@b0000000: request pin 66 (PE2) for b0012000.emac0
[    3.537699] nuc980-pinctrl apb:pinctrl@b0000000: request pin 67 (PE3) for b0012000.emac0
[    3.537741] nuc980-pinctrl apb:pinctrl@b0000000: request pin 68 (PE4) for b0012000.emac0
[    3.537783] nuc980-pinctrl apb:pinctrl@b0000000: request pin 69 (PE5) for b0012000.emac0
[    3.537824] nuc980-pinctrl apb:pinctrl@b0000000: request pin 70 (PE6) for b0012000.emac0
[    3.537866] nuc980-pinctrl apb:pinctrl@b0000000: request pin 71 (PE7) for b0012000.emac0
[    3.537908] nuc980-pinctrl apb:pinctrl@b0000000: request pin 72 (PE8) for b0012000.emac0
[    3.537949] nuc980-pinctrl apb:pinctrl@b0000000: request pin 73 (PE9) for b0012000.emac0
[    3.538208] nuc980-emac0 b0012000.emac0: obtain a copy of previously claimed pinctrl
[    3.567841] nuc980_mii_setup: ether->pdev->name = b0012000.emac0,ether->pdev->id = ffffffff 
[    3.576674] nuc980-emac0 b0012000.emac0: mdiobus_register
[    3.587133] ICPlus IP101A/G b0012000.emac0-ffffffff:00: no of_node; not parsing pinctrl DT
[    3.587316] ICPlus IP101A/G b0012000.emac0-ffffffff:00: ip101a_g_probe enter!
[    3.597183] ICPlus IP101A/G b0012000.emac0-ffffffff:00: ip101a_g_probe exit!
[    3.609616] nuc980-emac0 b0012000.emac0: phy_find_first
[    3.616458] nuc980-emac0 b0012000.emac0: phy_connect
[    3.621883] ICPlus IP101A/G b0012000.emac0 , ip101a_g_config_init enter!
[    3.628841] ICPlus IP101A/G b0012000.emac0 , ip101a_g_config_init exit!
[    3.636141] nuc980-emac0 b0012000.emac0: linkmode_copy
[   12.418066] nuc980-emac0 b0012000.emac0: eth0 is OPENED

使用NC-SI的日志信息

# dmesg | grep emac
[    0.547141] nuc980-pinctrl apb:pinctrl@b0000000: parse function(28): emac0
[    0.547191] nuc980-pinctrl apb:pinctrl@b0000000: group(0): emac0
[    0.547641] nuc980-pinctrl apb:pinctrl@b0000000: parse function(29): emac1
[    0.547691] nuc980-pinctrl apb:pinctrl@b0000000: group(0): emac1
[    3.526808] nuc980-pinctrl apb:pinctrl@b0000000: emac0: 10 0:64
[    3.526891] nuc980-pinctrl apb:pinctrl@b0000000: maps: function emac0 group emac0 num 11
[    3.527116] nuc980-pinctrl apb:pinctrl@b0000000: found group selector 82 for emac0
[    3.527649] nuc980-pinctrl apb:pinctrl@b0000000: request pin 64 (PE0) for b0012000.emac0
[    3.527699] nuc980-pinctrl apb:pinctrl@b0000000: request pin 65 (PE1) for b0012000.emac0
[    3.527749] nuc980-pinctrl apb:pinctrl@b0000000: request pin 66 (PE2) for b0012000.emac0
[    3.527791] nuc980-pinctrl apb:pinctrl@b0000000: request pin 67 (PE3) for b0012000.emac0
[    3.527833] nuc980-pinctrl apb:pinctrl@b0000000: request pin 68 (PE4) for b0012000.emac0
[    3.527883] nuc980-pinctrl apb:pinctrl@b0000000: request pin 69 (PE5) for b0012000.emac0
[    3.527924] nuc980-pinctrl apb:pinctrl@b0000000: request pin 70 (PE6) for b0012000.emac0
[    3.527966] nuc980-pinctrl apb:pinctrl@b0000000: request pin 71 (PE7) for b0012000.emac0
[    3.528008] nuc980-pinctrl apb:pinctrl@b0000000: request pin 72 (PE8) for b0012000.emac0
[    3.528049] nuc980-pinctrl apb:pinctrl@b0000000: request pin 73 (PE9) for b0012000.emac0
[    3.528316] nuc980-emac0 b0012000.emac0: obtain a copy of previously claimed pinctrl
[    3.528599] nuc980-emac0 b0012000.emac0: Using NCSI interface
[   12.314291] nuc980-emac0 b0012000.emac0: eth0 uses NC-SI subsystem.
[   12.320591] nuc980-emac0 b0012000.emac0: eth0 is OPENED
[   28.971699] nuc980-emac0 b0012000.emac0 eth0: NCSI: No channel found to configure!
[   28.979274] nuc980-emac0 b0012000.emac0 eth0: NCSI interface down
[   30.011583] nuc980-emac0 b0012000.emac0 eth0: Wrong NCSI state 0x100 in workqueue

nuc980_ether0.c代码改动:

static int nuc980_mii_setup(struct net_device *netdev)
{
    struct nuc980_ether *ether = netdev_priv(netdev);
    struct platform_device *pdev;
    struct phy_device *phydev;
    int i, err = 0;

    pdev = ether->pdev;

    if (ether->phy_dn) {
        ether->phy_dev = of_phy_connect(netdev, ether->phy_dn,
                    &adjust_link, 0, 0);
        if (!ether->phy_dn) {
            dev_err(&netdev->dev, "could not connect to phy %pOF\n",
                ether->phy_dn);
            return -ENODEV;
        }
        //注释掉这个return 0后,IP101GRI驱动加载的日志就出现了
        //return 0;
    }

    ether->mii_bus = mdiobus_alloc();
    if (!ether->mii_bus) {
        err = -ENOMEM;
        dev_err(&pdev->dev, "mdiobus_alloc() failed\n");
        goto out0;
    }

    ether->mii_bus->name = "nuc980_rmii0";
    ether->mii_bus->read = &nuc980_mdio_read;
    ether->mii_bus->write = &nuc980_mdio_write;
    ether->mii_bus->reset = &nuc980_mdio_reset;
    snprintf(ether->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
         ether->pdev->name, ether->pdev->id);
    ether->mii_bus->priv = ether;
    ether->mii_bus->parent = &ether->pdev->dev;

    if (!ether->mii_bus->irq) {
        err = -ENOMEM;
        dev_err(&pdev->dev, "kmalloc() failed\n");
        goto out1;

    }

    //...
}

设备树:

        emac0@b0012000 {
            status = "okay";
            phy-mode = "rmii";
            phy-handle = <&ethphy0>;
            mdio {
                #address-cells = <1>;
                #size-cells = <0>;
                ethphy0: ethernet-phy@0 {
                    compatible = "ethernet-phy-ieee802.3-c22";
                    reg = <0>;                  
                };
            };      
        };
ychuang3 commented 1 year ago

NC-SI 是另一種應用,需要搭配硬體

請問你用哪張板子做的測試? chili or iot? 請找一下板子上面打印的板子名稱 請使用 buildroot 編譯 https://github.com/OpenNuvoton/MA35D1_Buildroot

選擇對應的 defconfig 之後 make 產生的 image 就可以 work 了

不需要做任何多餘的修改

CodeMzc commented 1 year ago

是公司自己制作的板子。

好的,我试一下使用MA35D1_Buildroot看看能不能正常驱动IP101GRI。

ychuang3 commented 1 year ago

建議這麼做 ==> download 好 buildroot 之後

  1. make nuvoton_nuc980_iot_defconfig
  2. make

然後在 output/images 目錄下找到 Image 及 nuc980-iot-v1.0.dtb download 到開發板執行

如果還有問題, 最好先在 Nuvoton 開發板上面嘗試一下

CodeMzc commented 1 year ago

额,问题解决了,不是源码驱动的问题,而是phy的复位引脚是PE12,和设备树里 usbh_ehci 的pinctrl设置冲突,导致PE12一直是低电平,phy一直在复位。 把 usbh_ehci 节点 disabled 后网卡正常了,确实对emac0和驱动不需要做任何修改。

感谢你的支持!