iobuf.h File Reference

I/O buffers. More...

#include <stdint.h>
#include <assert.h>
#include <gpxe/list.h>

Go to the source code of this file.

Data Structures

struct  io_buffer
 A persistent I/O buffer. More...

Defines

#define IOB_ALIGN   2048
 I/O buffer alignment.
#define IOB_ZLEN   64
 Minimum I/O buffer length.
#define iob_reserve(iobuf, len)
#define iob_push(iobuf, len)
#define iob_pull(iobuf, len)
#define iob_put(iobuf, len)
#define iob_unput(iobuf, len)
#define iob_disown(iobuf)
 Disown an I/O buffer.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
static void * iob_reserve (struct io_buffer *iobuf, size_t len)
 Reserve space at start of I/O buffer.
static void * iob_push (struct io_buffer *iobuf, size_t len)
 Add data to start of I/O buffer.
static void * iob_pull (struct io_buffer *iobuf, size_t len)
 Remove data from start of I/O buffer.
static void * iob_put (struct io_buffer *iobuf, size_t len)
 Add data to end of I/O buffer.
static void iob_unput (struct io_buffer *iobuf, size_t len)
 Remove data from end of I/O buffer.
static void iob_empty (struct io_buffer *iobuf)
 Empty an I/O buffer.
static size_t iob_len (struct io_buffer *iobuf)
 Calculate length of data in an I/O buffer.
static size_t iob_headroom (struct io_buffer *iobuf)
 Calculate available space at start of an I/O buffer.
static size_t iob_tailroom (struct io_buffer *iobuf)
 Calculate available space at end of an I/O buffer.
static void iob_populate (struct io_buffer *iobuf, void *data, size_t len, size_t max_len)
 Create a temporary I/O buffer.
struct io_buffer *__malloc alloc_iob (size_t len)
 Allocate I/O buffer.
void free_iob (struct io_buffer *iobuf)
 Free I/O buffer.
void iob_pad (struct io_buffer *iobuf, size_t min_len)
 Pad I/O buffer.
int iob_ensure_headroom (struct io_buffer *iobuf, size_t len)
 Ensure I/O buffer has sufficient headroom.


Detailed Description

I/O buffers.

Definition in file iobuf.h.


Define Documentation

#define IOB_ALIGN   2048

I/O buffer alignment.

I/O buffers allocated via alloc_iob() 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.

Definition at line 25 of file iobuf.h.

Referenced by alloc_iob().

#define IOB_ZLEN   64

Minimum I/O buffer length.

alloc_iob() will round up the allocated length to this size if necessary. This is used on behalf of hardware that is not capable of auto-padding.

Definition at line 34 of file iobuf.h.

Referenced by alloc_iob(), and iob_pad().

#define iob_reserve ( iobuf,
len   ) 

#define iob_push ( iobuf,
len   ) 

Value:

( {                     \
        void *__result;                                 \
        __result = iob_push ( (iobuf), (len) );         \
        assert ( (iobuf)->data >= (iobuf)->head );      \
        __result; } )

Definition at line 91 of file iobuf.h.

Referenced by eth_push(), gdbudp_recv(), gdbudp_send(), ib_push(), iob_pad(), ipoib_push(), ipv4_tx(), ipv6_tx(), net80211_ll_push(), net80211_tx_mgmt(), tcp_xmit(), tcp_xmit_reset(), udp_tx(), and wpa_send_eapol().

#define iob_pull ( iobuf,
len   ) 

#define iob_put ( iobuf,
len   ) 

#define iob_unput ( iobuf,
len   ) 

Value:

do {                    \
        iob_unput ( (iobuf), (len) );                   \
        assert ( (iobuf)->tail >= (iobuf)->data );      \
        } while ( 0 )

Definition at line 142 of file iobuf.h.

Referenced by iob_pad(), ipv4_rx(), ipv6_rx(), net80211_rx(), and udp_rx().

#define iob_disown ( iobuf   ) 

Value:

( {                             \
        struct io_buffer *__iobuf = (iobuf);            \
        (iobuf) = NULL;                                 \
        __iobuf; } )
Disown an I/O buffer.

