mirror of
https://github.com/xcat2/xNBA.git
synced 2024-11-22 17:41:55 +00:00
Actually, it's probably a good idea to have packet buffers avoid 4kB
crossings.
This commit is contained in:
parent
00a1de964d
commit
cf3783b4ca
@ -17,6 +17,17 @@
|
||||
struct net_protocol;
|
||||
struct ll_protocol;
|
||||
|
||||
/**
|
||||
* Packet buffer alignment
|
||||
*
|
||||
* Packet buffers allocated via alloc_pkb() are guaranteed to be
|
||||
* physically aligned to this boundary. Some cards cannot DMA across
|
||||
* a 4kB boundary. With a standard Ethernet MTU, aligning to a 2kB
|
||||
* boundary is sufficient to guarantee no 4kB boundary crossings. For
|
||||
* a jumbo Ethernet MTU, a packet may be larger than 4kB anyway.
|
||||
*/
|
||||
#define PKBUFF_ALIGN 2048
|
||||
|
||||
/** A packet buffer
|
||||
*
|
||||
* This structure is used to represent a network packet within gPXE.
|
||||
|
@ -31,24 +31,36 @@
|
||||
*
|
||||
* @v len Required length of buffer
|
||||
* @ret pkb Packet buffer, or NULL if none available
|
||||
*
|
||||
* The packet buffer will be physically aligned to a multiple of
|
||||
* @c PKBUFF_SIZE.
|
||||
*/
|
||||
struct pk_buff * alloc_pkb ( size_t len ) {
|
||||
struct pk_buff *pkb = NULL;
|
||||
void *data;
|
||||
|
||||
/* Align buffer length */
|
||||
len = ( len + __alignof__ ( *pkb ) - 1 ) & ~ __alignof__ ( *pkb );
|
||||
|
||||
/* Allocate memory for buffer plus descriptor */
|
||||
pkb = malloc ( sizeof ( *pkb ) + len );
|
||||
if ( pkb ) {
|
||||
pkb->head = pkb->data = pkb->tail = ( void * ) ( pkb + 1 );
|
||||
pkb->end = pkb->head + len;
|
||||
}
|
||||
data = malloc_dma ( len + sizeof ( *pkb ), PKBUFF_ALIGN );
|
||||
if ( ! data )
|
||||
return NULL;
|
||||
|
||||
pkb = ( struct pk_buff * ) ( data + len );
|
||||
pkb->head = pkb->data = pkb->tail = data;
|
||||
pkb->end = pkb;
|
||||
return pkb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Free packet buffer
|
||||
*
|
||||
* @v pkb Packet buffer, or NULL
|
||||
* @v pkb Packet buffer
|
||||
*/
|
||||
void free_pkb ( struct pk_buff *pkb ) {
|
||||
free ( pkb );
|
||||
if ( pkb ) {
|
||||
free_dma ( pkb->head,
|
||||
( pkb->end - pkb->head ) + sizeof ( *pkb ) );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user