iPXE
Data Structures | Macros | Functions
iobuf.h File Reference

I/O buffers. More...

#include <stdint.h>
#include <assert.h>
#include <ipxe/list.h>
#include <ipxe/dma.h>

Go to the source code of this file.

Data Structures

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

Macros

#define IOB_ZLEN   128
 Minimum I/O buffer length and alignment. More...
 
#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. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 FILE_SECBOOT (PERMITTED)
 
static void * iob_reserve (struct io_buffer *iobuf, size_t len)
 Reserve space at start of I/O buffer. More...
 
static void * iob_push (struct io_buffer *iobuf, size_t len)
 Add data to start of I/O buffer. More...
 
static void * iob_pull (struct io_buffer *iobuf, size_t len)
 Remove data from start of I/O buffer. More...
 
static void * iob_put (struct io_buffer *iobuf, size_t len)
 Add data to end of I/O buffer. More...
 
static void iob_unput (struct io_buffer *iobuf, size_t len)
 Remove data from end of I/O buffer. More...
 
static void iob_empty (struct io_buffer *iobuf)
 Empty an I/O buffer. More...
 
static size_t iob_len (struct io_buffer *iobuf)
 Calculate length of data in an I/O buffer. More...
 
static size_t iob_headroom (struct io_buffer *iobuf)
 Calculate available space at start of an I/O buffer. More...
 
static size_t iob_tailroom (struct io_buffer *iobuf)
 Calculate available space at end of an I/O buffer. More...
 
static void iob_populate (struct io_buffer *iobuf, void *data, size_t len, size_t max_len)
 Create a temporary I/O buffer. More...
 
static __always_inline int iob_map (struct io_buffer *iobuf, struct dma_device *dma, size_t len, int flags)
 Map I/O buffer for DMA. More...
 
static __always_inline int iob_map_tx (struct io_buffer *iobuf, struct dma_device *dma)
 Map I/O buffer for transmit DMA. More...
 
static __always_inline int iob_map_rx (struct io_buffer *iobuf, struct dma_device *dma)
 Map empty I/O buffer for receive DMA. More...
 
static __always_inline physaddr_t iob_dma (struct io_buffer *iobuf)
 Get I/O buffer DMA address. More...
 
static __always_inline void iob_unmap (struct io_buffer *iobuf)
 Unmap I/O buffer for DMA. More...
 
struct io_buffer *__malloc alloc_iob_raw (size_t len, size_t align, size_t offset)
 Allocate I/O buffer with specified alignment and offset. More...
 
struct io_buffer *__malloc alloc_iob (size_t len)
 Allocate I/O buffer. More...
 
void free_iob (struct io_buffer *iobuf)
 Free I/O buffer. More...
 
struct io_buffer *__malloc alloc_rx_iob (size_t len, struct dma_device *dma)
 Allocate and map I/O buffer for receive DMA. More...
 
void free_rx_iob (struct io_buffer *iobuf)
 Unmap and free I/O buffer for receive DMA. More...
 
void iob_pad (struct io_buffer *iobuf, size_t min_len)
 Pad I/O buffer. More...
 
int iob_ensure_headroom (struct io_buffer *iobuf, size_t len)
 Ensure I/O buffer has sufficient headroom. More...
 
struct io_bufferiob_concatenate (struct list_head *list)
 Concatenate I/O buffers into a single buffer. More...
 
struct io_bufferiob_split (struct io_buffer *iobuf, size_t len)
 Split I/O buffer. More...
 

Detailed Description

I/O buffers.

Definition in file iobuf.h.

Macro Definition Documentation

◆ IOB_ZLEN

#define IOB_ZLEN   128

Minimum I/O buffer length and alignment.

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.

This length must be at least as large as the largest cacheline size that we expect to encounter, to allow for platforms where DMA devices are not in the same coherency domain as the CPU cache.

Definition at line 29 of file iobuf.h.

◆ iob_reserve

#define iob_reserve (   iobuf,
  len 
)
Value:
( { \
void *__result; \
__result = iob_reserve ( (iobuf), (len) ); \
assert ( (iobuf)->tail <= (iobuf)->end ); \
__result; } )
ring len
Length.
Definition: dwmac.h:231
#define iob_reserve(iobuf, len)
Definition: iobuf.h:72
uint32_t end
Ending offset.
Definition: netvsc.h:18

Definition at line 72 of file iobuf.h.

◆ iob_push

#define iob_push (   iobuf,
  len 
)
Value:
( { \
void *__result; \
__result = iob_push ( (iobuf), (len) ); \
assert ( (iobuf)->data >= (iobuf)->head ); \
__result; } )
#define iob_push(iobuf, len)
Definition: iobuf.h:89
uint8_t head
Head number.
Definition: int13.h:34
ring len
Length.
Definition: dwmac.h:231
uint8_t data[48]
Additional event data.
Definition: ena.h:22

Definition at line 89 of file iobuf.h.

◆ iob_pull

#define iob_pull (   iobuf,
  len 
)
Value:
( { \
void *__result; \
__result = iob_pull ( (iobuf), (len) ); \
assert ( (iobuf)->data <= (iobuf)->tail ); \
__result; } )
#define iob_pull(iobuf, len)
Definition: iobuf.h:107
ring len
Length.
Definition: dwmac.h:231
uint8_t data[48]
Additional event data.
Definition: ena.h:22

Definition at line 107 of file iobuf.h.

◆ iob_put

#define iob_put (   iobuf,
  len 
)
Value:
( { \
void *__result; \
__result = iob_put ( (iobuf), (len) ); \
assert ( (iobuf)->tail <= (iobuf)->end ); \
__result; } )
#define iob_put(iobuf, len)
Definition: iobuf.h:125
ring len
Length.
Definition: dwmac.h:231
uint32_t end
Ending offset.
Definition: netvsc.h:18

Definition at line 125 of file iobuf.h.

◆ iob_unput

#define iob_unput (   iobuf,
  len 
)
Value:
do { \
iob_unput ( (iobuf), (len) ); \
assert ( (iobuf)->tail >= (iobuf)->data ); \
} while ( 0 )
ring len
Length.
Definition: dwmac.h:231
uint8_t data[48]
Additional event data.
Definition: ena.h:22

