当前位置: 首页 > news >正文

Linux网络驱动之Fixed-Link(8)

接前一篇文章:Linux网络驱动之Fixed-Link(7)

本文内容参考:

linux phy fixed-link-CSDN博客

fixed-link 网口驱动设备树-CSDN博客

GMAC网卡Fixed-Link模式 - StepForwards - 博客园

RTL8367RB的国产P2P替代方案用JL6107-PC的可行性及实现方法-CSDN博客

linux phy处理流程一:探测phy设备_phy link过程-CSDN博客

设备树 fixed-link 使用说明-CSDN博客

Linux 网络驱动-MAC、PHY层驱动框架(三)_ethernet-phy-ieee802.3-c22-CSDN博客

特此致谢!

三、深入了解

4. Linux内核中Fixed-Link的相关内容

(2)PHY驱动(driver)匹配

上一回继续讲解of_phy_get_and_connect函数,讲到了of_phy_connect函数,本回开始解析该函数。为了便于理解和回顾,再次贴出of_phy_get_and_connect函数代码,在drivers/net/mdio/of_mdio.c中,如下:

/** * of_phy_get_and_connect * - Get phy node and connect to the phy described in the device tree * @dev: pointer to net_device claiming the phy * @np: Pointer to device tree node for the net_device claiming the phy * @hndlr: Link state callback for the network device * * If successful, returns a pointer to the phy_device with the embedded * struct device refcount incremented by one, or NULL on failure. The * refcount must be dropped by calling phy_disconnect() or phy_detach(). */ struct phy_device *of_phy_get_and_connect(struct net_device *dev, struct device_node *np, void (*hndlr)(struct net_device *)) { phy_interface_t iface; struct device_node *phy_np; struct phy_device *phy; int ret; ret = of_get_phy_mode(np, &iface); if (ret) return NULL; if (of_phy_is_fixed_link(np)) { ret = of_phy_register_fixed_link(np); if (ret < 0) { netdev_err(dev, "broken fixed-link specification\n"); return NULL; } phy_np = of_node_get(np); } else { phy_np = of_parse_phandle(np, "phy-handle", 0); if (!phy_np) return NULL; } phy = of_phy_connect(dev, phy_np, hndlr, 0, iface); of_node_put(phy_np); return phy; } EXPORT_SYMBOL(of_phy_get_and_connect);

前文书讲过,通过of_phy_register_fixed_link函数(最终是通过fixed_phy_register函数)完成了PHY设备(struct phy_device)设备的注册。接下来就要调用of_phy_connect函数来匹配PHY驱动(struct phy_driver)。当前正是讲到这个of_phy_connect函数。

of_phy_connect函数。其也在drivers/net/mdio/of_mdio.c中,代码如下:

/** * of_phy_connect - Connect to the phy described in the device tree * @dev: pointer to net_device claiming the phy * @phy_np: Pointer to device tree node for the PHY * @hndlr: Link state callback for the network device * @flags: flags to pass to the PHY * @iface: PHY data interface type * * If successful, returns a pointer to the phy_device with the embedded * struct device refcount incremented by one, or NULL on failure. The * refcount must be dropped by calling phy_disconnect() or phy_detach(). */ struct phy_device *of_phy_connect(struct net_device *dev, struct device_node *phy_np, void (*hndlr)(struct net_device *), u32 flags, phy_interface_t iface) { struct phy_device *phy = of_phy_find_device(phy_np); int ret; if (!phy) return NULL; phy->dev_flags |= flags; ret = phy_connect_direct(dev, phy, hndlr, iface); /* refcount is held by phy_connect_direct() on success */ put_device(&phy->mdio.dev); return ret ? NULL : phy; } EXPORT_SYMBOL(of_phy_connect);

先来看一下of_phy_connect函数的注释。

of_phy_connect函数的作用是,获取phy节点并连接到设备树中描述的phy。

参数说明:

  • dev:指向声称拥有phy的net_device的指针
  • phy_np:指向PHY设备树节点的指针
  • hndlr:网络设备的链路状态回调
  • flags:传递给PHY的标志
  • iface:PHY数据接口类型

返回值:

如果成功,返回一个指向phy_device的指针,其中嵌入的结构设备refcount递增1;否则返回NULL。
必须通过调用phy_disconnect()或phy_detach()来删除引用计数。

下一回开始解析函数具体内容。

http://www.jsqmd.com/news/357045/

相关文章:

  • 完整教程:如何在AIDL中传递List和Map数据类型?
  • 3分钟颠覆10年资源管理习惯:教育资源获取效率革命
  • Docker 镜像自动同步强大的系统 - 轻量级集群镜像分发强大的方案
  • 聊聊TraeCN最近的使用感受
  • 革新性英雄联盟助手:从青铜到王者的智能黑科技
  • Vibe Coding:我已经一周没手写代码了
  • 3款高效视频保存工具:从入门到精通的完整指南
  • DSO.ai:工具简介
  • 2024年付费墙工具深度解析:从技术原理到场景化选购指南
  • 解锁文件提取工具:探秘字节码恢复与反编译技术
  • 探讨北京观唐律师事务所实力如何,在各服务区域性价比哪家好? - 工业品网
  • 我靠一个冷知识,发明了「面向控制标记编程」范式
  • 5个秘诀解锁直播回放保存工具:从入门到精通的终极指南
  • 抖音视频智能采集系统:从需求洞察到架构实现的全维度技术解析
  • springboot个人健康管理系统
  • 突破5大设计瓶颈:AI脚本如何重构Illustrator工作流
  • 以下是针对工业上位机(C# WinForms / WPF)中 **OPC UA 集成** 的完整配置与落地指南,聚焦西门子 S7-1200/1500、Beckhoff、通用OPC UA Server等
  • 基于 ML.NET的纯 C# LSTM 设备故障预测完整落地方案,专为工业上位机设计,全程不依赖 Python/ONNX/外部运行时,适配工控机常见配置
  • 模仿加执行
  • 存档修改工具d2s-editor深度指南:从入门到精通的玩家进阶手册
  • Windows 11精简工具:让老旧电脑焕发新生的系统镜像优化神器
  • CSDN思维导图文章结构设计
  • 快手内容批量采集工具全攻略:从效率提升到内容资产化
  • 工业C#上位机稳定性终极方案:内存泄漏零容忍 + 分级异常自愈
  • League Akari:4个维度重构英雄联盟竞技体验
  • 基于2026年主流实践(TIA Portal V18/V19已普及,.NET 8/10下WinForms稳定,S7-1200原生支持OPC UA Server,推荐OPC UA而非旧S7协议)
  • 考研培训机构推荐,橙啦教育的产品特色适合你吗? - 工业设备
  • 聚焦工业上位机真实场景(Modbus/OPC UA采集、实时显示、报警、简单控制)
  • 合肥中锐学校环境好吗,在多地区办学口碑如何? - mypinpai
  • 5个技巧掌握视频下载工具:从4K视频保存到批量视频处理全攻略