前一段时间一直在看FCoE交换机方面的的代码,忽然老师让把前一段时间看过的师兄写的关于一个CNA卡的代码改一下,原来的CNA卡的驱动是一个字符设备驱动,现在要把它改成网络设备驱动,本来没有怎么在意,还是准备以交换机那边的为主,后来发现看了这么长时间的代码,真的需要好好地写一下代码了,再说以前看了很多关于网络设备的知识,很多东西都已经遗忘了,现在开始好好写一下这个驱动的代码,先把这个网卡做成一个以太网卡,然后在这个基础上在加工做成一个CNA卡。
这部分的内容有部分的内容参考csdn上面的别人的博客的中内容:http://blog.csdn.net/ropenyuan/article/details/6763663
我们知道,在网络设备驱动中,一个结构体至关重要,是网络设备的核心,就是struct net_device,在net/core/dev.c文件中有一个函数就是专门用来分配这样一个结构体的,
alloc_netdev() 这个函数用来生成一个net_device结构体,对其成员赋值并返回该结构体的指针。第一个参数是设备私有成员的大小,第二个参数为设备名,第三个参数为net_device的setup()函数指针。setup()函数接收的参数为struct net_device指针,用于预置net_device成员的值。