几个主要的模块的都写完了,下面开始介绍一下其他的函数。
和net_open对应的函数:
/* The inverse routine to net_open(). */
/*
①停止队列
②关闭网卡
③释放中断
*/
static int net_close(struct net_device *dev)
{
netif_stop_queue(dev);
writereg(dev, PP_RxCFG, 0);
writereg(dev, PP_TxCFG, 0);
writereg(dev, PP_BufCFG, 0);
writereg(dev, PP_BusCTL, 0);
free_irq(dev->irq, dev);
/* Update the statistics here. */
return 0;
}
再看一下cs8900是如何获取统计信息的:
/*
向用户反馈设备状态和统计信息
net_device_stats,这是一个net_local的结构体成员。
*/
static struct net_device_stats *
net_get_stats(struct net_device *dev)
{
struct net_local *lp = (struct net_local *)dev->priv;
unsigned long flags;
//不追了,这个就知道它是在读取各个寄存器状态的信息
//然后都存放在net_device_stats这个结构体中,结构体的具体定义在内核中实现。
spin_lock_irqsave(&lp->lock, flags);
/* Update the statistics from the device registers. */
lp->stats.rx_missed_errors += (readreg(dev, PP_RxMiss) >> 6);
lp->stats.collisions += (readreg(dev, PP_TxCol) >> 6);
spin_unlock_irqrestore(&lp->lock, flags);
return &lp->stats;
}
struct net_device_stats
{
unsigned long rx_packets; /* total packets received */
unsigned long tx_packets; /* total packets transmitted */
unsigned long rx_bytes; /* total bytes received */
unsigned long tx_bytes; /* total bytes transmitted */
unsigned long rx_errors; /* bad packets received */
unsigned long tx_errors; /* packet transmit problems */
unsigned long rx_dropped; /* no space in linux buffers */
unsigned long tx_dropped; /* no space available in linux */
unsigned long multicast; /* multicast packets received */
unsigned long collisions;
/* detailed rx_errors: */
unsigned long rx_length_errors;
unsigned long rx_over_errors; /* receiver ring buff overflow */
unsigned long rx_crc_errors; /* recved pkt with crc error */
unsigned long rx_frame_errors; /* recv'd frame alignment error */
unsigned long rx_fifo_errors; /* recv'r fifo overrun */
unsigned long rx_missed_errors; /* receiver missed packet */
/* detailed tx_errors */
unsigned long tx_aborted_errors;
unsigned long tx_carrier_errors;
unsigned long tx_fifo_errors;
unsigned long tx_heartbeat_errors;
unsigned long tx_window_errors;
/* for cslip etc */
unsigned long rx_compressed;
unsigned long tx_compressed;
};
大神一句话:对网卡的控制需要熟读硬件手册。
其实还有很多的函数没有写,同时我自己也有很多地方没有弄懂,不过三天都在看着不到七百行的代码了。我觉得我写的注释还可以,如果谁想要这套代码可以给我留言的。