Voxia OS v0.0.1
Hobby Project Operating System Targeting x86-64
Loading...
Searching...
No Matches
e1000.cpp File Reference
#include "e1000/e1000.hpp"
#include "ioforge/ioforge.h"
#include "ioforge/ioforge_nic.h"
#include <type.h>

Go to the source code of this file.

Data Structures

struct  rx_buf_lookup_entry
 

Macros

#define IO_ADDR_OFFSET   0x0
 
#define IO_DATA_OFFSET   0x4
 
#define REG_CTRL   0x0000
 
#define REG_STATUS   0x0008
 
#define REG_EEPROM   0x0014
 
#define REG_CTRL_EXT   0x0018
 
#define REG_IMASK   0x00D0
 
#define REG_RCTRL   0x0100
 
#define REG_RXDESCLO   0x2800
 
#define REG_RXDESCHI   0x2804
 
#define REG_RXDESCLEN   0x2808
 
#define REG_RXDESCHEAD   0x2810
 
#define REG_RXDESCTAIL   0x2818
 
#define IMS_RXT0   (1 << 7)
 
#define IMS_RXO   (1 << 6)
 
#define IMS_RXDMT0   (1 << 4)
 
#define IMS_LSC   (1 << 2)
 
#define IMS_RXQ0   (1 << 20)
 
#define IMS_TXQ0   (1 << 22)
 
#define IMS_OTHER   (1 << 24)
 
#define REG_TCTRL   0x0400
 
#define REG_TXDESCLO   0x3800
 
#define REG_TXDESCHI   0x3804
 
#define REG_TXDESCLEN   0x3808
 
#define REG_TXDESCHEAD   0x3810
 
#define REG_TXDESCTAIL   0x3818
 
#define REG_RDTR   0x2820
 
#define REG_RXDCTL   0x2828
 
#define REG_RADV   0x282C
 
#define REG_RSRPD   0x2C00
 
#define REG_TIPG   0x0410
 
#define ECTRL_SLU   0x40
 
#define RCTL_EN   (1 << 1)
 
#define RCTL_SBP   (1 << 2)
 
#define RCTL_UPE   (1 << 3)
 
#define RCTL_MPE   (1 << 4)
 
#define RCTL_LPE   (1 << 5)
 
#define RCTL_LBM_NONE   (0 << 6)
 
#define RCTL_LBM_PHY   (3 << 6)
 
#define RTCL_RDMTS_HALF   (0 << 8)
 
#define RTCL_RDMTS_QUARTER   (1 << 8)
 
#define RTCL_RDMTS_EIGHTH   (2 << 8)
 
#define RCTL_MO_36   (0 << 12)
 
#define RCTL_MO_35   (1 << 12)
 
#define RCTL_MO_34   (2 << 12)
 
#define RCTL_MO_32   (3 << 12)
 
#define RCTL_BAM   (1 << 15)
 
#define RCTL_VFE   (1 << 18)
 
#define RCTL_CFIEN   (1 << 19)
 
#define RCTL_CFI   (1 << 20)
 
#define RCTL_DPF   (1 << 22)
 
#define RCTL_PMCF   (1 << 23)
 
#define RCTL_SECRC   (1 << 26)
 
#define RCTL_BSIZE_256   (3 << 16)
 
#define RCTL_BSIZE_512   (2 << 16)
 
#define RCTL_BSIZE_1024   (1 << 16)
 
#define RCTL_BSIZE_2048   (0 << 16)
 
#define RCTL_BSIZE_4096   ((3 << 16) | (1 << 25))
 
#define RCTL_BSIZE_8192   ((2 << 16) | (1 << 25))
 
#define RCTL_BSIZE_16384   ((1 << 16) | (1 << 25))
 
#define CMD_EOP   (1 << 0)
 
#define CMD_IFCS   (1 << 1)
 
#define CMD_IC   (1 << 2)
 
#define CMD_RS   (1 << 3)
 
#define CMD_RPS   (1 << 4)
 
#define CMD_VLE   (1 << 6)
 
#define CMD_IDE   (1 << 7)
 
#define TCTL_EN   (1 << 1)
 
#define TCTL_PSP   (1 << 3)
 
#define TCTL_CT_SHIFT   4
 
#define TCTL_COLD_SHIFT   12
 
#define TCTL_SWXOFF   (1 << 22)
 
#define TCTL_RTLC   (1 << 24)
 
#define TSTA_DD   (1 << 0)
 
#define TSTA_EC   (1 << 1)
 
#define TSTA_LC   (1 << 2)
 
#define LSTA_TU   (1 << 3)
 
#define REG_ICR   0x00C0
 
#define ICR_TXDW   (1 << 0)
 
#define ICR_TXQE   (1 << 1)
 
#define ICR_LSC   (1 << 2)
 
#define ICR_RXSEQ   (1 << 3)
 
#define ICR_RXDMT0   (1 << 4)
 
#define ICR_RXO   (1 << 6)
 
#define ICR_RXT0   (1 << 7)
 
#define ICR_MDAC   (1 << 9)
 
#define ICR_RXCFG   (1 << 10)
 
#define ICR_GPI_EN0   (1 << 11)
 
#define ICR_GPI_EN1   (1 << 12)
 
#define ICR_GPI_EN2   (1 << 13)
 
#define ICR_GPI_EN3   (1 << 14)
 

Functions

static bool pool_pop (struct rx_buffer *out)
 
static void pool_push (uint8_t *vaddr, uint64_t paddr)
 

Variables

static struct e1000_rx_descrx_descs [256]
 
static struct e1000_rx_comp rx_comp [256]
 
static struct e1000_tx_desctx_descs [64]
 
static volatile int setup_tx_done = 0
 
static struct rx_buffer_pool rx_buffer_pool
 
static rx_buf_lookup_entry g_buf_lookup [1280]
 
static uint32_t g_buf_lookup_count = 0
 
static const char hexmap [] = "0123456789ABCDEF"
 

Macro Definition Documentation

◆ CMD_EOP

#define CMD_EOP   (1 << 0)

Definition at line 78 of file e1000.cpp.

Referenced by E1000Module::sendPacket().

◆ CMD_IC

#define CMD_IC   (1 << 2)

Definition at line 80 of file e1000.cpp.

◆ CMD_IDE

#define CMD_IDE   (1 << 7)

Definition at line 84 of file e1000.cpp.

◆ CMD_IFCS

#define CMD_IFCS   (1 << 1)

Definition at line 79 of file e1000.cpp.

Referenced by E1000Module::sendPacket().

◆ CMD_RPS

#define CMD_RPS   (1 << 4)

Definition at line 82 of file e1000.cpp.

◆ CMD_RS

#define CMD_RS   (1 << 3)

Definition at line 81 of file e1000.cpp.

Referenced by E1000Module::sendPacket().

◆ CMD_VLE

#define CMD_VLE   (1 << 6)

Definition at line 83 of file e1000.cpp.

◆ ECTRL_SLU

#define ECTRL_SLU   0x40

Definition at line 43 of file e1000.cpp.

◆ ICR_GPI_EN0

#define ICR_GPI_EN0   (1 << 11)

Definition at line 416 of file e1000.cpp.

◆ ICR_GPI_EN1

#define ICR_GPI_EN1   (1 << 12)

Definition at line 417 of file e1000.cpp.

◆ ICR_GPI_EN2

#define ICR_GPI_EN2   (1 << 13)

Definition at line 418 of file e1000.cpp.

◆ ICR_GPI_EN3

#define ICR_GPI_EN3   (1 << 14)

Definition at line 419 of file e1000.cpp.

◆ ICR_LSC

#define ICR_LSC   (1 << 2)

Definition at line 409 of file e1000.cpp.

◆ ICR_MDAC

#define ICR_MDAC   (1 << 9)

Definition at line 414 of file e1000.cpp.

◆ ICR_RXCFG

#define ICR_RXCFG   (1 << 10)

Definition at line 415 of file e1000.cpp.

◆ ICR_RXDMT0

#define ICR_RXDMT0   (1 << 4)

Definition at line 411 of file e1000.cpp.

◆ ICR_RXO

#define ICR_RXO   (1 << 6)

Definition at line 412 of file e1000.cpp.

◆ ICR_RXSEQ

#define ICR_RXSEQ   (1 << 3)

Definition at line 410 of file e1000.cpp.

◆ ICR_RXT0

#define ICR_RXT0   (1 << 7)

Definition at line 413 of file e1000.cpp.

◆ ICR_TXDW

#define ICR_TXDW   (1 << 0)

Definition at line 407 of file e1000.cpp.

◆ ICR_TXQE

#define ICR_TXQE   (1 << 1)

Definition at line 408 of file e1000.cpp.

◆ IMS_LSC

#define IMS_LSC   (1 << 2)

Definition at line 24 of file e1000.cpp.

◆ IMS_OTHER

#define IMS_OTHER   (1 << 24)

Definition at line 28 of file e1000.cpp.

Referenced by E1000Module::enableInterrupt(), and E1000Module::load().

◆ IMS_RXDMT0

#define IMS_RXDMT0   (1 << 4)

Definition at line 23 of file e1000.cpp.

◆ IMS_RXO

#define IMS_RXO   (1 << 6)

Definition at line 22 of file e1000.cpp.

◆ IMS_RXQ0

#define IMS_RXQ0   (1 << 20)

Definition at line 26 of file e1000.cpp.

Referenced by E1000Module::enableInterrupt(), and E1000Module::load().

◆ IMS_RXT0

#define IMS_RXT0   (1 << 7)

Definition at line 21 of file e1000.cpp.

◆ IMS_TXQ0

#define IMS_TXQ0   (1 << 22)

Definition at line 27 of file e1000.cpp.

Referenced by E1000Module::enableInterrupt(), and E1000Module::load().

◆ IO_ADDR_OFFSET

#define IO_ADDR_OFFSET   0x0

Definition at line 6 of file e1000.cpp.

◆ IO_DATA_OFFSET

#define IO_DATA_OFFSET   0x4

Definition at line 7 of file e1000.cpp.

◆ LSTA_TU

#define LSTA_TU   (1 << 3)

Definition at line 98 of file e1000.cpp.

◆ RCTL_BAM

#define RCTL_BAM   (1 << 15)

Definition at line 59 of file e1000.cpp.

Referenced by E1000Module::initReceiverX().

◆ RCTL_BSIZE_1024

#define RCTL_BSIZE_1024   (1 << 16)

Definition at line 70 of file e1000.cpp.

◆ RCTL_BSIZE_16384

#define RCTL_BSIZE_16384   ((1 << 16) | (1 << 25))

Definition at line 74 of file e1000.cpp.

◆ RCTL_BSIZE_2048

#define RCTL_BSIZE_2048   (0 << 16)

Definition at line 71 of file e1000.cpp.

Referenced by E1000Module::initReceiverX().

◆ RCTL_BSIZE_256

#define RCTL_BSIZE_256   (3 << 16)

Definition at line 68 of file e1000.cpp.

◆ RCTL_BSIZE_4096

#define RCTL_BSIZE_4096   ((3 << 16) | (1 << 25))

Definition at line 72 of file e1000.cpp.

◆ RCTL_BSIZE_512

#define RCTL_BSIZE_512   (2 << 16)

Definition at line 69 of file e1000.cpp.

◆ RCTL_BSIZE_8192

#define RCTL_BSIZE_8192   ((2 << 16) | (1 << 25))

Definition at line 73 of file e1000.cpp.

◆ RCTL_CFI

#define RCTL_CFI   (1 << 20)

Definition at line 62 of file e1000.cpp.

◆ RCTL_CFIEN

#define RCTL_CFIEN   (1 << 19)

Definition at line 61 of file e1000.cpp.

◆ RCTL_DPF

#define RCTL_DPF   (1 << 22)

Definition at line 63 of file e1000.cpp.

◆ RCTL_EN

#define RCTL_EN   (1 << 1)

Definition at line 45 of file e1000.cpp.

Referenced by E1000Module::initReceiverX().

◆ RCTL_LBM_NONE

#define RCTL_LBM_NONE   (0 << 6)

Definition at line 50 of file e1000.cpp.

◆ RCTL_LBM_PHY

#define RCTL_LBM_PHY   (3 << 6)

Definition at line 51 of file e1000.cpp.

◆ RCTL_LPE

#define RCTL_LPE   (1 << 5)

Definition at line 49 of file e1000.cpp.

◆ RCTL_MO_32

#define RCTL_MO_32   (3 << 12)

Definition at line 58 of file e1000.cpp.

◆ RCTL_MO_34

#define RCTL_MO_34   (2 << 12)

Definition at line 57 of file e1000.cpp.

◆ RCTL_MO_35

#define RCTL_MO_35   (1 << 12)

