8 * Packet buffers are used to contain network packets. Methods are
9 * provided for appending, prepending, etc. data.
15 #include <gpxe/list.h>
18 * Packet buffer alignment
20 * Packet buffers allocated via alloc_pkb() are guaranteed to be
21 * physically aligned to this boundary. Some cards cannot DMA across
22 * a 4kB boundary. With a standard Ethernet MTU, aligning to a 2kB
23 * boundary is sufficient to guarantee no 4kB boundary crossings. For
24 * a jumbo Ethernet MTU, a packet may be larger than 4kB anyway.
26 #define PKBUFF_ALIGN 2048
29 * Minimum packet buffer length
31 * alloc_pkb() will round up the allocated length to this size if
32 * necessary. This is used on behalf of hardware that is not capable
39 * This structure is used to represent a network packet within gPXE.
42 /** List of which this buffer is a member */
43 struct list_head list;
45 /** Start of the buffer */
51 /** End of the buffer */
56 * Reserve space at start of packet buffer
58 * @v pkb Packet buffer
59 * @v len Length to reserve
60 * @ret data Pointer to new start of buffer
62 static inline void * pkb_reserve ( struct pk_buff *pkb, size_t len ) {
65 assert ( pkb->tail <= pkb->end );
70 * Add data to start of packet buffer
72 * @v pkb Packet buffer
73 * @v len Length to add
74 * @ret data Pointer to new start of buffer
76 static inline void * pkb_push ( struct pk_buff *pkb, size_t len ) {
78 assert ( pkb->data >= pkb->head );
83 * Remove data from start of packet buffer
85 * @v pkb Packet buffer
86 * @v len Length to remove
87 * @ret data Pointer to new start of buffer
89 static inline void * pkb_pull ( struct pk_buff *pkb, size_t len ) {
91 assert ( pkb->data <= pkb->tail );
96 * Add data to end of packet buffer
98 * @v pkb Packet buffer
99 * @v len Length to add
100 * @ret data Pointer to newly added space
102 static inline void * pkb_put ( struct pk_buff *pkb, size_t len ) {
103 void *old_tail = pkb->tail;
105 assert ( pkb->tail <= pkb->end );
110 * Remove data from end of packet buffer
112 * @v pkb Packet buffer
113 * @v len Length to remove
115 static inline void pkb_unput ( struct pk_buff *pkb, size_t len ) {
117 assert ( pkb->tail >= pkb->data );
121 * Empty a packet buffer
123 * @v pkb Packet buffer
125 static inline void pkb_empty ( struct pk_buff *pkb ) {
126 pkb->tail = pkb->data;
130 * Calculate length of data in a packet buffer
132 * @v pkb Packet buffer
133 * @ret len Length of data in buffer
135 static inline size_t pkb_len ( struct pk_buff *pkb ) {
136 return ( pkb->tail - pkb->data );
140 * Calculate available space in a packet buffer
142 * @v pkb Packet buffer
143 * @ret len Length of data available in buffer
145 static inline size_t pkb_available ( struct pk_buff *pkb ) {
146 return ( pkb->end - pkb->tail );
149 extern struct pk_buff * alloc_pkb ( size_t len );
150 extern void free_pkb ( struct pk_buff *pkb );
152 #endif /* _GPXE_PKBUFF_H */