NXP iMX7双以太网配置

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了NXP iMX7双以太网配置相关的知识,希望对你有一定的参考价值。

参考技术A By

Toradex秦海

1). 简介

NXP iMX7是NXP基于Cortex-A7和Coretex-M4异构多核架构的ARM处理器,其中iMX7 Dual型号SoC支持两路MAC控制器,可以通过外置百兆或者千兆PHY芯片扩展两路以太网接口,本文就基于Toradex基于NXP iMX7 Dual SoC的ARM核心板模块Colibri iMX7D示例扩展两路以太网。

2). 第一路以太网

a). Colibri

iMX7D模块已经通过模块上面部署的一个Microchip KSZ8041NL 百兆PHY芯片默认支持了第一路百兆以太网

b). KSZ8041NL的参考电路请参考 这里 (原理图示例的SoC MAC端来自Toradex VF61 ARM模块的定义,在iMX7或者其他平台上面不能直接引用,请只参考PHY一侧的连接)

c). 由于选择的iMX7D ENET1 MAC RMII接口50MHz 参考时钟输出引脚GPIO1_IO12和另外一个M4核心的NMI输入引脚冲突,因此最终在设计中,这一路的KSZ8041PHY使用了外部参考时钟,没有使用iMX7 ENET1的参考时钟输出

d). 基于上述配置的第一步以太网对应的device tree节点定义和pinmux定义请参考如下,内核基于4.9.166版本

---------------------------------------

# arch/arm/boot/dts/imx7-colibri.dtsi

……

&fec1

       pinctrl-names = "default", "sleep";

       pinctrl-0 = <&pinctrl_enet1>;

       pinctrl-1 = <&pinctrl_enet1_sleep>;

       clocks = <&clks IMX7D_ENET1_IPG_ROOT_CLK>,

                <&clksIMX7D_ENET_AXI_ROOT_CLK>,

                <&clks IMX7D_ENET1_TIME_ROOT_CLK>,

                <&clksIMX7D_PLL_ENET_MAIN_50M_CLK>;

       clock-names = "ipg", "ahb", "ptp","enet_clk_ref";

       assigned-clocks = <&clks IMX7D_ENET1_TIME_ROOT_SRC>,

                          <&clksIMX7D_ENET1_TIME_ROOT_CLK>;

        assigned-clock-parents = <&clksIMX7D_PLL_ENET_MAIN_100M_CLK>;

       assigned-clock-rates = <0>, <100000000>;

       phy-mode = "rmii";

       phy-supply = <®_LDO1>;

       fsl,magic-packet;

;



&iomuxc



pinctrl_enet1: enet1grp

               fsl,pins = <

                       MX7D_PAD_ENET1_RGMII_RX_CTL__ENET1_RGMII_RX_CTL 0x73

                       MX7D_PAD_ENET1_RGMII_RD0__ENET1_RGMII_RD0       0x73

                       MX7D_PAD_ENET1_RGMII_RD1__ENET1_RGMII_RD1       0x73

                       MX7D_PAD_ENET1_RGMII_RXC__ENET1_RX_ER           0x73

                       MX7D_PAD_ENET1_RGMII_TX_CTL__ENET1_RGMII_TX_CTL 0x73

                       MX7D_PAD_ENET1_RGMII_TD0__ENET1_RGMII_TD0       0x73

                        MX7D_PAD_ENET1_RGMII_TD1__ENET1_RGMII_TD1       0x73

                       MX7D_PAD_GPIO1_IO12__CCM_ENET_REF_CLK1          0x73

                       MX7D_PAD_SD2_CD_B__ENET1_MDIO                   0x3

                       MX7D_PAD_SD2_WP__ENET1_MDC                      0x3

                >;

       ;

       pinctrl_enet1_sleep: enet1sleepgrp

                fsl,pins = <

                       MX7D_PAD_ENET1_RGMII_RX_CTL__GPIO7_IO4          0x0

                       MX7D_PAD_ENET1_RGMII_RD0__GPIO7_IO0             0x0

                       MX7D_PAD_ENET1_RGMII_RD1__GPIO7_IO1    0x0

                       MX7D_PAD_ENET1_RGMII_RXC__GPIO7_IO5    0x0

                       MX7D_PAD_ENET1_RGMII_TX_CTL__GPIO7_IO10 0x0

                        MX7D_PAD_ENET1_RGMII_TD0__GPIO7_IO6     0x0

                       MX7D_PAD_ENET1_RGMII_TD1__GPIO7_IO7    0x0

                       MX7D_PAD_GPIO1_IO12__GPIO1_IO12        0x0

                       MX7D_PAD_SD2_CD_B__GPIO5_IO9           0x0

                       MX7D_PAD_SD2_WP__GPIO5_IO10             0x0

                >;

       ;

