miniOS
x86_64 hobby kernel with SMP, VFS, and POSIX process model
Loading...
Searching...
No Matches
rtl8139.c File Reference
#include <miniOS/drivers/rtl8139.h>
#include <miniOS/arch/x86_64/port.h>
#include <miniOS/io.h>
#include <miniOS/mm/heap.h>
#include <miniOS/mm/vmm.h>
#include <miniOS/net/ethernet.h>
#include <string.h>
Include dependency graph for rtl8139.c:

Classes

struct  rtl8139_state_t

Macros

#define RTL8139_REG_MAC0   0x00
#define RTL8139_REG_MAR0   0x08
#define RTL8139_REG_TXSTATUS0   0x10
#define RTL8139_REG_TXADDR0   0x20
#define RTL8139_REG_RXBUF   0x30
#define RTL8139_REG_CMD   0x37
#define RTL8139_REG_CAPR   0x38
#define RTL8139_REG_CBR   0x3A
#define RTL8139_REG_IMR   0x3C
#define RTL8139_REG_ISR   0x3E
#define RTL8139_REG_TCR   0x40
#define RTL8139_REG_RCR   0x44
#define RTL8139_REG_CONFIG1   0x52
#define RTL8139_CMD_RESET   0x10
#define RTL8139_CMD_RX_ENABLE   0x08
#define RTL8139_CMD_TX_ENABLE   0x04
#define RTL8139_ISR_RX_OK   0x0001
#define RTL8139_ISR_RX_ERR   0x0002
#define RTL8139_ISR_TX_OK   0x0004
#define RTL8139_ISR_TX_ERR   0x0008
#define RTL8139_RX_STATUS_ROK   0x0001
#define RTL8139_TX_DESC_COUNT   4
#define RTL8139_RX_BUFFER_SIZE   8192
#define RTL8139_RX_PAD_SIZE   16
#define RTL8139_RX_WRAP_GUARD   2048
#define RTL8139_RX_RING_SIZE   (RTL8139_RX_BUFFER_SIZE + RTL8139_RX_PAD_SIZE + RTL8139_RX_WRAP_GUARD)

Functions

static void rtl_out8 (uint16_t port, uint8_t value)
static void rtl_out16 (uint16_t port, uint16_t value)
static void rtl_out32 (uint16_t port, uint32_t value)
static uint8_t rtl_in8 (uint16_t port)
static uint16_t rtl_in16 (uint16_t port)
static uint32_t rtl_in32 (uint16_t port)
bool rtl8139_tx_length_valid (size_t frame_len)
bool rtl8139_rx_status_valid (uint16_t status, size_t frame_len, size_t avail_len)
uint32_t rtl8139_ring_advance (uint32_t ring_offset, uint32_t consumed_len, uint32_t ring_size)
static void rtl8139_reset (uint16_t io_base)
static int rtl8139_open (netdev_t *dev)
static int rtl8139_get_mac (netdev_t *dev, uint8_t mac_out[6])
static bool rtl8139_get_link (netdev_t *dev)
static int rtl8139_xmit (netdev_t *dev, const void *frame, size_t frame_len)
int rtl8139_poll (netdev_t *dev)
int rtl8139_probe_and_init (void)
int rtl8139_rx_ready (void)

Variables

static uint8_t g_rtl8139_rx_buf [RTL8139_RX_RING_SIZE]
static uint8_t g_rtl8139_tx_buf [RTL8139_TX_DESC_COUNT][NET_MAX_FRAME_SIZE+4]
static rtl8139_state_t g_rtl8139_state
static netdev_t g_rtl8139_netdev
static const netdev_ops_t g_rtl8139_ops

Macro Definition Documentation

◆ RTL8139_CMD_RESET

#define RTL8139_CMD_RESET   0x10

◆ RTL8139_CMD_RX_ENABLE

#define RTL8139_CMD_RX_ENABLE   0x08

◆ RTL8139_CMD_TX_ENABLE

#define RTL8139_CMD_TX_ENABLE   0x04

◆ RTL8139_ISR_RX_ERR

#define RTL8139_ISR_RX_ERR   0x0002

◆ RTL8139_ISR_RX_OK

#define RTL8139_ISR_RX_OK   0x0001

◆ RTL8139_ISR_TX_ERR

#define RTL8139_ISR_TX_ERR   0x0008

◆ RTL8139_ISR_TX_OK

#define RTL8139_ISR_TX_OK   0x0004

◆ RTL8139_REG_CAPR

#define RTL8139_REG_CAPR   0x38

◆ RTL8139_REG_CBR

#define RTL8139_REG_CBR   0x3A

◆ RTL8139_REG_CMD

#define RTL8139_REG_CMD   0x37

◆ RTL8139_REG_CONFIG1

#define RTL8139_REG_CONFIG1   0x52

◆ RTL8139_REG_IMR

