1,首先从模块加载函数module_init(fec_enet_module_init);
static int __init fec_enet_module_init(void)
{
struct net_device *dev;
int i, j, err;
DECLARE_MAC_BUF(mac);
printk("FEC ENET Version 0.2\n");
for (i = 0; (i < FEC_MAX_PORTS); i++) {
dev = alloc_etherdev(sizeof(struct fec_enet_private));//申请一个网络设备其格式是fec_enet_private
if (!dev)
return -ENOMEM;
err = fec_enet_init(dev);
if (err) {
free_netdev(dev);
continue;
}
/
net_dev_array[i]=dev;
/
if (register_netdev(dev) != 0) {
/* XXX: missing cleanup here */
free_netdev(dev);
return -EIO;
}
printk("%s: ethernet %s\n",
dev->name, print_mac(mac, dev->dev_addr));
}
return 0;
}
2,关键结构体fec_enet_private定义了网络设备所用到的所有私有资源
struct fec_enet_private {
/* Hardware registers of the FEC device */
volatile fec_t*hwp;
struct net_device *netdev;
/* The saved address of a sent-in-place packet/buffer, for skfree(). */
unsigned char *tx_bounce[TX_RING_SIZE];
structsk_buff* tx_skbuff[TX_RING_SIZE];
ushortskb_cur;
ushortskb_dirty;
/* CPM dual port RAM relative addresses.
*/
cbd_t*rx_bd_base;/* Address of Rx and Tx buffers. */
cbd_t*tx_bd_base;
cbd_t*cur_rx, *cur_tx;/* The next free ring entry */
cbd_t*dirty_tx;/* The ring entries to be free()ed. */
uinttx_full;
spinlock_t lock;
uintphy_id;
uintphy_id_done;
uintphy_status;
uintphy_speed;
phy_info_t const*phy;
struct work_struct phy_task;
volatile fec_t*phy_hwp;
uintsequence_done;
uintmii_phy_task_queued;
uintphy_addr;
intindex;
intopened;
intlink;
intold_link;
intfull_duplex;
#ifdef CONFIG_M5445X
intspeed_10;
struct timer_list phy_timer;
unsigned long sTime;
unsigned long rxCount;
unsigned long bktCount;
unsigned long mTime;
unsigned long pktCount;
unsigned long bpkt_state;//for broadcast packet reject state machine
unsigned long bpkt_flag;//flag for reject broadcast packet
unsigned long pTime;
unsigned long bpkt_msk;
unsigned long tLimit;
unsigned long tCount;
unsigned long pkt_acount;//the all packet count in current slot
unsigned long bpkt_rcount;//the boradcast packet count in current slot
unsigned long bpkt_rlimit;//the broadcast packet receive limit
unsigned long pCount;//the total packet count
unsigned long bCount;//the total broadcast packet count
unsigned long flux_aCount;//byte count for all packet
unsigned long flux_aCount_st; //sticky of byte count for all packet
unsigned long flux_bCount;//byte count for broadcast packet
unsigned long flux_bCount_st; //sticky of byte count for broadcast packet
unsigned long flux_dCount[32];
unsigned long flux_rTime[32];
unsigned lon