|
AquilaOS documentation
How it works, and its code
|
The driver for Intel's 8254x (e1000) and 82574L Ethernet controllers. More...
#include <core/system.h>#include <core/arch.h>#include <core/module.h>#include <core/printk.h>#include <core/string.h>#include <cpu/io.h>#include <dev/pci.h>#include <mm/mm.h>#include <net/netif.h>#include <dev/irq.h>#include <aquila/errno.h>Go to the source code of this file.
Data Structures | |
| struct | rx_desc |
| A receive descriptor: a buffer, and what the controller put in it. More... | |
| struct | tx_desc |
| A transmit descriptor: a frame to send, and whether it was sent. More... | |
| struct | e1000 |
| The controller: there is one. More... | |
Macros | |
| #define | E1000_CTRL 0x0000 |
| #define | E1000_STATUS 0x0008 |
| #define | E1000_EERD 0x0014 |
| #define | E1000_ICR 0x00C0 |
| #define | E1000_IMS 0x00D0 |
| #define | E1000_IMC 0x00D8 |
| #define | E1000_RCTL 0x0100 |
| #define | E1000_TCTL 0x0400 |
| #define | E1000_TIPG 0x0410 |
| #define | E1000_RDBAL 0x2800 |
| #define | E1000_RDBAH 0x2804 |
| #define | E1000_RDLEN 0x2808 |
| #define | E1000_RDH 0x2810 |
| #define | E1000_RDT 0x2818 |
| #define | E1000_TDBAL 0x3800 |
| #define | E1000_TDBAH 0x3804 |
| #define | E1000_TDLEN 0x3808 |
| #define | E1000_TDH 0x3810 |
| #define | E1000_TDT 0x3818 |
| #define | E1000_MTA 0x5200 |
| #define | E1000_RAL 0x5400 |
| #define | E1000_RAH 0x5404 |
| #define | CTRL_ASDE (1 << 5) |
| #define | CTRL_SLU (1 << 6) |
| #define | CTRL_RST (1 << 26) |
| #define | STATUS_LU (1 << 1) |
| #define | EERD_START (1 << 0) |
| #define | EERD_DONE (1 << 4) |
| #define | ICR_TXDW (1 << 0) |
| #define | ICR_LSC (1 << 2) |
| #define | ICR_RXDMT0 (1 << 4) |
| #define | ICR_RXO (1 << 6) |
| #define | ICR_RXT0 (1 << 7) |
| #define | RCTL_EN (1 << 1) |
| #define | RCTL_BAM (1 << 15) |
| #define | RCTL_SECRC (1 << 26) |
| #define | TCTL_EN (1 << 1) |
| #define | TCTL_PSP (1 << 3) |
| #define | TCTL_CT (0x0F << 4) |
| #define | TCTL_COLD (0x40 << 12) |
| #define | RAH_AV (1U << 31) |
| #define | DESC_DD (1 << 0) |
| #define | DESC_EOP (1 << 1) |
| #define | TXCMD_EOP (1 << 0) |
| #define | TXCMD_IFCS (1 << 1) |
| #define | TXCMD_RS (1 << 3) |
| #define | RX_DESCS 32 |
| #define | TX_DESCS 32 |
| #define | BUF_SIZE 2048 |
Functions | |
| static uint32_t | reg_read (uint32_t reg) |
| Reads one of the controller's registers. | |
| static void | reg_write (uint32_t reg, uint32_t val) |
| Writes one of the controller's registers. | |
| static paddr_t | page_get (void **virt) |
| Allocates a zeroed page for the rings or buffers, once, at boot. | |
| static uint16_t | eeprom_read (uint8_t addr) |
| Reads a 16-bit word of the EEPROM, or returns 0 if the read doesn't finish in time. | |
| static void | mac_read (uint8_t mac[6]) |
| Reads the card's MAC address: from the receive address registers if they have it, from the EEPROM otherwise (and then tells the receiver). | |
| static void | rx_init (void) |
| Sets up the receive ring, every descriptor with its buffer, all of them the controller's, and turns the receiver on. | |
| static void | tx_init (void) |
| Sets up the transmit ring, every descriptor with its buffer and free, and turns the transmitter on. | |
| static int | e1000_transmit (struct netif *netif, struct netbuf *nb) |
| Sends a frame: it is copied into the next transmit buffer, and the controller is told. | |
| static void | rx_poll (void) |
| Gives the frames the controller received to the network stack, and their descriptors back to the controller. | |
| static void | link_check (void) |
| Marks the interface running or not, from whether the link is up. | |
| static void | e1000_irq (void *arg) |
| Handles the controller's interrupt: a change of the link, or frames received. | |
| static int | e1000_probe (void) |
| Finds a controller of the family on the PCI bus, sets it up, and registers its network interface. | |
Variables | |
| static struct e1000 | e1000 |
| static const uint16_t | device_ids [] |
The driver for Intel's 8254x (e1000) and 82574L Ethernet controllers.
The 82540EM is QEMU's default network card on x86. The controller receives frames into the buffers of a ring of descriptors, which it fills and interrupts for, and sends frames from a second ring. Both rings and their buffers are pages of memory, which the driver reaches through the direct map and whose physical addresses it gives the controller. A received frame is copied into a netbuf and given to the network stack; a frame to send is copied into a transmit buffer.
The 82574L (QEMU's e1000e) is driven the same way, with its legacy descriptors; it interrupts with MSI when there is an APIC to take it.
References: [1] - PCI/PCI-X Family of Gigabit Ethernet Controllers Software Developer's Manual (8254x), Intel, 317453 [2] - 82574 GbE Controller Family Datasheet, Intel, 317694
Definition in file e1000.c.
| #define CTRL_ASDE (1 << 5) |
Definition at line 59 of file e1000.c.
Referenced by e1000_probe().
| #define CTRL_RST (1 << 26) |
Definition at line 61 of file e1000.c.
Referenced by e1000_probe().
| #define CTRL_SLU (1 << 6) |
Definition at line 60 of file e1000.c.
Referenced by e1000_probe().
| #define DESC_DD (1 << 0) |
Definition at line 107 of file e1000.c.
Referenced by e1000_transmit(), rx_poll(), and tx_init().
| #define E1000_CTRL 0x0000 |
Definition at line 36 of file e1000.c.
Referenced by e1000_probe().
| #define E1000_EERD 0x0014 |
Definition at line 38 of file e1000.c.
Referenced by eeprom_read().
| #define E1000_ICR 0x00C0 |
Definition at line 39 of file e1000.c.
Referenced by e1000_irq(), and e1000_probe().
| #define E1000_IMC 0x00D8 |
Definition at line 41 of file e1000.c.
Referenced by e1000_probe().
| #define E1000_IMS 0x00D0 |
Definition at line 40 of file e1000.c.
Referenced by e1000_probe().
| #define E1000_MTA 0x5200 |
Definition at line 55 of file e1000.c.
Referenced by e1000_probe().
| #define E1000_RAH 0x5404 |
Definition at line 57 of file e1000.c.
Referenced by mac_read().
| #define E1000_RAL 0x5400 |
Definition at line 56 of file e1000.c.
Referenced by mac_read().
| #define E1000_RDT 0x2818 |
| #define E1000_STATUS 0x0008 |
Definition at line 37 of file e1000.c.
Referenced by link_check().
| #define E1000_TDT 0x3818 |
Definition at line 54 of file e1000.c.
Referenced by e1000_transmit(), and tx_init().
| #define EERD_DONE (1 << 4) |
Definition at line 66 of file e1000.c.
Referenced by eeprom_read().
| #define EERD_START (1 << 0) |
Definition at line 65 of file e1000.c.
Referenced by eeprom_read().
| #define ICR_LSC (1 << 2) |
Definition at line 69 of file e1000.c.
Referenced by e1000_irq(), and e1000_probe().
| #define ICR_RXDMT0 (1 << 4) |
Definition at line 70 of file e1000.c.
Referenced by e1000_irq(), and e1000_probe().
| #define ICR_RXO (1 << 6) |
Definition at line 71 of file e1000.c.
Referenced by e1000_irq(), and e1000_probe().
| #define ICR_RXT0 (1 << 7) |
Definition at line 72 of file e1000.c.
Referenced by e1000_irq(), and e1000_probe().
| #define RAH_AV (1U << 31) |
Definition at line 84 of file e1000.c.
Referenced by mac_read().
| #define STATUS_LU (1 << 1) |
Definition at line 63 of file e1000.c.
Referenced by link_check().
| #define TX_DESCS 32 |
Definition at line 115 of file e1000.c.
Referenced by e1000_transmit(), and tx_init().
| #define TXCMD_EOP (1 << 0) |
Definition at line 110 of file e1000.c.
Referenced by e1000_transmit().
| #define TXCMD_IFCS (1 << 1) |
Definition at line 111 of file e1000.c.
Referenced by e1000_transmit().
| #define TXCMD_RS (1 << 3) |
Definition at line 112 of file e1000.c.
Referenced by e1000_transmit().
|
static |
Handles the controller's interrupt: a change of the link, or frames received.
Definition at line 357 of file e1000.c.
References E1000_ICR, e1000_irq(), ICR_LSC, ICR_RXDMT0, ICR_RXO, ICR_RXT0, link_check(), reg_read(), and rx_poll().
Referenced by e1000_irq(), and e1000_probe().
|
static |
Finds a controller of the family on the PCI bus, sets it up, and registers its network interface.
Without one, it does nothing.
Definition at line 371 of file e1000.c.
References ioaddr::addr, pci_bar::addr, arch_mmio_map(), CTRL_ASDE, CTRL_RST, CTRL_SLU, device_ids, E1000_CTRL, E1000_ICR, E1000_IMC, E1000_IMS, e1000_irq(), E1000_MTA, e1000_probe(), e1000_transmit(), netif::flags, ICR_LSC, ICR_RXDMT0, ICR_RXO, ICR_RXT0, pci_bar::io, IOADDR_MMIO8, e1000::irq, irq_install(), link_check(), netif::mac, mac_read(), e1000::netif, netif_register(), NETIF_RUNNING, NULL, e1000::pci, pci_device_scan(), pci_enable(), pci_irq(), pci_msi_enable(), printk(), netif::priv, reg_read(), reg_write(), e1000::regs, rx_init(), pci_bar::size, netif::transmit, tx_init(), and ioaddr::type.
Referenced by e1000_probe().
Sends a frame: it is copied into the next transmit buffer, and the controller is told.
Returns 0, -EMSGSIZE for a frame too big, or -ENOBUFS if the ring is full (the frame is dropped).
Definition at line 279 of file e1000.c.
References BUF_SIZE, tx_desc::cmd, netbuf::data, DESC_DD, E1000_TDT, e1000_transmit(), netbuf::len, tx_desc::length, memcpy(), reg_write(), netif::stats, tx_desc::status, e1000::tx, e1000::tx_buf, TX_DESCS, e1000::tx_next, TXCMD_EOP, TXCMD_IFCS, and TXCMD_RS.
Referenced by e1000_probe(), and e1000_transmit().
Reads a 16-bit word of the EEPROM, or returns 0 if the read doesn't finish in time.
Definition at line 174 of file e1000.c.
References E1000_EERD, eeprom_read(), EERD_DONE, EERD_START, reg_read(), and reg_write().
Referenced by eeprom_read(), and mac_read().
|
static |
Marks the interface running or not, from whether the link is up.
Definition at line 347 of file e1000.c.
References E1000_STATUS, netif::flags, link_check(), e1000::netif, NETIF_RUNNING, reg_read(), and STATUS_LU.
Referenced by e1000_irq(), e1000_probe(), and link_check().
|
static |
Reads the card's MAC address: from the receive address registers if they have it, from the EEPROM otherwise (and then tells the receiver).
Definition at line 190 of file e1000.c.
References E1000_RAH, E1000_RAL, eeprom_read(), mac_read(), RAH_AV, reg_read(), and reg_write().
Referenced by e1000_probe(), and mac_read().
|
static |
Allocates a zeroed page for the rings or buffers, once, at boot.
Returns its physical address, and sets *virt to its kernel address. It panics if there is no memory: the kernel can't boot without that little.
Definition at line 161 of file e1000.c.
References arch_phys_map(), memset(), mm_page_alloc(), vm_page::paddr, page_get(), PAGE_SIZE, and panic.
Referenced by page_get(), rx_init(), and tx_init().
Reads one of the controller's registers.
Definition at line 146 of file e1000.c.
References io_in32(), reg_read(), and e1000::regs.
Referenced by e1000_irq(), e1000_probe(), eeprom_read(), link_check(), mac_read(), and reg_read().
Writes one of the controller's registers.
Definition at line 152 of file e1000.c.
References io_out32(), reg_write(), and e1000::regs.
Referenced by e1000_probe(), e1000_transmit(), eeprom_read(), mac_read(), reg_write(), rx_init(), rx_poll(), and tx_init().
|
static |
Sets up the receive ring, every descriptor with its buffer, all of them the controller's, and turns the receiver on.
Definition at line 216 of file e1000.c.
References rx_desc::addr, BUF_SIZE, E1000_RCTL, E1000_RDBAH, E1000_RDBAL, E1000_RDH, E1000_RDLEN, E1000_RDT, vm_page::paddr, page_get(), PAGE_SIZE, RCTL_BAM, RCTL_EN, RCTL_SECRC, reg_write(), e1000::rx, e1000::rx_buf, RX_DESCS, rx_init(), and e1000::rx_next.
Referenced by e1000_probe(), and rx_init().
|
static |
Gives the frames the controller received to the network stack, and their descriptors back to the controller.
Definition at line 311 of file e1000.c.
References DESC_DD, DESC_EOP, E1000_RDT, rx_desc::errors, netbuf::len, rx_desc::length, memcpy(), netbuf_alloc(), NETBUF_SIZE, e1000::netif, netif_input(), reg_write(), e1000::rx, e1000::rx_buf, RX_DESCS, e1000::rx_next, rx_poll(), netif::stats, and rx_desc::status.
Referenced by e1000_irq(), and rx_poll().
|
static |
Sets up the transmit ring, every descriptor with its buffer and free, and turns the transmitter on.
Definition at line 246 of file e1000.c.
References tx_desc::addr, BUF_SIZE, DESC_DD, E1000_TCTL, E1000_TDBAH, E1000_TDBAL, E1000_TDH, E1000_TDLEN, E1000_TDT, E1000_TIPG, vm_page::paddr, page_get(), PAGE_SIZE, reg_write(), tx_desc::status, TCTL_COLD, TCTL_CT, TCTL_EN, TCTL_PSP, e1000::tx, e1000::tx_buf, TX_DESCS, tx_init(), and e1000::tx_next.
Referenced by e1000_probe(), and tx_init().
|
static |
Definition at line 134 of file e1000.c.
Referenced by e1000_probe().
|
static |