|
@@ -31,24 +31,36 @@
|
31
|
31
|
*
|
32
|
32
|
* @v len Required length of buffer
|
33
|
33
|
* @ret pkb Packet buffer, or NULL if none available
|
|
34
|
+ *
|
|
35
|
+ * The packet buffer will be physically aligned to a multiple of
|
|
36
|
+ * @c PKBUFF_SIZE.
|
34
|
37
|
*/
|
35
|
38
|
struct pk_buff * alloc_pkb ( size_t len ) {
|
36
|
39
|
struct pk_buff *pkb = NULL;
|
|
40
|
+ void *data;
|
37
|
41
|
|
|
42
|
+ /* Align buffer length */
|
|
43
|
+ len = ( len + __alignof__ ( *pkb ) - 1 ) & ~ __alignof__ ( *pkb );
|
|
44
|
+
|
38
|
45
|
/* Allocate memory for buffer plus descriptor */
|
39
|
|
- pkb = malloc ( sizeof ( *pkb ) + len );
|
40
|
|
- if ( pkb ) {
|
41
|
|
- pkb->head = pkb->data = pkb->tail = ( void * ) ( pkb + 1 );
|
42
|
|
- pkb->end = pkb->head + len;
|
43
|
|
- }
|
|
46
|
+ data = malloc_dma ( len + sizeof ( *pkb ), PKBUFF_ALIGN );
|
|
47
|
+ if ( ! data )
|
|
48
|
+ return NULL;
|
|
49
|
+
|
|
50
|
+ pkb = ( struct pk_buff * ) ( data + len );
|
|
51
|
+ pkb->head = pkb->data = pkb->tail = data;
|
|
52
|
+ pkb->end = pkb;
|
44
|
53
|
return pkb;
|
45
|
54
|
}
|
46
|
55
|
|
47
|
56
|
/**
|
48
|
57
|
* Free packet buffer
|
49
|
58
|
*
|
50
|
|
- * @v pkb Packet buffer, or NULL
|
|
59
|
+ * @v pkb Packet buffer
|
51
|
60
|
*/
|
52
|
61
|
void free_pkb ( struct pk_buff *pkb ) {
|
53
|
|
- free ( pkb );
|
|
62
|
+ if ( pkb ) {
|
|
63
|
+ free_dma ( pkb->head,
|
|
64
|
+ ( pkb->end - pkb->head ) + sizeof ( *pkb ) );
|
|
65
|
+ }
|
54
|
66
|
}
|