---------------------------------------

3). 第二路以太网

a). 第二路以太网通过模块预留的RMII或者RGMII接口连接百兆PHY或者千兆PHY来扩展,Colibri iMX7D RMII或者RGMII接口管脚定义请参考 手册 5.4章节。

b). 同样使用KSZ8041NL 百兆PHY扩展的参考电路请参考 这里 (原理图示例的SoC MAC端来自Toradex VF61 ARM模块的定义,在iMX7或者其他平台上面不能直接引用,须按照上面手册定义连接),如需要连接千兆PHY,请参考所使用的千兆PHY(如Microchip KSZ9031RNL)手册进行连接

c). 通过ENET2 RMII接口连接KSZ8041NL百兆PHY的device tree配置参考如下patch,和上面第一路以太网不同,这次使用的iMX7 SoC内部的参考时钟输出给PHY,因此在clock项目配置会有不同

https://github.com/simonqin09/colibri_imx7_2nd_ethernet/blob/master/0001-imx7d-2nd-ethernet-support_update_20200218.patch

// 对于 &fec2节点中的“fsl,mii-exclusive” 参数,因为ENET1和ENET2分别使用其对应的MDIO总线,而不是共享一个MDIO总线,在4.9 kernel下,如果不配置这个参数,驱动会默认都使用ENET1的MDIO去配置ENET2,因此在这里是必须的。但在其他i.MX平台或者mainline kernel下则不一定需要。

// MX7D_PAD_EPDC_BDR0__CCM_ENET_REF_CLK2 配置为0x40000073,因为使用iMX7 SoC内部参考时钟,这个时钟要同时给PHY和MAC提供参考时钟,因此Input和Output都要配置使能,因此需要为0x40000073,关于pinctrl的更多说明请参考 这里 。

d). 通过RGMII连接千兆PHY的device tree配置请参考 这里

 

4). 总结

本文基于iMX7示例了双路以太网的设计和配置思路,同时对于其他支持双路MAC的NXP i.MX ARM处理器(如iMX8)的配置思路也都是一致的,只是具体的clock和pinmux定义等要做对应的适配

NXP iMX8M Plus 双网口性能测试

By Toradex 胡珊逢

Verdin iMX8M Plus 是 Toradex 采用 NXP 最新的 i.MX 8M Plus 处理器的计算机模块,其具有 4x Cortex-A53 和 Cortex-M7 核心,支持神经网络加速运算的 NPU,H.265 硬件编码,CAN FD ,以及双路千兆以太网。配合 Verdin 开发板,用户可以直接测试两路以太网。文章将对网络性能做简要的测试。

使用 Toradex Easy Installer 安装 Linux BSP v5.3.0, 默认的配置已经支持两路千兆以太网。因此安装完成重启后即可看到两个网络接口。

NXP iMX8M Plus 双网口性能测试_web618.png

----------------------------------

root@verdin-imx8mp:~# ifconfig

eth0      Link encap:Ethernet  HWaddr 00:14:2D:78:82:04  

          inet addr:192.168.20.120  Bcast:192.168.20.255  Mask:255.255.255.0

          inet6 addr: fe80::214:2dff:fe78:8204/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:5105505 errors:0 dropped:0 overruns:0 frame:0

          TX packets:5988237 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:7344324802 (6.8 GiB)  TX bytes:8611102924 (8.0 GiB)

          Interrupt:48

eth1      Link encap:Ethernet  HWaddr 00:14:2D:68:82:04  

          inet addr:192.168.200.150  Bcast:192.168.200.255  Mask:255.255.255.0

          inet6 addr: fe80::214:2dff:fe68:8204/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:6686311 errors:0 dropped:0 overruns:0 frame:0

          TX packets:247321 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:6234153398 (5.8 GiB)  TX bytes:8180651220 (7.6 GiB)

----------------------------------

Verdin 开发板分别和两台电脑相连,链路速度为 1000Mbps。

NXP iMX8M Plus 双网口性能测试_web686.png

IP 地址设置如下。

PC1:192.168.200.1

PC2:192.168.20.132

Eth0: 192.168.200.150

Eth1:192.168.20.120

测试场景为

l Eth0和 Eth1 单独向 PC1 和 PC2 发送数据

l Eth0和 Eth1同时向 PC1 和 PC2 发送数据

l Eth0和 Eth1 单独接收来自 PC1 和 PC2 的数据

l Eth0和 Eth1 同时接收来自 PC1 和 PC2 的数据

l Eth0 上的数据转发到 Eth1

期间测试模块 Eth0和 Eth1 的最大带宽以及 CPU 占用率。

Eth0和 Eth1 单独向 PC1 和 PC2 发送数据

在 PC1 和 PC2 上运行 iperf3 服务器。

----------------------------------

$ iperf3 -s

----------------------------------

在 Verdin iMX8M Plus 运行 iperf3 向 PC 发送数据。Eth0 和 Eth1 的测试数据如下。

Eth0:

----------------------------------

root@verdin-imx8mp:~# iperf3 -c 192.168.20.132

Connecting to host 192.168.20.132, port 5201

[  5] local 192.168.20.120 port 34982 connected to 192.168.20.132 port 5201

[ ID] Interval           Transfer     Bitrate         Retr  Cwnd

[  5]   0.00-1.00   sec   114 MBytes   957 Mbits/sec    0    373 KBytes       

[  5]   1.00-2.00   sec   112 MBytes   942 Mbits/sec    0    373 KBytes       

[  5]   2.00-3.00   sec   112 MBytes   937 Mbits/sec    0    410 KBytes       

[  5]   3.00-4.00   sec   112 MBytes   942 Mbits/sec    0    410 KBytes       

- - - - - - - - - - - - - - - - - - - - - - - - -

[ ID] Interval           Transfer     Bitrate         Retr

[  5]   0.00-10.00  sec  1.10 GBytes   942 Mbits/sec    0             sender

[  5]   0.00-10.00  sec  1.10 GBytes   941 Mbits/sec                  receiver

iperf Done.

----------------------------------

Eth1:

----------------------------------

root@verdin-imx8mp:~# iperf3 -c 192.168.200.1

Connecting to host 192.168.200.1, port 5201

[  5] local 192.168.200.150 port 59206 connected to 192.168.200.1 port 5201

[ ID] Interval           Transfer     Bitrate         Retr  Cwnd

[  5]   0.00-1.00   sec   111 MBytes   934 Mbits/sec    0   1.14 MBytes       

[  5]   1.00-2.00   sec   112 MBytes   944 Mbits/sec    0   1.23 MBytes       

[  5]   2.00-3.00   sec   111 MBytes   933 Mbits/sec    0   1.23 MBytes       

[  5]   3.00-4.00   sec   112 MBytes   943 Mbits/sec    0   1.23 MBytes       

- - - - - - - - - - - - - - - - - - - - - - - - -

[ ID] Interval           Transfer     Bitrate         Retr

[  5]   0.00-10.00  sec  1.09 GBytes   940 Mbits/sec    0             sender

[  5]   0.00-10.00  sec  1.09 GBytes   937 Mbits/sec                  receiver

iperf Done.

----------------------------------

Verdin iMX8M Plus CPU 占用率:

NXP iMX8M Plus 双网口性能测试_web1224.png

Eth0和 Eth1同时向 PC1 和 PC2 发送数据

Eth0:

----------------------------------

root@verdin-imx8mp:~# iperf3 -c 192.168.20.132

Connecting to host 192.168.20.132, port 5201

[  5] local 192.168.20.120 port 34994 connected to 192.168.20.132 port 5201

[ ID] Interval           Transfer     Bitrate         Retr  Cwnd

[  5]   0.00-1.00   sec   113 MBytes   949 Mbits/sec    0    438 KBytes       

[  5]   1.00-2.00   sec   112 MBytes   937 Mbits/sec    0    464 KBytes       

[  5]   2.00-3.00   sec   112 MBytes   943 Mbits/sec    0    464 KBytes       

[  5]   3.00-4.00   sec   111 MBytes   935 Mbits/sec    0    464 KBytes       

- - - - - - - - - - - - - - - - - - - - - - - - -

[ ID] Interval           Transfer     Bitrate         Retr

[  5]   0.00-10.00  sec  1.09 GBytes   940 Mbits/sec    0             sender

[  5]   0.00-10.00  sec  1.09 GBytes   939 Mbits/sec                  receiver

iperf Done.

----------------------------------

Eth1:

----------------------------------

root@verdin-imx8mp:~# iperf3 -c 192.168.200.1

Connecting to host 192.168.200.1, port 5201

[  5] local 192.168.200.150 port 59210 connected to 192.168.200.1 port 5201

[ ID] Interval           Transfer     Bitrate         Retr  Cwnd

[  5]   0.00-1.00   sec   111 MBytes   929 Mbits/sec    0   1.14 MBytes       

[  5]   1.00-2.00   sec   112 MBytes   944 Mbits/sec    0   1.14 MBytes       

[  5]   2.00-3.00   sec   111 MBytes   933 Mbits/sec    0   1.14 MBytes       

- - - - - - - - - - - - - - - - - - - - - - - - -

[ ID] Interval           Transfer     Bitrate         Retr

[  5]   0.00-10.00  sec  1.09 GBytes   936 Mbits/sec    0             sender

[  5]   0.00-10.00  sec  1.09 GBytes   933 Mbits/sec                  receiver

iperf Done.

----------------------------------

Verdin iMX8M Plus CPU 占用率:

NXP iMX8M Plus 双网口性能测试_web1353.png

Eth0和 Eth1 单独接收来自 PC1 和 PC2 的数据

在 Verdin iMX8M Plus 分别运行 iperf3 服务器,针对 Eth0 和 Eth1 使用不同的端口。

----------------------------------

root@verdin-imx8mp:~# iperf3 -B 192.168.20.120 -s

root@verdin-imx8mp:~# iperf3 -B 192.168.200.150 -p 5202 -s

----------------------------------

Eth0:

----------------------------------

root@verdin-imx8mp:~# iperf3 -B 192.168.20.120 -s

-----------------------------------------------------------

Server listening on 5201

-----------------------------------------------------------

Accepted connection from 192.168.20.132, port 48674

[  5] local 192.168.20.120 port 5201 connected to 192.168.20.132 port 48676

[ ID] Interval           Transfer     Bitrate

[  5]   0.00-1.00   sec   111 MBytes   933 Mbits/sec                  

[  5]   1.00-2.00   sec   111 MBytes   935 Mbits/sec                  

[  5]   2.00-3.00   sec   111 MBytes   934 Mbits/sec                  

[  5]   3.00-4.00   sec   111 MBytes   935 Mbits/sec                  

- - - - - - - - - - - - - - - - - - - - - - - - -

[ ID] Interval           Transfer     Bitrate

