[U-Boot] [RFC PATCH v1] net: Add headroom configuration

Chris Packham judge.packham at gmail.com
Fri Jan 15 05:03:04 CET 2016


Some network devices/drivers need to insert special tags in packets as
they are transmitted (e.g. Marvell's DSA tag for their switch devices).
Add an option to leave a little space at the start of the packets

Reviewed-by: Mark Tomlinson <mark.tomlinson at alliedtelesis.co.nz>
Signed-off-by: Chris Packham <judge.packham at gmail.com>
---
This is analogous to skb_headroom in Linux.

My primary motivation for this is a out of tree network driver for
a switch chip that needs a tag inserted between the Ethernet DA/SA and
the Ethertype. To do this the driver moves the DA/SA up instead of
moving the rest of the packet down. In order to support this there
needs to be enough space spare at the start of the packet to be
transmitted.

Even though my immediate need is for a device that is a long way off
being submitted upstream (if ever) I think this still may be useful for
users of mv88e61xx and similar L2 switches which can be configured to use
equivalent headers to direct packets out specific ports.

 include/net.h | 12 +++++++++++-
 net/Kconfig   | 12 ++++++++++++
 net/arp.c     |  2 +-
 net/net.c     |  2 +-
 4 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/include/net.h b/include/net.h
index ebed29a..b66507a 100644
--- a/include/net.h
+++ b/include/net.h
@@ -445,6 +445,16 @@ struct icmp_hdr {
 #define IP_ICMP_HDR_SIZE	(IP_HDR_SIZE + ICMP_HDR_SIZE)
 
 /*
+ * Headroom to allow for driver specific usage in transmitted
+ * packets.
+ */
+#ifndef CONFIG_NET_HEADROOM
+# define PKT_HEADROOM 0
+#else
+# define PKT_HEADROOM CONFIG_NET_HEADROOM
+#endif
+
+/*
  * Maximum packet size; used to allocate packet storage.
  * TFTP packets can be 524 bytes + IP header + ethernet header.
  * Lets be conservative, and go for 38 * 16.  (Must also be
@@ -457,7 +467,7 @@ struct icmp_hdr {
  * maximum packet size and multiple of 32 bytes =  1536
  */
 #define PKTSIZE			1518
-#define PKTSIZE_ALIGN		1536
+#define PKTSIZE_ALIGN		(1536 + PKT_HEADROOM)
 /*#define PKTSIZE		608*/
 
 /*
diff --git a/net/Kconfig b/net/Kconfig
index a44a783..a12917c 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -32,4 +32,16 @@ config NET_TFTP_VARS
 	  If unset, timeout and maximum are hard-defined as 1 second
 	  and 10 timouts per TFTP transfer.
 
+config NET_HEADROOM
+	int "Extra headroom in packets"
+	default 0
+	help
+	  Some network devices/drivers need to insert special tags
+	  in packets as they are transmitted. This option determines
+	  how much headroom to provide. The specified value should
+	  meet the dma memory alignment requirements for the platform.
+
+	  Unless you are using one of these devices it is safe to
+	  leave this unset.
+
 endif   # if NET
diff --git a/net/arp.c b/net/arp.c
index 824d2e9..35fe69a 100644
--- a/net/arp.c
+++ b/net/arp.c
@@ -45,7 +45,7 @@ void arp_init(void)
 	net_arp_wait_packet_ip.s_addr = 0;
 	net_arp_wait_reply_ip.s_addr = 0;
 	arp_wait_tx_packet_size = 0;
-	arp_tx_packet = &arp_tx_packet_buf[0] + (PKTALIGN - 1);
+	arp_tx_packet = &arp_tx_packet_buf[PKT_HEADROOM] + (PKTALIGN - 1);
 	arp_tx_packet -= (ulong)arp_tx_packet % PKTALIGN;
 }
 
diff --git a/net/net.c b/net/net.c
index fba111e..0b9d6f1 100644
--- a/net/net.c
+++ b/net/net.c
@@ -370,7 +370,7 @@ void net_init(void)
 		 */
 		int i;
 
-		net_tx_packet = &net_pkt_buf[0] + (PKTALIGN - 1);
+		net_tx_packet = &net_pkt_buf[PKT_HEADROOM] + (PKTALIGN - 1);
 		net_tx_packet -= (ulong)net_tx_packet % PKTALIGN;
 		for (i = 0; i < PKTBUFSRX; i++) {
 			net_rx_packets[i] = net_tx_packet +
-- 
2.7.0



More information about the U-Boot mailing list