From 0ba911bf126e29142bb6979b13b65b73c13e71c9 Mon Sep 17 00:00:00 2001 From: Stefan Kalkowski Date: Tue, 26 Apr 2022 11:13:02 +0200 Subject: [PATCH] virtio_nic_drv: remove deprecated server mode Ref genodelabs/genode#3961 --- .../raw/drivers_nic-virt_qemu/drivers.config | 1 - repos/os/src/drivers/nic/virtio/component.h | 207 +----------------- repos/os/src/drivers/nic/virtio/config.xsd | 2 - .../os/src/drivers/nic/virtio/mmio_device.cc | 46 +--- repos/os/src/drivers/nic/virtio/pci_device.cc | 41 +--- 5 files changed, 24 insertions(+), 273 deletions(-) diff --git a/repos/os/recipes/raw/drivers_nic-virt_qemu/drivers.config b/repos/os/recipes/raw/drivers_nic-virt_qemu/drivers.config index 193714a6fd..f0d2288642 100644 --- a/repos/os/recipes/raw/drivers_nic-virt_qemu/drivers.config +++ b/repos/os/recipes/raw/drivers_nic-virt_qemu/drivers.config @@ -37,7 +37,6 @@ - diff --git a/repos/os/src/drivers/nic/virtio/component.h b/repos/os/src/drivers/nic/virtio/component.h index ab486eddc2..5a7d5300c2 100644 --- a/repos/os/src/drivers/nic/virtio/component.h +++ b/repos/os/src/drivers/nic/virtio/component.h @@ -17,8 +17,7 @@ #include #include #include -#include -#include +#include #include #include #include @@ -30,9 +29,8 @@ namespace Virtio_nic { using namespace Genode; struct Main; - class Root; - class Session_component; class Device; + class Uplink_client; } @@ -422,205 +420,8 @@ class Virtio_nic::Device : Noncopyable }; -class Virtio_nic::Session_component : public Nic::Session_component, - public Device -{ - private: - - typedef Genode::Signal_handler Signal_handler; - - Signal_handler _irq_handler; - bool _link_up = false; - - void _handle_irq() - { - drv_handle_irq([&] () { - - _receive(); - - }, [&] () { - - if (link_state() == _link_up) { - return; - } - _link_up = !_link_up; - if (verbose()) - log("Link status changed: ", - (_link_up ? "on-line" : "off-line")); - - _link_state_changed(); - }); - } - - bool _send() - { - if (!_tx.sink()->ready_to_ack()) - return false; - - if (!_tx.sink()->packet_avail()) - return false; - - auto packet = _tx.sink()->get_packet(); - if (!packet.size() || !_tx.sink()->packet_valid(packet)) { - warning("Invalid tx packet"); - return true; - } - - if (link_state()) { - char const *data = _tx.sink()->packet_content(packet); - if (!tx_vq_write_pkt(data, packet.size())) { - warning("Failed to push packet into tx VirtIO queue!"); - return false; - } - } - - _tx.sink()->acknowledge_packet(packet); - return true; - } - - void _receive() - { - rx_vq_read_pkt( - [&] (Virtio_net_header const &, - char const *data, - size_t size) - { - if (!_rx.source()->ready_to_submit()) { - Genode::warning("Not ready to submit!"); - return false; - } - - try { - auto p = _rx.source()->alloc_packet(size); - char *dst = _rx.source()->packet_content(p); - Genode::memcpy(dst, data, size); - _rx.source()->submit_packet(p); - } catch (Session::Rx::Source::Packet_alloc_failed) { - Genode::warning("Packet alloc failed!"); - return false; - } - - return true; - }); - } - - void _handle_packet_stream() override - { - while (_rx.source()->ack_avail()) - _rx.source()->release_packet(_rx.source()->get_acked_packet()); - - rx_vq_ack_pkts(); - - bool sent_packets = false; - while (_send()) - sent_packets = true; - - if (sent_packets) { - _finish_sent_packets(); - } - } - - public: - - bool link_state() override - { - return read_link_state(); - } - - Nic::Mac_address mac_address() override - { - return read_mac_address(); - } - - Session_component(Genode::Env &env, - Genode::Allocator &rx_block_md_alloc, - Virtio::Device &device, - Platform::Connection &plat, - Genode::Xml_node const &xml, - Genode::size_t const tx_buf_size, - Genode::size_t const rx_buf_size) - : - Nic::Session_component { tx_buf_size, rx_buf_size, Genode::CACHED, - rx_block_md_alloc, env }, - Device { env, device, plat, xml }, - _irq_handler { env.ep(), *this, &Session_component::_handle_irq }, - _link_up { link_state() } - { - Virtio_nic::Device::init(_irq_handler); - _link_state_changed(); - if (verbose()) - Genode::log("Mac address: ", mac_address()); - } -}; - - -class Virtio_nic::Root : public Genode::Root_component -{ - private: - - struct Device_not_found : Genode::Exception { }; - - /* - * Noncopyable - */ - Root(Root const &) = delete; - Root &operator = (Root const &) = delete; - - Genode::Env &_env; - Virtio::Device &_device; - Platform::Connection &_plat; - Attached_rom_dataspace &_config_rom; - - Session_component *_create_session(const char *args) override - { - size_t ram_quota = Arg_string::find_arg(args, "ram_quota" ).ulong_value(0); - size_t tx_buf_size = Arg_string::find_arg(args, "tx_buf_size").ulong_value(0); - size_t rx_buf_size = Arg_string::find_arg(args, "rx_buf_size").ulong_value(0); - - /* - * Check if donated ram quota suffices for both communication - * buffers and check for overflow - */ - if (tx_buf_size + rx_buf_size < tx_buf_size || - tx_buf_size + rx_buf_size > ram_quota) { - error("insufficient 'ram_quota', got ", ram_quota, ", " - "need ", tx_buf_size + rx_buf_size); - throw Genode::Insufficient_ram_quota(); - } - - try { - return new (md_alloc()) Session_component( - _env, *md_alloc(), _device, _plat, _config_rom.xml(), - tx_buf_size, rx_buf_size); - } catch (...) { throw Service_denied(); } - } - - public: - - Root(Env &env, - Allocator &md_alloc, - Virtio::Device &device, - Platform::Connection &plat, - Attached_rom_dataspace &config_rom) - : - Root_component { env.ep(), md_alloc }, - _env { env }, - _device { device }, - _plat { plat }, - _config_rom { config_rom } - { } -}; - - -namespace Genode { - - class Uplink_client; -} - - -class Genode::Uplink_client : public Virtio_nic::Device, - public Uplink_client_base +class Virtio_nic::Uplink_client : public Virtio_nic::Device, + public Uplink_client_base { private: diff --git a/repos/os/src/drivers/nic/virtio/config.xsd b/repos/os/src/drivers/nic/virtio/config.xsd index acbf80129c..9deae92320 100644 --- a/repos/os/src/drivers/nic/virtio/config.xsd +++ b/repos/os/src/drivers/nic/virtio/config.xsd @@ -4,7 +4,6 @@ - @@ -20,7 +19,6 @@ - diff --git a/repos/os/src/drivers/nic/virtio/mmio_device.cc b/repos/os/src/drivers/nic/virtio/mmio_device.cc index 028cf60a4b..a0f3ceba40 100644 --- a/repos/os/src/drivers/nic/virtio/mmio_device.cc +++ b/repos/os/src/drivers/nic/virtio/mmio_device.cc @@ -17,9 +17,6 @@ #include #include -/* NIC driver includes */ -#include - /* local includes */ #include "component.h" @@ -32,39 +29,18 @@ struct Virtio_mmio_nic::Main { struct Device_not_found : Genode::Exception { }; - Env & env; - Heap heap { env.ram(), env.rm() }; - Platform::Connection platform { env }; - Platform::Device platform_device { platform, - Platform::Device::Type { "nic" } }; - Virtio::Device device { platform_device }; - Attached_rom_dataspace config_rom { env, "config" }; - Constructible root { }; - Constructible uplink_client { }; + Env & env; + Heap heap { env.ram(), env.rm() }; + Platform::Connection platform { env }; + Platform::Device platform_device { platform, + Platform::Device::Type { "nic" } }; + Virtio::Device device { platform_device }; + Attached_rom_dataspace config_rom { env, "config" }; + Virtio_nic::Uplink_client uplink_client { env, heap, device, + platform, config_rom.xml() }; - Main(Env &env) - try : env(env) - { - log("--- VirtIO MMIO NIC driver started ---"); - - Nic_driver_mode const mode { - read_nic_driver_mode(config_rom.xml()) }; - - switch (mode) { - case Nic_driver_mode::NIC_SERVER: - - root.construct(env, heap, device, platform, config_rom); - env.parent().announce(env.ep().manage(*root)); - break; - - case Nic_driver_mode::UPLINK_CLIENT: - - uplink_client.construct(env, heap, device, platform, - config_rom.xml()); - break; - } - } - catch (...) { env.parent().exit(-1); } + Main(Env & env) : env(env) { + log("--- VirtIO MMIO NIC driver started ---"); } }; diff --git a/repos/os/src/drivers/nic/virtio/pci_device.cc b/repos/os/src/drivers/nic/virtio/pci_device.cc index f0b5570dcb..1b5aa9e4d4 100644 --- a/repos/os/src/drivers/nic/virtio/pci_device.cc +++ b/repos/os/src/drivers/nic/virtio/pci_device.cc @@ -17,9 +17,6 @@ #include #include -/* NIC driver includes */ -#include - /* local includes */ #include "component.h" @@ -32,14 +29,14 @@ struct Virtio_pci_nic::Main { struct Device_not_found : Genode::Exception { }; - Genode::Env &env; - Genode::Heap heap { env.ram(), env.rm() }; - Platform::Connection pci { env }; - Platform::Device_client platform_device; - Virtio::Device virtio_device { env, platform_device }; - Attached_rom_dataspace config_rom { env, "config" }; - Genode::Constructible root { }; - Genode::Constructible uplink_client { }; + Genode::Env & env; + Genode::Heap heap { env.ram(), env.rm() }; + Platform::Connection pci { env }; + Platform::Device_client platform_device; + Virtio::Device virtio_device { env, platform_device }; + Attached_rom_dataspace config_rom { env, "config" }; + Virtio_nic::Uplink_client uplink_client { env, heap, virtio_device, + pci, config_rom.xml() }; Platform::Device_capability find_platform_device() { @@ -52,30 +49,10 @@ struct Virtio_pci_nic::Main } Main(Env &env) - try : env(env), platform_device(find_platform_device()) + : env(env), platform_device(find_platform_device()) { log("--- VirtIO PCI driver started ---"); - - Nic_driver_mode const mode { - read_nic_driver_mode(config_rom.xml()) }; - - switch (mode) { - case Nic_driver_mode::NIC_SERVER: - - root.construct(env, heap, virtio_device, pci, config_rom); - - env.parent().announce(env.ep().manage(*root)); - break; - - case Nic_driver_mode::UPLINK_CLIENT: - - uplink_client.construct( - env, heap, virtio_device, pci, config_rom.xml()); - - break; - } } - catch (...) { env.parent().exit(-1); } };