1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:07:44 +00:00

Kernel: Use AK::Span a bunch in the network adapter code

This commit is contained in:
Andreas Kling 2020-07-28 20:19:22 +02:00
parent fffc5896d8
commit f5ac4da993
12 changed files with 47 additions and 46 deletions

View file

@ -290,13 +290,13 @@ void RTL8139NetworkAdapter::read_mac_address()
set_mac_address(mac);
}
void RTL8139NetworkAdapter::send_raw(const u8* data, size_t length)
void RTL8139NetworkAdapter::send_raw(ReadonlyBytes payload)
{
#ifdef RTL8139_DEBUG
klog() << "RTL8139NetworkAdapter::send_raw length=" << length;
#endif
if (length > PACKET_SIZE_MAX) {
if (payload.size() > PACKET_SIZE_MAX) {
klog() << "RTL8139NetworkAdapter: packet was too big; discarding";
return;
}
@ -322,13 +322,14 @@ void RTL8139NetworkAdapter::send_raw(const u8* data, size_t length)
m_tx_next_buffer = (hw_buffer + 1) % 4;
}
memcpy(m_tx_buffers[hw_buffer]->vaddr().as_ptr(), data, length);
memset(m_tx_buffers[hw_buffer]->vaddr().as_ptr() + length, 0, TX_BUFFER_SIZE - length);
memcpy(m_tx_buffers[hw_buffer]->vaddr().as_ptr(), payload.data(), payload.size());
memset(m_tx_buffers[hw_buffer]->vaddr().as_ptr() + payload.size(), 0, TX_BUFFER_SIZE - payload.size());
// the rtl8139 will not actually emit packets onto the network if they're
// smaller than 64 bytes. the rtl8139 adds a checksum to the end of each
// packet, and that checksum is four bytes long, so we pad the packet to
// 60 bytes if necessary to make sure the whole thing is large enough.
auto length = payload.size();
if (length < 60) {
#ifdef RTL8139_DEBUG
klog() << "RTL8139NetworkAdapter: adjusting payload size from " << length << " to 60";
@ -365,7 +366,7 @@ void RTL8139NetworkAdapter::receive()
out16(REG_CAPR, m_rx_buffer_offset - 0x10);
m_rx_buffer_offset %= RX_BUFFER_SIZE;
did_receive(m_packet_buffer->vaddr().as_ptr(), length - 4);
did_receive({ m_packet_buffer->vaddr().as_ptr(), (size_t)(length - 4) });
}
void RTL8139NetworkAdapter::out8(u16 address, u8 data)