当前位置:网站首页>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
文件中.
边栏推荐
- Matlab矩阵基本操作(定义,运算)
- Foreign media right, apple on May be true in inventory
- Use of radiobutton
- 使用 GraphiQL 可视化 GraphQL 架构
- Delete the disk in good condition (recovery partition)
- mysql black window ~ build database and build table
- How to switch remote server in gerrit
- ASP.NET Core generates continuous Guid
- SIGABRT 报错时的注意事项和解决方法
- How does automated testing create business value?
猜你喜欢
Implementing distributed locks based on Redis (SETNX), case: Solving oversold orders under high concurrency
【7.29】Code Source - 【Arrangement】【Stone Game II】【Cow and Snacks】【Minimum Number of Spawns】【Sequence】
What is the difference between BI software in the domestic market?
长得很怪的箱图
OPPO在FaaS领域的探索与思考
Tencent Cloud Deployment----DevOps
复杂高维医学数据挖掘与疾病风险分类研究
Why is the field of hacking almost filled with boys?
第二届中国PWA开发者日
对话庄表伟:开源第一课
随机推荐
百度网盘网页版加速播放(有可用的网站吗)
Implementing click on the 3D model in RenderTexture in Unity
Emmet syntax
vb中如何连接mysql_vb怎么连接数据库「建议收藏」
The use of button controls
Replication Latency Case (1) - Eventual Consistency
第05章 存储引擎【1.MySQL架构篇】【MySQL高级】
Linux查看redis版本(查看mongodb版本)
Graham‘s Scan法求解凸包问题
ML.NET related resources
Precautions and solutions when SIGABRT error is reported
Website vulnerability repair service provider's analysis of unauthorized vulnerability
多主复制的适用场景(2)-需离线操作的客户端和协作编辑
gerrit中如何切换远程服务器
Doing things software development - the importance of law and understanding of reasonable conclusions
复制延迟案例(3)-单调读
MySQL database operations
6-22漏洞利用-postgresql数据库密码破解
Graham's Scan method for solving convex hull problems
MySQL multi-table union query