Parameters:
iobuf I/O buffer
There are many functions that take ownership of the I/O buffer they are passed as a parameter. The caller should not retain a pointer to the I/O buffer. Use iob_disown() to automatically nullify the caller's pointer, e.g.:

xfer_deliver_iob ( xfer, iob_disown ( iobuf ) );

This will ensure that iobuf is set to NULL for any code after the call to xfer_deliver_iob().

Definition at line 219 of file iobuf.h.

Referenced by arp_rx(), dhcp_tx(), efi_snp_transmit(), http_socket_deliver_iob(), ib_cmrc_xfer_deliver_iob(), icmp_rx(), net80211_probe_step(), tftp_rx(), tftp_rx_data(), udp_rx(), and undinet_poll().


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER   ) 

static void* iob_reserve ( struct io_buffer iobuf,
size_t  len 
) [inline, static]

Reserve space at start of I/O buffer.

Parameters:
iobuf I/O buffer
len Length to reserve
Return values:
data Pointer to new start of buffer

Definition at line 69 of file iobuf.h.

References io_buffer::data, and io_buffer::tail.

00069                                                                          {
00070         iobuf->data += len;
00071         iobuf->tail += len;
00072         return iobuf->data;
00073 }

static void* iob_push ( struct io_buffer iobuf,
size_t  len 
) [inline, static]

Add data to start of I/O buffer.

Parameters:
iobuf I/O buffer
len Length to add
Return values:
data Pointer to new start of buffer

Definition at line 87 of file iobuf.h.

References io_buffer::data.

00087                                                                       {
00088         iobuf->data -= len;
00089         return iobuf->data;
00090 }

static void* iob_pull ( struct io_buffer iobuf,
size_t  len 
) [inline, static]

Remove data from start of I/O buffer.

Parameters:
iobuf I/O buffer
len Length to remove
Return values:
data Pointer to new start of buffer

Definition at line 104 of file iobuf.h.

References assert, io_buffer::data, and io_buffer::tail.

00104                                                                       {
00105         iobuf->data += len;
00106         assert ( iobuf->data <= iobuf->tail );
00107         return iobuf->data;
00108 }

static void* iob_put ( struct io_buffer iobuf,
size_t  len 
) [inline, static]

Add data to end of I/O buffer.

Parameters:
iobuf I/O buffer
len Length to add
Return values:
data Pointer to newly added space

Definition at line 122 of file iobuf.h.

References io_buffer::tail.

00122                                                                      {
00123         void *old_tail = iobuf->tail;
00124         iobuf->tail += len;
00125         return old_tail;
00126 }

static void iob_unput ( struct io_buffer iobuf,
size_t  len 
) [inline, static]

Remove data from end of I/O buffer.

Parameters:
iobuf I/O buffer
len Length to remove

Definition at line 139 of file iobuf.h.

References io_buffer::tail.

00139                                                                      {
00140         iobuf->tail -= len;
00141 }

static void iob_empty ( struct io_buffer iobuf  )  [inline, static]

Empty an I/O buffer.

Parameters:
iobuf I/O buffer

Definition at line 152 of file iobuf.h.

References io_buffer::data, and io_buffer::tail.

00152                                                          {
00153         iobuf->tail = iobuf->data;
00154 }

static size_t iob_len ( struct io_buffer iobuf  )  [inline, static]

Calculate length of data in an I/O buffer.

Parameters:
iobuf I/O buffer
Return values:
len Length of data in buffer

Definition at line 162 of file iobuf.h.

References io_buffer::data, and io_buffer::tail.

Referenced by a3c90x_process_tx_packets(), a3c90x_transmit(), aoe_rx(), arbel_complete(), arbel_post_send(), ath5k_tx_processq(), ath5k_txbuf_setup(), atl1e_tx_map(), b44_transmit(), ccmp_decrypt(), ccmp_encrypt(), dhcp_deliver_iob(), downloader_xfer_deliver_iob(), e1000_transmit(), e1000e_transmit(), eapol_rx(), efab_transmit(), efi_snp_receive(), eth_pull(), falcon_build_tx_desc(), gdbudp_recv(), gdbudp_send(), hermon_complete(), hermon_fill_mlx_send_wqe(), hermon_fill_rc_send_wqe(), hermon_fill_ud_send_wqe(), http_rx_data(), http_socket_deliver_iob(), ib_cmrc_complete_recv(), ib_cmrc_xfer_deliver_iob(), ib_mi_complete_recv(), ib_pull(), ib_push(), icmp6_rx(), icmp_rx(), ifec_net_transmit(), igb_transmit(), iob_pad(), ipoib_complete_recv(), ipoib_pull(), ipoib_transmit(), ipv4_pshdr_chksum(), ipv4_reassemble(), ipv4_rx(), ipv4_tx(), ipv6_rx(), ipv6_tx(), ipv6_tx_csum(), legacy_transmit(), linda_post_send(), mtnic_transmit(), myri10ge_net_transmit(), natsemi_transmit(), ndp_process_advert(), net80211_accum_frags(), net80211_ll_pull(), net80211_probe_step(), net80211_rx_frag(), net_step(), netdev_rx(), netdev_tx(), phantom_refill_rx_ring(), phantom_transmit(), pnic_transmit(), posix_file_xfer_deliver_iob(), pxe_tftp_xfer_deliver_iob(), pxe_udp_deliver_iob(), pxenv_undi_isr(), read_user(), rtl8169_transmit(), rtl818x_tx(), rtl_transmit(), sis190_transmit(), skge_xmit_frame(), sky2_xmit_frame(), slam_mc_socket_deliver(), slam_pull_header(), slam_pull_value(), slam_socket_deliver(), srp_cmd(), srp_login(), srp_login_rej(), srp_login_rsp(), srp_rsp(), tcp_process_queue(), tcp_rx(), tcp_rx_data(), tcp_xmit(), tcp_xmit_reset(), tftp_rx(), tftp_rx_data(), tkip_decrypt(), tkip_encrypt(), udp_rx(), udp_tx(), undinet_poll(), undinet_transmit(), vxge_hw_fifo_txdl_buffer_set(), wep_decrypt(), wep_encrypt(), xfer_deliver_as_raw(), and xfer_deliver_iob_meta().

00162                                                          {
00163         return ( iobuf->tail - iobuf->data );
00164 }

static size_t iob_headroom ( struct io_buffer iobuf  )  [inline, static]

Calculate available space at start of an I/O buffer.

Parameters:
iobuf I/O buffer
Return values:
len Length of data available at start of buffer

Definition at line 172 of file iobuf.h.

References io_buffer::data, and io_buffer::head.

Referenced by iob_ensure_headroom(), iob_pad(), and net80211_probe_step().

00172                                                               {
00173         return ( iobuf->data - iobuf->head );
00174 }

static size_t iob_tailroom ( struct io_buffer iobuf  )  [inline, static]

Calculate available space at end of an I/O buffer.

Parameters:
iobuf I/O buffer
Return values:
len Length of data available at end of buffer

Definition at line 182 of file iobuf.h.

References io_buffer::end, and io_buffer::tail.

Referenced by arbel_complete(), arbel_post_recv(), ath5k_rxbuf_setup(), dhcp_tx(), hermon_complete(), hermon_post_recv(), ib_post_recv(), linda_post_recv(), slam_put_value(), tftp_send_rrq(), and undinet_poll().

00182                                                               {
00183         return ( iobuf->end - iobuf->tail );
00184 }

static void iob_populate ( struct io_buffer iobuf,
void *  data,
size_t  len,
size_t  max_len 
) [inline, static]

Create a temporary I/O buffer.

Parameters:
iobuf I/O buffer
data Data buffer
len Length of data
max_len Length of buffer
It is sometimes useful to use the iob_xxx() methods on temporary data buffers.

Definition at line 197 of file iobuf.h.

References io_buffer::data, io_buffer::end, io_buffer::head, and io_buffer::tail.

Referenced by hermon_fill_mlx_send_wqe(), linda_complete_recv(), and linda_post_send().

00198                                                                            {
00199         iobuf->head = iobuf->data = data;
00200         iobuf->tail = ( data + len );
00201         iobuf->end = ( data + max_len );
00202 }

