mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 05:35:06 +00:00
Kernel: Convert network adapter names to Kernel::KString
Another step of incremental progress of removing `AK::String` from the kernel, to harden against OOM.
This commit is contained in:
parent
33a9f908a6
commit
2770433d30
16 changed files with 64 additions and 68 deletions
|
@ -180,14 +180,14 @@ static bool is_valid_device_id(u16 device_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UNMAP_AFTER_INIT RefPtr<E1000ENetworkAdapter> E1000ENetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier)
|
UNMAP_AFTER_INIT RefPtr<E1000ENetworkAdapter> E1000ENetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier, NonnullOwnPtr<KString> interface_name)
|
||||||
{
|
{
|
||||||
if (pci_device_identifier.hardware_id().vendor_id != PCI::VendorID::Intel)
|
if (pci_device_identifier.hardware_id().vendor_id != PCI::VendorID::Intel)
|
||||||
return {};
|
return {};
|
||||||
if (!is_valid_device_id(pci_device_identifier.hardware_id().device_id))
|
if (!is_valid_device_id(pci_device_identifier.hardware_id().device_id))
|
||||||
return {};
|
return {};
|
||||||
u8 irq = pci_device_identifier.interrupt_line().value();
|
u8 irq = pci_device_identifier.interrupt_line().value();
|
||||||
auto adapter = adopt_ref_if_nonnull(new (nothrow) E1000ENetworkAdapter(pci_device_identifier.address(), irq));
|
auto adapter = adopt_ref_if_nonnull(new (nothrow) E1000ENetworkAdapter(pci_device_identifier.address(), irq, move(interface_name)));
|
||||||
if (!adapter)
|
if (!adapter)
|
||||||
return {};
|
return {};
|
||||||
if (adapter->initialize())
|
if (adapter->initialize())
|
||||||
|
@ -228,8 +228,8 @@ UNMAP_AFTER_INIT bool E1000ENetworkAdapter::initialize()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
UNMAP_AFTER_INIT E1000ENetworkAdapter::E1000ENetworkAdapter(PCI::Address address, u8 irq)
|
UNMAP_AFTER_INIT E1000ENetworkAdapter::E1000ENetworkAdapter(PCI::Address address, u8 irq, NonnullOwnPtr<KString> interface_name)
|
||||||
: E1000NetworkAdapter(address, irq)
|
: E1000NetworkAdapter(address, irq, move(interface_name))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace Kernel {
|
||||||
class E1000ENetworkAdapter final
|
class E1000ENetworkAdapter final
|
||||||
: public E1000NetworkAdapter {
|
: public E1000NetworkAdapter {
|
||||||
public:
|
public:
|
||||||
static RefPtr<E1000ENetworkAdapter> try_to_initialize(PCI::DeviceIdentifier const&);
|
static RefPtr<E1000ENetworkAdapter> try_to_initialize(PCI::DeviceIdentifier const&, NonnullOwnPtr<KString>);
|
||||||
|
|
||||||
virtual bool initialize() override;
|
virtual bool initialize() override;
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ public:
|
||||||
virtual StringView purpose() const override { return class_name(); }
|
virtual StringView purpose() const override { return class_name(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
E1000ENetworkAdapter(PCI::Address, u8 irq);
|
E1000ENetworkAdapter(PCI::Address, u8 irq, NonnullOwnPtr<KString>);
|
||||||
|
|
||||||
virtual StringView class_name() const override { return "E1000ENetworkAdapter"sv; }
|
virtual StringView class_name() const override { return "E1000ENetworkAdapter"sv; }
|
||||||
|
|
||||||
|
|
|
@ -158,14 +158,14 @@ UNMAP_AFTER_INIT static bool is_valid_device_id(u16 device_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UNMAP_AFTER_INIT RefPtr<E1000NetworkAdapter> E1000NetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier)
|
UNMAP_AFTER_INIT RefPtr<E1000NetworkAdapter> E1000NetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier, NonnullOwnPtr<KString> interface_name)
|
||||||
{
|
{
|
||||||
if (pci_device_identifier.hardware_id().vendor_id != PCI::VendorID::Intel)
|
if (pci_device_identifier.hardware_id().vendor_id != PCI::VendorID::Intel)
|
||||||
return {};
|
return {};
|
||||||
if (!is_valid_device_id(pci_device_identifier.hardware_id().device_id))
|
if (!is_valid_device_id(pci_device_identifier.hardware_id().device_id))
|
||||||
return {};
|
return {};
|
||||||
u8 irq = pci_device_identifier.interrupt_line().value();
|
u8 irq = pci_device_identifier.interrupt_line().value();
|
||||||
auto adapter = adopt_ref_if_nonnull(new (nothrow) E1000NetworkAdapter(pci_device_identifier.address(), irq));
|
auto adapter = adopt_ref_if_nonnull(new (nothrow) E1000NetworkAdapter(pci_device_identifier.address(), irq, move(interface_name)));
|
||||||
if (!adapter)
|
if (!adapter)
|
||||||
return {};
|
return {};
|
||||||
if (adapter->initialize())
|
if (adapter->initialize())
|
||||||
|
@ -219,13 +219,13 @@ UNMAP_AFTER_INIT bool E1000NetworkAdapter::initialize()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
UNMAP_AFTER_INIT E1000NetworkAdapter::E1000NetworkAdapter(PCI::Address address, u8 irq)
|
UNMAP_AFTER_INIT E1000NetworkAdapter::E1000NetworkAdapter(PCI::Address address, u8 irq, NonnullOwnPtr<KString> interface_name)
|
||||||
: PCI::Device(address)
|
: NetworkAdapter(move(interface_name))
|
||||||
|
, PCI::Device(address)
|
||||||
, IRQHandler(irq)
|
, IRQHandler(irq)
|
||||||
, m_rx_descriptors_region(MM.allocate_contiguous_kernel_region(Memory::page_round_up(sizeof(e1000_rx_desc) * number_of_rx_descriptors + 16), "E1000 RX Descriptors", Memory::Region::Access::ReadWrite).release_value())
|
, m_rx_descriptors_region(MM.allocate_contiguous_kernel_region(Memory::page_round_up(sizeof(e1000_rx_desc) * number_of_rx_descriptors + 16), "E1000 RX Descriptors", Memory::Region::Access::ReadWrite).release_value())
|
||||||
, m_tx_descriptors_region(MM.allocate_contiguous_kernel_region(Memory::page_round_up(sizeof(e1000_tx_desc) * number_of_tx_descriptors + 16), "E1000 TX Descriptors", Memory::Region::Access::ReadWrite).release_value())
|
, m_tx_descriptors_region(MM.allocate_contiguous_kernel_region(Memory::page_round_up(sizeof(e1000_tx_desc) * number_of_tx_descriptors + 16), "E1000 TX Descriptors", Memory::Region::Access::ReadWrite).release_value())
|
||||||
{
|
{
|
||||||
set_interface_name(pci_address());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UNMAP_AFTER_INIT E1000NetworkAdapter::~E1000NetworkAdapter()
|
UNMAP_AFTER_INIT E1000NetworkAdapter::~E1000NetworkAdapter()
|
||||||
|
|
|
@ -20,7 +20,7 @@ class E1000NetworkAdapter : public NetworkAdapter
|
||||||
, public PCI::Device
|
, public PCI::Device
|
||||||
, public IRQHandler {
|
, public IRQHandler {
|
||||||
public:
|
public:
|
||||||
static RefPtr<E1000NetworkAdapter> try_to_initialize(PCI::DeviceIdentifier const&);
|
static RefPtr<E1000NetworkAdapter> try_to_initialize(PCI::DeviceIdentifier const&, NonnullOwnPtr<KString>);
|
||||||
|
|
||||||
virtual bool initialize();
|
virtual bool initialize();
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ protected:
|
||||||
void setup_interrupts();
|
void setup_interrupts();
|
||||||
void setup_link();
|
void setup_link();
|
||||||
|
|
||||||
E1000NetworkAdapter(PCI::Address, u8 irq);
|
E1000NetworkAdapter(PCI::Address, u8 irq, NonnullOwnPtr<KString>);
|
||||||
virtual bool handle_irq(const RegisterState&) override;
|
virtual bool handle_irq(const RegisterState&) override;
|
||||||
virtual StringView class_name() const override { return "E1000NetworkAdapter"sv; }
|
virtual StringView class_name() const override { return "E1000NetworkAdapter"sv; }
|
||||||
|
|
||||||
|
|
|
@ -13,14 +13,17 @@ static bool s_loopback_initialized = false;
|
||||||
|
|
||||||
RefPtr<LoopbackAdapter> LoopbackAdapter::try_create()
|
RefPtr<LoopbackAdapter> LoopbackAdapter::try_create()
|
||||||
{
|
{
|
||||||
return adopt_ref_if_nonnull(new LoopbackAdapter());
|
auto interface_name = KString::try_create("loop"sv);
|
||||||
|
if (interface_name.is_error())
|
||||||
|
return {};
|
||||||
|
return adopt_ref_if_nonnull(new LoopbackAdapter(interface_name.release_value()));
|
||||||
}
|
}
|
||||||
|
|
||||||
LoopbackAdapter::LoopbackAdapter()
|
LoopbackAdapter::LoopbackAdapter(NonnullOwnPtr<KString> interface_name)
|
||||||
|
: NetworkAdapter(move(interface_name))
|
||||||
{
|
{
|
||||||
VERIFY(!s_loopback_initialized);
|
VERIFY(!s_loopback_initialized);
|
||||||
s_loopback_initialized = true;
|
s_loopback_initialized = true;
|
||||||
set_loopback_name();
|
|
||||||
set_mtu(65536);
|
set_mtu(65536);
|
||||||
set_mac_address({ 19, 85, 2, 9, 0x55, 0xaa });
|
set_mac_address({ 19, 85, 2, 9, 0x55, 0xaa });
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ class LoopbackAdapter final : public NetworkAdapter {
|
||||||
AK_MAKE_ETERNAL
|
AK_MAKE_ETERNAL
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LoopbackAdapter();
|
LoopbackAdapter(NonnullOwnPtr<KString>);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static RefPtr<LoopbackAdapter> try_create();
|
static RefPtr<LoopbackAdapter> try_create();
|
||||||
|
|
|
@ -137,7 +137,7 @@ struct [[gnu::packed]] received_packet_header {
|
||||||
u16 length;
|
u16 length;
|
||||||
};
|
};
|
||||||
|
|
||||||
UNMAP_AFTER_INIT RefPtr<NE2000NetworkAdapter> NE2000NetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier)
|
UNMAP_AFTER_INIT RefPtr<NE2000NetworkAdapter> NE2000NetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier, NonnullOwnPtr<KString> interface_name)
|
||||||
{
|
{
|
||||||
constexpr auto ne2k_ids = Array {
|
constexpr auto ne2k_ids = Array {
|
||||||
PCI::HardwareID { 0x10EC, 0x8029 }, // RealTek RTL-8029(AS)
|
PCI::HardwareID { 0x10EC, 0x8029 }, // RealTek RTL-8029(AS)
|
||||||
|
@ -157,16 +157,15 @@ UNMAP_AFTER_INIT RefPtr<NE2000NetworkAdapter> NE2000NetworkAdapter::try_to_initi
|
||||||
if (!ne2k_ids.span().contains_slow(pci_device_identifier.hardware_id()))
|
if (!ne2k_ids.span().contains_slow(pci_device_identifier.hardware_id()))
|
||||||
return {};
|
return {};
|
||||||
u8 irq = pci_device_identifier.interrupt_line().value();
|
u8 irq = pci_device_identifier.interrupt_line().value();
|
||||||
return adopt_ref_if_nonnull(new (nothrow) NE2000NetworkAdapter(pci_device_identifier.address(), irq));
|
return adopt_ref_if_nonnull(new (nothrow) NE2000NetworkAdapter(pci_device_identifier.address(), irq, move(interface_name)));
|
||||||
}
|
}
|
||||||
|
|
||||||
UNMAP_AFTER_INIT NE2000NetworkAdapter::NE2000NetworkAdapter(PCI::Address address, u8 irq)
|
UNMAP_AFTER_INIT NE2000NetworkAdapter::NE2000NetworkAdapter(PCI::Address address, u8 irq, NonnullOwnPtr<KString> interface_name)
|
||||||
: PCI::Device(address)
|
: NetworkAdapter(move(interface_name))
|
||||||
|
, PCI::Device(address)
|
||||||
, IRQHandler(irq)
|
, IRQHandler(irq)
|
||||||
, m_io_base(PCI::get_BAR0(pci_address()) & ~3)
|
, m_io_base(PCI::get_BAR0(pci_address()) & ~3)
|
||||||
{
|
{
|
||||||
set_interface_name(address);
|
|
||||||
|
|
||||||
dmesgln("NE2000: Found @ {}", pci_address());
|
dmesgln("NE2000: Found @ {}", pci_address());
|
||||||
|
|
||||||
dmesgln("NE2000: Port base: {}", m_io_base);
|
dmesgln("NE2000: Port base: {}", m_io_base);
|
||||||
|
|
|
@ -20,7 +20,7 @@ class NE2000NetworkAdapter final : public NetworkAdapter
|
||||||
, public PCI::Device
|
, public PCI::Device
|
||||||
, public IRQHandler {
|
, public IRQHandler {
|
||||||
public:
|
public:
|
||||||
static RefPtr<NE2000NetworkAdapter> try_to_initialize(PCI::DeviceIdentifier const&);
|
static RefPtr<NE2000NetworkAdapter> try_to_initialize(PCI::DeviceIdentifier const&, NonnullOwnPtr<KString>);
|
||||||
|
|
||||||
virtual ~NE2000NetworkAdapter() override;
|
virtual ~NE2000NetworkAdapter() override;
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ public:
|
||||||
virtual StringView purpose() const override { return class_name(); }
|
virtual StringView purpose() const override { return class_name(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NE2000NetworkAdapter(PCI::Address, u8 irq);
|
NE2000NetworkAdapter(PCI::Address, u8, NonnullOwnPtr<KString>);
|
||||||
virtual bool handle_irq(const RegisterState&) override;
|
virtual bool handle_irq(const RegisterState&) override;
|
||||||
virtual StringView class_name() const override { return "NE2000NetworkAdapter"sv; }
|
virtual StringView class_name() const override { return "NE2000NetworkAdapter"sv; }
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,8 @@
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
NetworkAdapter::NetworkAdapter()
|
NetworkAdapter::NetworkAdapter(NonnullOwnPtr<KString> interface_name)
|
||||||
|
: m_name(move(interface_name))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,18 +166,4 @@ void NetworkAdapter::set_ipv4_gateway(const IPv4Address& gateway)
|
||||||
m_ipv4_gateway = gateway;
|
m_ipv4_gateway = gateway;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkAdapter::set_interface_name(const PCI::Address& pci_address)
|
|
||||||
{
|
|
||||||
// Note: This stands for e - "Ethernet", p - "Port" as for PCI bus, "s" for slot as for PCI slot
|
|
||||||
auto name = String::formatted("ep{}s{}", pci_address.bus(), pci_address.device());
|
|
||||||
VERIFY(!NetworkingManagement::the().lookup_by_name(name));
|
|
||||||
m_name = move(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
void NetworkAdapter::set_loopback_name()
|
|
||||||
{
|
|
||||||
auto name = String("loop");
|
|
||||||
VERIFY(!NetworkingManagement::the().lookup_by_name(name));
|
|
||||||
m_name = move(name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ public:
|
||||||
|
|
||||||
virtual StringView class_name() const = 0;
|
virtual StringView class_name() const = 0;
|
||||||
|
|
||||||
const String& name() const { return m_name; }
|
StringView name() const { return m_name->view(); }
|
||||||
MACAddress mac_address() { return m_mac_address; }
|
MACAddress mac_address() { return m_mac_address; }
|
||||||
IPv4Address ipv4_address() const { return m_ipv4_address; }
|
IPv4Address ipv4_address() const { return m_ipv4_address; }
|
||||||
IPv4Address ipv4_netmask() const { return m_ipv4_netmask; }
|
IPv4Address ipv4_netmask() const { return m_ipv4_netmask; }
|
||||||
|
@ -94,14 +94,11 @@ public:
|
||||||
void send_packet(ReadonlyBytes);
|
void send_packet(ReadonlyBytes);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
NetworkAdapter();
|
NetworkAdapter(NonnullOwnPtr<KString>);
|
||||||
void set_interface_name(const PCI::Address&);
|
|
||||||
void set_mac_address(const MACAddress& mac_address) { m_mac_address = mac_address; }
|
void set_mac_address(const MACAddress& mac_address) { m_mac_address = mac_address; }
|
||||||
void did_receive(ReadonlyBytes);
|
void did_receive(ReadonlyBytes);
|
||||||
virtual void send_raw(ReadonlyBytes) = 0;
|
virtual void send_raw(ReadonlyBytes) = 0;
|
||||||
|
|
||||||
void set_loopback_name();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MACAddress m_mac_address;
|
MACAddress m_mac_address;
|
||||||
IPv4Address m_ipv4_address;
|
IPv4Address m_ipv4_address;
|
||||||
|
@ -116,7 +113,7 @@ private:
|
||||||
PacketList m_packet_queue;
|
PacketList m_packet_queue;
|
||||||
size_t m_packet_queue_size { 0 };
|
size_t m_packet_queue_size { 0 };
|
||||||
PacketList m_unused_packets;
|
PacketList m_unused_packets;
|
||||||
String m_name;
|
NonnullOwnPtr<KString> m_name;
|
||||||
u32 m_packets_in { 0 };
|
u32 m_packets_in { 0 };
|
||||||
u32 m_bytes_in { 0 };
|
u32 m_bytes_in { 0 };
|
||||||
u32 m_packets_out { 0 };
|
u32 m_packets_out { 0 };
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <Kernel/Arch/x86/IO.h>
|
#include <Kernel/Arch/x86/IO.h>
|
||||||
#include <Kernel/Bus/PCI/API.h>
|
#include <Kernel/Bus/PCI/API.h>
|
||||||
#include <Kernel/CommandLine.h>
|
#include <Kernel/CommandLine.h>
|
||||||
|
#include <Kernel/KString.h>
|
||||||
#include <Kernel/Memory/AnonymousVMObject.h>
|
#include <Kernel/Memory/AnonymousVMObject.h>
|
||||||
#include <Kernel/Multiboot.h>
|
#include <Kernel/Multiboot.h>
|
||||||
#include <Kernel/Net/E1000ENetworkAdapter.h>
|
#include <Kernel/Net/E1000ENetworkAdapter.h>
|
||||||
|
@ -75,15 +76,24 @@ RefPtr<NetworkAdapter> NetworkingManagement::lookup_by_name(const StringView& na
|
||||||
|
|
||||||
UNMAP_AFTER_INIT RefPtr<NetworkAdapter> NetworkingManagement::determine_network_device(PCI::DeviceIdentifier const& device_identifier) const
|
UNMAP_AFTER_INIT RefPtr<NetworkAdapter> NetworkingManagement::determine_network_device(PCI::DeviceIdentifier const& device_identifier) const
|
||||||
{
|
{
|
||||||
if (auto candidate = E1000NetworkAdapter::try_to_initialize(device_identifier); !candidate.is_null())
|
// Note: This stands for e - "Ethernet", p - "Port" as for PCI bus, "s" for slot as for PCI slot
|
||||||
|
auto name = String::formatted("ep{}s{}", device_identifier.address().bus(), device_identifier.address().device());
|
||||||
|
VERIFY(!NetworkingManagement::the().lookup_by_name(name));
|
||||||
|
|
||||||
|
// TODO: We need some way to to format data into a `KString`.
|
||||||
|
auto interface_name_or_error = KString::try_create(name.view());
|
||||||
|
if (interface_name_or_error.is_error())
|
||||||
|
return {};
|
||||||
|
auto interface_name = interface_name_or_error.release_value();
|
||||||
|
if (auto candidate = E1000NetworkAdapter::try_to_initialize(device_identifier, move(interface_name)); !candidate.is_null())
|
||||||
return candidate;
|
return candidate;
|
||||||
if (auto candidate = E1000ENetworkAdapter::try_to_initialize(device_identifier); !candidate.is_null())
|
if (auto candidate = E1000ENetworkAdapter::try_to_initialize(device_identifier, move(interface_name)); !candidate.is_null())
|
||||||
return candidate;
|
return candidate;
|
||||||
if (auto candidate = RTL8139NetworkAdapter::try_to_initialize(device_identifier); !candidate.is_null())
|
if (auto candidate = RTL8139NetworkAdapter::try_to_initialize(device_identifier, move(interface_name)); !candidate.is_null())
|
||||||
return candidate;
|
return candidate;
|
||||||
if (auto candidate = RTL8168NetworkAdapter::try_to_initialize(device_identifier); !candidate.is_null())
|
if (auto candidate = RTL8168NetworkAdapter::try_to_initialize(device_identifier, move(interface_name)); !candidate.is_null())
|
||||||
return candidate;
|
return candidate;
|
||||||
if (auto candidate = NE2000NetworkAdapter::try_to_initialize(device_identifier); !candidate.is_null())
|
if (auto candidate = NE2000NetworkAdapter::try_to_initialize(device_identifier, move(interface_name)); !candidate.is_null())
|
||||||
return candidate;
|
return candidate;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,24 +112,24 @@ namespace Kernel {
|
||||||
#define RX_BUFFER_SIZE 32768
|
#define RX_BUFFER_SIZE 32768
|
||||||
#define TX_BUFFER_SIZE PACKET_SIZE_MAX
|
#define TX_BUFFER_SIZE PACKET_SIZE_MAX
|
||||||
|
|
||||||
UNMAP_AFTER_INIT RefPtr<RTL8139NetworkAdapter> RTL8139NetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier)
|
UNMAP_AFTER_INIT RefPtr<RTL8139NetworkAdapter> RTL8139NetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier, NonnullOwnPtr<KString> interface_name)
|
||||||
{
|
{
|
||||||
constexpr PCI::HardwareID rtl8139_id = { 0x10EC, 0x8139 };
|
constexpr PCI::HardwareID rtl8139_id = { 0x10EC, 0x8139 };
|
||||||
if (pci_device_identifier.hardware_id() != rtl8139_id)
|
if (pci_device_identifier.hardware_id() != rtl8139_id)
|
||||||
return {};
|
return {};
|
||||||
u8 irq = pci_device_identifier.interrupt_line().value();
|
u8 irq = pci_device_identifier.interrupt_line().value();
|
||||||
return adopt_ref_if_nonnull(new (nothrow) RTL8139NetworkAdapter(pci_device_identifier.address(), irq));
|
return adopt_ref_if_nonnull(new (nothrow) RTL8139NetworkAdapter(pci_device_identifier.address(), irq, move(interface_name)));
|
||||||
}
|
}
|
||||||
|
|
||||||
UNMAP_AFTER_INIT RTL8139NetworkAdapter::RTL8139NetworkAdapter(PCI::Address address, u8 irq)
|
UNMAP_AFTER_INIT RTL8139NetworkAdapter::RTL8139NetworkAdapter(PCI::Address address, u8 irq, NonnullOwnPtr<KString> interface_name)
|
||||||
: PCI::Device(address)
|
: NetworkAdapter(move(interface_name))
|
||||||
|
, PCI::Device(address)
|
||||||
, IRQHandler(irq)
|
, IRQHandler(irq)
|
||||||
, m_io_base(PCI::get_BAR0(pci_address()) & ~1)
|
, m_io_base(PCI::get_BAR0(pci_address()) & ~1)
|
||||||
, m_rx_buffer(MM.allocate_contiguous_kernel_region(Memory::page_round_up(RX_BUFFER_SIZE + PACKET_SIZE_MAX), "RTL8139 RX", Memory::Region::Access::ReadWrite).release_value())
|
, m_rx_buffer(MM.allocate_contiguous_kernel_region(Memory::page_round_up(RX_BUFFER_SIZE + PACKET_SIZE_MAX), "RTL8139 RX", Memory::Region::Access::ReadWrite).release_value())
|
||||||
, m_packet_buffer(MM.allocate_contiguous_kernel_region(Memory::page_round_up(PACKET_SIZE_MAX), "RTL8139 Packet buffer", Memory::Region::Access::ReadWrite).release_value())
|
, m_packet_buffer(MM.allocate_contiguous_kernel_region(Memory::page_round_up(PACKET_SIZE_MAX), "RTL8139 Packet buffer", Memory::Region::Access::ReadWrite).release_value())
|
||||||
{
|
{
|
||||||
m_tx_buffers.ensure_capacity(RTL8139_TX_BUFFER_COUNT);
|
m_tx_buffers.ensure_capacity(RTL8139_TX_BUFFER_COUNT);
|
||||||
set_interface_name(address);
|
|
||||||
|
|
||||||
dmesgln("RTL8139: Found @ {}", pci_address());
|
dmesgln("RTL8139: Found @ {}", pci_address());
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ class RTL8139NetworkAdapter final : public NetworkAdapter
|
||||||
, public PCI::Device
|
, public PCI::Device
|
||||||
, public IRQHandler {
|
, public IRQHandler {
|
||||||
public:
|
public:
|
||||||
static RefPtr<RTL8139NetworkAdapter> try_to_initialize(PCI::DeviceIdentifier const&);
|
static RefPtr<RTL8139NetworkAdapter> try_to_initialize(PCI::DeviceIdentifier const&, NonnullOwnPtr<KString>);
|
||||||
|
|
||||||
virtual ~RTL8139NetworkAdapter() override;
|
virtual ~RTL8139NetworkAdapter() override;
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ public:
|
||||||
virtual StringView purpose() const override { return class_name(); }
|
virtual StringView purpose() const override { return class_name(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RTL8139NetworkAdapter(PCI::Address, u8 irq);
|
RTL8139NetworkAdapter(PCI::Address, u8 irq, NonnullOwnPtr<KString>);
|
||||||
virtual bool handle_irq(const RegisterState&) override;
|
virtual bool handle_irq(const RegisterState&) override;
|
||||||
virtual StringView class_name() const override { return "RTL8139NetworkAdapter"sv; }
|
virtual StringView class_name() const override { return "RTL8139NetworkAdapter"sv; }
|
||||||
|
|
||||||
|
|
|
@ -181,14 +181,14 @@ namespace Kernel {
|
||||||
#define TX_BUFFER_SIZE 0x1FF8
|
#define TX_BUFFER_SIZE 0x1FF8
|
||||||
#define RX_BUFFER_SIZE 0x1FF8 // FIXME: this should be increased (0x3FFF)
|
#define RX_BUFFER_SIZE 0x1FF8 // FIXME: this should be increased (0x3FFF)
|
||||||
|
|
||||||
UNMAP_AFTER_INIT RefPtr<RTL8168NetworkAdapter> RTL8168NetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier)
|
UNMAP_AFTER_INIT RefPtr<RTL8168NetworkAdapter> RTL8168NetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier, NonnullOwnPtr<KString> interface_name)
|
||||||
{
|
{
|
||||||
if (pci_device_identifier.hardware_id().vendor_id != PCI::VendorID::Realtek)
|
if (pci_device_identifier.hardware_id().vendor_id != PCI::VendorID::Realtek)
|
||||||
return {};
|
return {};
|
||||||
if (pci_device_identifier.hardware_id().device_id != 0x8168)
|
if (pci_device_identifier.hardware_id().device_id != 0x8168)
|
||||||
return {};
|
return {};
|
||||||
u8 irq = pci_device_identifier.interrupt_line().value();
|
u8 irq = pci_device_identifier.interrupt_line().value();
|
||||||
return adopt_ref_if_nonnull(new (nothrow) RTL8168NetworkAdapter(pci_device_identifier.address(), irq));
|
return adopt_ref_if_nonnull(new (nothrow) RTL8168NetworkAdapter(pci_device_identifier.address(), irq, move(interface_name)));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RTL8168NetworkAdapter::determine_supported_version() const
|
bool RTL8168NetworkAdapter::determine_supported_version() const
|
||||||
|
@ -236,15 +236,14 @@ bool RTL8168NetworkAdapter::determine_supported_version() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UNMAP_AFTER_INIT RTL8168NetworkAdapter::RTL8168NetworkAdapter(PCI::Address address, u8 irq)
|
UNMAP_AFTER_INIT RTL8168NetworkAdapter::RTL8168NetworkAdapter(PCI::Address address, u8 irq, NonnullOwnPtr<KString> interface_name)
|
||||||
: PCI::Device(address)
|
: NetworkAdapter(move(interface_name))
|
||||||
|
, PCI::Device(address)
|
||||||
, IRQHandler(irq)
|
, IRQHandler(irq)
|
||||||
, m_io_base(PCI::get_BAR0(pci_address()) & ~1)
|
, m_io_base(PCI::get_BAR0(pci_address()) & ~1)
|
||||||
, m_rx_descriptors_region(MM.allocate_contiguous_kernel_region(Memory::page_round_up(sizeof(TXDescriptor) * (number_of_rx_descriptors + 1)), "RTL8168 RX", Memory::Region::Access::ReadWrite).release_value())
|
, m_rx_descriptors_region(MM.allocate_contiguous_kernel_region(Memory::page_round_up(sizeof(TXDescriptor) * (number_of_rx_descriptors + 1)), "RTL8168 RX", Memory::Region::Access::ReadWrite).release_value())
|
||||||
, m_tx_descriptors_region(MM.allocate_contiguous_kernel_region(Memory::page_round_up(sizeof(RXDescriptor) * (number_of_tx_descriptors + 1)), "RTL8168 TX", Memory::Region::Access::ReadWrite).release_value())
|
, m_tx_descriptors_region(MM.allocate_contiguous_kernel_region(Memory::page_round_up(sizeof(RXDescriptor) * (number_of_tx_descriptors + 1)), "RTL8168 TX", Memory::Region::Access::ReadWrite).release_value())
|
||||||
{
|
{
|
||||||
set_interface_name(address);
|
|
||||||
|
|
||||||
dmesgln("RTL8168: Found @ {}", pci_address());
|
dmesgln("RTL8168: Found @ {}", pci_address());
|
||||||
dmesgln("RTL8168: I/O port base: {}", m_io_base);
|
dmesgln("RTL8168: I/O port base: {}", m_io_base);
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ class RTL8168NetworkAdapter final : public NetworkAdapter
|
||||||
, public PCI::Device
|
, public PCI::Device
|
||||||
, public IRQHandler {
|
, public IRQHandler {
|
||||||
public:
|
public:
|
||||||
static RefPtr<RTL8168NetworkAdapter> try_to_initialize(PCI::DeviceIdentifier const&);
|
static RefPtr<RTL8168NetworkAdapter> try_to_initialize(PCI::DeviceIdentifier const&, NonnullOwnPtr<KString>);
|
||||||
|
|
||||||
virtual ~RTL8168NetworkAdapter() override;
|
virtual ~RTL8168NetworkAdapter() override;
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ private:
|
||||||
static const size_t number_of_rx_descriptors = 64;
|
static const size_t number_of_rx_descriptors = 64;
|
||||||
static const size_t number_of_tx_descriptors = 16;
|
static const size_t number_of_tx_descriptors = 16;
|
||||||
|
|
||||||
RTL8168NetworkAdapter(PCI::Address, u8 irq);
|
RTL8168NetworkAdapter(PCI::Address, u8 irq, NonnullOwnPtr<KString>);
|
||||||
|
|
||||||
virtual bool handle_irq(const RegisterState&) override;
|
virtual bool handle_irq(const RegisterState&) override;
|
||||||
virtual StringView class_name() const override { return "RTL8168NetworkAdapter"sv; }
|
virtual StringView class_name() const override { return "RTL8168NetworkAdapter"sv; }
|
||||||
|
|
|
@ -170,9 +170,10 @@ KResult Socket::getsockopt(OpenFileDescription&, int level, int option, Userspac
|
||||||
if (size < IFNAMSIZ)
|
if (size < IFNAMSIZ)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
if (m_bound_interface) {
|
if (m_bound_interface) {
|
||||||
const auto& name = m_bound_interface->name();
|
auto name = m_bound_interface->name();
|
||||||
auto length = name.length() + 1;
|
auto length = name.length() + 1;
|
||||||
TRY(copy_to_user(static_ptr_cast<char*>(value), name.characters(), length));
|
auto characters = name.characters_without_null_termination();
|
||||||
|
TRY(copy_to_user(static_ptr_cast<char*>(value), characters, length));
|
||||||
size = length;
|
size = length;
|
||||||
return copy_to_user(value_size, &size);
|
return copy_to_user(value_size, &size);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue