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)) 与否.

发布了407 篇原创文章 · 获赞 150 · 访问量 38万+

猜你喜欢

转载自blog.csdn.net/ds1130071727/article/details/102626067
PHY
今日推荐