[  5]   0.00-10.00  sec  1.09 GBytes   934 Mbits/sec                  receiver

-----------------------------------------------------------

Server listening on 5201

-----------------------------------------------------------

----------------------------------

Eth1:

----------------------------------

root@verdin-imx8mp:~# iperf3 -B 192.168.200.150 -p 5202 -s

-----------------------------------------------------------

Server listening on 5202

-----------------------------------------------------------

Accepted connection from 192.168.200.1, port 47290

[  5] local 192.168.200.150 port 5202 connected to 192.168.200.1 port 47292

[ ID] Interval           Transfer     Bitrate

[  5]   0.00-1.00   sec   110 MBytes   919 Mbits/sec                  

[  5]   1.00-2.00   sec   112 MBytes   939 Mbits/sec                  

[  5]   2.00-3.00   sec   112 MBytes   941 Mbits/sec                  

[  5]   3.00-4.00   sec   112 MBytes   941 Mbits/sec                  

- - - - - - - - - - - - - - - - - - - - - - - - -

[ ID] Interval           Transfer     Bitrate

[  5]   0.00-10.00  sec  1.09 GBytes   938 Mbits/sec                  receiver

----------------------------------

Verdin iMX8M Plus CPU 占用率:

NXP iMX8M Plus 双网口性能测试_web1574.png

Eth0和 Eth1 同时接收来自 PC1 和 PC2 的数据

Eth0:

----------------------------------

root@verdin-imx8mp:~# iperf3 -B 192.168.20.120 -s

-----------------------------------------------------------

Server listening on 5201

-----------------------------------------------------------

Accepted connection from 192.168.20.132, port 48712

[  5] local 192.168.20.120 port 5201 connected to 192.168.20.132 port 48714

[ ID] Interval           Transfer     Bitrate

[  5]   0.00-1.00   sec   111 MBytes   931 Mbits/sec                  

[  5]   1.00-2.00   sec   111 MBytes   934 Mbits/sec                  

[  5]   2.00-3.00   sec   111 MBytes   934 Mbits/sec                  

[  5]   3.00-4.00   sec   111 MBytes   935 Mbits/sec                  

- - - - - - - - - - - - - - - - - - - - - - - - -

[ ID] Interval           Transfer     Bitrate

[  5]   0.00-10.00  sec  1.09 GBytes   934 Mbits/sec                  receiver

-----------------------------------------------------------

Server listening on 5201

-----------------------------------------------------------

----------------------------------

Eth1:

----------------------------------

root@verdin-imx8mp:~# iperf3 -B 192.168.200.150 -p 5202 -s

-----------------------------------------------------------

Server listening on 5202

-----------------------------------------------------------

Accepted connection from 192.168.200.1, port 47308

[  5] local 192.168.200.150 port 5202 connected to 192.168.200.1 port 47310

[ ID] Interval           Transfer     Bitrate

[  5]   0.00-1.00   sec   110 MBytes   919 Mbits/sec                  

[  5]   1.00-2.00   sec   112 MBytes   941 Mbits/sec                  

[  5]   2.00-3.00   sec   112 MBytes   941 Mbits/sec                  

[  5]   3.00-4.00   sec   112 MBytes   941 Mbits/sec                  

[  5]   4.00-5.00   sec   112 MBytes   941 Mbits/sec                  

- - - - - - - - - - - - - - - - - - - - - - - - -

[ ID] Interval           Transfer     Bitrate

[  5]   0.00-10.00  sec  1.08 GBytes   928 Mbits/sec                  receiver

-----------------------------------------------------------

Server listening on 5202

-----------------------------------------------------------

----------------------------------

Verdin iMX8M Plus CPU 占用率:

NXP iMX8M Plus 双网口性能测试_web1710.png

Eth上的数据转发到 Eth1

为了将 Eth0 的数据转发到 Eth1,需要设置 /etc/sysctl.conf 。

----------------------------------

# needed for routing, including masquerading or NAT

net/ipv4/ip_forward=1  

