标签:linux网卡数据流 linux网卡数据发送与接收 网卡数据流
通常网卡驱动代码量比较大,但是都离不开发送与接收,掌握好骨干也就好理解与调试了。
net_device_ops结构题的填充,在里实现了open与发送等操作:
static const struct net_device_ops xxx_netdev_ops = {
.ndo_open = xxx_net_open,
.ndo_stop = xxx_net_stop,
.ndo_start_xmit = xxx_start_xmit,
.ndo_get_stats = xxx_get_stats,
.ndo_tx_timeout = xxx_tx_timeout,
};
static int xxx_start_xmit(struct sk_buff *skb, struct net_device *dev){
---------
nwrite = filep->f_op->write(filep, skb->data, skb->len, &filep->f_pos);
set_fs(old_fs);
if (nwrite == skb->len) {
priv->stats.tx_packets++;
priv->stats.tx_bytes +=skb->len;
priv->netdev->trans_start = jiffies;
}
-----------
}
static int xxx_submit_skb(void *data)
{
--------
skb = netdev_alloc_skb(ndev, pkt_len + NET_IP_ALIGN); /* NET_IP_ALIGN is 2 */
if (!skb) {
printk(KERN_INFO "error: out of memory for rx'd frame\n");
priv->stats.rx_dropped++;
ret = -ENOMEM;
goto error;
}
skb_reserve(skb, NET_IP_ALIGN);
memcpy((skb_put(skb, pkt_len), pkt_len),buf,sizeof(buf);
skb->dev = priv->netdev;
skb->protocol = eth_type_trans(skb, priv->netdev);
priv->stats.rx_packets++;
priv->stats.rx_bytes += pkt_len;
ret = netif_rx(skb);
if (ret != 0)
printk(KERN_INFO "%s: netif_rx error\n", __func__);
--------
}
标签:linux网卡数据流 linux网卡数据发送与接收 网卡数据流
原文地址:http://blog.csdn.net/linux_devices_driver/article/details/39033351