L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
L4virtio::Driver::Virtio_net_device Class Reference

Simple class for accessing a virtio net device. More...

#include <virtio-net>

+ Inheritance diagram for L4virtio::Driver::Virtio_net_device:
+ Collaboration diagram for L4virtio::Driver::Virtio_net_device:

Data Structures

struct  Packet
 Structure for a network packet (header including data) with maximum size, assuming that no extra features have been negotiated. More...
 

Public Member Functions

int rx_queue_size () const
 Return the maximum receive queue size allowed by the device.
 
int tx_queue_size () const
 Return the maximum transmit queue size allowed by the device.
 
void setup_device (L4::Cap< L4virtio::Device > srvcap)
 Establish a connection to the device and set up shared memory.
 
l4virtio_net_config_t const & device_config () const
 Return a reference to the device configuration.
 
Packetrx_pkt (l4_uint16_t descno)
 Return a reference to the RX packet buffer of the specified descriptor, e.g.
 
l4_uint16_t wait_rx (l4_uint32_t *len=nullptr)
 Block until a network packet has been received from the device and return the descriptor number.
 
void finish_rx (l4_uint16_t descno)
 Free an RX descriptor number to make it available for the RX queue again.
 
void queue_rx ()
 Queue new available descriptors in the RX queue.
 
bool tx (std::function< l4_uint32_t(Packet &)> prepare)
 Attempt to allocate a descriptor in the TX queue and transmit the packet, after calling the prepare callback.
 
- Public Member Functions inherited from L4virtio::Driver::Device
void driver_connect (L4::Cap< L4virtio::Device > srvcap, bool manage_notify=true)
 Contacts the device and starts the initial handshake.
 
int bind_notification_irq (unsigned index, L4::Cap< L4::Triggerable > irq) const
 Register a triggerable to receive notifications from the device.
 
bool fail_state () const
 Return true if the device is in a fail state.
 
bool feature_negotiated (unsigned int feat) const
 Check if a particular feature bit was negotiated with the device.
 
int driver_acknowledge ()
 Finalize handshake with the device.
 
int register_ds (L4::Cap< L4Re::Dataspace > ds, l4_umword_t offset, l4_umword_t size, l4_uint64_t *devaddr)
 Share a dataspace with the device.
 
int config_queue (int num, unsigned size, l4_uint64_t desc_addr, l4_uint64_t avail_addr, l4_uint64_t used_addr)
 Send the virtqueue configuration to the device.
 
int max_queue_size (int num) const
 Maximum queue size allowed by the device.
 
int send_and_wait (Virtqueue &queue, l4_uint16_t descno)
 Send a request to the device and wait for it to be processed.
 
int wait (int index) const
 Wait for a notification from the device.
 
int wait_for_next_used (Virtqueue &queue, l4_uint32_t *len=nullptr) const
 Wait for the next item to arrive in the used queue and return it.
 
void send (Virtqueue &queue, l4_uint16_t descno)
 Send a request to the device.
 

Detailed Description

Simple class for accessing a virtio net device.

Definition at line 30 of file virtio-net.

Member Function Documentation

◆ finish_rx()

void L4virtio::Driver::Virtio_net_device::finish_rx ( l4_uint16_t  descno)
inline

Free an RX descriptor number to make it available for the RX queue again.

Parameters
descnoDescriptor number in the virtio queue.

Usually queue_rx() should be called afterwards to queue the freed descriptor(s).

Definition at line 194 of file virtio-net.

References L4virtio::Driver::Virtqueue::free_descriptor().

+ Here is the call graph for this function:

◆ rx_pkt()

Packet & L4virtio::Driver::Virtio_net_device::rx_pkt ( l4_uint16_t  descno)
inline

Return a reference to the RX packet buffer of the specified descriptor, e.g.

from wait_rx().

Parameters
descnoDescriptor number in the virtio queue.

Definition at line 158 of file virtio-net.

References L4virtio::Virtqueue::num().

+ Here is the call graph for this function:

◆ rx_queue_size()

int L4virtio::Driver::Virtio_net_device::rx_queue_size ( ) const
inline

Return the maximum receive queue size allowed by the device.

wait_rx() will return a descriptor number that is smaller than this size.

Definition at line 47 of file virtio-net.

References L4virtio::Driver::Device::max_queue_size().

Referenced by setup_device().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setup_device()

void L4virtio::Driver::Virtio_net_device::setup_device ( L4::Cap< L4virtio::Device srvcap)
inline

Establish a connection to the device and set up shared memory.

Parameters
srvcapIPC capability of the channel to the server.

This function starts a handshake with the device and sets up the virtqueues for communication and the additional data structures for the network device.

Definition at line 66 of file virtio-net.

References L4virtio::Virtqueue::Desc::addr, L4virtio::Virtqueue::avail_offset(), L4Re::chkcap(), L4Re::chksys(), L4virtio::Driver::Device::config_queue(), L4Re::Mem_alloc::Continuous, L4virtio::Driver::Virtqueue::desc(), L4virtio::Driver::Device::driver_acknowledge(), L4virtio::Driver::Device::driver_connect(), L4Re::Env::env(), L4Re::Rm::Unique_region< T >::get(), L4virtio::Driver::Virtqueue::init_queue(), L4_EINVAL, L4_ENODEV, L4_PAGESHIFT, l4_round_size(), L4VIRTIO_FEATURE_VERSION_1, L4VIRTIO_ID_NET, l4virtio_set_feature(), L4::Ipc::make_cap_rw(), L4Re::Mem_alloc::Pinned, L4virtio::Driver::Device::register_ds(), L4Re::Rm::F::RW, rx_queue_size(), L4Re::Rm::F::Search_addr, L4virtio::Virtqueue::total_size(), tx_queue_size(), and L4virtio::Virtqueue::used_offset().

+ Here is the call graph for this function:

◆ tx()

bool L4virtio::Driver::Virtio_net_device::tx ( std::function< l4_uint32_t(Packet &)>  prepare)
inline

Attempt to allocate a descriptor in the TX queue and transmit the packet, after calling the prepare callback.

Parameters
prepareFunction that fills the packet with data, should return the length of the data copied to the packet.
Return values
trueThe packet was queued.
falseTX queue is full.

The prepare callback should fill the packet with data and return the length of the packet data (without the size of the virtio-net packet header).

Definition at line 224 of file virtio-net.

References L4virtio::Driver::Virtqueue::alloc_descriptor(), L4virtio::Driver::Virtqueue::desc(), L4virtio::Virtqueue::Desc::len, and L4virtio::Driver::Device::send().

+ Here is the call graph for this function:

◆ tx_queue_size()

int L4virtio::Driver::Virtio_net_device::tx_queue_size ( ) const
inline

Return the maximum transmit queue size allowed by the device.

tx() will fail if the amount of queued packets exceeds this size.

Definition at line 54 of file virtio-net.

References L4virtio::Driver::Device::max_queue_size().

Referenced by setup_device().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ wait_rx()

l4_uint16_t L4virtio::Driver::Virtio_net_device::wait_rx ( l4_uint32_t len = nullptr)
inline

Block until a network packet has been received from the device and return the descriptor number.

Parameters
[out]len(optional) Length of valid data in RX packet.
Returns
Descriptor number of received packet.

The packet data can be obtained with rx_pkt(). finish_rx() should be called after the packet buffer can be returned to the RX queue.

Definition at line 176 of file virtio-net.

References L4Re::chksys(), and L4virtio::Driver::Device::wait_for_next_used().

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: