Retro Rocket Kernel
BASIC-Powered Operating System
rtl8139.h File Reference
#include <kernel.h>

Data Structures

struct  tx_desc_t
 Transfer description. More...
 
struct  rtl8139_dev_t
 PCI device configuration. More...
 

Macros

#define RTL8139_VENDOR_ID   0x10EC
 
#define RTL8139_DEVICE_ID   0x8139
 
#define RX_BUF_SIZE   8192
 
#define CAPR   0x38
 
#define RX_READ_POINTER_MASK   (~3)
 
#define CR_RST   0x10
 
#define CR_RE   0x08
 
#define CR_TE   0x04
 
#define CR_BUFE   0x01
 
#define get_mac_addr(x)   rtl8139_get_mac_addr(x)
 

Enumerations

enum  rtl8139_recv_status {
  ROK = 0x01 , RER = 0x02 , TOK = 0x04 , TER = 0x08 ,
  X_TOK = 0x8000
}
 
enum  rtl8139_tx_status_bits {
  TX_SIZE = 0b00000000000000000001111111111111 , TX_OWN = 0b00000000000000000010000000000000 , TX_TUN = 0b00000000000000000100000000000000 , TX_TOK = 0b00000000000000001000000000000000 ,
  TX_EARLY_THRESHOLD = 0b00000000001111110000000000000000 , TX_RESERVED = 0b00000000110000000000000000000000 , TX_NCC = 0b00001111000000000000000000000000 , TX_CDH = 0b00010000000000000000000000000000 ,
  TX_OWC = 0b00100000000000000000000000000000 , TX_TABT = 0b01000000000000000000000000000000 , TX_CRS = 0b10000000000000000000000000000000
}
 
enum  rtl8139_rx_status_bits {
  RX_ROK = 0b00000000000000000000000000000001 , RX_FAE = 0b00000000000000000000000000000010 , RX_CRC = 0b00000000000000000000000000000100 , RX_LONG = 0b00000000000000000000000000001000 ,
  RX_RUNT = 0b00000000000000000000000000010000 , RX_ISE = 0b00000000000000000000000000100000 , RX_RESERVED = 0b00000000000000000000111111000000 , RX_BAR = 0b00000000000000000001000000000000 ,
  RX_PAM = 0b00000000000000000010000000000000 , RX_MAR = 0b00000000000000000100000000000000
}
 
enum  rtl8139_interrupt_reg_bits {
  RX_OK = 0x01 , RX_ERR = 0x02 , TX_OK = 0x04 , TX_ERR = 0x08 ,
  RX_OVERFLOW = 0x10 , RX_UNDERRUN = 0x20 , RX_FIFO_OVERFLOW = 0x40 , CABLE_LENGTH_CHANGE = 0x2000 ,
  PCS_TIMEOUT = 0x4000 , PCI_ERR = 0x8000 , INT_DEFAULT = TX_OK | RX_OK
}
 
enum  rtl8139_chip_cmd_bits { RXBUFEMPTY = 0x01 , CMDTXENB = 0x04 , CMDRXENB = 0x08 , CMDRESET = 0x10 }
 
enum  rtl8139_rxconfig_bits {
  RX_ACCEPTALLPHYS = 0x01 , RX_ACCEPTMYPHYS = 0x02 , RX_ACCEPTMULTICAST = 0x04 , RX_ACCEPTBROADCAST = 0x08 ,
  RX_ACCEPTRUNT = 0x10 , RX_ACCEPTERR = 0x20 , RX_CFGWRAP = 0x80
}
 
enum  rtl8139_registers {
  MAC0 = 0x00 , MAC1 = 0x04 , MAR0 = 0x08 , TxStatus0 = 0x10 ,
  TxAddr0 = 0x20 , RxBuf = 0x30 , RxEarlyCnt = 0x34 , RxEarlyStatus = 0x36 ,
  ChipCmd = 0x37 , RxBufPtr = 0x38 , RxBufAddr = 0x3A , IntrMask = 0x3C ,
  IntrStatus = 0x3E , TxConfig = 0x40 , RxConfig = 0x44 , Timer = 0x48 ,
  RxMissed = 0x4C , Cfg9346 = 0x50 , Config0 = 0x51 , Config1 = 0x52 ,
  FlashReg = 0x54 , GPPinData = 0x58 , GPPinDir = 0x59 , MII_SMI = 0x5A ,
  HltClk = 0x5B , MultiIntr = 0x5C , TxSummary = 0x60 , MII_BMCR = 0x62 ,
  MII_BMSR = 0x64 , NWayAdvert = 0x66 , NWayLPAR = 0x68 , NWayExpansion = 0x6A ,
  FIFOTMS = 0x70 , CSCR = 0x74 , PARA78 = 0x78 , PARA7c = 0x7C
}
 Port registers for RTL8139 https://datasheetspdf.com/pdf-file/1092361/RealtekMicroelectronics/RTL8139B/1. More...
 

Functions

