Linux Ethernet PHY 驱动

今年在FPGA上和IC那边一起验证了MAC/PHY, 基于linux 3.6.4, 这边小结一下代码.

phy的初始化顺序
第一步
phy_init
  mdio_bus_init
    bus_register(&mdio_bus_type);//autoprobe
  phy_driver_register(&genphy_driver);

第二步, 具体的phy驱动的初始化(以icplus为例)
icplus_init
  phy_drivers_register(icplus_driver, ARRAY_SIZE(icplus_driver));
    phy_driver_register
      new_driver->driver.bus = &mdio_bus_type; //也是mdio_bus_type
      new_driver->driver.probe = phy_probe;
      new_driver->driver.remove = phy_remove;
      driver_register
        bus_add_driver
          driver_attach //下面没跑,因为先注册的是driver, 还没有match的device, 只是示例而已
            __driver_attach
              driver_match_device
                drv->bus->match //也就是 mdio_bus_type 里面的 mdio_bus_match

第三步,网卡驱动
mt_eth_init
  platform_driver_register(&mt_eth_driver);
    mt_eth_drv_probe
      mt_eth_mii_init
        mdiobus_register
          device_register
            device_add
              bus_add_device
              bus_probe_device
                device_attach
                  __device_attach
                    driver_match_device
                      drv->bus->match //也就是 mdio_bus_type 里面的 mdio_bus_match
                    driver_probe_device
                      really_probe
                        dev->bus->probe//也就是 phy_probe, 此时是PHY_READY状态
                          phydev->drv->probe //如果有,则调用具体phy的probe,比如icplus的 mdiobus_scan
            get_phy_device
              get_phy_id
              phy_device_create //PHY_DOWN状态
          mdiobus_scan
            phy_device_register
              device_register //然后就和上面的流程一样了
        mt_eth_mii_probe // 和mdiobus_register同一级, 在mt_eth_mii_init 中调用
          phy_connect
            bus_find_device_by_name
            phy_connect_direct
              phy_attach_direct // 此时是PHY_READY状态
                phy_init_hw
                  phydev->drv->config_init(phydev);//icplus中的具体实现
            phy_start_machine
              调度delayed_work, 其实就是 phy_state_machine
                mt_eth_adjust_link

补充一下mdio_bus_match, 会发现其实是看 ((phydrv->phy_id & phydrv->phy_id_mask) == (phydev->phy_id & phydrv->phy_id_mask)) 与否.

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值