#define RTL8139_REG_IMR   0x3C

◆ RTL8139_REG_ISR

#define RTL8139_REG_ISR   0x3E

◆ RTL8139_REG_MAC0

#define RTL8139_REG_MAC0   0x00

◆ RTL8139_REG_MAR0

#define RTL8139_REG_MAR0   0x08

◆ RTL8139_REG_RCR

#define RTL8139_REG_RCR   0x44

◆ RTL8139_REG_RXBUF

#define RTL8139_REG_RXBUF   0x30

◆ RTL8139_REG_TCR

#define RTL8139_REG_TCR   0x40

◆ RTL8139_REG_TXADDR0

#define RTL8139_REG_TXADDR0   0x20

◆ RTL8139_REG_TXSTATUS0

#define RTL8139_REG_TXSTATUS0   0x10

◆ RTL8139_RX_BUFFER_SIZE

#define RTL8139_RX_BUFFER_SIZE   8192

◆ RTL8139_RX_PAD_SIZE

#define RTL8139_RX_PAD_SIZE   16

◆ RTL8139_RX_RING_SIZE

#define RTL8139_RX_RING_SIZE   (RTL8139_RX_BUFFER_SIZE + RTL8139_RX_PAD_SIZE + RTL8139_RX_WRAP_GUARD)

◆ RTL8139_RX_STATUS_ROK

#define RTL8139_RX_STATUS_ROK   0x0001

◆ RTL8139_RX_WRAP_GUARD

#define RTL8139_RX_WRAP_GUARD   2048

◆ RTL8139_TX_DESC_COUNT

#define RTL8139_TX_DESC_COUNT   4

Function Documentation

◆ rtl8139_get_link()

bool rtl8139_get_link ( netdev_t * dev)
static

◆ rtl8139_get_mac()

int rtl8139_get_mac ( netdev_t * dev,
uint8_t mac_out[6] )
static
Here is the call graph for this function:

◆ rtl8139_open()

int rtl8139_open ( netdev_t * dev)
static

◆ rtl8139_poll()

int rtl8139_poll ( netdev_t * dev)
Here is the call graph for this function:

◆ rtl8139_probe_and_init()

int rtl8139_probe_and_init ( void )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rtl8139_reset()

void rtl8139_reset ( uint16_t io_base)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rtl8139_ring_advance()

uint32_t rtl8139_ring_advance ( uint32_t ring_offset,
uint32_t consumed_len,
uint32_t ring_size )
Here is the caller graph for this function:

◆ rtl8139_rx_ready()

int rtl8139_rx_ready ( void )
Here is the call graph for this function:

◆ rtl8139_rx_status_valid()

bool rtl8139_rx_status_valid ( uint16_t status,
size_t frame_len,
size_t avail_len )
Here is the caller graph for this function:

◆ rtl8139_tx_length_valid()

bool rtl8139_tx_length_valid ( size_t frame_len)
Here is the caller graph for this function:

◆ rtl8139_xmit()

int rtl8139_xmit ( netdev_t * dev,
const void * frame,
size_t frame_len )
static
Here is the call graph for this function:

◆ rtl_in16()

uint16_t rtl_in16 ( uint16_t port)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rtl_in32()

uint32_t rtl_in32 ( uint16_t port)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rtl_in8()

uint8_t rtl_in8 ( uint16_t port)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rtl_out16()

void rtl_out16 ( uint16_t port,
uint16_t value )
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rtl_out32()

void rtl_out32 ( uint16_t port,
uint32_t value )
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rtl_out8()

void rtl_out8 ( uint16_t port,
uint8_t value )
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ g_rtl8139_netdev

netdev_t g_rtl8139_netdev
static

◆ g_rtl8139_ops

const netdev_ops_t g_rtl8139_ops
static
Initial value:
= {
.open = rtl8139_open,
.poll = rtl8139_poll,
.xmit = rtl8139_xmit,
.get_mac = rtl8139_get_mac,
.get_link = rtl8139_get_link,
}
static int rtl8139_open(netdev_t *dev)
Definition rtl8139.c:132
static int rtl8139_xmit(netdev_t *dev, const void *frame, size_t frame_len)
Definition rtl8139.c:151
static int rtl8139_get_mac(netdev_t *dev, uint8_t mac_out[6])
Definition rtl8139.c:138
static bool rtl8139_get_link(netdev_t *dev)
Definition rtl8139.c:145
int rtl8139_poll(netdev_t *dev)
Definition rtl8139.c:194

◆ g_rtl8139_rx_buf

uint8_t g_rtl8139_rx_buf[RTL8139_RX_RING_SIZE]
static

◆ g_rtl8139_state

rtl8139_state_t g_rtl8139_state
static

◆ g_rtl8139_tx_buf

uint8_t g_rtl8139_tx_buf[RTL8139_TX_DESC_COUNT][NET_MAX_FRAME_SIZE+4]
static