Snla 450
Snla 450
Application Note
How to Integrate Linux Driver Into Your System
Alvaro Reyes
ABSTRACT
Linux drivers are essential software components that allow the operating system to communicate with hardware
devices such as graphics cards, printers, and Ethernet physical layer devices (PHY). Without the drivers, Linux
is unable to use the hardware effectively, resulting in devices not being recognized or functioning properly. This
document aims to provide comprehensive guidance for developers seeking to integrate PHY functionality into
Linux-based systems. By detailing the intricacies of PHY driver implementation within the Linux kernel, this
application note equips developers with the knowledge and tools necessary to make sure seamless integration,
designed for performance, and compatibility across a wide range of hardware platforms.
Table of Contents
1 Texas Instruments Ethernet PHY Drivers............................................................................................................................. 2
2 Ethernet PHY Driver Overview.............................................................................................................................................. 2
2.1 Exploring Linux Driver Types............................................................................................................................................. 3
3 Driver Integration....................................................................................................................................................................4
3.1 Linux Device Tree.............................................................................................................................................................. 4
3.2 Integrating Driver................................................................................................................................................................7
4 Common Terminal Commands.............................................................................................................................................. 8
4.1 Initialization Commands..................................................................................................................................................... 8
4.2 Functional Commands..................................................................................................................................................... 10
4.3 Diagnostic Commands..................................................................................................................................................... 12
5 Summary............................................................................................................................................................................... 16
6 References............................................................................................................................................................................ 16
Trademarks
All trademarks are the property of their respective owners.
SNLA450 – JULY 2024 How to Integrate Linux Driver Into Your System 1
Submit Document Feedback
Copyright © 2024 Texas Instruments Incorporated
Texas Instruments Ethernet PHY Drivers www.ti.com
2 How to Integrate Linux Driver Into Your System SNLA450 – JULY 2024
Submit Document Feedback
Copyright © 2024 Texas Instruments Incorporated
www.ti.com Ethernet PHY Driver Overview
Network Utilities
Applications iperf ping ethtool
User Space
Kernel Space
Ctrl/Status
MAC Driver PHY Driver
Software
Hardware
SNLA450 – JULY 2024 How to Integrate Linux Driver Into Your System 3
Submit Document Feedback
Copyright © 2024 Texas Instruments Incorporated
Driver Integration www.ti.com
3 Driver Integration
Integrating a driver into a Linux system involves several key steps to provide seamless compatibility and
functionality. Initially, developers must compile the driver code to generate a loadable kernel module or
incorporate the code directly into the kernel (the latter is preferred for faster PHY recognition during MDIO
probe).
The following sections describe the process in greater detail with the following setup. The J721EXCPXEVM
common processor board is used with the J721EXSOMG01EVM TDA4VM and DRA829V socketed system on
module. The Linux-RT SDK is used to evaluate Linux Kernel version 5.10 on the board. The common processor
board natively has one Ethernet port, using the DP83867E Ethernet PHY. A plug in daughter card with four
additional Ethernet ports is plugged into the common processor board's EVM expansion connector, where the
drivers for the Ethernet PHYs are not included in the processor's SDK.
3.1 Linux Device Tree
A Linux device tree is a data structure used to describe the hardware components and configuration in
embedded systems. The device tree provides a standardized way for the operating system to understand the
hardware layout, including details about the processor, memory, buses. and peripherals. Device tree data is
typically stored in a binary format (.dtb file) and is passed to the Linux kernel during boot-up. The kernel then
uses this information to dynamically bind device tree nodes and initialize hardware components, allowing for
efficient and flexible hardware support across different embedded platforms without the need for hard-coding
hardware details into the kernel.
The Device Tree Codeblock is an example of how four Ethernet PHYs on the daughter card are configured in the
device tree file. CPSW refers to the MAC interface of the processor and the main node definitions to consider
are:
• &cpsw0 {} which initializes four RGMII interfaces
• cpsw0_portn {} which initializes further details for each port
– phy-mode: sets the MAC interface of that port
– phy-handle: defines how to set up the PHY
• <&cpsw9g_phyx> is used to set the PHY Address
– Note that x does not set the PHY Address and is only a naming convention. The address is
assigned lower in the Device Tree Codeblock, inside the cpsw9g_mdio{} definition.
• reg = <x>;
•
RGMII delays can be set here too, an example can be seen in the J721E common processor board dts
file, line 744, and in the RGMII Codeblock.
– Typically our RGMII delay recommendation is to configure the PHY to delay both TX and RX CLK
by 2.0ns (referred to as shift mode), while the processor is set to 0 delay (referred to as align
mode). See Table 3-1 for more information.
• However, many TI processors have an internal 2.0ns delay on the TX lines that cannot be
disabled. In the RGMII Codeblock, only RX delay is configured on the PHY for this reason.
– phys
• Setting which eth# each port is assigned
– <&cpsw0_phy_gmii_sel n>
4 How to Integrate Linux Driver Into Your System SNLA450 – JULY 2024
Submit Document Feedback
Copyright © 2024 Texas Instruments Incorporated
www.ti.com Driver Integration
RGMII Codeblock:
&davinci_mdio {
phy0: ethernet-phy@0 { //PHY0 is defined and passed to phy-handle
reg = <0>;
ti,rx-internal-delay = <DP83867_RGMIIDCTL_2_00_NS>;
ti,fifo-depth = <DP83867_PHYCR_FIFO_DEPTH_4_B_NIB>;
};
};
&cpsw_port1 {
phy-mode = "rgmii-rxid";
phy-handle = <&phy0>;
};
SNLA450 – JULY 2024 How to Integrate Linux Driver Into Your System 5
Submit Document Feedback
Copyright © 2024 Texas Instruments Incorporated
Driver Integration www.ti.com
&cpsw0 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&mdio_pins_default
&rgmii1_pins_default
&rgmii2_pins_default
&rgmii3_pins_default
&rgmii4_pins_default
>;
};
&cpsw0_port1 {
phy-handle = <&cpsw9g_phy0>;
phy-mode = "rgmii-rxid";
mac-address = [00 00 00 00 00 00];
phys = <&cpsw0_phy_gmii_sel 1>;
};
&cpsw0_port2 {
phy-handle = <&cpsw9g_phy4>;
phy-mode = "rgmii-rxid";
mac-address = [00 00 00 00 00 00];
phys = <&cpsw0_phy_gmii_sel 2>;
};
&cpsw0_port3 {
phy-handle = <&cpsw9g_phy5>;
phy-mode = "rgmii-rxid";
mac-address = [00 00 00 00 00 00];
phys = <&cpsw0_phy_gmii_sel 3>;
};
&cpsw0_port4 {
phy-handle = <&cpsw9g_phy8>;
phy-mode = "rgmii-rxid";
mac-address = [00 00 00 00 00 00];
phys = <&cpsw0_phy_gmii_sel 4>;
};
&cpsw9g_mdio {
bus_freq = <1000000>;
#address-cells = <1>;
#size-cells = <0>;
cpsw9g_phy0: ethernet-phy@0 {
reg = <0>;
};
cpsw9g_phy4: ethernet-phy@4 {
reg = <4>;
};
cpsw9g_phy5: ethernet-phy@5 {
reg = <5>;
};
cpsw9g_phy8: ethernet-phy@8 {
reg = <8>;
};
};
When the board is running, the terminal command dmesg grep | mdio can be used to confirm the PHY address
(phy[x]) and eth port (ethn).
6 How to Integrate Linux Driver Into Your System SNLA450 – JULY 2024
Submit Document Feedback
Copyright © 2024 Texas Instruments Incorporated
www.ti.com Driver Integration
TI-Linux-kernel is the LKD in this example. From here, you can navigate to:
LKD/drivers/net/phy/
Copy newDriver.c into this directory. Within this same directory are Makefile and Kconfig , both files need to be
edited for newDriver.c to be built.
Edit Makefile
Add the following line to the Makefile. Note the assignment is newDriver.o and not newDriver.c
obj-$(CONFIG_newDriver_PHY) += newDriver.o
Edit Kconfig
Add the following lines to the Kconfig,
config newDriver PHY
tristate "<Insert Company name> newDriver PHY"
--help--
Supports the newDriver PHY.
After both the Makefile and Kconfig files have been edited, return to the LKD. From here, go to:
LKD/arch/arm64/configs
Note
If your processor is 32 bit instead of 64 bit, go into the 'arm' folder instead of 'arm64'.
Here you can find a defconfig file, add the following line:
CONFIG_newDriver_PHY = y
The naming convention, CONFIG_newDriver_PHY, needs to match what was set in the Makefile.
From here, you can return to the SDK install directory and run the make command on the terminal.
Note
Not all kernel's can be built by running make, consult your SDK's documentation for correct procedure
to build kernel, u-boot, and dtb files.
SNLA450 – JULY 2024 How to Integrate Linux Driver Into Your System 7
Submit Document Feedback
Copyright © 2024 Texas Instruments Incorporated
Common Terminal Commands www.ti.com
This message indicates that the PHY is not found on the MDIO bus, which can be caused by several issues. The
most common being a missing or incorrect device tree (see Section 3.1 for more information), but can also be
due to a non-functional PHY or a bad MDIO connection.
Once the PHY can be detected on the MDIO bus, another common error message is:
Both the driver unknown and Generic PHY messages indicate that the driver file is not loaded correctly, built,
or completely missing; and Linux loaded a generic driver that won't function well with the PHY. In this case,
verify that the driver was successfully compiled and added to Linux. See Section 3.2 for more information on this
process.
Finally, an example of a good output looks like this:
Here we can see the phy[0] is identified as the DP83867 and assigned as port eth0
Note
PHY[n], where n represents the PHY Address can be different than the ethx where x represents which
port that PHY is assigned to. For example, PHY address can be 8 while being assigned to port eth0.
8 How to Integrate Linux Driver Into Your System SNLA450 – JULY 2024
Submit Document Feedback
Copyright © 2024 Texas Instruments Incorporated
www.ti.com Common Terminal Commands
4.1.2 ifconfig
ifconfig(case sensitive) is a Linux terminal command that displays network interfaces and can also be used to
determine if the driver has been loaded correctly. ifconfig -ethx down deactivates the interface and ifconfig
-ethx up activates it; which loads the driver again, similarly to when the board is powered on initially.
root@j7-evm:~# ifconfig
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 metric 1
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
ether 02:42:f9:5b:d7:a4 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
SNLA450 – JULY 2024 How to Integrate Linux Driver Into Your System 9
Submit Document Feedback
Copyright © 2024 Texas Instruments Incorporated
Common Terminal Commands www.ti.com
4.2.2 Ethtool
Ethtool is used to access or change network driver settings.
• Ethtool -ethx
– Ethx represents which network device you are referring to. If a board has two Ethernet ports, there can be
eth0 and eth1
– Command tells current status and configuration of that Ethernet device
• This is an easy way to confirm the PHYADDRESS of a port
ethtool eth0
Settings for eth0:
Supported ports: [ TP MII ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supported pause frame use: Symmetric
Supports auto-negotiation: Yes
Supported FEC modes: Not reported
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised pause frame use: Symmetric
Advertised auto-negotiation: Yes
Advertised FEC modes: Not reported
Link partner advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Link partner advertised pause frame use: Symmetric Receive-only
Link partner advertised auto-negotiation: Yes
Link partner advertised FEC modes: Not reported
Speed: 1000Mb/s
Duplex: Full
Auto-negotiation: on
master-slave cfg: preferred slave
master-slave status: slave
Port: Twisted Pair
PHYAD: 0
Transceiver: external
MDI-X: Unknown
Supports Wake-on: ubgs
Wake-on: d
SecureOn password: 00:00:00:00:00:00
Current message level: 0x000020f7 (8439)
drv probe link ifdown ifup rx_err tx_err hw
Link detected: yes
10 How to Integrate Linux Driver Into Your System SNLA450 – JULY 2024
Submit Document Feedback
Copyright © 2024 Texas Instruments Incorporated
www.ti.com Common Terminal Commands
Note
This command has no output. ethtool eth3 | grep master-slave is run to check the current status
SNLA450 – JULY 2024 How to Integrate Linux Driver Into Your System 11
Submit Document Feedback
Copyright © 2024 Texas Instruments Incorporated
Common Terminal Commands www.ti.com
4.3.2 TDR
Time Domain Reflectometer (TDR) is a function that identifies a fault in the cable. Not all Ethernet PHYs have
the TDR feature, be sure to check the PHY's data sheet to confirm. For TI's automotive single pair Ethernet
(SPE) PHYs to correctly run TDR, the Master/Slave state of the PHY must be known.
When PHY is Master:
• If cable is connected (good link)
– PHY drops link, performs TDR, and regains link
• If cable is disconnected or damaged
– PHY performs TDR and outputs:
• Fault Type
– Open or Short
• Distance of fault in meters
When PHY is Slave:
• If cable is connected (good link)
– Link partner (Master) needs to be forced silent (not transmitting any packets), otherwise TDR will fail
• Cable can be disconnected from Master to run TDR as Slave
In the codeblock below, eth3 is initially linked up with a known good cable and configured as Master. TDR is run
and completes as expected, with no fault detected. After TDR is completed, the cable is unplugged from the link
partner, resulting in eth3: Link is Down. TDR is then run again.
12 How to Integrate Linux Driver Into Your System SNLA450 – JULY 2024
Submit Document Feedback
Copyright © 2024 Texas Instruments Incorporated
www.ti.com Common Terminal Commands
In the codeblock below, eth4 is initially linked up with a known good cable and configured as Slave. TDR is run
and fails as expected. Next the cable is unplugged from the link partner, resulting in eth4: Link is Down. TDR is
then run again.
root@j7-evm:~# ethtool --cable-test eth4
am65-cpsw-nuss c000000.ethernet eth4: Link is Down
PHY is set as Slave.
Cable test started for device eth4.
Cable test completed for device eth4.
TDR HAS FAILED
root@j7-evm:~# am65-cpsw-nuss c000000.ethernet eth4: Link is Up - 100Mbps/Full - flow control off
SNLA450 – JULY 2024 How to Integrate Linux Driver Into Your System 13
Submit Document Feedback
Copyright © 2024 Texas Instruments Incorporated
Common Terminal Commands www.ti.com
With ping successfully working, we can attempt to perform a throughput test using iPerf, an open-source tool
used to measure network performance/bandwidth. iPerf needs to be installed on both machines (testboard and
Linux PC) to function.
14 How to Integrate Linux Driver Into Your System SNLA450 – JULY 2024
Submit Document Feedback
Copyright © 2024 Texas Instruments Incorporated
www.ti.com Common Terminal Commands
iPerf Example:
1. On the test board, run the command iperf -s to configure the test board as the server.
2. On the Linux PC, run the command iperf -c 169.254.132.250 (the IP address of the server), to configure the
Linux PC as a client and connects to the server.
The codeblock below is captured from the testboard. Here we can see 1.09 GB of data successfully transferred
and the Bandwidth is very close to the advertised speed of the network port (1000Mbps).
root@j7-evm:~# iperf -s
------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 128 KByte (default)
------------------------------------------------------------
[ 4] local 169.254.132.250 port 5001 connected with 169.254.132.246 port 37356
[ ID] Interval Transfer Bandwidth
[ 4] 0.0-10.0 sec 1.09 GBytes 933 Mbits/sec //This step happens after the Linux PC connects
as a client
SNLA450 – JULY 2024 How to Integrate Linux Driver Into Your System 15
Submit Document Feedback
Copyright © 2024 Texas Instruments Incorporated
Summary www.ti.com
5 Summary
This application note provides a comprehensive overview of basic Linux PHY driver terminology, guiding users
through the integration of a new Ethernet driver into a system and offering insights into common terminal
commands for debugging purposes. From foundational concepts to practical implementation, this resource
equips developers with the knowledge and tools necessary to navigate the complexities of Linux driver
development efficiently.
6 References
• Texas Instruments, ti-ethernet-software Github.
• Ethtool, Linux Manual Page.
• iPerf, Speed Test Tool.
16 How to Integrate Linux Driver Into Your System SNLA450 – JULY 2024
Submit Document Feedback
Copyright © 2024 Texas Instruments Incorporated
IMPORTANT NOTICE AND DISCLAIMER
TI PROVIDES TECHNICAL AND RELIABILITY DATA (INCLUDING DATA SHEETS), DESIGN RESOURCES (INCLUDING REFERENCE
DESIGNS), APPLICATION OR OTHER DESIGN ADVICE, WEB TOOLS, SAFETY INFORMATION, AND OTHER RESOURCES “AS IS”
AND WITH ALL FAULTS, AND DISCLAIMS ALL WARRANTIES, EXPRESS AND IMPLIED, INCLUDING WITHOUT LIMITATION ANY
IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT OF THIRD
PARTY INTELLECTUAL PROPERTY RIGHTS.
These resources are intended for skilled developers designing with TI products. You are solely responsible for (1) selecting the appropriate
TI products for your application, (2) designing, validating and testing your application, and (3) ensuring your application meets applicable
standards, and any other safety, security, regulatory or other requirements.
These resources are subject to change without notice. TI grants you permission to use these resources only for development of an
application that uses the TI products described in the resource. Other reproduction and display of these resources is prohibited. No license
is granted to any other TI intellectual property right or to any third party intellectual property right. TI disclaims responsibility for, and you
will fully indemnify TI and its representatives against, any claims, damages, costs, losses, and liabilities arising out of your use of these
resources.
TI’s products are provided subject to TI’s Terms of Sale or other applicable terms available either on ti.com or provided in conjunction with
such TI products. TI’s provision of these resources does not expand or otherwise alter TI’s applicable warranties or warranty disclaimers for
TI products.
TI objects to and rejects any additional or different terms you may have proposed. IMPORTANT NOTICE
Mailing Address: Texas Instruments, Post Office Box 655303, Dallas, Texas 75265
Copyright © 2024, Texas Instruments Incorporated