Definition at line 140 of file iobuf.h.

◆ iob_disown

#define iob_disown (   iobuf)
Value:
( { \
struct io_buffer *__iobuf = (iobuf); \
(iobuf) = NULL; \
__iobuf; } )
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
A persistent I/O buffer.
Definition: iobuf.h:38

Disown an I/O buffer.

Parameters
iobufI/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 217 of file iobuf.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ iob_reserve()

static void* iob_reserve ( struct io_buffer iobuf,
size_t  len 
)
inlinestatic

Reserve space at start of I/O buffer.

Parameters
iobufI/O buffer
lenLength to reserve
Return values
dataPointer to new start of buffer

Definition at line 67 of file iobuf.h.

67  {
68  iobuf->data += len;
69  iobuf->tail += len;
70  return iobuf->data;
71 }
void * tail
End of data.
Definition: iobuf.h:55
ring len
Length.
Definition: dwmac.h:231
void * data
Start of data.
Definition: iobuf.h:53

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

◆ iob_push()

static void* iob_push ( struct io_buffer iobuf,
size_t  len 
)
inlinestatic

Add data to start of I/O buffer.

Parameters
iobufI/O buffer
lenLength to add
Return values
dataPointer to new start of buffer

Definition at line 85 of file iobuf.h.

85  {
86  iobuf->data -= len;
87  return iobuf->data;
88 }
ring len
Length.
Definition: dwmac.h:231
void * data
Start of data.
Definition: iobuf.h:53

References io_buffer::data, and len.

◆ iob_pull()

static void* iob_pull ( struct io_buffer iobuf,
size_t  len 
)
inlinestatic

Remove data from start of I/O buffer.

Parameters
iobufI/O buffer
lenLength to remove
Return values
dataPointer to new start of buffer

Definition at line 102 of file iobuf.h.

102  {
103  iobuf->data += len;
104  assert ( iobuf->data <= iobuf->tail );
105  return iobuf->data;
106 }
void * tail
End of data.
Definition: iobuf.h:55
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
ring len
Length.
Definition: dwmac.h:231
void * data
Start of data.
Definition: iobuf.h:53

References assert(), io_buffer::data, len, and io_buffer::tail.

◆ iob_put()

static void* iob_put ( struct io_buffer iobuf,
size_t  len 
)
inlinestatic

Add data to end of I/O buffer.

Parameters
iobufI/O buffer
lenLength to add
Return values
dataPointer to newly added space

Definition at line 120 of file iobuf.h.

120  {
121  void *old_tail = iobuf->tail;
122  iobuf->tail += len;
123  return old_tail;
124 }
void * tail
End of data.
Definition: iobuf.h:55
ring len
Length.
Definition: dwmac.h:231

References len, and io_buffer::tail.

◆ iob_unput()

static void iob_unput ( struct io_buffer iobuf,
size_t  len 
)
inlinestatic

Remove data from end of I/O buffer.

Parameters
iobufI/O buffer
lenLength to remove

Definition at line 137 of file iobuf.h.

137  {
138  iobuf->tail -= len;
139 }
void * tail
End of data.
Definition: iobuf.h:55
ring len
Length.
Definition: dwmac.h:231

References len, and io_buffer::tail.

◆ iob_empty()

static void iob_empty ( struct io_buffer iobuf)
inlinestatic

Empty an I/O buffer.

Parameters
iobufI/O buffer

Definition at line 150 of file iobuf.h.

150  {
151  iobuf->tail = iobuf->data;
152 }
void * tail
End of data.
Definition: iobuf.h:55
void * data
Start of data.
Definition: iobuf.h:53

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

◆ iob_len()

static size_t iob_len ( struct io_buffer iobuf)
inlinestatic

Calculate length of data in an I/O buffer.

Parameters
iobufI/O buffer
Return values
lenLength of data in buffer

Definition at line 160 of file iobuf.h.

160  {
161  return ( iobuf->tail - iobuf->data );
162 }
void * tail
End of data.
Definition: iobuf.h:55
void * data
Start of data.
Definition: iobuf.h:53

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

Referenced by a3c90x_process_tx_packets(), a3c90x_transmit(), acm_control_transmit(), acm_intr_complete(), acm_transmit(), aoe_rx(), aoecmd_rx(), aoecmd_tx(), arbel_fill_mlx_send_wqe(), arbel_fill_rc_send_wqe(), arbel_fill_ud_send_wqe(), arp_rx(), ath5k_tx_processq(), ath5k_txbuf_setup(), ath_tx_send_normal(), ath_tx_setup_buffer(), atl1e_tx_map(), atl_transmit(), axge_in_complete(), axge_intr_complete(), axge_out_transmit(), b44_transmit(), bnxt_add_vlan(), bnxt_tx(), bnxt_tx_adjust_pkt(), bnxt_tx_complete(), ccmp_decrypt(), ccmp_encrypt(), cgem_transmit(), dhcp_deliver(), dhcpv6_rx(), dhcpv6_tx(), dm96xx_in_complete(), dm96xx_intr_complete(), dm96xx_out_transmit(), dns_xfer_deliver(), dwmac_transmit(), eapol_eap_rx(), eapol_rx(), ecm_intr_complete(), efab_transmit(), efi_download_deliver_iob(), efi_pxe_udp_read(), efi_snp_receive(), efi_undi_get_status(), efi_usb_async_complete(), efi_usb_sync_transfer(), efx_hunt_build_tx_desc(), efx_hunt_transmit(), ehci_endpoint_message(), ehci_endpoint_stream(), ena_transmit(), eoib_complete_recv(), eoib_duplicate(), eoib_transmit(), eth_pull(), eth_slow_lacp_dump(), eth_slow_marker_dump(), eth_slow_rx(), exanic_transmit(), falcon_build_tx_desc(), fc_els_rx(), fc_ns_query_deliver(), fc_port_deliver(), fcoe_deliver(), fcoe_fip_rx(), fcoe_rx(), fcpcmd_recv_rddata(), fcpcmd_recv_rsp(), fcpcmd_recv_unknown(), fcpcmd_recv_xfer_rdy(), fcpcmd_send_wrdata(), forcedeth_transmit(), fragment_reassemble(), ftp_control_deliver(), gdbudp_recv(), gdbudp_send(), golan_post_send(), gve_poll_rx(), gve_transmit(), hermon_fill_eth_send_wqe(), hermon_fill_mlx_send_wqe(), hermon_fill_rc_send_wqe(), hermon_fill_ud_send_wqe(), http_conn_deliver(), http_rx_chunk_data(), http_rx_linebuf(), http_rx_transfer_identity(), hub_complete(), ib_cmrc_complete_recv(), ib_cmrc_xfer_deliver(), ib_mi_complete_recv(), ib_pull(), ib_push(), icmp_rx_echo_reply(), icmp_rx_echo_request(), icmp_tx_echo(), icmpv4_rx(), icmpv6_rx(), icplus_transmit(), ifec_net_transmit(), igbvf_transmit(), imux_in_complete(), imux_rx_tcp(), imux_tx(), imux_tx_tcp(), intel_transmit(), intelxl_transmit(), iob_concatenate(), iob_map_rx(), iob_map_tx(), iob_pad(), iob_split(), iob_unmap(), ipair_deliver(), iphone_in_complete(), ipoib_complete_recv(), ipoib_transmit(), ipv4_pshdr_chksum(), ipv4_rx(), ipv4_tx(), ipv6_rx(), ipv6_tx(), iscsi_socket_deliver(), jme_fill_tx_desc(), jme_tx_clean(), legacy_transmit(), linda_post_send(), lldp_rx(), loopback_wait(), mnpnet_transmit(), myri10ge_net_transmit(), myson_transmit(), natsemi_transmit(), ncm_in_complete(), ncm_intr_complete(), ncm_out_transmit(), ndp_rx_neighbour(), ndp_rx_router_advertisement(), net80211_accum_frags(), net80211_ll_pull(), net80211_probe_step(), net80211_rx_frag(), net_poll(), netdev_rx(), netdev_tx(), netfront_transmit(), netvsc_transmit(), nfs_deliver(), nii_transmit(), ntp_deliver(), pcnet32_transmit(), peerblk_deliver(), peerblk_raw_rx(), peerblk_retrieval_rx(), peerdisc_socket_rx(), phantom_refill_rx_ring(), phantom_transmit(), ping_rx(), pinger_deliver(), pnic_transmit(), posix_file_xfer_deliver(), pxe_tftp_xfer_deliver(), pxenv_udp_read(), pxenv_undi_isr(), qib7322_post_send(), rdc_transmit(), read(), realtek_transmit(), rhine_transmit(), rndis_rx(), rndis_rx_data(), rndis_rx_initialise(), rndis_rx_message(), rndis_rx_query_oid(), rndis_rx_set_oid(), rndis_rx_status(), rndis_tx_complete_err(), rndis_tx_data(), rndis_tx_defer(), rndis_tx_message(), rtl818x_tx(), shomron_fill_eth_send_wqe(), sis190_transmit(), skge_xmit_frame(), sky2_xmit_frame(), slam_mc_socket_deliver(), slam_pull_header(), slam_pull_value(), slam_socket_deliver(), smsc75xx_in_complete(), smsc75xx_out_transmit(), smsc95xx_in_complete(), smsc95xx_out_transmit(), smscusb_intr_complete(), snpnet_transmit(), srp_login(), srpdev_deliver(), stp_rx(), tcp_process_rx_queue(), tcp_process_tx_queue(), tcp_rx(), tcp_rx_data(), tcp_rx_enqueue(), tcp_xmit_reset(), tcp_xmit_sack(), tftp_rx(), tftp_rx_data(), tg3_transmit(), tg3_tx_complete(), tkip_decrypt(), tkip_encrypt(), tls_cipherstream_deliver(), tls_hmac_list(), tls_new_alert(), tls_new_change_cipher(), tls_new_ciphertext(), tls_new_handshake(), tls_new_record(), tls_new_unknown(), tls_send_record(), tls_verify_padding(), txnic_send(), udp_rx(), udp_tx(), uhci_endpoint_message(), uhci_endpoint_poll(), uhci_endpoint_stream(), uhci_enqueue(), undinet_poll(), undinet_transmit(), usb_control(), usb_message(), usb_refill_limit(), usb_stream(), usbblk_in_complete(), usbio_bulk_in_poll(), usbio_bulk_out_poll(), usbio_control_poll(), usbio_endpoint_message(), usbio_interrupt_poll(), usbkbd_complete(), velocity_transmit(), virtnet_enqueue_iob(), virtnet_process_rx_packets(), vlan_rx(), vmbus_send_data(), vmxnet3_poll_tx(), vmxnet3_transmit(), vxge_hw_fifo_txdl_buffer_set(), wep_decrypt(), wep_encrypt(), xcm_deliver(), xfer_deliver(), xferbuf_deliver(), xhci_endpoint_message(), and xhci_endpoint_stream().

◆ iob_headroom()

static size_t iob_headroom ( struct io_buffer iobuf)
inlinestatic

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

Parameters
iobufI/O buffer
Return values
lenLength of data available at start of buffer

Definition at line 170 of file iobuf.h.

170  {
171  return ( iobuf->data - iobuf->head );
172 }
void * head
Start of the buffer.
Definition: iobuf.h:51
void * data
Start of data.
Definition: iobuf.h:53

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

Referenced by eoib_transmit(), fragment_reassemble(), iob_ensure_headroom(), iob_pad(), net80211_probe_step(), and usb_message().

◆ iob_tailroom()

static size_t iob_tailroom ( struct io_buffer iobuf)
inlinestatic

◆ iob_populate()

static void iob_populate ( struct io_buffer iobuf,
void *  data,
size_t  len,
size_t  max_len 
)
inlinestatic

Create a temporary I/O buffer.

Parameters
iobufI/O buffer
dataData buffer
lenLength of data
max_lenLength of buffer

It is sometimes useful to use the iob_xxx() methods on temporary data buffers.

Definition at line 195 of file iobuf.h.

196  {
197  iobuf->head = iobuf->data = data;
198  iobuf->tail = ( data + len );
199  iobuf->end = ( data + max_len );
200 }
void * tail
End of data.
Definition: iobuf.h:55
ring len
Length.
Definition: dwmac.h:231
void * end
End of the buffer.
Definition: iobuf.h:57
void * head
Start of the buffer.
Definition: iobuf.h:51
void * data
Start of data.
Definition: iobuf.h:53
uint8_t data[48]
Additional event data.
Definition: ena.h:22

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

Referenced by add_tls(), arbel_fill_mlx_send_wqe(), efi_undi_fill_header(), hermon_fill_mlx_send_wqe(), linda_complete_recv(), linda_post_send(), qib7322_complete_recv(), and qib7322_post_send().

◆ iob_map()

static __always_inline int iob_map ( struct io_buffer iobuf,
struct dma_device dma,
size_t  len,
int  flags 
)
inlinestatic

Map I/O buffer for DMA.

Parameters
iobufI/O buffer
dmaDMA device
lenLength to map
flagsMapping flags
Return values
rcReturn status code

Definition at line 231 of file iobuf.h.

233  {
234  return dma_map ( dma, &iobuf->map, iobuf->data, len, flags );
235 }
struct dma_mapping map
DMA mapping.
Definition: iobuf.h:48
ring len
Length.
Definition: dwmac.h:231
uint8_t flags
Flags.
Definition: ena.h:18
void * data
Start of data.
Definition: iobuf.h:53
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.

References io_buffer::data, dma(), flags, len, and io_buffer::map.

Referenced by iob_map_rx(), iob_map_tx(), xhci_endpoint_message(), and xhci_endpoint_stream().

◆ iob_map_tx()

static __always_inline int iob_map_tx ( struct io_buffer iobuf,
struct dma_device dma 
)
inlinestatic

Map I/O buffer for transmit DMA.

Parameters
iobufI/O buffer
dmaDMA device
Return values
rcReturn status code

Definition at line 244 of file iobuf.h.

245  {
246  return iob_map ( iobuf, dma, iob_len ( iobuf ), DMA_TX );
247 }
#define DMA_TX
Device will read data from host memory.
Definition: dma.h:135
static __always_inline int iob_map(struct io_buffer *iobuf, struct dma_device *dma, size_t len, int flags)
Map I/O buffer for DMA.
Definition: iobuf.h:231
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:160
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.

References dma(), DMA_TX, iob_len(), and iob_map().

Referenced by cgem_transmit(), netdev_tx(), rdc_transmit(), and realtek_transmit().

◆ iob_map_rx()

static __always_inline int iob_map_rx ( struct io_buffer iobuf,
struct dma_device dma 
)
inlinestatic

Map empty I/O buffer for receive DMA.

Parameters
iobufI/O buffer
dmaDMA device
Return values
rcReturn status code

Definition at line 256 of file iobuf.h.

257  {
258  assert ( iob_len ( iobuf ) == 0 );
259  return iob_map ( iobuf, dma, iob_tailroom ( iobuf ), DMA_RX );
260 }
#define DMA_RX
Device will write data to host memory.
Definition: dma.h:138
static __always_inline int iob_map(struct io_buffer *iobuf, struct dma_device *dma, size_t len, int flags)
Map I/O buffer for DMA.
Definition: iobuf.h:231
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:160
static size_t iob_tailroom(struct io_buffer *iobuf)
Calculate available space at end of an I/O buffer.
Definition: iobuf.h:180
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.

References assert(), dma(), DMA_RX, iob_len(), iob_map(), and iob_tailroom().

Referenced by alloc_rx_iob().

◆ iob_dma()

static __always_inline physaddr_t iob_dma ( struct io_buffer iobuf)
inlinestatic

Get I/O buffer DMA address.

Parameters
iobufI/O buffer
Return values
addrDMA address

Definition at line 268 of file iobuf.h.

268  {
269  return dma ( &iobuf->map, iobuf->data );
270 }
struct dma_mapping map
DMA mapping.
Definition: iobuf.h:48
void * data
Start of data.
Definition: iobuf.h:53
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.

References io_buffer::data, dma(), and io_buffer::map.

Referenced by atl_rx_ring_fill(), atl_transmit(), bnxt_set_rx_desc(), bnxt_tx(), cgem_refill_rx(), cgem_transmit(), dwmac_refill_rx(), dwmac_transmit(), intel_refill_rx(), intel_transmit(), intelxl_refill_rx(), intelxl_transmit(), rdc_refill_rx(), rdc_transmit(), realtek_refill_rx(), realtek_transmit(), virtnet_enqueue_iob(), xhci_endpoint_message(), and xhci_endpoint_stream().

◆ iob_unmap()

static __always_inline void iob_unmap ( struct io_buffer iobuf)
inlinestatic

Unmap I/O buffer for DMA.

Parameters
iobufI/O buffer
dmaDMA device
Return values
rcReturn status code

Definition at line 279 of file iobuf.h.

279  {
280  dma_unmap ( &iobuf->map, iob_len ( iobuf ) );
281 }
struct dma_mapping map
DMA mapping.
Definition: iobuf.h:48
void dma_unmap(struct dma_mapping *map, size_t len)
Unmap buffer.
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:160

References dma_unmap(), iob_len(), and io_buffer::map.

Referenced by alloc_rx_iob(), free_rx_iob(), net_discard(), netdev_rx(), netdev_rx_err(), netdev_tx_err(), xhci_endpoint_close(), xhci_endpoint_message(), xhci_endpoint_stream(), and xhci_transfer().

◆ alloc_iob_raw()

struct io_buffer* __malloc alloc_iob_raw ( size_t  len,
size_t  align,
size_t  offset 
)

Allocate I/O buffer with specified alignment and offset.

Parameters
lenRequired length of buffer
alignPhysical alignment
offsetOffset from physical alignment
Return values
iobufI/O buffer, or NULL if none available

align will be rounded up to the nearest power of two.

Definition at line 49 of file iobuf.c.

49  {
50  struct io_buffer *iobuf;
51  size_t headroom;
52  size_t tailroom;
53  size_t padding;
54  size_t threshold;
55  unsigned int align_log2;
56  void *data;
57 
58  /* Round up requested alignment and calculate initial headroom
59  * and tailroom to ensure that no cachelines are shared
60  * between I/O buffer data and other data structures.
61  */
62  if ( align < IOB_ZLEN )
63  align = IOB_ZLEN;
64  headroom = ( offset & ( IOB_ZLEN - 1 ) );
65  tailroom = ( ( - len - offset ) & ( IOB_ZLEN - 1 ) );
66  padding = ( headroom + tailroom );
67  offset -= headroom;
68  len += padding;
69  if ( len < padding )
70  return NULL;
71 
72  /* Round up alignment to the nearest power of two, avoiding
73  * a potentially undefined shift operation.
74  */
75  align_log2 = fls ( align - 1 );
76  if ( align_log2 >= ( 8 * sizeof ( align ) ) )
77  return NULL;
78  align = ( 1UL << align_log2 );
79 
80  /* Calculate length threshold */
81  assert ( align >= sizeof ( *iobuf ) );
82  threshold = ( align - sizeof ( *iobuf ) );
83 
84  /* Allocate buffer plus an inline descriptor as a single unit,
85  * unless doing so would push the total size over the
86  * alignment boundary.
87  */
88  if ( len <= threshold ) {
89 
90  /* Allocate memory for buffer plus descriptor */
91  data = malloc_phys_offset ( len + sizeof ( *iobuf ), align,
92  offset );
93  if ( ! data )
94  return NULL;
95  iobuf = ( data + len );
96 
97  } else {
98 
99  /* Allocate memory for buffer */
100  data = malloc_phys_offset ( len, align, offset );
101  if ( ! data )
102  return NULL;
103 
104  /* Allocate memory for descriptor */
105  iobuf = malloc ( sizeof ( *iobuf ) );
106  if ( ! iobuf ) {
107  free_phys ( data, len );
108  return NULL;
109  }
110  }
111 
112  /* Populate descriptor */
113  memset ( &iobuf->map, 0, sizeof ( iobuf->map ) );
114  iobuf->head = data;
115  iobuf->data = iobuf->tail = ( data + headroom );
116  iobuf->end = ( data + len );
117 
118  return iobuf;
119 }
struct dma_mapping map
DMA mapping.
Definition: iobuf.h:48
void * tail
End of data.
Definition: iobuf.h:55
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
ring len
Length.
Definition: dwmac.h:231
void * malloc_phys_offset(size_t size, size_t phys_align, size_t offset)
Allocate memory with specified physical alignment and offset.
Definition: malloc.c:685
void * end
End of the buffer.
Definition: iobuf.h:57
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:621
void * head
Start of the buffer.
Definition: iobuf.h:51
#define IOB_ZLEN
Minimum I/O buffer length and alignment.
Definition: iobuf.h:29
void * data
Start of data.
Definition: iobuf.h:53
void free_phys(void *ptr, size_t size)
Free memory allocated with malloc_phys()
Definition: malloc.c:723
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
#define fls(x)
Find last (i.e.
Definition: strings.h:167
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
void * memset(void *dest, int character, size_t len) __nonnull
A persistent I/O buffer.
Definition: iobuf.h:38

References assert(), data, io_buffer::data, io_buffer::end, fls, free_phys(), io_buffer::head, IOB_ZLEN, len, malloc(), malloc_phys_offset(), io_buffer::map, memset(), NULL, offset, and io_buffer::tail.

Referenced by alloc_iob(), alloc_iob_fail_okx(), alloc_iob_okx(), ath_rx_init(), ath_rx_tasklet(), iob_concatenate(), ipoib_alloc_iob(), and tls_newdata_process_header().

◆ alloc_iob()

struct io_buffer* __malloc alloc_iob ( size_t  len)

Allocate I/O buffer.

Parameters
lenRequired length of buffer
Return values
iobufI/O buffer, or NULL if none available

The I/O buffer will be physically aligned on its own size (rounded up to the nearest power of two), up to a maximum of page-size alignment.

Definition at line 131 of file iobuf.c.

131  {
132  size_t align;
133 
134  /* Pad to minimum length */
135  if ( len < IOB_ZLEN )
136  len = IOB_ZLEN;
137 
138  /* Align buffer on its own size (up to page size) to avoid
139  * potential problems with boundary-crossing DMA.
140  */
141  align = len;
142  if ( align > PAGE_SIZE )
143  align = PAGE_SIZE;
144 
145  return alloc_iob_raw ( len, align, 0 );
146 }
struct io_buffer * alloc_iob_raw(size_t len, size_t align, size_t offset)
Allocate I/O buffer with specified alignment and offset.
Definition: iobuf.c:49
#define PAGE_SIZE
Page size.
Definition: io.h:28
ring len
Length.
Definition: dwmac.h:231
#define IOB_ZLEN
Minimum I/O buffer length and alignment.
Definition: iobuf.h:29

References alloc_iob_raw(), IOB_ZLEN, len, and PAGE_SIZE.

Referenced by a3c90x_refill_rx_ring(), acm_control_receive(), alloc_rx_iob(), aoecmd_tx(), arp_tx_request(), ath5k_rx_iob_alloc(), atl1e_clean_rx_irq(), axge_in_complete(), b44_init_rx_ring(), b44_rx_refill(), ccmp_decrypt(), ccmp_encrypt(), eapol_tx(), efab_fill_rx_queue(), efi_snp_transmit(), efi_usb_sync_transfer(), efx_hunt_rxq_fill(), ena_refill_rx(), eoib_duplicate(), exanic_poll_rx(), fcoe_alloc_iob(), fcoe_fip_tx_keepalive(), fcoe_fip_tx_solicitation(), fcoe_fip_tx_vlan(), fragment_reassemble(), gdbudp_send(), gve_poll_rx(), http_rx_chunk_data(), hunt_mcdi_init(), ib_mi_send(), icplus_refill_rx(), ifec_get_rx_desc(), igbvf_refill_rx_ring(), igbvf_setup_rx_resources(), imux_alloc_iob(), imux_tx_syn(), imux_tx_version(), iob_split(), jme_make_new_rx_buf(), legacy_poll(), loopback_test(), mnpnet_poll_rx(), myri10ge_net_open(), myri10ge_net_poll(), myson_refill_rx(), natsemi_refill_rx(), ncm_in_complete(), ndp_tx_ll_addr(), net80211_accum_frags(), net80211_probe_start(), net80211_probe_step(), net80211_send_assoc(), net80211_send_auth(), net80211_send_disassoc(), netfront_refill_rx(), nii_poll_rx(), nv_alloc_rx(), pcnet32_refill_rx_ring(), phantom_refill_rx_ring(), ping_alloc_iob(), pnic_poll(), pxenv_undi_transmit(), realtek_legacy_poll_rx(), rhine_refill_rx(), rndis_alloc_iob(), rtl818x_handle_rx(), rtl818x_init_rx_ring(), sis190_alloc_rx_iob(), skge_rx_refill(), sky2_rx_alloc(), snpnet_poll_rx(), tcp_xmit_reset(), tcp_xmit_sack(), tg3_alloc_rx_iob(), tkip_decrypt(), tkip_encrypt(), txnic_refill_rq(), udp_xfer_alloc_iob(), undinet_poll(), usb_control(), usb_prefill(), usb_refill_limit(), usbblk_out_command(), usbblk_out_data(), velocity_refill_rx(), vmbus_xfer_page_iobufs(), vmxnet3_refill_rx(), vxge_hw_ring_replenish(), vxge_hw_vpath_poll_rx(), wep_decrypt(), wep_encrypt(), wpa_alloc_frame(), and xfer_alloc_iob().

◆ free_iob()

void free_iob ( struct io_buffer iobuf)

Free I/O buffer.

Parameters
iobufI/O buffer

Definition at line 153 of file iobuf.c.

153  {
154  size_t len;
155 
156  /* Allow free_iob(NULL) to be valid */
157  if ( ! iobuf )
158  return;
159 
160  /* Sanity checks */
161  assert ( iobuf->head <= iobuf->data );
162  assert ( iobuf->data <= iobuf->tail );
163  assert ( iobuf->tail <= iobuf->end );
164  assert ( ! dma_mapped ( &iobuf->map ) );
165 
166  /* Free buffer */
167  len = ( iobuf->end - iobuf->head );
168  if ( iobuf->end == iobuf ) {
169 
170  /* Descriptor is inline */
171  free_phys ( iobuf->head, ( len + sizeof ( *iobuf ) ) );
172 
173  } else {
174 
175  /* Descriptor is detached */
176  free_phys ( iobuf->head, len );
177  free ( iobuf );
178  }
179 }
struct dma_mapping map
DMA mapping.
Definition: iobuf.h:48
void * tail
End of data.
Definition: iobuf.h:55
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
ring len
Length.
Definition: dwmac.h:231
static __always_inline int dma_mapped(struct dma_mapping *map)
Check if DMA unmapping is required.
Definition: dma.h:442
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
void * end
End of the buffer.
Definition: iobuf.h:57
void * head
Start of the buffer.
Definition: iobuf.h:51
void * data
Start of data.
Definition: iobuf.h:53
void free_phys(void *ptr, size_t size)
Free memory allocated with malloc_phys()
Definition: malloc.c:723

References assert(), io_buffer::data, dma_mapped(), io_buffer::end, free, free_phys(), io_buffer::head, len, io_buffer::map, and io_buffer::tail.

Referenced by __vxge_hw_ring_delete(), a3c90x_free_rx_iobuf(), acm_control_receive(), acm_in_complete(), acm_intr_complete(), alloc_iob_okx(), alloc_rx_iob(), aoe_rx(), aoecmd_rx(), arp_rx(), ath5k_rxbuf_free(), ath9k_stop(), ath9k_tx(), ath_rx_cleanup(), axge_in_complete(), axge_intr_complete(), b44_free_rx_ring(), b44_rx_refill(), ccmp_decrypt(), dhcp_deliver(), dhcp_tx(), dhcpv6_rx(), dm96xx_in_complete(), dm96xx_intr_complete(), dns_xfer_deliver(), eapol_eap_rx(), eapol_key_rx(), eapol_rx(), ecm_in_complete(), ecm_intr_complete(), efab_free_resources(), efab_receive(), efi_download_deliver_iob(), efi_local_step(), efi_pxe_udp_close(), efi_pxe_udp_deliver(), efi_pxe_udp_read(), efi_pxe_udp_write(), efi_snp_flush(), efi_snp_receive(), efi_snp_transmit(), efi_usb_async_complete(), efi_usb_sync_transfer(), efx_hunt_close(), ena_empty_rx(), eoib_heartbeat_rx(), eth_slow_marker_rx(), eth_slow_rx(), fc_els_rx(), fc_ns_query_deliver(), fc_port_deliver(), fc_xchg_rx(), fc_xchg_tx(), fcoe_deliver(), fcoe_fip_rx(), fcoe_rx(), fcpcmd_recv_rddata(), fcpcmd_recv_rsp(), fcpcmd_recv_unknown(), fcpcmd_recv_xfer_rdy(), fragment_expired(), fragment_reassemble(), free_rx_iob(), free_tls(), ftp_control_deliver(), gdbudp_recv(), http_conn_deliver(), http_content_deliver(), http_tx_request(), hunt_mcdi_fini(), ib_cmrc_complete_recv(), ib_cmrc_complete_send(), ib_cmrc_xfer_deliver(), ib_complete_recv(), ib_complete_send(), ib_mi_complete_recv(), ib_mi_send(), ib_refill_recv(), icmp_rx_echo_reply(), icmp_rx_echo_request(), icmp_tx_echo_request(), icmpv4_rx(), icmpv6_rx(), icplus_close(), ifec_free(), igbvf_free_rx_resources(), imux_in_complete(), imux_out_complete(), imux_rx_tcp(), imux_tx(), iob_concatenate(), ipair_deliver(), iphone_in_complete(), ipv4_rx(), ipv4_tx(), ipv6_rx(), ipv6_tx(), iscsi_socket_deliver(), jme_free_rx_buf(), legacy_poll(), lldp_rx(), loopback_wait(), lotest_flush(), lotest_rx(), myri10ge_net_close(), myri10ge_net_open(), myson_close(), natsemi_close(), ncm_intr_complete(), ndp_rx_neighbour(), ndp_rx_router_advertisement(), 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_discard(), net_poll(), net_rx(), netdev_rx_err(), netdev_tx_err(), netfront_close(), netfront_discard(), netvsc_recv_data(), nfs_deliver(), nfs_mount_deliver(), nfs_pm_deliver(), nii_close(), ntp_deliver(), nv_free_rxtx_resources(), pcnet32_free_rx_resources(), peerblk_deliver(), peerblk_raw_rx(), peerblk_retrieval_rx(), peerdisc_socket_rx(), phantom_close(), ping_rx(), pinger_deliver(), posix_file_free(), posix_file_xfer_deliver(), pxe_tftp_xfer_deliver(), pxe_udp_deliver(), pxe_udp_discard(), pxenv_udp_close(), pxenv_udp_read(), pxenv_undi_isr(), pxenv_undi_transmit(), rarp_rx(), read(), rhine_close(), rndis_rx_initialise(), rndis_rx_query_oid(), rndis_rx_set_oid(), rndis_rx_status(), rndis_tx_complete_err(), rndis_tx_halt(), rndis_tx_initialise(), rndis_tx_oid(), rtl818x_free_rx_ring(), sis190_free(), skge_rx_clean(), sky2_rx_clean(), slam_mc_socket_deliver(), slam_socket_deliver(), slam_tx_nack(), smsc75xx_in_complete(), smsc95xx_in_complete(), smscusb_intr_complete(), snpnet_close(), srpdev_deliver(), stp_rx(), tcp_close(), tcp_discard(), tcp_process_tx_queue(), tcp_rx(), tcp_rx_data(), tcp_rx_enqueue(), tcpip_rx(), tcpip_tx(), tftp_rx(), tftp_rx_data(), tg3_rx_iob_free(), tkip_decrypt(), tls_cipherstream_deliver(), tls_new_record(), tls_newdata_process_header(), tls_plainstream_deliver(), tls_send_record(), txnic_destroy_rq(), udp_rx(), udp_tx(), unregister_usb(), usb_control(), usb_flush(), usbblk_in_complete(), usbblk_out_command(), usbblk_out_complete(), usbblk_out_data(), velocity_close(), vlan_rx(), vmbus_xfer_page_iobufs(), vxge_hw_ring_replenish(), wep_decrypt(), xcm_deliver(), xfer_deliver(), and xferbuf_deliver().

◆ alloc_rx_iob()

struct io_buffer* __malloc alloc_rx_iob ( size_t  len,
struct dma_device dma 
)

Allocate and map I/O buffer for receive DMA.

Parameters
lenLength of I/O buffer
dmaDMA device
Return values
iobufI/O buffer, or NULL on error

Definition at line 188 of file iobuf.c.

188  {
189  struct io_buffer *iobuf;
190  int rc;
191 
192  /* Allocate I/O buffer */
193  iobuf = alloc_iob ( len );
194  if ( ! iobuf )
195  goto err_alloc;
196 
197  /* Map I/O buffer */
198  if ( ( rc = iob_map_rx ( iobuf, dma ) ) != 0 )
199  goto err_map;
200 
201  return iobuf;
202 
203  iob_unmap ( iobuf );
204  err_map:
205  free_iob ( iobuf );
206  err_alloc:
207  return NULL;
208 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:153
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:131
static __always_inline void iob_unmap(struct io_buffer *iobuf)
Unmap I/O buffer for DMA.
Definition: iobuf.h:279
ring len
Length.
Definition: dwmac.h:231
static __always_inline int iob_map_rx(struct io_buffer *iobuf, struct dma_device *dma)
Map empty I/O buffer for receive DMA.
Definition: iobuf.h:256
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
A persistent I/O buffer.
Definition: iobuf.h:38

References alloc_iob(), dma(), free_iob(), iob_map_rx(), iob_unmap(), len, NULL, and rc.

Referenced by atl_rx_ring_fill(), bnxt_alloc_rx_iob(), cgem_refill_rx(), dwmac_refill_rx(), intel_refill_rx(), intelxl_refill_rx(), rdc_refill_rx(), realtek_refill_rx(), and virtnet_refill_rx_virtqueue().

◆ free_rx_iob()

void free_rx_iob ( struct io_buffer iobuf)

Unmap and free I/O buffer for receive DMA.

Parameters
iobufI/O buffer

Definition at line 215 of file iobuf.c.

215  {
216 
217  /* Unmap I/O buffer */
218  iob_unmap ( iobuf );
219 
220  /* Free I/O buffer */
221  free_iob ( iobuf );
222 }
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:153
static __always_inline void iob_unmap(struct io_buffer *iobuf)
Unmap I/O buffer for DMA.
Definition: iobuf.h:279

References free_iob(), and iob_unmap().

Referenced by bnxt_free_rx_iob(), cgem_close(), dwmac_close(), intel_empty_rx(), intelxl_empty_rx(), rdc_close(), realtek_close(), and virtnet_close().

◆ iob_pad()

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 50 of file iobpad.c.

50  {
51  void *data;
52  size_t len;
53  size_t headroom;
54  signed int pad_len;
55 
56  assert ( min_len <= IOB_ZLEN );
57 
58  /* Move packet data to start of I/O buffer. This will both
59  * align the data (since I/O buffers are aligned to
60  * IOB_ALIGN) and give us sufficient space for the
61  * zero-padding
62  */
63  data = iobuf->data;
64  len = iob_len ( iobuf );
65  headroom = iob_headroom ( iobuf );
66  iob_push ( iobuf, headroom );
67  memmove ( iobuf->data, data, len );
68  iob_unput ( iobuf, headroom );
69 
70  /* Pad to minimum packet length */
71  pad_len = ( min_len - iob_len ( iobuf ) );
72  if ( pad_len > 0 )
73  memset ( iob_put ( iobuf, pad_len ), 0, pad_len );
74 }
#define iob_put(iobuf, len)
Definition: iobuf.h:125
#define iob_push(iobuf, len)
Definition: iobuf.h:89
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
ring len
Length.
Definition: dwmac.h:231
#define iob_unput(iobuf, len)
Definition: iobuf.h:140
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:160
void * memmove(void *dest, const void *src, size_t len) __nonnull
long pad_len
Definition: bigint.h:31
static size_t iob_headroom(struct io_buffer *iobuf)
Calculate available space at start of an I/O buffer.
Definition: iobuf.h:170
#define IOB_ZLEN
Minimum I/O buffer length and alignment.
Definition: iobuf.h:29
void * data
Start of data.
Definition: iobuf.h:53
uint8_t data[48]
Additional event data.
Definition: ena.h:22
void * memset(void *dest, int character, size_t len) __nonnull

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

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

◆ iob_ensure_headroom()

int iob_ensure_headroom ( struct io_buffer iobuf,
size_t  len 
)

Ensure I/O buffer has sufficient headroom.

Parameters
iobufI/O buffer
lenRequired 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 235 of file iobuf.c.

235  {
236 
237  if ( iob_headroom ( iobuf ) >= len )
238  return 0;
239  return -ENOBUFS;
240 }
ring len
Length.
Definition: dwmac.h:231
static size_t iob_headroom(struct io_buffer *iobuf)
Calculate available space at start of an I/O buffer.
Definition: iobuf.h:170
#define ENOBUFS
No buffer space available.
Definition: errno.h:499

References ENOBUFS, iob_headroom(), and len.

Referenced by axge_out_transmit(), dm96xx_out_transmit(), efi_pxe_udp_deliver(), ncm_out_transmit(), pxe_udp_deliver(), smsc75xx_out_transmit(), smsc95xx_out_transmit(), and udp_tx().

◆ iob_concatenate()

struct io_buffer* iob_concatenate ( struct list_head list)

Concatenate I/O buffers into a single buffer.

Parameters
listList of I/O buffers
Return values
iobufConcatenated I/O buffer, or NULL on allocation failure

After a successful concatenation, the list will be empty.

Definition at line 250 of file iobuf.c.

250  {
251  struct io_buffer *iobuf;
252  struct io_buffer *tmp;
253  struct io_buffer *concatenated;
254  size_t len = 0;
255 
256  /* If the list contains only a single entry, avoid an
257  * unnecessary additional allocation.
258  */
259  if ( list_is_singular ( list ) ) {
260  iobuf = list_first_entry ( list, struct io_buffer, list );
261  INIT_LIST_HEAD ( list );
262  return iobuf;
263  }
264 
265  /* Calculate total length */
266  list_for_each_entry ( iobuf, list, list )
267  len += iob_len ( iobuf );
268 
269  /* Allocate new I/O buffer */
270  concatenated = alloc_iob_raw ( len, IOB_ZLEN, 0 );
271  if ( ! concatenated )
272  return NULL;
273 
274  /* Move data to new I/O buffer */
275  list_for_each_entry_safe ( iobuf, tmp, list, list ) {
276  list_del ( &iobuf->list );
277  memcpy ( iob_put ( concatenated, iob_len ( iobuf ) ),
278  iobuf->data, iob_len ( iobuf ) );
279  free_iob ( iobuf );
280  }
281 
282  return concatenated;
283 }
#define iob_put(iobuf, len)
Definition: iobuf.h:125
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:153
struct io_buffer * alloc_iob_raw(size_t len, size_t align, size_t offset)
Allocate I/O buffer with specified alignment and offset.
Definition: iobuf.c:49
unsigned long tmp
Definition: linux_pci.h:65
#define list_first_entry(list, type, member)
Get the container of the first entry in a list.
Definition: list.h:334
#define list_del(list)
Delete an entry from a list.
Definition: list.h:120
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:432
ring len
Length.
Definition: dwmac.h:231
#define list_for_each_entry_safe(pos, tmp, head, member)
Iterate over entries in a list, safe against deletion of the current entry.
Definition: list.h:459
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:160
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:46
#define list_is_singular(list)
Test whether a list has just one entry.
Definition: list.h:150
struct list_head list
List of which this buffer is a member.
Definition: iobuf.h:45
#define IOB_ZLEN
Minimum I/O buffer length and alignment.
Definition: iobuf.h:29
void * data
Start of data.
Definition: iobuf.h:53
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
A persistent I/O buffer.
Definition: iobuf.h:38

References alloc_iob_raw(), io_buffer::data, free_iob(), INIT_LIST_HEAD, iob_len(), iob_put, IOB_ZLEN, len, io_buffer::list, list_del, list_first_entry, list_for_each_entry, list_for_each_entry_safe, list_is_singular, memcpy(), NULL, and tmp.

Referenced by netfront_poll_rx(), and tls_new_record().

◆ iob_split()

struct io_buffer* iob_split ( struct io_buffer iobuf,
size_t  len 
)

Split I/O buffer.

Parameters
iobufI/O buffer
lenLength to split into a new I/O buffer
Return values
splitNew I/O buffer, or NULL on allocation failure

Split the first len bytes of the existing I/O buffer into a separate I/O buffer. The resulting buffers are likely to have no headroom or tailroom.

If this call fails, then the original buffer will be unmodified.

Definition at line 298 of file iobuf.c.

298  {
299  struct io_buffer *split;
300 
301  /* Sanity checks */
302  assert ( len <= iob_len ( iobuf ) );
303 
304  /* Allocate new I/O buffer */
305  split = alloc_iob ( len );
306  if ( ! split )
307  return NULL;
308 
309  /* Copy in data */
310  memcpy ( iob_put ( split, len ), iobuf->data, len );
311  iob_pull ( iobuf, len );
312  return split;
313 }
#define iob_pull(iobuf, len)
Definition: iobuf.h:107
#define iob_put(iobuf, len)
Definition: iobuf.h:125
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:131
void * memcpy(void *dest, const void *src, size_t len) __nonnull
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
ring len
Length.
Definition: dwmac.h:231
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:160
void * data
Start of data.
Definition: iobuf.h:53
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
A persistent I/O buffer.
Definition: iobuf.h:38

References alloc_iob(), assert(), io_buffer::data, iob_len(), iob_pull, iob_put, len, memcpy(), and NULL.