struct io_buffer* __malloc alloc_iob ( size_t  len  )  [read]

Allocate I/O buffer.

Parameters:
len Required length of buffer
Return values:
iobuf I/O buffer, or NULL if none available
The I/O buffer will be physically aligned to a multiple of IOBUF_SIZE.

Definition at line 41 of file iobuf.c.

References io_buffer::data, io_buffer::end, io_buffer::head, IOB_ALIGN, IOB_ZLEN, malloc_dma(), NULL, and io_buffer::tail.

Referenced by a3c90x_refill_rx_ring(), aoe_send_command(), arp_resolve(), ath5k_rx_iob_alloc(), atl1e_clean_rx_irq(), b44_init_rx_ring(), b44_rx_refill(), ccmp_decrypt(), ccmp_encrypt(), default_xfer_alloc_iob(), e1000_refill_rx_ring(), e1000e_refill_rx_ring(), efab_fill_rx_queue(), efi_snp_transmit(), gdbudp_send(), ib_mi_send(), ib_refill_recv(), icmp6_send_solicit(), ifec_get_rx_desc(), igb_refill_rx_ring(), ipv4_reassemble(), legacy_poll(), mtnic_alloc_iobuf(), myri10ge_net_open(), myri10ge_net_poll(), natsemi_open(), natsemi_poll(), net80211_accum_frags(), net80211_probe_start(), net80211_probe_step(), net80211_send_assoc(), net80211_send_auth(), net80211_send_disassoc(), phantom_refill_rx_ring(), pnic_poll(), pxenv_undi_transmit(), rtl8169_refill_rx_ring(), rtl818x_handle_rx(), rtl818x_init_rx_ring(), rtl_poll(), sis190_alloc_rx_iob(), skge_rx_refill(), sky2_rx_alloc(), tcp_xmit(), tcp_xmit_reset(), tkip_decrypt(), tkip_encrypt(), udp_alloc_iob(), undinet_poll(), vxge_hw_ring_replenish(), vxge_hw_vpath_poll_rx(), wep_decrypt(), wep_encrypt(), and wpa_alloc_frame().

00041                                             {
00042         struct io_buffer *iobuf = NULL;
00043         void *data;
00044 
00045         /* Pad to minimum length */
00046         if ( len < IOB_ZLEN )
00047                 len = IOB_ZLEN;
00048 
00049         /* Align buffer length */
00050         len = ( len + __alignof__( *iobuf ) - 1 ) &
00051                 ~( __alignof__( *iobuf ) - 1 );
00052         
00053         /* Allocate memory for buffer plus descriptor */
00054         data = malloc_dma ( len + sizeof ( *iobuf ), IOB_ALIGN );
00055         if ( ! data )
00056                 return NULL;
00057 
00058         iobuf = ( struct io_buffer * ) ( data + len );
00059         iobuf->head = iobuf->data = iobuf->tail = data;
00060         iobuf->end = iobuf;
00061         return iobuf;
00062 }

void free_iob ( struct io_buffer iobuf  ) 

Free I/O buffer.

Parameters:
iobuf I/O buffer

Definition at line 69 of file iobuf.c.

References assert, io_buffer::data, io_buffer::end, free_dma(), io_buffer::head, and io_buffer::tail.

Referenced by __vxge_hw_ring_delete(), a3c90x_free_rx_iobuf(), aoe_rx(), arp_rx(), ath5k_rxbuf_free(), b44_free_rx_ring(), ccmp_decrypt(), dhcp_deliver_iob(), dhcp_tx(), downloader_xfer_deliver_iob(), e1000_free_rx_resources(), e1000e_free_rx_resources(), eapol_key_rx(), eapol_rx(), efab_free_resources(), efab_receive(), efi_snp_receive(), efi_snp_transmit(), gdbudp_recv(), http_socket_deliver_iob(), ib_cmrc_complete_recv(), ib_cmrc_complete_send(), ib_cmrc_xfer_deliver_iob(), ib_complete_recv(), ib_complete_send(), ib_mi_complete_recv(), ib_mi_send(), ib_refill_recv(), icmp6_rx(), icmp_rx(), ifec_free(), igb_free_rx_resources(), ipv4_reassemble(), ipv4_rx(), ipv4_tx(), ipv6_rx(), ipv6_tx(), legacy_poll(), mtnic_free_io_buffers(), mtnic_process_rx_cq(), myri10ge_net_close(), myri10ge_net_open(), natsemi_close(), natsemi_open(), net80211_free_frags(), net80211_free_wlan(), net80211_handle_mgmt(), net80211_probe_finish_all(), net80211_probe_finish_best(), net80211_probe_step(), net80211_rx(), net80211_rx_frag(), net80211_tx_mgmt(), net_rx(), net_step(), net_tx(), netdev_rx_err(), netdev_tx_complete_err(), phantom_close(), posix_file_free(), posix_file_xfer_deliver_iob(), pxe_tftp_xfer_deliver_iob(), pxe_udp_deliver_iob(), pxenv_undi_isr(), pxenv_undi_transmit(), rarp_rx(), read_user(), rtl8169_free_rx_resources(), rtl818x_free_rx_ring(), sis190_free(), skge_rx_clean(), sky2_rx_clean(), slam_mc_socket_deliver(), slam_socket_deliver(), srp_login_rej(), srp_login_rsp(), srp_rsp(), srp_unrecognised(), tcp_close(), tcp_process_queue(), tcp_rx(), tcp_rx_data(), tcpip_rx(), tcpip_tx(), tftp_rx(), tftp_rx_data(), tkip_decrypt(), tls_send_plaintext(), udp_rx(), udp_tx(), vxge_hw_ring_replenish(), wep_decrypt(), and xfer_deliver_as_raw().

00069                                           {
00070         if ( iobuf ) {
00071                 assert ( iobuf->head <= iobuf->data );
00072                 assert ( iobuf->data <= iobuf->tail );
00073                 assert ( iobuf->tail <= iobuf->end );
00074                 free_dma ( iobuf->head,
00075                            ( iobuf->end - iobuf->head ) + sizeof ( *iobuf ) );
00076         }
00077 }

void iob_pad ( struct io_buffer iobuf,
size_t  min_len 
)

Pad I/O buffer.

Parameters:
iobuf I/O buffer
min_len Minimum 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 44 of file iobpad.c.

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

Referenced by legacy_transmit(), myri10ge_net_transmit(), pnic_transmit(), rtl_transmit(), and sis190_transmit().

00044                                                          {
00045         void *data;
00046         size_t len;
00047         size_t headroom;
00048         signed int pad_len;
00049 
00050         assert ( min_len <= IOB_ZLEN );
00051 
00052         /* Move packet data to start of I/O buffer.  This will both
00053          * align the data (since I/O buffers are aligned to
00054          * IOB_ALIGN) and give us sufficient space for the
00055          * zero-padding
00056          */
00057         data = iobuf->data;
00058         len = iob_len ( iobuf );
00059         headroom = iob_headroom ( iobuf );
00060         iob_push ( iobuf, headroom );
00061         memmove ( iobuf->data, data, len );
00062         iob_unput ( iobuf, headroom );
00063 
00064         /* Pad to minimum packet length */
00065         pad_len = ( min_len - iob_len ( iobuf ) );
00066         if ( pad_len > 0 )
00067                 memset ( iob_put ( iobuf, pad_len ), 0, pad_len );
00068 }

int iob_ensure_headroom ( struct io_buffer iobuf,
size_t  len 
)

Ensure I/O buffer has sufficient headroom.

Parameters:
iobuf I/O buffer
len Required headroom
This function currently only checks for the required headroom; it does not reallocate the I/O buffer if required. If we ever have a code path that requires this functionality, it's a fairly trivial change to make.

Definition at line 90 of file iobuf.c.

References ENOBUFS, and iob_headroom().

Referenced by udp_tx().

00090                                                                 {
00091 
00092         if ( iob_headroom ( iobuf ) >= len )
00093                 return 0;
00094         return -ENOBUFS;
00095 }


Generated on Tue Apr 6 20:01:51 2010 for gPXE by  doxygen 1.5.7.1