mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-17 08:37:17 -04:00
Use the RX thread
This commit is contained in:
parent
8231945e75
commit
77790c7435
@ -30,6 +30,7 @@ struct interface_descriptor {
|
|||||||
|
|
||||||
mutable mutex<> tx_lock; //To synchronize the queue
|
mutable mutex<> tx_lock; //To synchronize the queue
|
||||||
mutable semaphore tx_sem;
|
mutable semaphore tx_sem;
|
||||||
|
mutable semaphore rx_sem;
|
||||||
|
|
||||||
size_t rx_thread_pid;
|
size_t rx_thread_pid;
|
||||||
size_t tx_thread_pid;
|
size_t tx_thread_pid;
|
||||||
|
@ -16,8 +16,8 @@
|
|||||||
|
|
||||||
struct semaphore {
|
struct semaphore {
|
||||||
private:
|
private:
|
||||||
spinlock lock;
|
mutable spinlock lock;
|
||||||
size_t value;
|
volatile size_t value;
|
||||||
circular_buffer<scheduler::pid_t, 16> queue;
|
circular_buffer<scheduler::pid_t, 16> queue;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "physical_allocator.hpp"
|
#include "physical_allocator.hpp"
|
||||||
#include "scheduler.hpp"
|
#include "scheduler.hpp"
|
||||||
#include "logging.hpp"
|
#include "logging.hpp"
|
||||||
|
#include "ethernet_layer.hpp"
|
||||||
|
|
||||||
#include "fs/sysfs.hpp"
|
#include "fs/sysfs.hpp"
|
||||||
|
|
||||||
@ -29,7 +30,11 @@ void rx_thread(void* data){
|
|||||||
logging::logf(logging::log_level::TRACE, "network: RX Thread for interface %u started (pid:%u)\n", interface.id, pid);
|
logging::logf(logging::log_level::TRACE, "network: RX Thread for interface %u started (pid:%u)\n", interface.id, pid);
|
||||||
|
|
||||||
while(true){
|
while(true){
|
||||||
scheduler::block_process(pid);
|
interface.rx_sem.acquire();
|
||||||
|
|
||||||
|
auto packet = interface.rx_queue.pop();
|
||||||
|
network::ethernet::decode(interface, packet);
|
||||||
|
delete[] packet.payload;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,6 +75,7 @@ void network::init(){
|
|||||||
interface.driver_data = nullptr;
|
interface.driver_data = nullptr;
|
||||||
interface.tx_lock.init(1);
|
interface.tx_lock.init(1);
|
||||||
interface.tx_sem.init(0);
|
interface.tx_sem.init(0);
|
||||||
|
interface.rx_sem.init(0);
|
||||||
|
|
||||||
if(pci_device.vendor_id == 0x10EC && pci_device.device_id == 0x8139){
|
if(pci_device.vendor_id == 0x10EC && pci_device.device_id == 0x8139){
|
||||||
interface.enabled = true;
|
interface.enabled = true;
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "paging.hpp"
|
#include "paging.hpp"
|
||||||
#include "semaphore.hpp"
|
#include "semaphore.hpp"
|
||||||
#include "paging.hpp"
|
#include "paging.hpp"
|
||||||
|
#include "int_lock.hpp"
|
||||||
|
|
||||||
#include "ethernet_layer.hpp"
|
#include "ethernet_layer.hpp"
|
||||||
|
|
||||||
@ -88,6 +89,7 @@ struct rtl8139_t {
|
|||||||
|
|
||||||
void packet_handler(interrupt::syscall_regs*, void* data){
|
void packet_handler(interrupt::syscall_regs*, void* data){
|
||||||
auto& desc = *static_cast<rtl8139_t*>(data);
|
auto& desc = *static_cast<rtl8139_t*>(data);
|
||||||
|
auto& interface = *desc.interface;
|
||||||
|
|
||||||
// Get the interrupt status
|
// Get the interrupt status
|
||||||
auto status = in_word(desc.iobase + ISR);
|
auto status = in_word(desc.iobase + ISR);
|
||||||
@ -126,9 +128,14 @@ void packet_handler(interrupt::syscall_regs*, void* data){
|
|||||||
std::copy_n(packet_buffer, packet_payload, packet_only_length);
|
std::copy_n(packet_buffer, packet_payload, packet_only_length);
|
||||||
|
|
||||||
network::ethernet::packet packet(packet_buffer, packet_only_length);
|
network::ethernet::packet packet(packet_buffer, packet_only_length);
|
||||||
network::ethernet::decode(*desc.interface, packet);
|
|
||||||
|
|
||||||
delete[] packet_buffer;
|
direct_int_lock lock;
|
||||||
|
|
||||||
|
logging::logf(logging::log_level::TRACE, "rtl8139: interface 1 %u\n", reinterpret_cast<size_t>(&interface));
|
||||||
|
interface.rx_queue.push(packet);
|
||||||
|
logging::logf(logging::log_level::TRACE, "rtl8139: interface 2 %u\n", reinterpret_cast<size_t>(&interface));
|
||||||
|
interface.rx_sem.release();
|
||||||
|
logging::logf(logging::log_level::TRACE, "rtl8139: interface 3 %u\n", reinterpret_cast<size_t>(&interface));
|
||||||
}
|
}
|
||||||
|
|
||||||
cur_rx = (cur_rx + packet_length + 4 + 3) & ~3; //align on 4 bytes
|
cur_rx = (cur_rx + packet_length + 4 + 3) & ~3; //align on 4 bytes
|
||||||
|
Loading…
x
Reference in New Issue
Block a user