- 论坛徽章:
- 0
|
原帖由 zoorror 于 2009-7-30 15:45 发表 ![]()
pkt_size = rx_size - 4,是把接收包前面4字节去掉(低2字节状态,高2字节长度)就得到数据包长度,至于双字节对齐的方法能看懂,关键就是这个-16看不懂,因为根据后面的代码skb_reserve (skb, NET_IP_ALIGN);/* ...
我感觉这里的注释有问题吧,你看一下skbuff.h中的描述:
/*
* CPUs often take a performance hit when accessing unaligned memory
* locations. The actual performance hit varies, it can be small if the
* hardware handles it or large if we have to take an exception and fix it
* in software.
*
* Since an ethernet header is 14 bytes network drivers often end up with
* the IP header at an unaligned offset. The IP header can be aligned by
* shifting the start of the packet by 2 bytes. Drivers should do this
* with:
*
* skb_reserve(NET_IP_ALIGN);
*
* The downside to this alignment of the IP header is that the DMA is now
* unaligned. On some architectures the cost of an unaligned DMA is high
* and this cost outweighs the gains made by aligning the IP header.
*
* Since this trade off varies between architectures, we allow NET_IP_ALIGN
* to be overridden.
*/
#ifndef NET_IP_ALIGN
#define NET_IP_ALIGN 2
#endif |
不知道为啥驱动代码中写了个16。这个前面保留两个字节的用法是很常见的,主要是Ethernet头一般是字节或short访问,并且使用相对少,所以主要是对齐IP及后面的TCP头。这里的16应该和这个对齐没什么关系。 |
|