Definition at line 56 of file e1000.cpp.

◆ RCTL_MO_36

#define RCTL_MO_36   (0 << 12)

Definition at line 55 of file e1000.cpp.

◆ RCTL_MPE

#define RCTL_MPE   (1 << 4)

Definition at line 48 of file e1000.cpp.

◆ RCTL_PMCF

#define RCTL_PMCF   (1 << 23)

Definition at line 64 of file e1000.cpp.

◆ RCTL_SBP

#define RCTL_SBP   (1 << 2)

Definition at line 46 of file e1000.cpp.

◆ RCTL_SECRC

#define RCTL_SECRC   (1 << 26)

Definition at line 65 of file e1000.cpp.

Referenced by E1000Module::initReceiverX().

◆ RCTL_UPE

#define RCTL_UPE   (1 << 3)

Definition at line 47 of file e1000.cpp.

◆ RCTL_VFE

#define RCTL_VFE   (1 << 18)

Definition at line 60 of file e1000.cpp.

◆ REG_CTRL

#define REG_CTRL   0x0000

Definition at line 9 of file e1000.cpp.

Referenced by E1000Module::linkup().

◆ REG_CTRL_EXT

#define REG_CTRL_EXT   0x0018

Definition at line 12 of file e1000.cpp.

◆ REG_EEPROM

#define REG_EEPROM   0x0014

Definition at line 11 of file e1000.cpp.

Referenced by E1000Module::detectEeprom(), and E1000Module::readEeprom().

◆ REG_ICR

#define REG_ICR   0x00C0

Definition at line 101 of file e1000.cpp.

Referenced by E1000Module::enableInterrupt().

◆ REG_IMASK

#define REG_IMASK   0x00D0

Definition at line 13 of file e1000.cpp.

Referenced by E1000Module::disableInterrupt(), and E1000Module::enableInterrupt().

◆ REG_RADV

#define REG_RADV   0x282C

Definition at line 39 of file e1000.cpp.

Referenced by E1000Module::initReceiverX().

◆ REG_RCTRL

#define REG_RCTRL   0x0100

Definition at line 14 of file e1000.cpp.

Referenced by E1000Module::initReceiverX().

◆ REG_RDTR

#define REG_RDTR   0x2820

Definition at line 37 of file e1000.cpp.

Referenced by E1000Module::initReceiverX().

◆ REG_RSRPD

#define REG_RSRPD   0x2C00

Definition at line 40 of file e1000.cpp.

◆ REG_RXDCTL

#define REG_RXDCTL   0x2828

Definition at line 38 of file e1000.cpp.

Referenced by E1000Module::initReceiverX().

◆ REG_RXDESCHEAD

#define REG_RXDESCHEAD   0x2810

Definition at line 18 of file e1000.cpp.

Referenced by E1000Module::initReceiverX().

◆ REG_RXDESCHI

#define REG_RXDESCHI   0x2804

Definition at line 16 of file e1000.cpp.

Referenced by E1000Module::initReceiverX().

◆ REG_RXDESCLEN

#define REG_RXDESCLEN   0x2808

Definition at line 17 of file e1000.cpp.

Referenced by E1000Module::initReceiverX().

◆ REG_RXDESCLO

#define REG_RXDESCLO   0x2800

Definition at line 15 of file e1000.cpp.

Referenced by E1000Module::initReceiverX().

◆ REG_RXDESCTAIL

#define REG_RXDESCTAIL   0x2818

Definition at line 19 of file e1000.cpp.

Referenced by E1000Module::initReceiverX(), and E1000Module::receiveHandle().

◆ REG_STATUS

#define REG_STATUS   0x0008

Definition at line 10 of file e1000.cpp.

◆ REG_TCTRL

#define REG_TCTRL   0x0400

Definition at line 30 of file e1000.cpp.

Referenced by E1000Module::initTransmitterX().

◆ REG_TIPG

#define REG_TIPG   0x0410

Definition at line 42 of file e1000.cpp.

Referenced by E1000Module::initTransmitterX().

◆ REG_TXDESCHEAD

#define REG_TXDESCHEAD   0x3810

Definition at line 34 of file e1000.cpp.

Referenced by E1000Module::initTransmitterX().

◆ REG_TXDESCHI

#define REG_TXDESCHI   0x3804

Definition at line 32 of file e1000.cpp.

