当前位置:网站首页>i.MX6ULL driver development | 33 - NXP original network device driver reading (LAN8720 PHY)
i.MX6ULL driver development | 33 - NXP original network device driver reading (LAN8720 PHY)
2022-07-31 15:57:00 【Mculover666】
在LinuxYou can see it in the kernel boot logPHY使用的驱动为SMSC LAN8720:
一、设备树节点
in the device tree description file of the board,The descriptions of the two Ethernet ports are as follows:
&fec1 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_enet1 &pinctrl_fec1_reset>;
phy-mode = "rmii";
phy-handle = <ðphy0>;
phy-reset-gpios = <&gpio5 7 GPIO_ACTIVE_LOW>;
phy-reset-duration = <200>;
status = "okay";
};
&fec2 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_enet2 &pinctrl_fec2_reset>;
phy-mode = "rmii";
phy-handle = <ðphy1>;
phy-reset-gpios = <&gpio5 8 GPIO_ACTIVE_LOW>;
phy-reset-duration = <200>;
status = "okay";
mdio {
#address-cells = <1>;
#size-cells = <0>;
ethphy0: ethernet-[email protected]0 {
compatible = "ethernet-phy-ieee802.3-c22";
smsc,disable-energy-detect;
reg = <0>;
};
ethphy1: ethernet-[email protected]1 {
compatible = "ethernet-phy-ieee802.3-c22";
smsc,disable-energy-detect;
reg = <1>;
};
};
};
1. imx6ull MACDescription of the peripheral node
The Ethernet peripheral node name is fec1和fec2,And this is the supplemental description,所以在imx6ullFind the description in the chip-level description file:
&fec1 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_enet1 &pinctrl_fec1_reset>;
phy-mode = "rmii";
phy-handle = <ðphy0>;
phy-reset-gpios = <&gpio5 7 GPIO_ACTIVE_LOW>;
phy-reset-duration = <200>;
status = "okay";
};
&fec2 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_enet2 &pinctrl_fec2_reset>;
phy-mode = "rmii";
phy-handle = <ðphy1>;
phy-reset-gpios = <&gpio5 8 GPIO_ACTIVE_LOW>;
phy-reset-duration = <200>;
status = "okay";
mdio {
#address-cells = <1>;
#size-cells = <0>;
ethphy0: ethernet-[email protected]0 {
compatible = "ethernet-phy-ieee802.3-c22";
smsc,disable-energy-detect;
reg = <0>;
};
ethphy1: ethernet-[email protected]1 {
compatible = "ethernet-phy-ieee802.3-c22";
smsc,disable-energy-detect;
reg = <1>;
};
};
};
Find Compatibility as "fsl,imx6ul-fec",According to this compatibility, the driver source code can be found as drivers/net/ethernet/freescale/fec_main.c.
The binding document is:Documentation/devicetree/bindings/net/fsl-fec.txt,given in the bindings documentationFECDescription required by the peripheral:
- compatible : Should be “fsl,-fec”
- reg : Address and length of the register set for the device
- interrupts : Should contain fec interrupt
- phy-mode : See ethernet.txt file in the same directory
其中phy-mode节点的值如下:
- phy-mode: string, operation mode of the PHY interface;
supported values are “mii”, “gmii”, “sgmii”, “qsgmii”, “tbi”, “rev-mii”, “rmii”, “rgmii”,“rgmii-id”, “rgmii-rxid”, “rgmii-txid”, “rtbi”, “smii”, “xgmii”; this is now a de-facto standard property;
Some optional properties are as follows(节选):
- phy-reset-gpios : Should specify the gpio for phy reset
- phy-reset-duration : Reset duration in milliseconds.
- phy-supply : regulator that powers the Ethernet PHY.
- phy-handle : phandle to the PHY device connected to this device.
- fixed-link : Assume a fixed link. See fixed-link.txt in the same directory. Use instead of phy-handle.
2. mdioDescription of the bus node
mdioFor and external usePHY芯片通信,And the actual development board externalPHY芯片有关,兼容性是"ethernet-phy-ieee802.3-c22",According to the compatibility, find the corresponding binding document as Documentation/devicetree/bindings/net/phy.txt.
The required properties are given below:
- interrupts :
<a b>where a is the interrupt number and b is a field that represents an encoding of the sense and level information for the interrupt. This should be encoded based on the information in section 2) depending on the type of interrupt controller you have. - interrupt-parent : the phandle for the interrupt controller that services interrupts for this device.
- reg : The ID number for the phy, usually a small integer
Compatibility is an optional attribute,指定PHYInformation on the internal registers of the chip.
- compatible: Compatible list, may contain “ethernet-phy-ieee802.3-c22” or “ethernet-phy-ieee802.3-c45” for PHYs that implement IEEE802.3 clause 22 or IEEE802.3 clause 45 specifications. If neither of these are specified, the default is to assume clause 22. The compatible list may also contain other elements.
Wrote in Atom's tutorial,In the case of opening two network ports,将GPIO1_IO07和GPIO_1O06设置为ENET1的MDC和MDIOIt will cause the network to work abnormally,所以设置在ENET2上.
二、FECPeripheral network driver source code reading
对于imx6ull而言,The network driver is mainly divided into two parts:imx6ullNetwork peripheral drivers as wellPHY芯片驱动.
其中imx6ullNetwork peripheral drivers areNXPOriginally written,PHYThe chip driver is a generic driver file.
Compatibility is found according to the device tree description"fsl,imx6ul-fec",According to this compatibility, the driver source code can be found as drivers/net/ethernet/freescale/fec_main.c.
1. fec_probe挂载函数
(1)申请net_device
(2)处理fec私有数据
(3)从设备树获取phy-handle属性的值、获取phy-mode
(4)获取时钟并使能时钟
(5)复位PHY
phy复位函数如下:
(6)初始化enet
In this function the queue is allocated、申请DMA、设置MAC地址.初始化net_device的netdev_ops和ethtool_ops成员:
之后,还设置poll函数来支持NAPI机制:
(7)MII/RMII接口的初始化
(8)申请中断
(9)Register the network card to the system
2. fec_netdev_ops操作集

