2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
2019-08-22 01:06:55 +10:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/OwnPtr.h>
|
2021-06-25 09:46:17 +03:00
|
|
|
#include <Kernel/Bus/PCI/Access.h>
|
|
|
|
#include <Kernel/Bus/PCI/Device.h>
|
2020-06-24 14:07:28 -06:00
|
|
|
#include <Kernel/IO.h>
|
2019-08-22 01:06:55 +10:00
|
|
|
#include <Kernel/Net/NetworkAdapter.h>
|
2020-06-24 14:07:28 -06:00
|
|
|
#include <Kernel/Random.h>
|
2019-08-22 01:06:55 +10:00
|
|
|
|
2020-02-16 01:27:42 +01:00
|
|
|
namespace Kernel {
|
|
|
|
|
2019-08-22 01:06:55 +10:00
|
|
|
#define RTL8139_TX_BUFFER_COUNT 4
|
|
|
|
|
|
|
|
class RTL8139NetworkAdapter final : public NetworkAdapter
|
2020-02-22 19:45:32 +02:00
|
|
|
, public PCI::Device {
|
2019-08-22 01:06:55 +10:00
|
|
|
public:
|
2021-06-04 07:43:16 +03:00
|
|
|
static RefPtr<RTL8139NetworkAdapter> try_to_initialize(PCI::Address);
|
2019-08-22 01:06:55 +10:00
|
|
|
|
|
|
|
virtual ~RTL8139NetworkAdapter() override;
|
|
|
|
|
2020-07-28 20:19:22 +02:00
|
|
|
virtual void send_raw(ReadonlyBytes) override;
|
2019-08-22 01:14:00 +10:00
|
|
|
virtual bool link_up() override { return m_link_up; }
|
2021-07-25 20:16:42 +02:00
|
|
|
virtual i32 link_speed() override;
|
|
|
|
virtual bool link_full_duplex() override;
|
2019-08-22 01:06:55 +10:00
|
|
|
|
2021-07-11 01:46:09 +02:00
|
|
|
virtual StringView purpose() const override { return class_name(); }
|
2020-03-05 19:13:55 +02:00
|
|
|
|
2019-08-22 01:06:55 +10:00
|
|
|
private:
|
2021-06-04 07:43:16 +03:00
|
|
|
RTL8139NetworkAdapter(PCI::Address, u8 irq);
|
2021-06-05 09:00:18 +03:00
|
|
|
virtual bool handle_irq(const RegisterState&) override;
|
2021-07-11 17:59:38 +02:00
|
|
|
virtual StringView class_name() const override { return "RTL8139NetworkAdapter"sv; }
|
2019-08-22 01:06:55 +10:00
|
|
|
|
|
|
|
void reset();
|
|
|
|
void read_mac_address();
|
|
|
|
|
|
|
|
void receive();
|
|
|
|
|
|
|
|
void out8(u16 address, u8 data);
|
|
|
|
void out16(u16 address, u16 data);
|
|
|
|
void out32(u16 address, u32 data);
|
|
|
|
u8 in8(u16 address);
|
|
|
|
u16 in16(u16 address);
|
|
|
|
u32 in32(u16 address);
|
|
|
|
|
2020-03-01 16:16:26 +02:00
|
|
|
IOAddress m_io_base;
|
2019-08-22 01:06:55 +10:00
|
|
|
u8 m_interrupt_line { 0 };
|
2021-08-06 13:49:36 +02:00
|
|
|
OwnPtr<Memory::Region> m_rx_buffer;
|
2019-08-22 01:06:55 +10:00
|
|
|
u16 m_rx_buffer_offset { 0 };
|
2021-08-06 13:49:36 +02:00
|
|
|
Vector<OwnPtr<Memory::Region>> m_tx_buffers;
|
2019-08-22 01:06:55 +10:00
|
|
|
u8 m_tx_next_buffer { 0 };
|
2021-08-06 13:49:36 +02:00
|
|
|
OwnPtr<Memory::Region> m_packet_buffer;
|
2019-08-22 01:06:55 +10:00
|
|
|
bool m_link_up { false };
|
2020-06-24 14:07:28 -06:00
|
|
|
EntropySource m_entropy_source;
|
2019-08-22 01:06:55 +10:00
|
|
|
};
|
2020-02-16 01:27:42 +01:00
|
|
|
}
|