mirror of
https://github.com/RGBCube/serenity
synced 2025-05-21 15:45:07 +00:00
Kernel/Net: Generate interface name near construction point
This change allows the Kernel to actually construct other interfaces besides the E1000 type. This solves a breakage that was introduced recently because of move semantics. A couple of points on this patch: 1. In current situation, we can waste time to create a KString and throw it for nothing. This patch ensures we only create it near construction point so we know we actually need it. 2. It's very likely to assume that non-x86 machines will expose network device with a device tree (or with ACPI). The raspberry pi machine is a good example of that. Therefore, each driver should explicitly ask the correct interface name generation method, and this patch simplifies this pattern greatly, especially in a case where the same network device can appear as a PCI device or as device in another bus type on the same platform target. For example, the (in)famous ne2000 device can be used either as a PCI device or as an ISA device, depending on the model. 3. In my opinion, it seems much more readable to construct the name near calling point of the object constructor than to just pass it with move semantics.
This commit is contained in:
parent
4f9aefadef
commit
64aaf263a2
12 changed files with 55 additions and 26 deletions
|
@ -9,6 +9,7 @@
|
|||
#include <Kernel/Bus/PCI/API.h>
|
||||
#include <Kernel/Debug.h>
|
||||
#include <Kernel/Net/NE2000NetworkAdapter.h>
|
||||
#include <Kernel/Net/NetworkingManagement.h>
|
||||
#include <Kernel/Sections.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
@ -137,7 +138,7 @@ struct [[gnu::packed]] received_packet_header {
|
|||
u16 length;
|
||||
};
|
||||
|
||||
UNMAP_AFTER_INIT RefPtr<NE2000NetworkAdapter> NE2000NetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier, NonnullOwnPtr<KString> interface_name)
|
||||
UNMAP_AFTER_INIT RefPtr<NE2000NetworkAdapter> NE2000NetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier)
|
||||
{
|
||||
constexpr auto ne2k_ids = Array {
|
||||
PCI::HardwareID { 0x10EC, 0x8029 }, // RealTek RTL-8029(AS)
|
||||
|
@ -157,7 +158,11 @@ UNMAP_AFTER_INIT RefPtr<NE2000NetworkAdapter> NE2000NetworkAdapter::try_to_initi
|
|||
if (!ne2k_ids.span().contains_slow(pci_device_identifier.hardware_id()))
|
||||
return {};
|
||||
u8 irq = pci_device_identifier.interrupt_line().value();
|
||||
return adopt_ref_if_nonnull(new (nothrow) NE2000NetworkAdapter(pci_device_identifier.address(), irq, move(interface_name)));
|
||||
// FIXME: Better propagate errors here
|
||||
auto interface_name_or_error = NetworkingManagement::generate_interface_name_from_pci_address(pci_device_identifier);
|
||||
if (interface_name_or_error.is_error())
|
||||
return {};
|
||||
return adopt_ref_if_nonnull(new (nothrow) NE2000NetworkAdapter(pci_device_identifier.address(), irq, interface_name_or_error.release_value()));
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT NE2000NetworkAdapter::NE2000NetworkAdapter(PCI::Address address, u8 irq, NonnullOwnPtr<KString> interface_name)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue