![]() |
L4Re Operating System Framework
Interface and Usage Documentation
|
Simple class for accessing a virtio net device. More...
#include <virtio-net>
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. | |
| int | bind_rx_notification_irq (L4::Cap< L4::Thread > thread, l4_umword_t label) |
| Bind the rx notification IRQ to the specified thread. | |
| Packet & | rx_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. | |
Simple class for accessing a virtio net device.
Definition at line 30 of file virtio-net.
|
inline |
Bind the rx notification IRQ to the specified thread.
| thread | Thread to bind the notification IRQ to. |
| label | Label to assign to the IRQ. |
Definition at line 169 of file virtio-net.
References l4_error().
|
inline |
Free an RX descriptor number to make it available for the RX queue again.
| descno | Descriptor number in the virtio queue. |
Usually queue_rx() should be called afterwards to queue the freed descriptor(s).
Definition at line 230 of file virtio-net.
|
inline |
Return a reference to the RX packet buffer of the specified descriptor, e.g.
from wait_rx().
| descno | Descriptor number in the virtio queue. |
Definition at line 180 of file virtio-net.
|
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().
|
inline |
Establish a connection to the device and set up shared memory.
| srvcap | IPC 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 L4Re::chkcap(), L4Re::chksys(), L4virtio::Driver::Device::config_queue(), L4Re::Mem_alloc::Continuous, L4virtio::Driver::Device::driver_acknowledge(), L4virtio::Driver::Device::driver_connect(), L4Re::Env::env(), L4_EINVAL, L4_ENODEV, l4_error(), L4_PAGESHIFT, l4_round_size(), L4VIRTIO_FEATURE_VERSION_1, L4VIRTIO_ID_NET, l4virtio_set_feature(), L4::Ipc::make_cap_rw(), L4Re::Util::make_unique_cap(), L4Re::Mem_alloc::Pinned, L4virtio::Driver::Device::register_ds(), L4Re::Rm::F::RW, rx_queue_size(), L4Re::Rm::F::Search_addr, and tx_queue_size().
|
inline |
Attempt to allocate a descriptor in the TX queue and transmit the packet, after calling the prepare callback.
| prepare | Function that fills the packet with data, should return the length of the data copied to the packet. |
| true | The packet was queued. |
| false | TX 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 260 of file virtio-net.
References L4virtio::Driver::Device::send().
|
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().
|
inline |
Block until a network packet has been received from the device and return the descriptor number.
| [out] | len | (optional) Length of valid data in RX 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 202 of file virtio-net.
References L4Re::chksys().