9.网卡驱动程序框架

网卡驱动程序框架:

app:  socket

--------------------------------------------------

           ---------------

           --------------- 若干层网络协议--纯软件

           ---------------

           ---------------

hard_start_xmit||  /\

               \/  ||  netif_rx   sk_buff

           ---------------

          硬件相关的驱动程序(要提供hard_start_xmit, 有数据时要用netif_rx上报)           

--------------------------------------------------

               硬件           

怎么写网卡驱动程序?

1. 分配一个net_device结构体

2. 设置:

2.1 发包函数: hard_start_xmit

2.2 收到数据时(在中断处理函数里)用netif_rx上报数据

2.3 其他设置

3. 注册: register_netdevice

代码:

https://github.com/China-wzs/Linux-driver/blob/master/7.%E7%BD%91%E5%8D%A1%E9%A9%B1%E5%8A%A8.rar

测试1th/2th:

1. insmod virt_net.ko

2. ifconfig vnet0 3.3.3.3

   ifconfig // 查看

3. ping 3.3.3.3  // ping自己成功   ,表明ip只是纯软件层,不经过硬件驱动层

    ping 3.3.3.4  // 死机   ,当ping外部时,经过硬件驱动层,由于还没有配置完成,会死机。

测试DM9000C驱动程序:

1. 把dm9dev9000c.c放到内核的drivers/net目录下

2. 修改drivers/net/Makefile

obj-$(CONFIG_DM9000) += dm9000.o

改为

obj-$(CONFIG_DM9000) += dm9dev9000c.o

3. make uImage

   使用新内核启动

4.

使用NFS启动

ifconfig eth0 192.168.1.17

ping 192.168.1.1   

猜你喜欢

转载自blog.csdn.net/weixin_40535588/article/details/89352138