Tweaked virtio device initialization to conform to more stricter enforcement of protocol on firecracker side
Makes OSv boot on newest firecracker. Signed-off-by: Waldemar Kozaczuk <[email protected]> --- drivers/virtio-blk.cc | 5 ++++- drivers/virtio-net.cc | 21 ++++++++++++++------- drivers/virtio-net.hh | 7 +++++++ drivers/virtio2.cc | 5 +++-- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/drivers/virtio-blk.cc b/drivers/virtio-blk.cc index 3784c453..148b036f 100644 --- a/drivers/virtio-blk.cc +++ b/drivers/virtio-blk.cc @@ -122,6 +122,9 @@ blk::blk(mmio_device& _dev) setup_features(); read_config(); + // Generic init of virtqueues + probe_virt_queues(); + //register the single irq callback for the block sched::thread* t = sched::thread::make([this] { this->req_done(); }, sched::thread::attr().name("virtio-blk")); @@ -318,7 +321,7 @@ hw_driver* blk::probe(hw_device* dev) //once we have a virtio_device class if (auto mmio_dev = dynamic_cast<mmio_device*>(dev)) { if (mmio_dev->get_id() == hw_device_id(0x0, VIRTIO_ID_BLOCK)) { - debug_early("virtio-blk::probe() -> found virtio-mmio device ...\n"); + //debug_early("virtio-blk::probe() -> found virtio-mmio device ...\n"); return new blk(*mmio_dev); } } diff --git a/drivers/virtio-net.cc b/drivers/virtio-net.cc index 9ad5d48a..3ae9ab9e 100644 --- a/drivers/virtio-net.cc +++ b/drivers/virtio-net.cc @@ -224,12 +224,26 @@ bool net::ack_irq() return false; } +void net::pre_init() +{ + _driver_name = "virtio-net"; + virtio_i("VIRTIO NET INSTANCE"); + _id = _instance++; + + setup_features(); + read_config(); + + // Generic init of virtqueues + probe_virt_queues(); +} + //TODO: For now this driver is hardcoded to expect mmio_device // but eventually we could introduce some sort of virtio_device // interface class that pci_device and mmio_device would implement/extend // from. net::net(mmio_device& dev) : virtio_mmio_driver(dev), + _bla(this), _rxq(get_virt_queue(0), [this] { this->receiver(); }), _txq(this, get_virt_queue(1)) { @@ -237,13 +251,6 @@ net::net(mmio_device& dev) poll_task->set_priority(sched::thread::priority_infinity); - _driver_name = "virtio-net"; - virtio_i("VIRTIO NET INSTANCE"); - _id = _instance++; - - setup_features(); - read_config(); - //TODO: Legacy vs non-legacy -> the non-legacy header includes one more field _hdr_size = sizeof(net_hdr_mrg_rxbuf); diff --git a/drivers/virtio-net.hh b/drivers/virtio-net.hh index 6edca97a..e9c9c667 100644 --- a/drivers/virtio-net.hh +++ b/drivers/virtio-net.hh @@ -208,6 +208,7 @@ public: explicit net(mmio_device& dev); virtual ~net(); + void pre_init(); virtual std::string get_name() const { return _driver_name; } void read_config(); @@ -301,6 +302,12 @@ private: wakeup_stats tx_wakeup_stats; }; + struct bla { + bla(virtio::net *_net) { + _net->pre_init(); + } + } _bla; + /* Single Rx queue object */ struct rxq { rxq(vring* vq, std::function<void ()> poll_func) diff --git a/drivers/virtio2.cc b/drivers/virtio2.cc index 09410888..cb4f1253 100644 --- a/drivers/virtio2.cc +++ b/drivers/virtio2.cc @@ -44,10 +44,11 @@ virtio_mmio_driver::virtio_mmio_driver(mmio_device& dev) reset_host_side(); // Acknowledge device - add_dev_status(VIRTIO_CONFIG_S_ACKNOWLEDGE | VIRTIO_CONFIG_S_DRIVER); + add_dev_status(VIRTIO_CONFIG_S_ACKNOWLEDGE); + add_dev_status(VIRTIO_CONFIG_S_DRIVER); // Generic init of virtqueues - probe_virt_queues(); + //probe_virt_queues(); } virtio_mmio_driver::~virtio_mmio_driver() -- 2.19.1 -- You received this message because you are subscribed to the Google Groups "OSv Development" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
