mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:28:12 +00:00
Kernel: Propagate errors during network adapter detection/initialization
When scanning for network adapters, we give each driver a chance to claim the PCI device and whoever claims it first gets to keep it. Before this patch, the driver API returned a LockRefPtr<AdapterType>, which made it impossible to propagate errors that occurred during detection and/or initialization. This patch changes the API so that errors can bubble all the way out the PCI enumeration in NetworkingManagement::initialize() where we perform all the network adapter auto-detection on boot. When we eventually start to support hot-plugging network adapter in the future, it will be even more important to propagate errors instead of swallowing them. Importantly, before this patch, some errors were "handled" by panicking the kernel. This is no longer the case. 7 FIXMEs were killed in the making of this commit. :^)
This commit is contained in:
parent
9a849c10ae
commit
30d3f2789e
12 changed files with 58 additions and 73 deletions
|
@ -138,7 +138,7 @@ struct [[gnu::packed]] received_packet_header {
|
|||
u16 length;
|
||||
};
|
||||
|
||||
UNMAP_AFTER_INIT LockRefPtr<NE2000NetworkAdapter> NE2000NetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier)
|
||||
UNMAP_AFTER_INIT ErrorOr<LockRefPtr<NE2000NetworkAdapter>> NE2000NetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier)
|
||||
{
|
||||
constexpr auto ne2k_ids = Array {
|
||||
PCI::HardwareID { 0x10EC, 0x8029 }, // RealTek RTL-8029(AS)
|
||||
|
@ -156,14 +156,11 @@ UNMAP_AFTER_INIT LockRefPtr<NE2000NetworkAdapter> NE2000NetworkAdapter::try_to_i
|
|||
PCI::HardwareID { 0x8c4a, 0x1980 }, // Winbond W89C940 (misprogrammed)
|
||||
};
|
||||
if (!ne2k_ids.span().contains_slow(pci_device_identifier.hardware_id()))
|
||||
return {};
|
||||
return nullptr;
|
||||
u8 irq = pci_device_identifier.interrupt_line().value();
|
||||
// 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 {};
|
||||
auto registers_io_window = MUST(IOWindow::create_for_pci_device_bar(pci_device_identifier, PCI::HeaderType0BaseRegister::BAR0));
|
||||
return adopt_lock_ref_if_nonnull(new (nothrow) NE2000NetworkAdapter(pci_device_identifier.address(), irq, move(registers_io_window), interface_name_or_error.release_value()));
|
||||
auto interface_name = TRY(NetworkingManagement::generate_interface_name_from_pci_address(pci_device_identifier));
|
||||
auto registers_io_window = TRY(IOWindow::create_for_pci_device_bar(pci_device_identifier, PCI::HeaderType0BaseRegister::BAR0));
|
||||
return TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) NE2000NetworkAdapter(pci_device_identifier.address(), irq, move(registers_io_window), move(interface_name))));
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT NE2000NetworkAdapter::NE2000NetworkAdapter(PCI::Address address, u8 irq, NonnullOwnPtr<IOWindow> registers_io_window, NonnullOwnPtr<KString> interface_name)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue