summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brown2007-01-11 06:25:50 +0100
committerMichael Brown2007-01-11 06:25:50 +0100
commita3ed0cbbc7d81c345d791835cb4d97176dc404b6 (patch)
tree34d6eeb572737852b54ce611c6bcc4a1027daaf6
parentChange FTP to use a data buffer rather than a callback function. (diff)
downloadipxe-a3ed0cbbc7d81c345d791835cb4d97176dc404b6.tar.gz
ipxe-a3ed0cbbc7d81c345d791835cb4d97176dc404b6.tar.xz
ipxe-a3ed0cbbc7d81c345d791835cb4d97176dc404b6.zip
Extract packet-padding login from rtl8139.c to a separate pkbpad.c file.
-rw-r--r--src/drivers/net/rtl8139.c23
-rw-r--r--src/include/gpxe/pkbuff.h1
-rw-r--r--src/net/pkbpad.c66
3 files changed, 69 insertions, 21 deletions
diff --git a/src/drivers/net/rtl8139.c b/src/drivers/net/rtl8139.c
index 08130b230..81b6ccfb6 100644
--- a/src/drivers/net/rtl8139.c
+++ b/src/drivers/net/rtl8139.c
@@ -367,10 +367,6 @@ static void rtl_close ( struct net_device *netdev ) {
*/
static int rtl_transmit ( struct net_device *netdev, struct pk_buff *pkb ) {
struct rtl8139_nic *rtl = netdev->priv;
- void *data;
- size_t len;
- size_t headroom;
- signed int pad_len;
/* Check for space in TX ring */
if ( rtl->tx.pkb[rtl->tx.next] != NULL ) {
@@ -378,23 +374,8 @@ static int rtl_transmit ( struct net_device *netdev, struct pk_buff *pkb ) {
return -ENOBUFS;
}
- /* Move packet data to start of packet buffer. This will both
- * align the data (since packet buffers are aligned to
- * PKB_ALIGN) and give us sufficient space for the
- * zero-padding
- */
- data = pkb->data;
- len = pkb_len ( pkb );
- headroom = pkb_headroom ( pkb );
- pkb_push ( pkb, headroom );
- memmove ( pkb->data, data, len );
- pkb_unput ( pkb, headroom );
- assert ( ( virt_to_bus ( pkb->data ) & 0x3 ) == 0 );
-
- /* Pad to minimum packet length */
- pad_len = ( ETH_ZLEN - pkb_len ( pkb ) );
- if ( pad_len > 0 )
- memset ( pkb_put ( pkb, pad_len ), 0, pad_len );
+ /* Pad and align packet */
+ pkb_pad ( pkb, ETH_ZLEN );
/* Add to TX ring */
DBG ( "TX id %d at %lx+%x\n", rtl->tx.next,
diff --git a/src/include/gpxe/pkbuff.h b/src/include/gpxe/pkbuff.h
index dc3d24c4b..85bcc0369 100644
--- a/src/include/gpxe/pkbuff.h
+++ b/src/include/gpxe/pkbuff.h
@@ -158,5 +158,6 @@ static inline size_t pkb_tailroom ( struct pk_buff *pkb ) {
extern struct pk_buff * alloc_pkb ( size_t len );
extern void free_pkb ( struct pk_buff *pkb );
+extern void pkb_pad ( struct pk_buff *pkb, size_t min_len );
#endif /* _GPXE_PKBUFF_H */
diff --git a/src/net/pkbpad.c b/src/net/pkbpad.c
new file mode 100644
index 000000000..e12e46b94
--- /dev/null
+++ b/src/net/pkbpad.c
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/**
+ * @file
+ *
+ * Packet buffer padding
+ *
+ */
+
+#include <string.h>
+#include <gpxe/pkbuff.h>
+
+/**
+ * Pad packet buffer
+ *
+ * @v pkb Packet buffer
+ * @v min_len Minimum length
+ *
+ * This function pads and aligns packet buffers, for devices that
+ * aren't capable of padding in hardware, or that require specific
+ * alignment in TX buffers. The packet data will end up aligned to a
+ * multiple of @c PKB_ALIGN.
+ *
+ * @c min_len must not exceed @v PKB_ZLEN.
+ */
+void pkb_pad ( struct pk_buff *pkb, size_t min_len ) {
+ void *data;
+ size_t len;
+ size_t headroom;
+ signed int pad_len;
+
+ assert ( min_len <= PKB_ZLEN );
+
+ /* Move packet data to start of packet buffer. This will both
+ * align the data (since packet buffers are aligned to
+ * PKB_ALIGN) and give us sufficient space for the
+ * zero-padding
+ */
+ data = pkb->data;
+ len = pkb_len ( pkb );
+ headroom = pkb_headroom ( pkb );
+ pkb_push ( pkb, headroom );
+ memmove ( pkb->data, data, len );
+ pkb_unput ( pkb, headroom );
+
+ /* Pad to minimum packet length */
+ pad_len = ( min_len - pkb_len ( pkb ) );
+ if ( pad_len > 0 )
+ memset ( pkb_put ( pkb, pad_len ), 0, pad_len );
+}