Referenced by E1000Module::initTransmitterX().

◆ REG_TXDESCLEN

#define REG_TXDESCLEN   0x3808

Definition at line 33 of file e1000.cpp.

Referenced by E1000Module::initTransmitterX().

◆ REG_TXDESCLO

#define REG_TXDESCLO   0x3800

Definition at line 31 of file e1000.cpp.

Referenced by E1000Module::initTransmitterX().

◆ REG_TXDESCTAIL

#define REG_TXDESCTAIL   0x3818

Definition at line 35 of file e1000.cpp.

Referenced by E1000Module::initTransmitterX(), and E1000Module::sendPacket().

◆ RTCL_RDMTS_EIGHTH

#define RTCL_RDMTS_EIGHTH   (2 << 8)

Definition at line 54 of file e1000.cpp.

◆ RTCL_RDMTS_HALF

#define RTCL_RDMTS_HALF   (0 << 8)

Definition at line 52 of file e1000.cpp.

◆ RTCL_RDMTS_QUARTER

#define RTCL_RDMTS_QUARTER   (1 << 8)

Definition at line 53 of file e1000.cpp.

◆ TCTL_COLD_SHIFT

#define TCTL_COLD_SHIFT   12

Definition at line 91 of file e1000.cpp.

Referenced by E1000Module::initTransmitterX().

◆ TCTL_CT_SHIFT

#define TCTL_CT_SHIFT   4

Definition at line 90 of file e1000.cpp.

Referenced by E1000Module::initTransmitterX().

◆ TCTL_EN

#define TCTL_EN   (1 << 1)

Definition at line 88 of file e1000.cpp.

Referenced by E1000Module::initTransmitterX().

◆ TCTL_PSP

#define TCTL_PSP   (1 << 3)

Definition at line 89 of file e1000.cpp.

Referenced by E1000Module::initTransmitterX().

◆ TCTL_RTLC

#define TCTL_RTLC   (1 << 24)

Definition at line 93 of file e1000.cpp.

Referenced by E1000Module::initTransmitterX().

◆ TCTL_SWXOFF

#define TCTL_SWXOFF   (1 << 22)

Definition at line 92 of file e1000.cpp.

◆ TSTA_DD

#define TSTA_DD   (1 << 0)

Definition at line 95 of file e1000.cpp.

Referenced by E1000Module::initTransmitterX().

◆ TSTA_EC

#define TSTA_EC   (1 << 1)

Definition at line 96 of file e1000.cpp.

◆ TSTA_LC

#define TSTA_LC   (1 << 2)

Definition at line 97 of file e1000.cpp.

Function Documentation

◆ pool_pop()

static bool pool_pop ( struct rx_buffer * out)
static

◆ pool_push()

Variable Documentation

◆ g_buf_lookup

rx_buf_lookup_entry g_buf_lookup[1280]
static

Definition at line 116 of file e1000.cpp.

Referenced by E1000Module::initReceiverX(), and E1000Module::storeBufferToPool().

◆ g_buf_lookup_count

uint32_t g_buf_lookup_count = 0
static

Definition at line 117 of file e1000.cpp.

Referenced by E1000Module::initReceiverX(), and E1000Module::storeBufferToPool().

◆ hexmap

const char hexmap[] = "0123456789ABCDEF"
static

Definition at line 160 of file e1000.cpp.

Referenced by E1000Module::syncMacAddress().

◆ rx_buffer_pool

struct rx_buffer_pool rx_buffer_pool
static

Definition at line 110 of file e1000.cpp.

◆ rx_comp

struct e1000_rx_comp rx_comp[256]
static

Definition at line 104 of file e1000.cpp.

Referenced by E1000Module::initReceiverX(), and E1000Module::receiveHandle().

◆ rx_descs

struct e1000_rx_desc* rx_descs[256]
static

Definition at line 103 of file e1000.cpp.

Referenced by E1000Module::initReceiverX(), and E1000Module::receiveHandle().

◆ setup_tx_done

volatile int setup_tx_done = 0
static

Definition at line 107 of file e1000.cpp.

Referenced by E1000Module::initTransmitterX(), and E1000Module::sendPacket().

◆ tx_descs

struct e1000_tx_desc* tx_descs[64]
static

Definition at line 105 of file e1000.cpp.

Referenced by E1000Module::initTransmitterX(), and E1000Module::sendPacket().