net驱动
2025-04-01 23:41:05 0 举报
zynq 7020 linux 网络驱动
作者其他创作
大纲/内容
• 作用:为每个发现的 PHY 设备调用 device_add ,将它们注册到内核的设备模型中。• 目的:使每个 PHY 设备能够被内核管理和识别,同时在 /sys 文件系统中创建对应的设备目录。...bus_probe_device(dev);...
bp->mii_bus->name = \"MACB_mii_bus\";bp->mii_bus->read = &macb_mdio_read;bp->mii_bus->write = &macb_mdio_write;bp->mii_bus->priv = bp;bp->mii_bus->parent = &bp->pdev->dev;if (np && of_phy_is_fixed_link(np)) { err = font color=\"#e74f4c\
phy_probe - probe and init a PHY device
void device_initial_probe(struct device *dev)
int mdiobus_register_device(struct mdio_device *mdiodev)
2
font color=\"#e74f4c\
1
static int __netif_receive_skb(struct sk_buff *skb)
err = register_netdevice(dev);
new_driver->mdiodrv.flags |= MDIO_DEVICE_IS_PHY;new_driver->mdiodrv.driver.name = new_driver->name;new_driver->mdiodrv.driver.bus = &mdio_bus_type;new_driver->mdiodrv.driver.probe = phy_probe;new_driver->mdiodrv.driver.remove = phy_remove;new_driver->mdiodrv.driver.owner = owner;retval = driver_register(&new_driver->mdiodrv.driver);
int __init netdev_kobject_init(void)
static int netif_receive_skb_internal(struct sk_buff *skb)
1、struct macb *bp = netdev_priv(dev);2、
ret = class_register(&mdio_bus_class);if (!ret) { ret = bus_register(&mdio_bus_type); if (ret) class_unregister(&mdio_bus_class);}
frome function(macb_init) -- >/* setup appropriated routines according to adapter type */if (macb_is_gem(bp)) { bp->macbgem_ops.mog_rx = gem_rx; dev->ethtool_ops = &gem_ethtool_ops;} else { bp->macbgem_ops.mog_rx = font color=\"#e74f4c\
int __init mdio_bus_init(void)
static int __init net_dev_init(void)
4
* __mdiobus_register - bring up all the PHYs on a given bus and attach them to bus * @bus: target mii_bus * @owner: module containing bus accessor functionserr = device_register(&bus->dev);for (i = 0; i < PHY_MAX_ADDR; i++) { if ((bus->phy_mask & (1 << i)) == 0) { struct phy_device *phydev; phydev = font color=\"#e74f4c\
......../span style=\"font-size:inherit;\
static int macb_probe(struct platform_device *pdev)
int __init dev_proc_init(void)
int register_netdevice(struct net_device *dev)
/** * struct device - The basic device structure * @parent:The device's \"parent\
mdiodev->bus->mdio_map[mdiodev->addr] = mdiodev;
int register_netdev(struct net_device *dev)
module_init(mdio_bus_init);
ret = __netif_receive_skb(skb);
void bus_probe_device(struct device *dev)
static int macb_init(struct platform_device *pdev)
通用局部定义
match
if (!proc_create_net(\"dev\
static int __net_init dev_proc_net_init(struct net *net)
在 __mdiobus_register 中多次调用 device_add 的原因如下:1. 注册 mii_bus 设备:将 mii_bus 设备本身注册到内核中。2. 注册 PHY 设备:扫描 MDIO 总线上的所有 PHY 设备,并为每个发现的 PHY 设备调用 device_add ,将它们注册到内核中
case GRO_NORMAL: if (netif_receive_skb_internal(skb))
static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];kobj_ns_ops_tbl[type] = ops;
struct bus_type *bus = dev->bus;struct subsys_interface *sif;if (!bus) return;if (bus->p->drivers_autoprobe) font color=\"#e74f4c\
err = font color=\"#e74f4c\
static const struct device_type mdio_bus_phy_type = { .name = \"PHY\
为什么要注册bus->dev?后面有注册phy设备的动作,为什么还要注册mii_bus设备本身?在 Linux 内核的网络驱动中, mii_bus 设备(即 MDIO 总线设备)和 PHY 设备都需要注册到内核的设备模型中,原因如下:(1)MDIO 总线作为一个独立的设备存在 --> mii_bus 表示一个 MDIO(Management Data Input/Output)总线,它本身是一个硬件实体,负责管理和通信多个 PHY 设备。(2)设备模型的层次化管理 --> Linux 内核的设备模型是层次化的,设备之间存在父子关系。 mii_bus 设备作为父设备,PHY 设备作为子设备。注册 mii_bus 设备后,可以为后续注册的 PHY 设备提供一个明确的归属关系,形成一个完整的设备树。(3)提供统一的设备访问接口注册 mii_bus 设备后,内核会为其分配一个设备类( mdio_bus_class ),并将其添加到设备模型中。这样,内核可以通过统一的接口访问和操作 MDIO 总线设备,例如读取设备属性、发送控制命令等。
__netif_receive_skb_one_core
• 作用:将 mii_bus 设备本身注册到内核的设备模型中。• 目的:使 mii_bus 设备能够被内核管理和识别,同时在 /sys 文件系统中创建对应的设备目录device_initialize(dev);return device_add(dev);
struct device_node *np = pdev->dev.of_node;int (*init)(struct platform_device *) = macb_config->init;init(pdev);...err = register_netdev(dev);...err = macb_mii_init(bp);
r = font color=\"#e74f4c\
return pt_prev->font color=\"#e74f4c\
struct bus_type mdio_bus_type = { .name= \"mdio_bus\
int device_register(struct device *dev)
3
kobj_ns_type_register(&net_ns_type_operations);return class_register(&net_class);
int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
struct phy_device *phydev;int err;phydev = font color=\"#e74f4c\
int device_add(struct device *dev)
static struct class mdio_bus_class = { .name= \"mdio_bus\
ret = font color=\"#e74f4c\
static int macb_mii_probe(struct net_device *dev)
int phy_device_register(struct phy_device *phydev)
if (phydrv->match_phy_device)return phydrv->match_phy_device(phydev);return (phydrv->phy_id & phydrv->phy_id_mask) ==(phydev->phy_id & phydrv->phy_id_mask);
if (dev->bus->probe) { ret = dev->bus->probe(dev); if (ret) goto probe_failed;} else if (drv->probe) { ret = drv->probe(dev); if (ret) goto probe_failed;}
static int __init phy_init(void)
module_phy_driver(realtek_drvs);
static struct pernet_operations __net_initdata dev_proc_ops = { .init = font color=\"#e74f4c\
static int macb_mii_init(struct macb *bp)
static int phy_probe(struct device *dev)
subsys_initcall(net_dev_init);
0 条评论
下一页