void rtl8139_send_packet (void *data, uint32_t len)
 Send a raw packet. More...
 
void rtl8139_handler (uint8_t isr, uint64_t error, uint64_t irq, void *opaque)
 Handle RTL8139 interrupt. More...
 
bool init_rtl8139 ()
 Initialise RTL8139. More...
 
char * read_mac_addr ()
 Get the MAC address of the card in display format. More...
 
void receive_packet ()
 Handle receipt of packet from ISR. More...
 
void rtl8139_get_mac_addr ()
 Get the mac address from the IO ports. More...
 

Detailed Description

Author
Craig Edwards (craig.nosp@m.edwa.nosp@m.rds@b.nosp@m.rain.nosp@m.box.c.nosp@m.c)

Macro Definition Documentation

◆ CAPR

#define CAPR   0x38

◆ CR_BUFE

#define CR_BUFE   0x01

◆ CR_RE

#define CR_RE   0x08

◆ CR_RST

#define CR_RST   0x10

◆ CR_TE

#define CR_TE   0x04

◆ get_mac_addr

#define get_mac_addr (   x)    rtl8139_get_mac_addr(x)

◆ RTL8139_DEVICE_ID

#define RTL8139_DEVICE_ID   0x8139

◆ RTL8139_VENDOR_ID

#define RTL8139_VENDOR_ID   0x10EC

◆ RX_BUF_SIZE

#define RX_BUF_SIZE   8192

◆ RX_READ_POINTER_MASK

#define RX_READ_POINTER_MASK   (~3)

Enumeration Type Documentation

◆ rtl8139_chip_cmd_bits

Enumerator
RXBUFEMPTY 
CMDTXENB 
CMDRXENB 
CMDRESET 

◆ rtl8139_interrupt_reg_bits

Enumerator
RX_OK 
RX_ERR 
TX_OK 
TX_ERR 
RX_OVERFLOW 
RX_UNDERRUN 
RX_FIFO_OVERFLOW 
CABLE_LENGTH_CHANGE 
PCS_TIMEOUT 
PCI_ERR 
INT_DEFAULT 

◆ rtl8139_recv_status

Enumerator
ROK 
RER 
TOK 
TER 
X_TOK 

◆ rtl8139_registers

Port registers for RTL8139 https://datasheetspdf.com/pdf-file/1092361/RealtekMicroelectronics/RTL8139B/1.

  1. Register Descriptions
Enumerator
MAC0 
MAC1 
MAR0 
TxStatus0 
TxAddr0 
RxBuf 
RxEarlyCnt 
RxEarlyStatus 
ChipCmd 
RxBufPtr 
RxBufAddr 
IntrMask 
IntrStatus 
TxConfig 
RxConfig 
Timer 
RxMissed 
Cfg9346 
Config0 
Config1 
FlashReg 
GPPinData 
GPPinDir 
MII_SMI 
HltClk 
MultiIntr 
TxSummary 
MII_BMCR 
MII_BMSR 
NWayAdvert 
NWayLPAR 
NWayExpansion 
FIFOTMS 
CSCR 
PARA78 
PARA7c 

◆ rtl8139_rx_status_bits

Enumerator
RX_ROK 
RX_FAE 
RX_CRC 
RX_LONG 
RX_RUNT 
RX_ISE 
RX_RESERVED 
RX_BAR 
RX_PAM 
RX_MAR 

◆ rtl8139_rxconfig_bits

Enumerator
RX_ACCEPTALLPHYS 
RX_ACCEPTMYPHYS 
RX_ACCEPTMULTICAST 
RX_ACCEPTBROADCAST 
RX_ACCEPTRUNT 
RX_ACCEPTERR 
RX_CFGWRAP 

◆ rtl8139_tx_status_bits

Enumerator
TX_SIZE 
TX_OWN 
TX_TUN 
TX_TOK 
TX_EARLY_THRESHOLD 
TX_RESERVED 
TX_NCC 
TX_CDH 
TX_OWC 
TX_TABT 
TX_CRS 

Function Documentation

◆ init_rtl8139()

bool init_rtl8139 ( )

Initialise RTL8139.

Returns
true card detected and initialised
false card not detected, or would not reset

◆ read_mac_addr()

char* read_mac_addr ( )

Get the MAC address of the card in display format.

Returns
char* MAC address

◆ receive_packet()

void receive_packet ( )

Handle receipt of packet from ISR.

◆ rtl8139_get_mac_addr()

void rtl8139_get_mac_addr ( )

Get the mac address from the IO ports.

◆ rtl8139_handler()

void rtl8139_handler ( uint8_t  isr,
uint64_t  error,
uint64_t  irq,
void *  opaque 
)

Handle RTL8139 interrupt.

Parameters
isrISR number (32 + ISR)
errorerror code
irqActual IRQ number
opaquePointer to device details

◆ rtl8139_send_packet()

void rtl8139_send_packet ( void *  data,
uint32_t  len 
)

Send a raw packet.

Parameters
datapacket data
lenpacket length