b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

Linux网络设备驱动程序体系结构分为四层()(2)

电脑杂谈  发布时间:2021-05-02 22:01:38  来源:网络整理

struct net_device

([3) struct net_device_ops

网络设备的操作方法的集合。

1002 struct net_device_ops {
1003         int          (*ndo_init)(struct net_device *dev);
1004         void         (*ndo_uninit)(struct net_device *dev);
1005         int          (*ndo_open)(struct net_device *dev);//打开网络接口设备,获得设备需要的I/O地址、IRQ、DMA通道等
1006         int          (*ndo_stop)(struct net_device *dev);//停止网络接口设备,与open()函数的作用相反
1007         netdev_tx_t  (*ndo_start_xmit) (struct sk_buff *skb,struct net_device *dev);//启动数据包的发送,当系统调用驱动程序的xmit函数时,需要向其传入一个sk_buff结构体指针,以使得驱动程序能获取从上层传递下来的数据包
1013         void         (*ndo_change_rx_flags)(struct net_device *dev,int flags);
1015         void         (*ndo_set_rx_mode)(struct net_device *dev);
1016         int          (*ndo_set_mac_address)(struct net_device *dev,void *addr);//用于设置设备的MAC地址
1018         int          (*ndo_validate_addr)(struct net_device *dev);
1019         int          (*ndo_do_ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd);//用于进行设备特定的I/O控制
1021         int          (*ndo_set_config)(struct net_device *dev, struct ifmap *map);       //用于配置接口,也可用于改变设备的I/O地址和中断号
1023         int          (*ndo_change_mtu)(struct net_device *dev, int new_mtu);
1025         int          (*ndo_neigh_setup)(struct net_device *dev,struct neigh_parms *);
1027         void         (*ndo_tx_timeout) (struct net_device *dev);//当数据包的发送超时时,ndo_tx_timeout()函数会被调用,该函数需采取重新启动数据包发送过程或重新启动硬件等措施来恢复网络设备到正常状态
1028 
1148 };

3.相关API

([1)分配/释放net_device

程序多开器实现原理_网络设备器驱动程序_程序多开器下载

//linux/etherdevice.h
/**
 * 分配及初始化net_device对象()
 * @sizeof_priv - 私有数据大小(单位:字节数)
 * 返回值:失败:NULL, 成功:net_device对象的首地址
 */
struct net_device *alloc_etherdev(int sizeof_priv);
//linux/netdevice.h
/**
 * 分配及初始化net_device对象
 * @int sizeof_priv - 私有数据大小(单位:字节数)
 * @const char *name - 物理接口名("名称%d")
 * @unsigned char name_assign_type - NET_NAME_UNKNOWN
 * @void (*setup)(struct net_device *) - 初始化函数
 * 返回值:失败:NULL成功:net_device对象的首地址
 */
struct net_device *alloc_netdev(int sizeof_priv, const char *name,unsigned char name_assign_type,void (*setup)(struct net_device *));
//释放
void free_netdev(struct net_device *dev);

([2)以太网的初始化

初始化以太网设备时应调用它。其主要功能是根据以太网标准初始化net_device对象。

void ether_setup(struct net_device *dev);

([3)注册/注销net_device

//注册
int register_netdev(struct net_device *dev);
//注销
void unregister_netdev(struct net_device *dev);

([4)开始/停止发送队列

//开启发送队列
void netif_start_queue(struct net_device *dev)
//停止发送队列
void netif_stop_queue(struct net_device *dev)

4.网络设备的中断处理功能

中断处理功能

是用于在网络设备媒体层和设备驱动程序功能层之间发送数据的接口。网卡接收到的数据是通过中断报告的,因此网络驱动程序中的中断处理功能是第一次团队接收到的数据用于本地处理,此函数最终必须调用netif_rx()才能将接收到的数据报告给协议界面层。

5.网络设备驱动程序示例

转载了DM9000驱动程序分析文章,该文章非常详细,感谢作者的贡献。全面分析Linux DM9000网卡驱动程序


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-372582-2.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    • 明成祖朱棣
      明成祖朱棣

      不惹事自然无事

    • 韩生才
      韩生才

      一会儿又说要解除伊拉克的武装要入侵伊拉克

    热点图片
    拼命载入中...