6#include <sys/kassert.h>
9#include <sys/semaphore.h>
15#include <machine/pmap.h>
26 { 0x8086100e,
"E1000", 0 },
37#define E1000_REG_CTRL 0x0000
38#define E1000_REG_STATUS 0x0008
39#define E1000_REG_EECD 0x0010
40#define E1000_REG_EERD 0x0014
41#define E1000_REG_ICR 0x00C0
42#define E1000_REG_ICS 0x00C8
43#define E1000_REG_IMS 0x00D0
44#define E1000_REG_IMC 0x00D8
45#define E1000_REG_RCTL 0x0100
46#define E1000_REG_TCTL 0x0400
48#define E1000_REG_RDBAL 0x2800
49#define E1000_REG_RDBAH 0x2804
50#define E1000_REG_RDLEN 0x2808
51#define E1000_REG_RDH 0x2810
52#define E1000_REG_RDT 0x2818
53#define E1000_REG_RDTR 0x2820
55#define E1000_REG_TDBAL 0x3800
56#define E1000_REG_TDBAH 0x3804
57#define E1000_REG_TDLEN 0x3808
58#define E1000_REG_TDH 0x3810
59#define E1000_REG_TDT 0x3818
60#define E1000_REG_TIDV 0x3820
61#define E1000_REG_TADV 0x382C
63#define E1000_REG_MTABASE 0x5200
66#define NVM_MAC_ADDR 0x0000
67#define NVM_DEVICE_ID 0x000D
68#define NVM_VENDOR_ID 0x000E
71#define CTRL_SLU (1 << 6)
74#define RCTL_EN (1 << 1)
75#define RCTL_SBP (1 << 2)
76#define RCTL_UPE (1 << 3)
77#define RCTL_MPE (1 << 4)
78#define RCTL_LPE (1 << 5)
79#define RCTL_BSIZE_1K (0x1 << 16)
80#define RCTL_BSIZE_2K (0x0 << 16)
81#define RCTL_BSIZE_4K ((1 << 25) | (0x3 << 16))
82#define RCTL_BSIZE_8K ((1 << 25) | (0x2 << 16))
83#define RCTL_BSIZE_16K ((1 << 25) | (0x1 << 16))
86#define TCTL_EN (1 << 1)
87#define TCTL_PSP (1 << 3)
90#define ICR_TXDW (1 << 0)
91#define ICR_LSC (1 << 2)
92#define ICR_RXO (1 << 6)
93#define ICR_RXT0 (1 << 7)
104#define RDESC_STATUS_EOP (1 << 1)
105#define RDESC_STATUS_DD (1 << 0)
107#define RDESC_ERROR_RDE (1 << 7)
108#define RDESC_ERROR_CE (1 << 0)
120#define TDESC_CMD_RS (1 << 3)
121#define TDESC_CMD_IC (1 << 2)
122#define TDESC_CMD_IFCS (1 << 1)
123#define TDESC_CMD_EOP (1 << 0)
142#define E1000_TX_QLEN 128
143#define E1000_RX_QLEN 128
145#define E1000_MAX_MTU 9000
221 return (
uint16_t)((val >> 16) & 0x0000FFFF);
252 kprintf(
"E1000: Error in RX Queue %x\n",
275 kprintf(
"E1000 (%d:%d) Interrupt\n",
307 kprintf(
"E1000: Unhandled cause %08x\n", cause);
384 for (i = 0; i < 128; i++) {
443 ASSERT((
void *)ethDev == (
void *)ðDev->
nic);
463 kprintf(
"E1000: BAR%d base=%08x size=%08x %s\n",
480 kprintf(
"E1000: MAC XX:XX:XX:XX:XX:XX\n");
481 for (
int i = 0; i < 3; i++) {
uint16_t PCI_GetVendorID(PCIDevice *dev)
uint16_t PCI_GetDeviceID(PCIDevice *dev)
void PCI_Configure(PCIDevice *dev)
#define E1000_REG_MTABASE
void E1000_TXPoll(E1000Dev *dev)
static void MMIO_Write32(E1000Dev *dev, uint64_t addr, uint32_t val)
static uint16_t E1000_EEPROM_Read(E1000Dev *dev, uint8_t addr)
static E1000Device deviceList[]
volatile uint16_t special
void E1000_RXPoll(E1000Dev *dev)
static uint32_t MMIO_Read32(E1000Dev *dev, uint64_t addr)
int E1000_Enqueue(NIC *nic, MBuf *mbuf, NICCB cb, void *arg)
void E1000_Configure(PCIDevice dev)
void E1000_TXInit(E1000Dev *dev)
void RXPOOL_Free(void *buf)
int E1000_Dequeue(NIC *nic, MBuf *mbuf, NICCB cb, void *arg)
void E1000_Init(uint32_t bus, uint32_t slot, uint32_t func)
void E1000_Interrupt(void *arg)
volatile uint16_t special
void E1000_RXInit(E1000Dev *dev)
void IRQ_Register(int irq, struct IRQHandler *h)
int kprintf(const char *fmt,...)
void Slab_Free(Slab *slab, void *obj)
void * PAlloc_AllocPage()
void * Slab_Alloc(Slab *slab) __attribute__((malloc))
#define DEFINE_SLAB(_type, _pool)
void Slab_Init(Slab *slab, const char *name, uintptr_t objsz, uintptr_t align)
void NIC_AddNIC(NIC *nic)
void(* NICCB)(int, void *)
PCIBAR bars[PCI_MAX_BARS]
void Semaphore_Release(Semaphore *sema)
void Semaphore_Acquire(Semaphore *sema)
void Semaphore_Init(Semaphore *sema, int count, const char *name)
void Spinlock_Unlock(Spinlock *lock) __UNLOCK_EX(*lock)
#define SPINLOCK_TYPE_NORMAL
void Spinlock_Lock(Spinlock *lock) __LOCK_EX(*lock)
void Spinlock_Init(Spinlock *lock, const char *name, uint64_t type)
void * memcpy(void *dst, const void *src, size_t len)
int(* tx)(NIC *, MBuf *, NICCB, void *)
int(* rx)(NIC *, MBuf *, NICCB, void *)