其中最重要的是 fec_enet_start_xmit 函数实现,Used to start sending packets:
in the send function,The data of the upper layer passes throughskb传入,首先对skb进行判断,是否为GSO数据,如果是则使用 fec_enet_txq_submit_tso 发送,如果不是则使用 fec_enet_txq_submit_skb 发送.
3. napi机制
The service function for network interruption is as follows,It can be seen that the most important thing in the interrupt service function is to proceednapi的调度:
启动napi调度后,It will be registered during initializationnapiThe polling function to receive data:
三、Linux内核PHY子系统与MDIO总线
PHY子系统也是一个设备、总线和驱动模型,分为PHY设备、PHY驱动以及MDIO总线.
1. PHY设备
Linux内核使用phy_device结构体来表示PHY设备,定义在文件include/linux/phy.h中.
一个PHY设备对应一个phy_device实例,使用下面的API完成PHY设备的注册:
int phy_device_register(struct phy_device *phy);
2. PHY驱动
Linux内核使用phy_driver结构体表示PHY驱动,定义在文件include/linux/phy.h中.
这个结构体比较大,编写PHY驱动的主要工作就是实现这些函数.
3. MDIO总线
PHY子系统中,因为PHY设备是通过MDIO接口来管理的,The bus model isMDIO总线,负责匹配PHY设备和PHY驱动.
在文件drivers/net/phy/mdio_bus.c中定义了mdio_bys_type结构体来表示MDIO总线:
The matching function for the bus ismdio_bus_match,该函数实现如下:
可以看到,如果PHY设备与PHY驱动匹配,则使用指定的PHY驱动,Use if it doesn't matchLinux内核自带的通用PHY驱动.
四、LinuxGeneric provided by the kernelPHY驱动
通用PHY驱动名字为“Generic PHY”,在drivers/net/phy/phy_device.c文件中实现.
phy_init是整个PHY子系统的入口函数,Which registers a generic with the kernelPHY驱动:genphy_driver,该数组定义如下:
Two general ones are providedPHY驱动,一个是针对10/100/1000M网络,另一个是针对10G网络的.
五、LAN8720A PHY驱动
SMSC针对自家的PHYThe chip also wrote the corresponding driver file,其中包含了LAN8720A这个PHY芯片,实现在drivers/net/phy/smsc.c文件中.
边栏推荐
- Linux check redis version (check mongodb version)
- Unity 之 图集属性详解和代码示例 -- 拓展一键自动打包图集工具
- MySQL基础篇【单行函数】
- 2020 WeChat applet decompilation tutorial (can applet decompile source code be used)
- 贪吃蛇项目(简单)
- border控件的使用
- tensorflow2.0 cnn(layerwise)
- Single-cell sequencing workflow (single-cell RNA sequencing)
- C程序是如何跑起来的01 —— 普通可执行文件的构成
- 字符指针赋值[通俗易懂]
猜你喜欢
随机推荐
长得很怪的箱图
第05章 存储引擎【1.MySQL架构篇】【MySQL高级】
Codeforces Round #796 (Div. 2) (A-D)
hough变换检测直线原理(opencv霍夫直线检测)
字符指针赋值[通俗易懂]
Applicable Scenarios of Multi-Master Replication (1) - Multi-IDC
The use of button controls
After the form is submitted, the page does not jump [easy to understand]
MySQL的相关问题
Premiere Pro 2022 for (pr 2022)v22.5.0
WPF项目--控件入门基础用法,必知必会XAML
ASP.NET Core 产生连续 Guid
tensorflow2.0 cnn(layerwise)
Use of radiobutton
[MySQL] Mysql paradigm and the role of foreign keys
Why don't you make a confession during the graduation season?
EF Core 2.2中将ORM框架生成的SQL语句输出到控制台
The normal form of the database (first normal form, second normal form, third normal form, BCNF normal form) "recommended collection"
Graham's Scan method for solving convex hull problems
MySQL常用语句整理