----------------------------------

然后运行 sysctl 另设置生效,当然重启系统也可以。

----------------------------------

root@verdin-imx8mp:~# sysctl -p

----------------------------------

设置转发规则。

----------------------------------

root@verdin-imx8mp:~# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

root@verdin-imx8mp:~# iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT

root@verdin-imx8mp:~# iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT

----------------------------------

在 PC2 上启动 iperf3 服务器,PC 1 运行 iper3 客户端发送数据,所有的数据由 Verdin iMX8M Plus 负责从 Eth0 转发到 Eth1 上。

PC2 Server:

----------------------------------

$ iperf3 -s

-----------------------------------------------------------

Server listening on 5201

-----------------------------------------------------------

Accepted connection from 192.168.20.120, port 55360

[  5] local 192.168.20.132 port 5201 connected to 192.168.20.120 port 55362

[ ID] Interval           Transfer     Bitrate

[  5]   0.00-1.00   sec   105 MBytes   881 Mbits/sec                  

[  5]   1.00-2.00   sec   111 MBytes   928 Mbits/sec                  

[  5]   2.00-3.00   sec   110 MBytes   921 Mbits/sec                  

- - - - - - - - - - - - - - - - - - - - - - - - -

[ ID] Interval           Transfer     Bitrate

[  5]   0.00-10.00  sec  1.08 GBytes   931 Mbits/sec                  receiver

----------------------------------

PC1 Client:

----------------------------------

$ iperf3 -c 192.168.20.132

Connecting to host 192.168.20.132, port 5201

[  5] local 192.168.200.1 port 55362 connected to 192.168.20.132 port 5201

[ ID] Interval           Transfer     Bitrate         Retr  Cwnd

[  5]   0.00-1.00   sec   108 MBytes   904 Mbits/sec    0    471 KBytes       

[  5]   1.00-2.00   sec   110 MBytes   926 Mbits/sec    0    492 KBytes       

[  5]   2.00-3.00   sec   109 MBytes   916 Mbits/sec    0    492 KBytes       

[  5]   3.00-4.00   sec   112 MBytes   938 Mbits/sec    0    492 KBytes       

- - - - - - - - - - - - - - - - - - - - - - - - -

[ ID] Interval           Transfer     Bitrate         Retr

[  5]   0.00-10.00  sec  1.09 GBytes   934 Mbits/sec    0             sender

[  5]   0.00-10.00  sec  1.08 GBytes   931 Mbits/sec                  receiver

----------------------------------

Verdin iMX8M Plus CPU 占用率:

NXP iMX8M Plus 双网口性能测试_web2105.png

数据汇总如下。

NXP iMX8M Plus 双网口性能测试_web2117.png

两个千兆网口无论是在单独还是同时收发数据时都达到920Mbps 以上,包括网口之间的数据转发,基本接近满带宽。在 CPU 占用方面,当两个千兆网口以接近满带宽速率同时工作时,其中一个核心站占用率会超过 70%。

总结

Verdin iMX8M Plus 的双网口设计为多网口需求的应用提供了理想的选择,例如在工业自动化中,一个网口运行实时性要求高的应用如 EtherCAT,而另外一个则可以用于一般的网络通信。或者另一个网口可以用作冗余接口,或者连接两个不同的网络。Verdin iMX8M Plus 还有许多其他实用的功能,我们会在后续的文章进行介绍

以上是关于NXP iMX7双以太网配置的主要内容,如果未能解决你的问题,请参考以下文章

i.MX6ULL驱动开发 | 33 - NXP原厂网络设备驱动浅读(LAN8720 PHY)

centos 6.4系统双网卡绑定配置详解

Linux如何配置双网卡绑定bond

《嵌入操作系统 – 玩转ART-Pi开发板》第8章 APT-Pi双网络实现自动切换

《嵌入操作系统 – 玩转ART-Pi开发板》第8章 APT-Pi双网络实现自动切换

如何用bat命令实现启用&禁用以太网