mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 22:18:11 +00:00

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. :^)
49 lines
1.4 KiB
C++
49 lines
1.4 KiB
C++
/*
|
|
* Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Function.h>
|
|
#include <AK/NonnullOwnPtr.h>
|
|
#include <AK/Types.h>
|
|
#include <Kernel/Bus/PCI/Definitions.h>
|
|
#include <Kernel/Library/NonnullLockRefPtr.h>
|
|
#include <Kernel/Library/NonnullLockRefPtrVector.h>
|
|
#include <Kernel/Locking/SpinlockProtected.h>
|
|
#include <Kernel/Memory/Region.h>
|
|
#include <Kernel/Net/NetworkAdapter.h>
|
|
|
|
namespace Kernel {
|
|
|
|
class NetworkAdapter;
|
|
class NetworkingManagement {
|
|
friend class NetworkAdapter;
|
|
|
|
public:
|
|
static NetworkingManagement& the();
|
|
static bool is_initialized();
|
|
bool initialize();
|
|
|
|
static ErrorOr<NonnullOwnPtr<KString>> generate_interface_name_from_pci_address(PCI::DeviceIdentifier const&);
|
|
|
|
NetworkingManagement();
|
|
|
|
void for_each(Function<void(NetworkAdapter&)>);
|
|
ErrorOr<void> try_for_each(Function<ErrorOr<void>(NetworkAdapter&)>);
|
|
|
|
LockRefPtr<NetworkAdapter> from_ipv4_address(IPv4Address const&) const;
|
|
LockRefPtr<NetworkAdapter> lookup_by_name(StringView) const;
|
|
|
|
NonnullLockRefPtr<NetworkAdapter> loopback_adapter() const;
|
|
|
|
private:
|
|
ErrorOr<NonnullLockRefPtr<NetworkAdapter>> determine_network_device(PCI::DeviceIdentifier const&) const;
|
|
|
|
SpinlockProtected<NonnullLockRefPtrVector<NetworkAdapter>> m_adapters { LockRank::None };
|
|
LockRefPtr<NetworkAdapter> m_loopback_adapter;
|
|
};
|
|
|
|
}
|