news 2026/6/12 11:09:08

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

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
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()来删除引用计数。

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

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/6/10 12:23:50

抖音视频采集工具:从需求痛点到高效解决方案的技术实践指南

抖音视频采集工具&#xff1a;从需求痛点到高效解决方案的技术实践指南 【免费下载链接】douyin-downloader 项目地址: https://gitcode.com/GitHub_Trending/do/douyin-downloader 问题定位&#xff1a;不同使用频率用户的核心困境是什么&#xff1f; 在当今内容驱动…

作者头像 李华
网站建设 2026/6/10 10:59:50

突破设备壁垒:AudioShare实现跨平台音频自由流动

突破设备壁垒&#xff1a;AudioShare实现跨平台音频自由流动 【免费下载链接】AudioShare 将Windows的音频在其他Android设备上实时播放。Share windows audio 项目地址: https://gitcode.com/gh_mirrors/audi/AudioShare 你是否曾想过让电脑播放的音乐同时在手机、平板…

作者头像 李华
网站建设 2026/6/10 12:59:39

Silk-V3全能音频解码器:一站式解决社交平台音频格式兼容难题

Silk-V3全能音频解码器&#xff1a;一站式解决社交平台音频格式兼容难题 【免费下载链接】silk-v3-decoder [Skype Silk Codec SDK]Decode silk v3 audio files (like wechat amr, aud files, qq slk files) and convert to other format (like mp3). Batch conversion support…

作者头像 李华
网站建设 2026/6/10 19:05:29

网络复习篇——网络基础(一)

目录 一.同一数据链路发送数据 二.网络协议栈与操作系统的关系 三.封装&#xff0c;解包&#xff0c;分用 四.IP协议的屏蔽作用 五.IP地址 VS Mac地址 在看完《图解http》和《图解TCP/IP》之后我又把C的网络课进行二刷&#xff0c;加深自己的理解。 一.同一数据链路发送数…

作者头像 李华
网站建设 2026/6/10 14:20:38

【万金油-变更管理】信息系统项目管理师案例分析

信息系统项目管理师案例分析【项目配置管理万金油】内容&#xff0c;摘自&#xff1a;科科过纸质书《案例集分析》第86~87页&#xff0c;并配套配置管理历年真题解析。1、变更管理可能出现的问题&#xff08;1&#xff09;未提交书面变更申请&#xff0c;项目经理没有按照变更管…

作者头像 李华
网站建设 2026/6/10 14:20:54

音乐制作电子软件FL Studio2025.2.4.5242中文版新功能介绍

FL Studio2025.2.4.5242中文版是制作电子音乐的首选软件&#xff0c;也是目前行业中最优秀的完整的软件音乐制作环境或数字音频工作站&#xff0c;中文也叫做水果软件&#xff0c;可以编曲、剪辑、录音、混音&#xff0c;让你的计算机成为全功能录音室。其软件内置众多电子合成…

作者头像 李华