mirror of https://github.com/ipxe/ipxe.git
Actually, it's probably a good idea to have packet buffers avoid 4kB
crossings.pull/1/head
parent
00a1de964d
commit
cf3783b4ca
|
@ -17,6 +17,17 @@
|
||||||
struct net_protocol;
|
struct net_protocol;
|
||||||
struct ll_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
|
/** A packet buffer
|
||||||
*
|
*
|
||||||
* This structure is used to represent a network packet within gPXE.
|
* This structure is used to represent a network packet within gPXE.
|
||||||
|
|
|
@ -31,24 +31,36 @@
|
||||||
*
|
*
|
||||||
* @v len Required length of buffer
|
* @v len Required length of buffer
|
||||||
* @ret pkb Packet buffer, or NULL if none available
|
* @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 * alloc_pkb ( size_t len ) {
|
||||||
struct pk_buff *pkb = NULL;
|
struct pk_buff *pkb = NULL;
|
||||||
|
void *data;
|
||||||
|
|
||||||
|
/* Align buffer length */
|
||||||
|
len = ( len + __alignof__ ( *pkb ) - 1 ) & ~ __alignof__ ( *pkb );
|
||||||
|
|
||||||
/* Allocate memory for buffer plus descriptor */
|
/* Allocate memory for buffer plus descriptor */
|
||||||
pkb = malloc ( sizeof ( *pkb ) + len );
|
data = malloc_dma ( len + sizeof ( *pkb ), PKBUFF_ALIGN );
|
||||||
if ( pkb ) {
|
if ( ! data )
|
||||||
pkb->head = pkb->data = pkb->tail = ( void * ) ( pkb + 1 );
|
return NULL;
|
||||||
pkb->end = pkb->head + len;
|
|
||||||
}
|
pkb = ( struct pk_buff * ) ( data + len );
|
||||||
|
pkb->head = pkb->data = pkb->tail = data;
|
||||||
|
pkb->end = pkb;
|
||||||
return pkb;
|
return pkb;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Free packet buffer
|
* Free packet buffer
|
||||||
*
|
*
|
||||||
* @v pkb Packet buffer, or NULL
|
* @v pkb Packet buffer
|
||||||
*/
|
*/
|
||||||
void free_pkb ( struct pk_buff *pkb ) {
|
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