iPXE
Functions
iobpad.c File Reference

I/O buffer padding. More...

#include <string.h>
#include <ipxe/iobuf.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
void iob_pad (struct io_buffer *iobuf, size_t min_len)
 Pad I/O buffer.

Detailed Description

I/O buffer padding.

Definition in file iobpad.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
void iob_pad ( struct io_buffer iobuf,
size_t  min_len 
)

Pad I/O buffer.

Parameters:
iobufI/O buffer
min_lenMinimum length

This function pads and aligns I/O 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 IOB_ALIGN.

min_len must not exceed

Parameters:
IOB_ZLEN.

Definition at line 49 of file iobpad.c.

References assert, io_buffer::data, data, iob_headroom(), iob_len(), iob_push, iob_put, iob_unput, IOB_ZLEN, len, memmove(), and memset().

Referenced by eoib_transmit(), forcedeth_transmit(), legacy_transmit(), myri10ge_net_transmit(), pnic_transmit(), realtek_transmit(), rhine_transmit(), sis190_transmit(), tg3_transmit(), and velocity_transmit().

                                                         {
        void *data;
        size_t len;
        size_t headroom;
        signed int pad_len;

        assert ( min_len <= IOB_ZLEN );

        /* Move packet data to start of I/O buffer.  This will both
         * align the data (since I/O buffers are aligned to
         * IOB_ALIGN) and give us sufficient space for the
         * zero-padding
         */
        data = iobuf->data;
        len = iob_len ( iobuf );
        headroom = iob_headroom ( iobuf );
        iob_push ( iobuf, headroom );
        memmove ( iobuf->data, data, len );
        iob_unput ( iobuf, headroom );

        /* Pad to minimum packet length */
        pad_len = ( min_len - iob_len ( iobuf ) );
        if ( pad_len > 0 )
                memset ( iob_put ( iobuf, pad_len ), 0, pad_len );
}