mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 20:37:34 +00:00
Kernel: Add an initial implementation of virtio-net driver
It can be exercised by setting SERENITY_ETHERNET_DEVICE_TYPE=virtio-net-pci.
This commit is contained in:
parent
b00a23b0b6
commit
6cdb1f0415
5 changed files with 347 additions and 0 deletions
60
Kernel/Net/VirtIO/VirtIONetworkAdapter.h
Normal file
60
Kernel/Net/VirtIO/VirtIONetworkAdapter.h
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Kirill Nikolaev <cyril7@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Kernel/Bus/VirtIO/Device.h>
|
||||
#include <Kernel/Memory/RingBuffer.h>
|
||||
#include <Kernel/Net/NetworkAdapter.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class VirtIONetworkAdapter
|
||||
: public VirtIO::Device
|
||||
, public NetworkAdapter {
|
||||
|
||||
public:
|
||||
static ErrorOr<bool> probe(PCI::DeviceIdentifier const&);
|
||||
static ErrorOr<NonnullRefPtr<NetworkAdapter>> create(PCI::DeviceIdentifier const&);
|
||||
virtual ~VirtIONetworkAdapter() override = default;
|
||||
|
||||
// VirtIO::Device
|
||||
virtual ErrorOr<void> initialize_virtio_resources() override;
|
||||
virtual StringView device_name() const override { return class_name(); }
|
||||
|
||||
// NetworkAdapter
|
||||
virtual StringView class_name() const override { return "VirtIONetworkAdapter"sv; }
|
||||
virtual Type adapter_type() const override { return Type::Ethernet; }
|
||||
virtual ErrorOr<void> initialize(Badge<NetworkingManagement>) override;
|
||||
|
||||
virtual bool link_up() override { return m_link_up; }
|
||||
virtual bool link_full_duplex() override { return m_link_duplex; }
|
||||
virtual i32 link_speed() override { return m_link_speed; }
|
||||
|
||||
private:
|
||||
explicit VirtIONetworkAdapter(PCI::DeviceIdentifier const&, NonnullOwnPtr<KString> interface_name);
|
||||
|
||||
// VirtIO::Device
|
||||
virtual bool handle_device_config_change() override;
|
||||
virtual void handle_queue_update(u16 queue_index) override;
|
||||
|
||||
// NetworkAdapter
|
||||
virtual void send_raw(ReadonlyBytes) override;
|
||||
|
||||
private:
|
||||
VirtIO::Configuration const* m_device_config { nullptr };
|
||||
|
||||
// FIXME: Make atomic as they are read without sync.
|
||||
// Note that VirtIO::NetworkAdapter may also have the same defect.
|
||||
bool m_link_up { false };
|
||||
i32 m_link_speed { LINKSPEED_INVALID };
|
||||
bool m_link_duplex { false };
|
||||
|
||||
OwnPtr<Memory::RingBuffer> m_rx_buffers;
|
||||
OwnPtr<Memory::RingBuffer> m_tx_buffers;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue