From 67efb746c492c25fac4d77aa16b808a8aa26089d Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 19 Feb 2023 22:24:32 +0100 Subject: pfinet: Align packets The Ethernet header is 14 bytes long, and thus leads to IP header misalignment. This uses skb_reserve to introduce 2 bytes of padding to realign IP headers. --- pfinet/linux-src/include/linux/skbuff.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'pfinet/linux-src') diff --git a/pfinet/linux-src/include/linux/skbuff.h b/pfinet/linux-src/include/linux/skbuff.h index 00f9ab2a..46eb995e 100644 --- a/pfinet/linux-src/include/linux/skbuff.h +++ b/pfinet/linux-src/include/linux/skbuff.h @@ -498,6 +498,30 @@ static __inline__ int skb_tailroom(struct sk_buff *skb) return skb->end-skb->tail; } +/* + * 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(skb, 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 + static __inline__ void skb_reserve(struct sk_buff *skb, unsigned int len) { skb->data+=len; -- cgit v1.2.3