iPXE
|
Realtek 10/100/1000 network card driver. More...
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <byteswap.h>
#include <ipxe/netdevice.h>
#include <ipxe/ethernet.h>
#include <ipxe/if_ether.h>
#include <ipxe/iobuf.h>
#include <ipxe/malloc.h>
#include <ipxe/pci.h>
#include <ipxe/dma.h>
#include <ipxe/nvs.h>
#include <ipxe/threewire.h>
#include <ipxe/bitbash.h>
#include <ipxe/mii.h>
#include "realtek.h"
Go to the source code of this file.
Functions | |
FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
static void | realtek_dump (struct realtek_nic *rtl) |
Dump all registers (for debugging) More... | |
static void | realtek_spi_open_bit (struct bit_basher *basher) |
Open bit-bashing interface. More... | |
static void | realtek_spi_close_bit (struct bit_basher *basher) |
Close bit-bashing interface. More... | |
static int | realtek_spi_read_bit (struct bit_basher *basher, unsigned int bit_id) |
Read input bit. More... | |
static void | realtek_spi_write_bit (struct bit_basher *basher, unsigned int bit_id, unsigned long data) |
Set/clear output bit. More... | |
static int | realtek_init_eeprom (struct net_device *netdev) |
Initialise EEPROM. More... | |
static int | realtek_mii_read (struct mii_interface *mdio, unsigned int phy __unused, unsigned int reg) |
Read from MII register. More... | |
static int | realtek_mii_write (struct mii_interface *mdio, unsigned int phy __unused, unsigned int reg, unsigned int data) |
Write to MII register. More... | |
static int | realtek_reset (struct realtek_nic *rtl) |
Reset hardware. More... | |
static int | realtek_phy_speed (struct realtek_nic *rtl) |
Configure PHY for Gigabit operation. More... | |
static int | realtek_phy_reset (struct realtek_nic *rtl) |
Reset PHY. More... | |
static void | realtek_check_link (struct net_device *netdev) |
Check link state. More... | |
static int | realtek_create_buffer (struct realtek_nic *rtl) |
Create receive buffer (legacy mode) More... | |
static void | realtek_destroy_buffer (struct realtek_nic *rtl) |
Destroy receive buffer (legacy mode) More... | |
static int | realtek_create_ring (struct realtek_nic *rtl, struct realtek_ring *ring) |
Create descriptor ring. More... | |
static void | realtek_destroy_ring (struct realtek_nic *rtl, struct realtek_ring *ring) |
Destroy descriptor ring. More... | |
static void | realtek_refill_rx (struct realtek_nic *rtl) |
Refill receive descriptor ring. More... | |
static int | realtek_open (struct net_device *netdev) |
Open network device. More... | |
static void | realtek_close (struct net_device *netdev) |
Close network device. More... | |
static int | realtek_transmit (struct net_device *netdev, struct io_buffer *iobuf) |
Transmit packet. More... | |
static void | realtek_poll_tx (struct net_device *netdev) |
Poll for completed packets. More... | |
static void | realtek_legacy_poll_rx (struct net_device *netdev) |
Poll for received packets (legacy mode) More... | |
static void | realtek_poll_rx (struct net_device *netdev) |
Poll for received packets. More... | |
static void | realtek_poll (struct net_device *netdev) |
Poll for completed and received packets. More... | |
static void | realtek_irq (struct net_device *netdev, int enable) |
Enable or disable interrupts. More... | |
static void | realtek_detect (struct realtek_nic *rtl) |
Detect device type. More... | |
static int | realtek_probe (struct pci_device *pci) |
Probe PCI device. More... | |
static void | realtek_remove (struct pci_device *pci) |
Remove PCI device. More... | |
Variables | |
static const uint8_t | realtek_eeprom_bits [] |
Pin mapping for SPI bit-bashing interface. More... | |
static struct bit_basher_operations | realtek_basher_ops |
SPI bit-bashing interface. More... | |
static struct mii_operations | realtek_mii_operations |
Realtek MII operations. More... | |
static struct net_device_operations | realtek_operations |
Realtek network device operations. More... | |
static struct pci_device_id | realtek_nics [] |
Realtek PCI device IDs. More... | |
struct pci_driver realtek_driver | __pci_driver |
Realtek PCI driver. More... | |
Realtek 10/100/1000 network card driver.
Based on the following datasheets:
http://www.datasheetarchive.com/dl/Datasheets-8/DSA-153536.pdf http://www.datasheetarchive.com/indexdl/Datasheet-028/DSA00494723.pdf
Definition in file realtek.c.
FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
|
static |
|
static |
Open bit-bashing interface.
basher | Bit-bashing interface |
Definition at line 103 of file realtek.c.
References spi_bit_basher::basher, container_of, readb(), realtek_nic::regs, RTL_9346CR, RTL_9346CR_EEM_EEPROM, realtek_nic::spibit, and writeb().
|
static |
Close bit-bashing interface.
basher | Bit-bashing interface |
Definition at line 117 of file realtek.c.
References spi_bit_basher::basher, container_of, readb(), realtek_nic::regs, RTL_9346CR, RTL_9346CR_EEM_NORMAL, realtek_nic::spibit, and writeb().
|
static |
Read input bit.
basher | Bit-bashing interface |
bit_id | Bit number |
zero | Input is a logic 0 |
non-zero | Input is a logic 1 |
Definition at line 134 of file realtek.c.
References spi_bit_basher::basher, container_of, DBG_DISABLE, DBG_ENABLE, DBGLVL_IO, readb(), realtek_eeprom_bits, reg, realtek_nic::regs, RTL_9346CR, and realtek_nic::spibit.
|
static |
Set/clear output bit.
basher | Bit-bashing interface |
bit_id | Bit number |
data | Value to write |
Definition at line 154 of file realtek.c.
References spi_bit_basher::basher, container_of, data, DBG_DISABLE, DBG_ENABLE, DBGLVL_IO, readb(), realtek_eeprom_bits, reg, realtek_nic::regs, RTL_9346CR, realtek_nic::spibit, and writeb().
|
static |
Initialise EEPROM.
netdev | Network device |
rc | Return status code |
Definition at line 184 of file realtek.c.
References spi_bit_basher::basher, spi_bit_basher::bus, cpu_to_le16, DBGC, realtek_nic::eeprom, ENODEV, id, init_spi_bit_basher(), le16_to_cpu, spi_bus::mode, netdev, NULL, realtek_nic::nvo, nvo_init(), spi_device::nvs, nvs_read(), bit_basher::op, net_device::priv, rc, readb(), readl(), realtek_basher_ops, net_device::refcnt, realtek_nic::regs, RTL_CONFIG1, RTL_CONFIG1_VPD, RTL_EEPROM_ID, RTL_EEPROM_ID_MAGIC, RTL_EEPROM_VPD, RTL_EEPROM_VPD_LEN, RTL_RCR, RTL_RCR_9356SEL, SPI_MODE_THREEWIRE, realtek_nic::spibit, and strerror().
Referenced by realtek_probe().
|
static |
Read from MII register.
mdio | MII interface |
phy | PHY address |
reg | Register address |
value | Data read, or negative error |
Definition at line 251 of file realtek.c.
References container_of, DBGC, ENOTSUP, ETIMEDOUT, realtek_nic::have_phy_regs, realtek_nic::mdio, readl(), reg, realtek_nic::regs, RTL_MII_MAX_WAIT_US, RTL_PHYAR, RTL_PHYAR_DATA, RTL_PHYAR_FLAG, RTL_PHYAR_VALUE, udelay(), value, and writel().
|
static |
Write to MII register.
mdio | MII interface |
phy | PHY address |
reg | Register address |
data | Data to write |
rc | Return status code |
Definition at line 292 of file realtek.c.
References container_of, data, DBGC, ENOTSUP, ETIMEDOUT, realtek_nic::have_phy_regs, realtek_nic::mdio, readl(), reg, realtek_nic::regs, RTL_MII_MAX_WAIT_US, RTL_PHYAR, RTL_PHYAR_FLAG, RTL_PHYAR_VALUE, udelay(), and writel().
|
static |
Reset hardware.
rtl | Realtek device |
rc | Return status code |
Definition at line 342 of file realtek.c.
References DBGC, ETIMEDOUT, mdelay(), readb(), realtek_nic::regs, RTL_CR, RTL_CR_RST, RTL_RESET_MAX_WAIT_MS, and writeb().
Referenced by realtek_close(), realtek_probe(), and realtek_remove().
|
static |
Configure PHY for Gigabit operation.
rtl | Realtek device |
rc | Return status code |
Definition at line 370 of file realtek.c.
References ADVERTISE_1000FULL, ADVERTISE_1000HALF, DBGC, realtek_nic::mii, MII_CTRL1000, mii_read(), mii_write(), rc, and strerror().
Referenced by realtek_phy_reset().
|
static |
Reset PHY.
rtl | Realtek device |
rc | Return status code |
Definition at line 400 of file realtek.c.
References DBGC, realtek_nic::have_phy_regs, realtek_nic::mii, MII_MMD_DATA, mii_reset(), mii_restart(), mii_write(), rc, realtek_phy_speed(), and strerror().
Referenced by realtek_probe().
|
static |
Check link state.
netdev | Network device |
Definition at line 455 of file realtek.c.
References DBGC, realtek_nic::have_phy_regs, realtek_nic::mii, mii_dump(), netdev, netdev_link_down(), netdev_link_up(), net_device::priv, readb(), realtek_nic::regs, RTL_MSR, RTL_MSR_AUX_STATUS, RTL_MSR_LINKB, RTL_MSR_RXFCE, RTL_MSR_RXPF, RTL_MSR_SPEED_10, RTL_MSR_TXFCE, RTL_MSR_TXPF, RTL_PHYSTATUS, RTL_PHYSTATUS_1000MF, RTL_PHYSTATUS_100M, RTL_PHYSTATUS_10M, RTL_PHYSTATUS_ENTBI, RTL_PHYSTATUS_FULLDUP, RTL_PHYSTATUS_LINKSTS, RTL_PHYSTATUS_RXFLOW, and RTL_PHYSTATUS_TXFLOW.
Referenced by realtek_open(), realtek_poll(), and realtek_probe().
|
static |
Create receive buffer (legacy mode)
rtl | Realtek device |
rc | Return status code |
Definition at line 518 of file realtek.c.
References realtek_rx_buffer::data, DBGC, realtek_nic::dma, dma(), dma_alloc(), ENOMEM, realtek_nic::legacy, len, realtek_rx_buffer::map, realtek_nic::regs, RTL_RBSTART, RTL_RXBUF_ALIGN, RTL_RXBUF_LEN, RTL_RXBUF_PAD, realtek_nic::rxbuf, virt_to_phys(), and writel().
Referenced by realtek_open().
|
static |
Destroy receive buffer (legacy mode)
rtl | Realtek device |
Definition at line 547 of file realtek.c.
References realtek_rx_buffer::data, dma_free(), realtek_nic::legacy, len, realtek_rx_buffer::map, NULL, realtek_rx_buffer::offset, realtek_nic::regs, RTL_RBSTART, RTL_RXBUF_LEN, RTL_RXBUF_PAD, realtek_nic::rxbuf, and writel().
Referenced by realtek_close(), and realtek_open().
|
static |
Create descriptor ring.
rtl | Realtek device |
ring | Descriptor ring |
rc | Return status code |
Definition at line 571 of file realtek.c.
References address, DBGC, realtek_ring::desc, realtek_nic::dma, dma(), dma_alloc(), ENOMEM, realtek_nic::legacy, realtek_ring::len, realtek_ring::map, memset(), realtek_ring::reg, realtek_nic::regs, RTL_RING_ALIGN, virt_to_phys(), and writel().
Referenced by realtek_open().
|
static |
Destroy descriptor ring.
rtl | Realtek device |
ring | Descriptor ring |
Definition at line 606 of file realtek.c.
References realtek_ring::cons, realtek_ring::desc, dma_free(), realtek_nic::legacy, realtek_ring::len, realtek_ring::map, NULL, realtek_ring::prod, realtek_ring::reg, realtek_nic::regs, and writel().
Referenced by realtek_close(), and realtek_open().
|
static |
Refill receive descriptor ring.
rtl | Realtek device |
Definition at line 631 of file realtek.c.
References alloc_rx_iob(), assert(), realtek_ring::cons, cpu_to_le16, cpu_to_le64, io_buffer::data, DBGC2, realtek_ring::desc, realtek_nic::dma, iob_dma(), realtek_nic::legacy, NULL, realtek_ring::prod, RTL_DESC_EOR, RTL_DESC_OWN, RTL_NUM_RX_DESC, RTL_RX_MAX_LEN, rx, realtek_nic::rx, realtek_nic::rx_iobuf, virt_to_phys(), and wmb().
Referenced by realtek_open(), and realtek_poll().
|
static |
Open network device.
netdev | Network device |
rc | Return status code |
Definition at line 679 of file realtek.c.
References netdev, net_device::priv, rc, readl(), realtek_check_link(), realtek_create_buffer(), realtek_create_ring(), realtek_destroy_buffer(), realtek_destroy_ring(), realtek_refill_rx(), realtek_nic::regs, RTL_CR, RTL_CR_RE, RTL_CR_TE, RTL_MAR0, RTL_MAR4, RTL_RCR, RTL_RCR_AAP, RTL_RCR_AB, RTL_RCR_AM, RTL_RCR_APM, RTL_RCR_MXDMA_DEFAULT, RTL_RCR_MXDMA_MASK, RTL_RCR_RBLEN_DEFAULT, RTL_RCR_RBLEN_MASK, RTL_RCR_RXFTH_DEFAULT, RTL_RCR_RXFTH_MASK, RTL_RCR_STOP_WORKING, RTL_RCR_WRAP, RTL_TCR, RTL_TCR_MXDMA_DEFAULT, RTL_TCR_MXDMA_MASK, realtek_nic::rx, realtek_nic::tx, writeb(), and writel().
|
static |
Close network device.
netdev | Network device |
Definition at line 743 of file realtek.c.
References free_rx_iob(), realtek_nic::legacy, netdev, NULL, net_device::priv, realtek_destroy_buffer(), realtek_destroy_ring(), realtek_reset(), realtek_nic::regs, RTL_CR, RTL_NUM_RX_DESC, realtek_nic::rx, realtek_nic::rx_iobuf, realtek_nic::tx, and writeb().
|
static |
Transmit packet.
netdev | Network device |
iobuf | I/O buffer |
rc | Return status code |
Definition at line 778 of file realtek.c.
References realtek_ring::cons, cpu_to_le16, cpu_to_le64, io_buffer::data, DBGC2, realtek_ring::desc, realtek_nic::dma, ETH_ZLEN, iob_dma(), iob_len(), iob_map_tx(), iob_pad(), realtek_nic::legacy, netdev, netdev_tx_defer(), net_device::priv, realtek_ring::prod, rc, realtek_nic::regs, RTL_DESC_EOR, RTL_DESC_FS, RTL_DESC_LS, RTL_DESC_OWN, RTL_NUM_TX_DESC, RTL_TPPOLL_NPQ, RTL_TSAD, RTL_TSD, RTL_TSD_ERTXTH_DEFAULT, realtek_nic::tppoll, tx, realtek_nic::tx, virt_to_phys(), wmb(), writeb(), and writel().
|
static |
Poll for completed packets.
netdev | Network device |
Definition at line 841 of file realtek.c.
References realtek_ring::cons, cpu_to_le16, DBGC2, realtek_ring::desc, realtek_nic::legacy, netdev, netdev_tx_complete_next(), net_device::priv, realtek_ring::prod, readl(), realtek_nic::regs, RTL_DESC_OWN, RTL_NUM_TX_DESC, RTL_TSD, RTL_TSD_OWN, tx, and realtek_nic::tx.
Referenced by realtek_poll().
|
static |
Poll for received packets (legacy mode)
netdev | Network device |
Definition at line 881 of file realtek.c.
References alloc_iob(), cpu_to_le16, realtek_rx_buffer::data, DBGC, DBGC2, EIO, ENOMEM, iob_put, iob_unput, le16_to_cpu, len, memcpy(), netdev, netdev_rx(), netdev_rx_err(), NULL, realtek_rx_buffer::offset, net_device::priv, readb(), readw(), realtek_nic::regs, RTL_CAPR, RTL_CR, RTL_CR_BUFE, RTL_RXBUF_LEN, RTL_STAT_ROK, rx, realtek_nic::rxbuf, and writew.
Referenced by realtek_poll_rx().
|
static |
Poll for received packets.
netdev | Network device |
Definition at line 937 of file realtek.c.
References realtek_ring::cons, cpu_to_le16, DBGC, DBGC2, realtek_ring::desc, EIO, iob_put, le16_to_cpu, realtek_nic::legacy, len, netdev, netdev_rx(), netdev_rx_err(), NULL, net_device::priv, realtek_ring::prod, realtek_legacy_poll_rx(), RTL_DESC_OWN, RTL_DESC_RES, RTL_DESC_SIZE_MASK, RTL_NUM_RX_DESC, rx, realtek_nic::rx, and realtek_nic::rx_iobuf.
Referenced by realtek_poll().
|
static |
Poll for completed and received packets.
netdev | Network device |
Definition at line 987 of file realtek.c.
References isr, netdev, net_device::priv, readw(), realtek_check_link(), realtek_poll_rx(), realtek_poll_tx(), realtek_refill_rx(), realtek_nic::regs, RTL_IRQ_PUN_LINKCHG, RTL_IRQ_RER, RTL_IRQ_ROK, RTL_IRQ_TER, RTL_IRQ_TOK, RTL_ISR, and writew.
|
static |
Enable or disable interrupts.
netdev | Network device |
enable | Interrupts should be enabled |
Definition at line 1019 of file realtek.c.
References imr, netdev, net_device::priv, realtek_nic::regs, RTL_IMR, RTL_IRQ_PUN_LINKCHG, RTL_IRQ_RER, RTL_IRQ_ROK, RTL_IRQ_TER, RTL_IRQ_TOK, and writew.
|
static |
Detect device type.
rtl | Realtek device |
Definition at line 1050 of file realtek.c.
References spi_bit_basher::bus, spi_device::bus, DBGC, realtek_nic::dma, dma_set_mask_64bit(), realtek_nic::eeprom, realtek_nic::have_phy_regs, realtek_nic::legacy, readw(), realtek_nic::regs, RTL_CPCR, RTL_CPCR_CPRX, RTL_CPCR_CPTX, RTL_CPCR_DAC, RTL_CPCR_MULRW, RTL_CPCR_VLAN, RTL_RMS, RTL_RX_MAX_LEN, RTL_TPPOLL_8139CP, RTL_TPPOLL_8169, realtek_nic::spibit, realtek_nic::tppoll, and writew.
Referenced by realtek_probe().
|
static |
Probe PCI device.
pci | PCI device |
rc | Return status code |
Definition at line 1109 of file realtek.c.
References adjust_pci_device(), alloc_etherdev(), spi_device::bus, DBGC, pci_device::dev, net_device::dev, pci_device::dma, realtek_nic::dma, realtek_nic::eeprom, ENODEV, ENOMEM, ETH_ALEN, net_device::hw_addr, iounmap(), realtek_nic::mdio, mdio_init(), pci_device::membase, memset(), realtek_nic::mii, mii_init(), netdev, netdev_init(), netdev_nullify(), netdev_put(), netdev_settings(), realtek_nic::nvo, nvo_block::nvs, spi_device::nvs, nvs_read(), pci_ioremap(), pci_set_drvdata(), net_device::priv, rc, readb(), realtek_check_link(), realtek_detect(), realtek_init_eeprom(), realtek_init_ring(), realtek_mii_operations, realtek_operations, realtek_phy_reset(), realtek_reset(), register_netdev(), register_nvo(), realtek_nic::regs, RTL_BAR_SIZE, RTL_EEPROM_MAC, RTL_IDR0, RTL_NUM_RX_DESC, RTL_NUM_TX_DESC, RTL_RDSAR, RTL_TNPDS, realtek_nic::rx, strerror(), realtek_nic::tx, and unregister_netdev().
|
static |
Remove PCI device.
pci | PCI device |
Definition at line 1213 of file realtek.c.
References iounmap(), netdev, netdev_nullify(), netdev_put(), realtek_nic::nvo, nvo_block::nvs, pci_get_drvdata(), net_device::priv, realtek_reset(), realtek_nic::regs, unregister_netdev(), and unregister_nvo().
|
static |
Pin mapping for SPI bit-bashing interface.
Definition at line 91 of file realtek.c.
Referenced by realtek_spi_read_bit(), and realtek_spi_write_bit().
|
static |
SPI bit-bashing interface.
Definition at line 171 of file realtek.c.
Referenced by realtek_init_eeprom().
|
static |
Realtek MII operations.
Definition at line 324 of file realtek.c.
Referenced by realtek_probe().
|
static |
Realtek network device operations.
Definition at line 1030 of file realtek.c.
Referenced by realtek_probe().
|
static |
struct pci_driver realtek_driver __pci_driver |
Realtek PCI driver.