mirror of
https://github.com/xcat2/xNBA.git
synced 2024-12-14 23:31:39 +00:00
Extract packet-padding login from rtl8139.c to a separate pkbpad.c file.
This commit is contained in:
parent
6918cf9e9e
commit
a3ed0cbbc7
@ -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,
|
||||
|
@ -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 */
|
||||
|
66
src/net/pkbpad.c
Normal file
66
src/net/pkbpad.c
Normal file
@ -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 );
|
||||
}
|
Loading…
Reference in New Issue
Block a user