iPXE
Functions | Variables
realtek.c File Reference

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/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...
 

Detailed Description

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.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ realtek_dump()

static void realtek_dump ( struct realtek_nic rtl)
static

Dump all registers (for debugging)

Parameters
rtlRealtek device

Definition at line 67 of file realtek.c.

67  {
68  uint8_t regs[256];
69  unsigned int i;
70 
71  /* Do nothing unless debug output is enabled */
72  if ( ! DBG_LOG )
73  return;
74 
75  /* Dump registers (via byte accesses; may not work for all registers) */
76  for ( i = 0 ; i < sizeof ( regs ) ; i++ )
77  regs[i] = readb ( rtl->regs + i );
78  DBGC ( rtl, "REALTEK %p register dump:\n", rtl );
79  DBGC_HDA ( rtl, 0, regs, sizeof ( regs ) );
80 }
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
void * regs
Registers.
Definition: realtek.h:278
#define DBGC_HDA(...)
Definition: compiler.h:506
unsigned char uint8_t
Definition: stdint.h:10
struct i386_regs regs
Definition: registers.h:15
#define DBG_LOG
Definition: compiler.h:317

References DBG_LOG, DBGC, DBGC_HDA, readb(), regs, and realtek_nic::regs.

◆ realtek_spi_open_bit()

static void realtek_spi_open_bit ( struct bit_basher basher)
static

Open bit-bashing interface.

Parameters
basherBit-bashing interface

Definition at line 102 of file realtek.c.

102  {
103  struct realtek_nic *rtl = container_of ( basher, struct realtek_nic,
104  spibit.basher );
105 
106  /* Enable EEPROM access */
108  readb ( rtl->regs + RTL_9346CR ); /* Ensure write reaches chip */
109 }
struct bit_basher basher
Bit-bashing interface.
Definition: spi_bit.h:20
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
void * regs
Registers.
Definition: realtek.h:278
void writeb(uint8_t data, volatile uint8_t *io_addr)
Write byte to memory-mapped device.
#define RTL_9346CR
93C46 (93C56) Command Register (byte)
Definition: realtek.h:161
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
A Realtek network card.
Definition: realtek.h:276
#define RTL_9346CR_EEM_EEPROM
EEPROM mode.
Definition: realtek.h:163
struct spi_bit_basher spibit
SPI bit-bashing interface.
Definition: realtek.h:280

References spi_bit_basher::basher, container_of, readb(), realtek_nic::regs, RTL_9346CR, RTL_9346CR_EEM_EEPROM, realtek_nic::spibit, and writeb().

◆ realtek_spi_close_bit()

static void realtek_spi_close_bit ( struct bit_basher basher)
static

Close bit-bashing interface.

Parameters
basherBit-bashing interface

Definition at line 116 of file realtek.c.

116  {
117  struct realtek_nic *rtl = container_of ( basher, struct realtek_nic,
118  spibit.basher );
119 
120  /* Disable EEPROM access */
122  readb ( rtl->regs + RTL_9346CR ); /* Ensure write reaches chip */
123 }
struct bit_basher basher
Bit-bashing interface.
Definition: spi_bit.h:20
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
void * regs
Registers.
Definition: realtek.h:278
void writeb(uint8_t data, volatile uint8_t *io_addr)
Write byte to memory-mapped device.
#define RTL_9346CR
93C46 (93C56) Command Register (byte)
Definition: realtek.h:161
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
A Realtek network card.
Definition: realtek.h:276
#define RTL_9346CR_EEM_NORMAL
Normal mode.
Definition: realtek.h:164
struct spi_bit_basher spibit
SPI bit-bashing interface.
Definition: realtek.h:280

References spi_bit_basher::basher, container_of, readb(), realtek_nic::regs, RTL_9346CR, RTL_9346CR_EEM_NORMAL, realtek_nic::spibit, and writeb().

◆ realtek_spi_read_bit()

static int realtek_spi_read_bit ( struct bit_basher basher,
unsigned int  bit_id 
)
static

Read input bit.

Parameters
basherBit-bashing interface
bit_idBit number
Return values
zeroInput is a logic 0
non-zeroInput is a logic 1

Definition at line 133 of file realtek.c.

134  {
135  struct realtek_nic *rtl = container_of ( basher, struct realtek_nic,
136  spibit.basher );
137  uint8_t mask = realtek_eeprom_bits[bit_id];
138  uint8_t reg;
139 
141  reg = readb ( rtl->regs + RTL_9346CR );
142  DBG_ENABLE ( DBGLVL_IO );
143  return ( reg & mask );
144 }
struct bit_basher basher
Bit-bashing interface.
Definition: spi_bit.h:20
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
#define DBGLVL_IO
Definition: compiler.h:322
#define DBG_ENABLE(level)
Definition: compiler.h:313
#define DBG_DISABLE(level)
Definition: compiler.h:312
void * regs
Registers.
Definition: realtek.h:278
static const uint8_t realtek_eeprom_bits[]
Pin mapping for SPI bit-bashing interface.
Definition: realtek.c:90
#define RTL_9346CR
93C46 (93C56) Command Register (byte)
Definition: realtek.h:161
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
A Realtek network card.
Definition: realtek.h:276
static unsigned int unsigned int reg
Definition: intel.h:245
unsigned char uint8_t
Definition: stdint.h:10
struct spi_bit_basher spibit
SPI bit-bashing interface.
Definition: realtek.h:280

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.

◆ realtek_spi_write_bit()

static void realtek_spi_write_bit ( struct bit_basher basher,
unsigned int  bit_id,
unsigned long  data 
)
static

Set/clear output bit.

Parameters
basherBit-bashing interface
bit_idBit number
dataValue to write

Definition at line 153 of file realtek.c.

154  {
155  struct realtek_nic *rtl = container_of ( basher, struct realtek_nic,
156  spibit.basher );
157  uint8_t mask = realtek_eeprom_bits[bit_id];
158  uint8_t reg;
159 
161  reg = readb ( rtl->regs + RTL_9346CR );
162  reg &= ~mask;
163  reg |= ( data & mask );
164  writeb ( reg, rtl->regs + RTL_9346CR );
165  readb ( rtl->regs + RTL_9346CR ); /* Ensure write reaches chip */
166  DBG_ENABLE ( DBGLVL_IO );
167 }
struct bit_basher basher
Bit-bashing interface.
Definition: spi_bit.h:20
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
#define DBGLVL_IO
Definition: compiler.h:322
#define DBG_ENABLE(level)
Definition: compiler.h:313
#define DBG_DISABLE(level)
Definition: compiler.h:312
void * regs
Registers.
Definition: realtek.h:278
static const uint8_t realtek_eeprom_bits[]
Pin mapping for SPI bit-bashing interface.
Definition: realtek.c:90
void writeb(uint8_t data, volatile uint8_t *io_addr)
Write byte to memory-mapped device.
#define RTL_9346CR
93C46 (93C56) Command Register (byte)
Definition: realtek.h:161
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
A Realtek network card.
Definition: realtek.h:276
static unsigned int unsigned int reg
Definition: intel.h:245
unsigned char uint8_t
Definition: stdint.h:10
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
struct spi_bit_basher spibit
SPI bit-bashing interface.
Definition: realtek.h:280

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().

◆ realtek_init_eeprom()

static int realtek_init_eeprom ( struct net_device netdev)
static

Initialise EEPROM.

Parameters
netdevNetwork device
Return values
rcReturn status code

Definition at line 183 of file realtek.c.

183  {
184  struct realtek_nic *rtl = netdev->priv;
185  uint16_t id;
186  int rc;
187 
188  /* Initialise SPI bit-bashing interface */
191  init_spi_bit_basher ( &rtl->spibit );
192 
193  /* Detect EEPROM type and initialise three-wire device */
194  if ( readl ( rtl->regs + RTL_RCR ) & RTL_RCR_9356SEL ) {
195  DBGC ( rtl, "REALTEK %p EEPROM is a 93C56\n", rtl );
196  init_at93c56 ( &rtl->eeprom, 16 );
197  } else {
198  DBGC ( rtl, "REALTEK %p EEPROM is a 93C46\n", rtl );
199  init_at93c46 ( &rtl->eeprom, 16 );
200  }
201 
202  /* Check for EEPROM presence. Some onboard NICs will have no
203  * EEPROM connected, with the BIOS being responsible for
204  * programming the initial register values.
205  */
206  if ( ( rc = nvs_read ( &rtl->eeprom.nvs, RTL_EEPROM_ID,
207  &id, sizeof ( id ) ) ) != 0 ) {
208  DBGC ( rtl, "REALTEK %p could not read EEPROM ID: %s\n",
209  rtl, strerror ( rc ) );
210  return rc;
211  }
212  if ( id != cpu_to_le16 ( RTL_EEPROM_ID_MAGIC ) ) {
213  DBGC ( rtl, "REALTEK %p EEPROM ID incorrect (%#04x); assuming "
214  "no EEPROM\n", rtl, le16_to_cpu ( id ) );
215  return -ENODEV;
216  }
217 
218  /* Initialise space for non-volatile options, if available
219  *
220  * We use offset 0x40 (i.e. address 0x20), length 0x40. This
221  * block is marked as VPD in the Realtek datasheets, so we use
222  * it only if we detect that the card is not supporting VPD.
223  */
224  if ( readb ( rtl->regs + RTL_CONFIG1 ) & RTL_CONFIG1_VPD ) {
225  DBGC ( rtl, "REALTEK %p EEPROM in use for VPD; cannot use "
226  "for options\n", rtl );
227  } else {
228  nvo_init ( &rtl->nvo, &rtl->eeprom.nvs, RTL_EEPROM_VPD,
230  }
231 
232  return 0;
233 }
struct bit_basher basher
Bit-bashing interface.
Definition: spi_bit.h:20
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned short uint16_t
Definition: stdint.h:11
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
#define RTL_RCR_9356SEL
EEPROM is a 93C56.
Definition: realtek.h:154
#define RTL_EEPROM_ID_MAGIC
EEPROM code word magic value.
Definition: realtek.h:174
static struct bit_basher_operations realtek_basher_ops
SPI bit-bashing interface.
Definition: realtek.c:170
struct nvo_block nvo
Non-volatile options.
Definition: realtek.h:284
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define RTL_EEPROM_ID
Word offset of ID code word within EEPROM.
Definition: realtek.h:171
#define DBGC(...)
Definition: compiler.h:505
#define RTL_EEPROM_VPD
Word offset of VPD / non-volatile options within EEPROM.
Definition: realtek.h:180
void * regs
Registers.
Definition: realtek.h:278
struct bit_basher_operations * op
Bit-bashing operations.
Definition: bitbash.h:57
unsigned int mode
SPI interface mode.
Definition: spi.h:136
#define RTL_EEPROM_VPD_LEN
Length of VPD / non-volatile options within EEPROM.
Definition: realtek.h:183
#define RTL_CONFIG1
Configuration Register 1 (byte)
Definition: realtek.h:186
#define RTL_CONFIG1_VPD
Vital Product Data enabled.
Definition: realtek.h:187
void * priv
Driver private data.
Definition: netdevice.h:425
void init_spi_bit_basher(struct spi_bit_basher *spibit)
Initialise SPI bit-bashing interface.
Definition: spi_bit.c:235
static struct net_device * netdev
Definition: gdbudp.c:52
A Realtek network card.
Definition: realtek.h:276
uint8_t id
Request identifier.
Definition: ena.h:12
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
struct refcnt refcnt
Reference counter.
Definition: netdevice.h:350
void nvo_init(struct nvo_block *nvo, struct nvs_device *nvs, size_t address, size_t len, int(*resize)(struct nvo_block *nvo, size_t len), struct refcnt *refcnt)
Initialise non-volatile stored options.
Definition: nvo.c:273
#define ENODEV
No such device.
Definition: errno.h:509
#define le16_to_cpu(value)
Definition: byteswap.h:112
struct spi_bus bus
SPI bus.
Definition: spi_bit.h:18
struct nvs_device nvs
NVS device.
Definition: spi.h:88
#define cpu_to_le16(value)
Definition: byteswap.h:106
int nvs_read(struct nvs_device *nvs, unsigned int address, void *data, size_t len)
Read from non-volatile storage device.
Definition: nvs.c:75
#define SPI_MODE_THREEWIRE
Threewire-compatible mode.
Definition: spi.h:199
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
#define RTL_RCR
Receive (Rx) Configuration Register (dword)
Definition: realtek.h:142
struct spi_bit_basher spibit
SPI bit-bashing interface.
Definition: realtek.h:280
struct spi_device eeprom
EEPROM.
Definition: realtek.h:282

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().

◆ realtek_mii_read()

static int realtek_mii_read ( struct mii_interface mdio,
unsigned int phy  __unused,
unsigned int  reg 
)
static

Read from MII register.

Parameters
mdioMII interface
phyPHY address
regRegister address
Return values
valueData read, or negative error

Definition at line 250 of file realtek.c.

251  {
252  struct realtek_nic *rtl =
253  container_of ( mdio, struct realtek_nic, mdio );
254  unsigned int i;
255  uint32_t value;
256 
257  /* Fail if PHYAR register is not present */
258  if ( ! rtl->have_phy_regs )
259  return -ENOTSUP;
260 
261  /* Initiate read */
262  writel ( RTL_PHYAR_VALUE ( 0, reg, 0 ), rtl->regs + RTL_PHYAR );
263 
264  /* Wait for read to complete */
265  for ( i = 0 ; i < RTL_MII_MAX_WAIT_US ; i++ ) {
266 
267  /* If read is not complete, delay 1us and retry */
268  value = readl ( rtl->regs + RTL_PHYAR );
269  if ( ! ( value & RTL_PHYAR_FLAG ) ) {
270  udelay ( 1 );
271  continue;
272  }
273 
274  /* Return register value */
275  return ( RTL_PHYAR_DATA ( value ) );
276  }
277 
278  DBGC ( rtl, "REALTEK %p timed out waiting for MII read\n", rtl );
279  return -ETIMEDOUT;
280 }
#define RTL_MII_MAX_WAIT_US
Maximum time to wait for PHY access, in microseconds.
Definition: realtek.h:210
int have_phy_regs
PHYAR and PHYSTATUS registers are present.
Definition: realtek.h:293
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
void * regs
Registers.
Definition: realtek.h:278
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
#define RTL_PHYAR_VALUE(flag, reg, data)
Construct PHY Access Register value.
Definition: realtek.h:204
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
void udelay(unsigned long usecs)
Delay for a fixed number of microseconds.
Definition: timer.c:60
A Realtek network card.
Definition: realtek.h:276
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
static unsigned int unsigned int reg
Definition: intel.h:245
#define RTL_PHYAR
PHY Access Register (dword, 8169 only)
Definition: realtek.h:200
unsigned int uint32_t
Definition: stdint.h:12
struct mii_interface mdio
MII interface.
Definition: realtek.h:286
#define RTL_PHYAR_DATA(value)
Extract PHY Access Register data.
Definition: realtek.h:207
#define RTL_PHYAR_FLAG
Read/write flag.
Definition: realtek.h:201
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669

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().

◆ realtek_mii_write()

static int realtek_mii_write ( struct mii_interface mdio,
unsigned int phy  __unused,
unsigned int  reg,
unsigned int  data 
)
static

Write to MII register.

Parameters
mdioMII interface
phyPHY address
regRegister address
dataData to write
Return values
rcReturn status code

Definition at line 291 of file realtek.c.

293  {
294  struct realtek_nic *rtl =
295  container_of ( mdio, struct realtek_nic, mdio );
296  unsigned int i;
297 
298  /* Fail if PHYAR register is not present */
299  if ( ! rtl->have_phy_regs )
300  return -ENOTSUP;
301 
302  /* Initiate write */
304  rtl->regs + RTL_PHYAR );
305 
306  /* Wait for write to complete */
307  for ( i = 0 ; i < RTL_MII_MAX_WAIT_US ; i++ ) {
308 
309  /* If write is not complete, delay 1us and retry */
310  if ( readl ( rtl->regs + RTL_PHYAR ) & RTL_PHYAR_FLAG ) {
311  udelay ( 1 );
312  continue;
313  }
314 
315  return 0;
316  }
317 
318  DBGC ( rtl, "REALTEK %p timed out waiting for MII write\n", rtl );
319  return -ETIMEDOUT;
320 }
#define RTL_MII_MAX_WAIT_US
Maximum time to wait for PHY access, in microseconds.
Definition: realtek.h:210
int have_phy_regs
PHYAR and PHYSTATUS registers are present.
Definition: realtek.h:293
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
void * regs
Registers.
Definition: realtek.h:278
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
#define RTL_PHYAR_VALUE(flag, reg, data)
Construct PHY Access Register value.
Definition: realtek.h:204
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
void udelay(unsigned long usecs)
Delay for a fixed number of microseconds.
Definition: timer.c:60
A Realtek network card.
Definition: realtek.h:276
static unsigned int unsigned int reg
Definition: intel.h:245
#define RTL_PHYAR
PHY Access Register (dword, 8169 only)
Definition: realtek.h:200
struct mii_interface mdio
MII interface.
Definition: realtek.h:286
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
#define RTL_PHYAR_FLAG
Read/write flag.
Definition: realtek.h:201
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669

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().

◆ realtek_reset()

static int realtek_reset ( struct realtek_nic rtl)
static

Reset hardware.

Parameters
rtlRealtek device
Return values
rcReturn status code

Definition at line 341 of file realtek.c.

341  {
342  unsigned int i;
343 
344  /* Issue reset */
345  writeb ( RTL_CR_RST, rtl->regs + RTL_CR );
346 
347  /* Wait for reset to complete */
348  for ( i = 0 ; i < RTL_RESET_MAX_WAIT_MS ; i++ ) {
349 
350  /* If reset is not complete, delay 1ms and retry */
351  if ( readb ( rtl->regs + RTL_CR ) & RTL_CR_RST ) {
352  mdelay ( 1 );
353  continue;
354  }
355 
356  return 0;
357  }
358 
359  DBGC ( rtl, "REALTEK %p timed out waiting for reset\n", rtl );
360  return -ETIMEDOUT;
361 }
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
void * regs
Registers.
Definition: realtek.h:278
void writeb(uint8_t data, volatile uint8_t *io_addr)
Write byte to memory-mapped device.
#define RTL_CR_RST
Reset.
Definition: realtek.h:109
#define RTL_CR
Command Register (byte)
Definition: realtek.h:108
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
#define RTL_RESET_MAX_WAIT_MS
Maximum time to wait for a reset, in milliseconds.
Definition: realtek.h:115
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669

References DBGC, ETIMEDOUT, mdelay(), readb(), realtek_nic::regs, RTL_CR, RTL_CR_RST, RTL_RESET_MAX_WAIT_MS, and writeb().

Referenced by realtek_probe(), and realtek_remove().

◆ realtek_phy_speed()

static int realtek_phy_speed ( struct realtek_nic rtl)
static

Configure PHY for Gigabit operation.

Parameters
rtlRealtek device
Return values
rcReturn status code

Definition at line 369 of file realtek.c.

369  {
370  int ctrl1000;
371  int rc;
372 
373  /* Read CTRL1000 register */
374  ctrl1000 = mii_read ( &rtl->mii, MII_CTRL1000 );
375  if ( ctrl1000 < 0 ) {
376  rc = ctrl1000;
377  DBGC ( rtl, "REALTEK %p could not read CTRL1000: %s\n",
378  rtl, strerror ( rc ) );
379  return rc;
380  }
381 
382  /* Advertise 1000Mbps speeds */
383  ctrl1000 |= ( ADVERTISE_1000FULL | ADVERTISE_1000HALF );
384  if ( ( rc = mii_write ( &rtl->mii, MII_CTRL1000, ctrl1000 ) ) != 0 ) {
385  DBGC ( rtl, "REALTEK %p could not write CTRL1000: %s\n",
386  rtl, strerror ( rc ) );
387  return rc;
388  }
389 
390  return 0;
391 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define ADVERTISE_1000FULL
Definition: mii.h:131
#define DBGC(...)
Definition: compiler.h:505
struct mii_device mii
MII device.
Definition: realtek.h:288
#define MII_CTRL1000
Definition: mii.h:24
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define ADVERTISE_1000HALF
Definition: mii.h:132
static int mii_read(int phy_id, int location)
Definition: epic100.c:499
static int mii_write(struct mii_device *mii, unsigned int reg, unsigned int data)
Write to MII register.
Definition: mii.h:104

References ADVERTISE_1000FULL, ADVERTISE_1000HALF, DBGC, realtek_nic::mii, MII_CTRL1000, mii_read(), mii_write(), rc, and strerror().

Referenced by realtek_phy_reset().

◆ realtek_phy_reset()

static int realtek_phy_reset ( struct realtek_nic rtl)
static

Reset PHY.

Parameters
rtlRealtek device
Return values
rcReturn status code

Definition at line 399 of file realtek.c.

399  {
400  int rc;
401 
402  /* Do nothing if we have no separate PHY register access */
403  if ( ! rtl->have_phy_regs )
404  return 0;
405 
406  /* Perform MII reset */
407  if ( ( rc = mii_reset ( &rtl->mii ) ) != 0 ) {
408  DBGC ( rtl, "REALTEK %p could not reset MII: %s\n",
409  rtl, strerror ( rc ) );
410  return rc;
411  }
412 
413  /* Some cards (e.g. RTL8169SC) do not advertise Gigabit by
414  * default. Try to enable advertisement of Gigabit speeds.
415  */
416  if ( ( rc = realtek_phy_speed ( rtl ) ) != 0 ) {
417  /* Ignore failures, since the register may not be
418  * present on non-Gigabit PHYs (e.g. RTL8101).
419  */
420  }
421 
422  /* Restart autonegotiation */
423  if ( ( rc = mii_restart ( &rtl->mii ) ) != 0 ) {
424  DBGC ( rtl, "REALTEK %p could not restart MII: %s\n",
425  rtl, strerror ( rc ) );
426  return rc;
427  }
428 
429  return 0;
430 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int have_phy_regs
PHYAR and PHYSTATUS registers are present.
Definition: realtek.h:293
#define DBGC(...)
Definition: compiler.h:505
int mii_restart(struct mii_device *mii)
Restart autonegotiation.
Definition: mii.c:43
struct mii_device mii
MII device.
Definition: realtek.h:288
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
int mii_reset(struct mii_device *mii)
Reset MII device.
Definition: mii.c:74
static int realtek_phy_speed(struct realtek_nic *rtl)
Configure PHY for Gigabit operation.
Definition: realtek.c:369

References DBGC, realtek_nic::have_phy_regs, realtek_nic::mii, mii_reset(), mii_restart(), rc, realtek_phy_speed(), and strerror().

Referenced by realtek_probe().

◆ realtek_check_link()

static void realtek_check_link ( struct net_device netdev)
static

Check link state.

Parameters
netdevNetwork device

Definition at line 444 of file realtek.c.

444  {
445  struct realtek_nic *rtl = netdev->priv;
446  uint8_t phystatus;
447  uint8_t msr;
448  int link_up;
449 
450  /* Determine link state */
451  if ( rtl->have_phy_regs ) {
452  mii_dump ( &rtl->mii );
453  phystatus = readb ( rtl->regs + RTL_PHYSTATUS );
454  link_up = ( phystatus & RTL_PHYSTATUS_LINKSTS );
455  DBGC ( rtl, "REALTEK %p PHY status is %02x (%s%s%s%s%s%s, "
456  "Link%s, %sDuplex)\n", rtl, phystatus,
457  ( ( phystatus & RTL_PHYSTATUS_ENTBI ) ? "TBI" : "GMII" ),
458  ( ( phystatus & RTL_PHYSTATUS_TXFLOW ) ?
459  ", TxFlow" : "" ),
460  ( ( phystatus & RTL_PHYSTATUS_RXFLOW ) ?
461  ", RxFlow" : "" ),
462  ( ( phystatus & RTL_PHYSTATUS_1000MF ) ?
463  ", 1000Mbps" : "" ),
464  ( ( phystatus & RTL_PHYSTATUS_100M ) ?
465  ", 100Mbps" : "" ),
466  ( ( phystatus & RTL_PHYSTATUS_10M ) ?
467  ", 10Mbps" : "" ),
468  ( ( phystatus & RTL_PHYSTATUS_LINKSTS ) ?
469  "Up" : "Down" ),
470  ( ( phystatus & RTL_PHYSTATUS_FULLDUP ) ?
471  "Full" : "Half" ) );
472  } else {
473  msr = readb ( rtl->regs + RTL_MSR );
474  link_up = ( ! ( msr & RTL_MSR_LINKB ) );
475  DBGC ( rtl, "REALTEK %p media status is %02x (Link%s, "
476  "%dMbps%s%s%s%s%s)\n", rtl, msr,
477  ( ( msr & RTL_MSR_LINKB ) ? "Down" : "Up" ),
478  ( ( msr & RTL_MSR_SPEED_10 ) ? 10 : 100 ),
479  ( ( msr & RTL_MSR_TXFCE ) ? ", TxFlow" : "" ),
480  ( ( msr & RTL_MSR_RXFCE ) ? ", RxFlow" : "" ),
481  ( ( msr & RTL_MSR_AUX_STATUS ) ? ", AuxPwr" : "" ),
482  ( ( msr & RTL_MSR_TXPF ) ? ", TxPause" : "" ),
483  ( ( msr & RTL_MSR_RXPF ) ? ", RxPause" : "" ) );
484  }
485 
486  /* Report link state */
487  if ( link_up ) {
489  } else {
491  }
492 }
#define RTL_MSR_RXPF
RX pause flag.
Definition: realtek.h:197
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
#define RTL_MSR_SPEED_10
10Mbps
Definition: realtek.h:194
#define RTL_MSR_LINKB
Inverse of link status.
Definition: realtek.h:195
#define RTL_MSR_TXPF
TX pause flag.
Definition: realtek.h:196
#define RTL_PHYSTATUS_RXFLOW
RX flow control enabled.
Definition: realtek.h:216
int have_phy_regs
PHYAR and PHYSTATUS registers are present.
Definition: realtek.h:293
#define DBGC(...)
Definition: compiler.h:505
#define RTL_PHYSTATUS_100M
100Mbps
Definition: realtek.h:218
#define RTL_MSR_AUX_STATUS
Aux power present.
Definition: realtek.h:193
void * regs
Registers.
Definition: realtek.h:278
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
Definition: netdevice.c:186
#define RTL_MSR
Media Status Register (byte, 8139 only)
Definition: realtek.h:190
#define RTL_MSR_TXFCE
TX flow control enabled.
Definition: realtek.h:191
struct mii_device mii
MII device.
Definition: realtek.h:288
void * priv
Driver private data.
Definition: netdevice.h:425
#define RTL_PHYSTATUS_FULLDUP
Full duplex.
Definition: realtek.h:221
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:768
static struct net_device * netdev
Definition: gdbudp.c:52
A Realtek network card.
Definition: realtek.h:276
#define RTL_PHYSTATUS_ENTBI
TBI / GMII mode.
Definition: realtek.h:214
#define RTL_PHYSTATUS_LINKSTS
Link ok.
Definition: realtek.h:220
unsigned char uint8_t
Definition: stdint.h:10
static void mii_dump(struct mii_device *mii)
Dump MII registers (for debugging)
Definition: mii.h:116
#define RTL_MSR_RXFCE
RX flow control enabled.
Definition: realtek.h:192
#define RTL_PHYSTATUS_TXFLOW
TX flow control enabled.
Definition: realtek.h:215
#define RTL_PHYSTATUS
PHY (GMII, MII, or TBI) Status Register (byte, 8169 only)
Definition: realtek.h:213
#define RTL_PHYSTATUS_10M
10Mbps
Definition: realtek.h:219
#define RTL_PHYSTATUS_1000MF
1000Mbps full-duplex
Definition: realtek.h:217

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().

◆ realtek_create_buffer()

static int realtek_create_buffer ( struct realtek_nic rtl)
static

Create receive buffer (legacy mode)

Parameters
rtlRealtek device
Return values
rcReturn status code

Definition at line 507 of file realtek.c.

507  {
508  size_t len = ( RTL_RXBUF_LEN + RTL_RXBUF_PAD );
510  int rc;
511 
512  /* Do nothing unless in legacy mode */
513  if ( ! rtl->legacy )
514  return 0;
515 
516  /* Allocate buffer */
518  if ( ! rtl->rx_buffer ) {
519  rc = -ENOMEM;
520  goto err_alloc;
521  }
522  address = virt_to_bus ( rtl->rx_buffer );
523 
524  /* Check that card can support address */
525  if ( address & ~0xffffffffULL ) {
526  DBGC ( rtl, "REALTEK %p cannot support 64-bit RX buffer "
527  "address\n", rtl );
528  rc = -ENOTSUP;
529  goto err_64bit;
530  }
531 
532  /* Program buffer address */
533  writel ( address, rtl->regs + RTL_RBSTART );
534  DBGC ( rtl, "REALTEK %p receive buffer is at [%08llx,%08llx,%08llx)\n",
535  rtl, ( ( unsigned long long ) address ),
536  ( ( unsigned long long ) address + RTL_RXBUF_LEN ),
537  ( ( unsigned long long ) address + len ) );
538 
539  return 0;
540 
541  err_64bit:
542  free_dma ( rtl->rx_buffer, len );
543  rtl->rx_buffer = NULL;
544  err_alloc:
545  return rc;
546 }
#define RTL_RXBUF_ALIGN
Receive buffer alignment.
Definition: realtek.h:105
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint64_t address
Base address.
Definition: ena.h:24
#define DBGC(...)
Definition: compiler.h:505
void * regs
Registers.
Definition: realtek.h:278
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
#define ENOMEM
Not enough space.
Definition: errno.h:534
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:183
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
void * rx_buffer
Receive buffer (legacy mode)
Definition: realtek.h:304
unsigned long physaddr_t
Definition: stdint.h:20
int legacy
Legacy datapath mode.
Definition: realtek.h:291
uint32_t len
Length.
Definition: ena.h:14
#define RTL_RXBUF_LEN
Receive buffer length.
Definition: realtek.h:99
static void *__malloc malloc_dma(size_t size, size_t phys_align)
Allocate memory for DMA.
Definition: malloc.h:66
#define RTL_RXBUF_PAD
Receive buffer padding.
Definition: realtek.h:102
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
#define RTL_RBSTART
Receive Buffer Start Address (dword, 8139 only)
Definition: realtek.h:96
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References address, DBGC, ENOMEM, ENOTSUP, free_dma(), realtek_nic::legacy, len, malloc_dma(), NULL, rc, realtek_nic::regs, RTL_RBSTART, RTL_RXBUF_ALIGN, RTL_RXBUF_LEN, RTL_RXBUF_PAD, realtek_nic::rx_buffer, virt_to_bus(), and writel().

Referenced by realtek_open().

◆ realtek_destroy_buffer()

static void realtek_destroy_buffer ( struct realtek_nic rtl)
static

Destroy receive buffer (legacy mode)

Parameters
rtlRealtek device

Definition at line 553 of file realtek.c.

553  {
554  size_t len = ( RTL_RXBUF_LEN + RTL_RXBUF_PAD );
555 
556  /* Do nothing unless in legacy mode */
557  if ( ! rtl->legacy )
558  return;
559 
560  /* Clear buffer address */
561  writel ( 0, rtl->regs + RTL_RBSTART );
562 
563  /* Free buffer */
564  free_dma ( rtl->rx_buffer, len );
565  rtl->rx_buffer = NULL;
566  rtl->rx_offset = 0;
567 }
unsigned int rx_offset
Offset within receive buffer (legacy mode)
Definition: realtek.h:306
void * regs
Registers.
Definition: realtek.h:278
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
void * rx_buffer
Receive buffer (legacy mode)
Definition: realtek.h:304
int legacy
Legacy datapath mode.
Definition: realtek.h:291
uint32_t len
Length.
Definition: ena.h:14
#define RTL_RXBUF_LEN
Receive buffer length.
Definition: realtek.h:99
#define RTL_RXBUF_PAD
Receive buffer padding.
Definition: realtek.h:102
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
#define RTL_RBSTART
Receive Buffer Start Address (dword, 8139 only)
Definition: realtek.h:96
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References free_dma(), realtek_nic::legacy, len, NULL, realtek_nic::regs, RTL_RBSTART, RTL_RXBUF_LEN, RTL_RXBUF_PAD, realtek_nic::rx_buffer, realtek_nic::rx_offset, and writel().

Referenced by realtek_close(), and realtek_open().

◆ realtek_create_ring()

static int realtek_create_ring ( struct realtek_nic rtl,
struct realtek_ring ring 
)
static

Create descriptor ring.

Parameters
rtlRealtek device
ringDescriptor ring
Return values
rcReturn status code

Definition at line 576 of file realtek.c.

577  {
579 
580  /* Do nothing in legacy mode */
581  if ( rtl->legacy )
582  return 0;
583 
584  /* Allocate descriptor ring */
585  ring->desc = malloc_dma ( ring->len, RTL_RING_ALIGN );
586  if ( ! ring->desc )
587  return -ENOMEM;
588 
589  /* Initialise descriptor ring */
590  memset ( ring->desc, 0, ring->len );
591 
592  /* Program ring address */
593  address = virt_to_bus ( ring->desc );
594  writel ( ( ( ( uint64_t ) address ) >> 32 ),
595  rtl->regs + ring->reg + 4 );
596  writel ( ( address & 0xffffffffUL ), rtl->regs + ring->reg );
597  DBGC ( rtl, "REALTEK %p ring %02x is at [%08llx,%08llx)\n",
598  rtl, ring->reg, ( ( unsigned long long ) address ),
599  ( ( unsigned long long ) address + ring->len ) );
600 
601  return 0;
602 }
struct realtek_descriptor * desc
Descriptors.
Definition: realtek.h:249
uint64_t address
Base address.
Definition: ena.h:24
#define DBGC(...)
Definition: compiler.h:505
unsigned long long uint64_t
Definition: stdint.h:13
void * regs
Registers.
Definition: realtek.h:278
unsigned int reg
Descriptor start address register.
Definition: realtek.h:256
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define RTL_RING_ALIGN
Descriptor ring alignment.
Definition: realtek.h:50
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:183
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
size_t len
Length (in bytes)
Definition: realtek.h:258
unsigned long physaddr_t
Definition: stdint.h:20
int legacy
Legacy datapath mode.
Definition: realtek.h:291
static void *__malloc malloc_dma(size_t size, size_t phys_align)
Allocate memory for DMA.
Definition: malloc.h:66
void * memset(void *dest, int character, size_t len) __nonnull

References address, DBGC, realtek_ring::desc, ENOMEM, realtek_nic::legacy, realtek_ring::len, malloc_dma(), memset(), realtek_ring::reg, realtek_nic::regs, RTL_RING_ALIGN, virt_to_bus(), and writel().

Referenced by realtek_open().

◆ realtek_destroy_ring()

static void realtek_destroy_ring ( struct realtek_nic rtl,
struct realtek_ring ring 
)
static

Destroy descriptor ring.

Parameters
rtlRealtek device
ringDescriptor ring

Definition at line 610 of file realtek.c.

611  {
612 
613  /* Reset producer and consumer counters */
614  ring->prod = 0;
615  ring->cons = 0;
616 
617  /* Do nothing more if in legacy mode */
618  if ( rtl->legacy )
619  return;
620 
621  /* Clear ring address */
622  writel ( 0, rtl->regs + ring->reg );
623  writel ( 0, rtl->regs + ring->reg + 4 );
624 
625  /* Free descriptor ring */
626  free_dma ( ring->desc, ring->len );
627  ring->desc = NULL;
628 }
struct realtek_descriptor * desc
Descriptors.
Definition: realtek.h:249
unsigned int prod
Producer index.
Definition: realtek.h:251
void * regs
Registers.
Definition: realtek.h:278
unsigned int reg
Descriptor start address register.
Definition: realtek.h:256
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
size_t len
Length (in bytes)
Definition: realtek.h:258
unsigned int cons
Consumer index.
Definition: realtek.h:253
int legacy
Legacy datapath mode.
Definition: realtek.h:291
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References realtek_ring::cons, realtek_ring::desc, free_dma(), realtek_nic::legacy, realtek_ring::len, NULL, realtek_ring::prod, realtek_ring::reg, realtek_nic::regs, and writel().

Referenced by realtek_close(), and realtek_open().

◆ realtek_refill_rx()

static void realtek_refill_rx ( struct realtek_nic rtl)
static

Refill receive descriptor ring.

Parameters
rtlRealtek device

Definition at line 635 of file realtek.c.

635  {
636  struct realtek_descriptor *rx;
637  struct io_buffer *iobuf;
638  unsigned int rx_idx;
640  int is_last;
641 
642  /* Do nothing in legacy mode */
643  if ( rtl->legacy )
644  return;
645 
646  while ( ( rtl->rx.prod - rtl->rx.cons ) < RTL_NUM_RX_DESC ) {
647 
648  /* Allocate I/O buffer */
649  iobuf = alloc_iob ( RTL_RX_MAX_LEN );
650  if ( ! iobuf ) {
651  /* Wait for next refill */
652  return;
653  }
654 
655  /* Get next receive descriptor */
656  rx_idx = ( rtl->rx.prod++ % RTL_NUM_RX_DESC );
657  is_last = ( rx_idx == ( RTL_NUM_RX_DESC - 1 ) );
658  rx = &rtl->rx.desc[rx_idx];
659 
660  /* Populate receive descriptor */
661  address = virt_to_bus ( iobuf->data );
662  rx->address = cpu_to_le64 ( address );
663  rx->length = cpu_to_le16 ( RTL_RX_MAX_LEN );
664  wmb();
665  rx->flags = ( cpu_to_le16 ( RTL_DESC_OWN ) |
666  ( is_last ? cpu_to_le16 ( RTL_DESC_EOR ) : 0 ) );
667  wmb();
668 
669  /* Record I/O buffer */
670  assert ( rtl->rx_iobuf[rx_idx] == NULL );
671  rtl->rx_iobuf[rx_idx] = iobuf;
672 
673  DBGC2 ( rtl, "REALTEK %p RX %d is [%llx,%llx)\n", rtl, rx_idx,
674  ( ( unsigned long long ) address ),
675  ( ( unsigned long long ) address + RTL_RX_MAX_LEN ) );
676  }
677 }
struct realtek_descriptor * desc
Descriptors.
Definition: realtek.h:249
wmb()
A packet descriptor.
Definition: realtek.h:21
unsigned int prod
Producer index.
Definition: realtek.h:251
#define RTL_RX_MAX_LEN
Receive buffer length.
Definition: realtek.h:243
uint64_t address
Base address.
Definition: ena.h:24
#define cpu_to_le64(value)
Definition: byteswap.h:108
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:128
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:183
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct realtek_ring rx
Receive descriptor ring.
Definition: realtek.h:300
Descriptor is owned by NIC.
Definition: realtek.h:38
uint32_t rx
Maximum number of receive queues.
Definition: intelvf.h:16
unsigned int cons
Consumer index.
Definition: realtek.h:253
End of descriptor ring.
Definition: realtek.h:40
unsigned long physaddr_t
Definition: stdint.h:20
int legacy
Legacy datapath mode.
Definition: realtek.h:291
#define DBGC2(...)
Definition: compiler.h:522
void * data
Start of data.
Definition: iobuf.h:44
#define cpu_to_le16(value)
Definition: byteswap.h:106
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct io_buffer * rx_iobuf[RTL_NUM_RX_DESC]
Receive I/O buffers.
Definition: realtek.h:302
#define RTL_NUM_RX_DESC
Number of receive descriptors.
Definition: realtek.h:240
A persistent I/O buffer.
Definition: iobuf.h:32

References address, alloc_iob(), assert(), realtek_ring::cons, cpu_to_le16, cpu_to_le64, io_buffer::data, DBGC2, realtek_ring::desc, 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_bus(), and wmb().

Referenced by realtek_open(), and realtek_poll().

◆ realtek_open()

static int realtek_open ( struct net_device netdev)
static

Open network device.

Parameters
netdevNetwork device
Return values
rcReturn status code

Definition at line 685 of file realtek.c.

685  {
686  struct realtek_nic *rtl = netdev->priv;
687  uint32_t tcr;
688  uint32_t rcr;
689  int rc;
690 
691  /* Create transmit descriptor ring */
692  if ( ( rc = realtek_create_ring ( rtl, &rtl->tx ) ) != 0 )
693  goto err_create_tx;
694 
695  /* Create receive descriptor ring */
696  if ( ( rc = realtek_create_ring ( rtl, &rtl->rx ) ) != 0 )
697  goto err_create_rx;
698 
699  /* Create receive buffer */
700  if ( ( rc = realtek_create_buffer ( rtl ) ) != 0 )
701  goto err_create_buffer;
702 
703  /* Accept all packets */
704  writel ( 0xffffffffUL, rtl->regs + RTL_MAR0 );
705  writel ( 0xffffffffUL, rtl->regs + RTL_MAR4 );
706 
707  /* Enable transmitter and receiver. RTL8139 requires that
708  * this happens before writing to RCR.
709  */
710  writeb ( ( RTL_CR_TE | RTL_CR_RE ), rtl->regs + RTL_CR );
711 
712  /* Configure transmitter */
713  tcr = readl ( rtl->regs + RTL_TCR );
714  tcr &= ~RTL_TCR_MXDMA_MASK;
715  tcr |= RTL_TCR_MXDMA_DEFAULT;
716  writel ( tcr, rtl->regs + RTL_TCR );
717 
718  /* Configure receiver */
719  rcr = readl ( rtl->regs + RTL_RCR );
725  writel ( rcr, rtl->regs + RTL_RCR );
726 
727  /* Fill receive ring */
728  realtek_refill_rx ( rtl );
729 
730  /* Update link state */
732 
733  return 0;
734 
735  realtek_destroy_buffer ( rtl );
736  err_create_buffer:
737  realtek_destroy_ring ( rtl, &rtl->rx );
738  err_create_rx:
739  realtek_destroy_ring ( rtl, &rtl->tx );
740  err_create_tx:
741  return rc;
742 }
#define RTL_RCR_AB
Accept broadcast packets.
Definition: realtek.h:155
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define RTL_TCR_MXDMA_DEFAULT
Definition: realtek.h:139
#define RTL_CR_RE
Receiver Enable.
Definition: realtek.h:110
static void realtek_destroy_ring(struct realtek_nic *rtl, struct realtek_ring *ring)
Destroy descriptor ring.
Definition: realtek.c:610
#define RTL_RCR_WRAP
Overrun receive buffer.
Definition: realtek.h:153
static int realtek_create_buffer(struct realtek_nic *rtl)
Create receive buffer (legacy mode)
Definition: realtek.c:507
#define RTL_RCR_AM
Accept multicast packets.
Definition: realtek.h:156
#define RTL_TCR
Transmit (Tx) Configuration Register (dword)
Definition: realtek.h:136
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
void * regs
Registers.
Definition: realtek.h:278
void writeb(uint8_t data, volatile uint8_t *io_addr)
Write byte to memory-mapped device.
#define RTL_RCR_STOP_WORKING
Here be dragons.
Definition: realtek.h:143
#define RTL_RCR_MXDMA_DEFAULT
Definition: realtek.h:152
void * priv
Driver private data.
Definition: netdevice.h:425
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
struct realtek_ring rx
Receive descriptor ring.
Definition: realtek.h:300
static struct net_device * netdev
Definition: gdbudp.c:52
A Realtek network card.
Definition: realtek.h:276
static void realtek_destroy_buffer(struct realtek_nic *rtl)
Destroy receive buffer (legacy mode)
Definition: realtek.c:553
#define RTL_TCR_MXDMA_MASK
Definition: realtek.h:138
#define RTL_CR
Command Register (byte)
Definition: realtek.h:108
#define RTL_CR_TE
Transmit Enable.
Definition: realtek.h:111
static void realtek_check_link(struct net_device *netdev)
Check link state.
Definition: realtek.c:444
#define RTL_RCR_RXFTH_DEFAULT
Definition: realtek.h:146
#define RTL_RCR_RBLEN_MASK
Definition: realtek.h:148
#define RTL_RCR_AAP
Accept all packets.
Definition: realtek.h:158
static void realtek_refill_rx(struct realtek_nic *rtl)
Refill receive descriptor ring.
Definition: realtek.c:635
#define RTL_RCR_RXFTH_MASK
Definition: realtek.h:145
unsigned int uint32_t
Definition: stdint.h:12
#define RTL_MAR4
Multicast Register 4 (dword)
Definition: realtek.h:75
#define RTL_RCR_RBLEN_DEFAULT
Definition: realtek.h:149
static int realtek_create_ring(struct realtek_nic *rtl, struct realtek_ring *ring)
Create descriptor ring.
Definition: realtek.c:576
#define RTL_RCR_MXDMA_MASK
Definition: realtek.h:151
#define RTL_MAR0
Multicast Register 0 (dword)
Definition: realtek.h:72
struct realtek_ring tx
Transmit descriptor ring.
Definition: realtek.h:298
#define RTL_RCR_APM
Accept physical match.
Definition: realtek.h:157
#define RTL_RCR
Receive (Rx) Configuration Register (dword)
Definition: realtek.h:142

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().

◆ realtek_close()

static void realtek_close ( struct net_device netdev)
static

Close network device.

Parameters
netdevNetwork device

Definition at line 749 of file realtek.c.

749  {
750  struct realtek_nic *rtl = netdev->priv;
751  unsigned int i;
752 
753  /* Disable receiver and transmitter */
754  writeb ( 0, rtl->regs + RTL_CR );
755 
756  /* Destroy receive buffer */
757  realtek_destroy_buffer ( rtl );
758 
759  /* Destroy receive descriptor ring */
760  realtek_destroy_ring ( rtl, &rtl->rx );
761 
762  /* Discard any unused receive buffers */
763  for ( i = 0 ; i < RTL_NUM_RX_DESC ; i++ ) {
764  if ( rtl->rx_iobuf[i] )
765  free_iob ( rtl->rx_iobuf[i] );
766  rtl->rx_iobuf[i] = NULL;
767  }
768 
769  /* Destroy transmit descriptor ring */
770  realtek_destroy_ring ( rtl, &rtl->tx );
771 }
static void realtek_destroy_ring(struct realtek_nic *rtl, struct realtek_ring *ring)
Destroy descriptor ring.
Definition: realtek.c:610
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:145
void * regs
Registers.
Definition: realtek.h:278
void writeb(uint8_t data, volatile uint8_t *io_addr)
Write byte to memory-mapped device.
void * priv
Driver private data.
Definition: netdevice.h:425
struct realtek_ring rx
Receive descriptor ring.
Definition: realtek.h:300
static struct net_device * netdev
Definition: gdbudp.c:52
A Realtek network card.
Definition: realtek.h:276
static void realtek_destroy_buffer(struct realtek_nic *rtl)
Destroy receive buffer (legacy mode)
Definition: realtek.c:553
#define RTL_CR
Command Register (byte)
Definition: realtek.h:108
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct realtek_ring tx
Transmit descriptor ring.
Definition: realtek.h:298
struct io_buffer * rx_iobuf[RTL_NUM_RX_DESC]
Receive I/O buffers.
Definition: realtek.h:302
#define RTL_NUM_RX_DESC
Number of receive descriptors.
Definition: realtek.h:240

References free_iob(), netdev, NULL, net_device::priv, realtek_destroy_buffer(), realtek_destroy_ring(), realtek_nic::regs, RTL_CR, RTL_NUM_RX_DESC, realtek_nic::rx, realtek_nic::rx_iobuf, realtek_nic::tx, and writeb().

◆ realtek_transmit()

static int realtek_transmit ( struct net_device netdev,
struct io_buffer iobuf 
)
static

Transmit packet.

Parameters
netdevNetwork device
iobufI/O buffer
Return values
rcReturn status code

Definition at line 780 of file realtek.c.

781  {
782  struct realtek_nic *rtl = netdev->priv;
783  struct realtek_descriptor *tx;
784  unsigned int tx_idx;
786  int is_last;
787 
788  /* Get next transmit descriptor */
789  if ( ( rtl->tx.prod - rtl->tx.cons ) >= RTL_NUM_TX_DESC ) {
790  netdev_tx_defer ( netdev, iobuf );
791  return 0;
792  }
793  tx_idx = ( rtl->tx.prod++ % RTL_NUM_TX_DESC );
794 
795  /* Transmit packet */
796  if ( rtl->legacy ) {
797 
798  /* Pad and align packet */
799  iob_pad ( iobuf, ETH_ZLEN );
800  address = virt_to_bus ( iobuf->data );
801 
802  /* Check that card can support address */
803  if ( address & ~0xffffffffULL ) {
804  DBGC ( rtl, "REALTEK %p cannot support 64-bit TX "
805  "buffer address\n", rtl );
806  return -ENOTSUP;
807  }
808 
809  /* Add to transmit ring */
810  writel ( address, rtl->regs + RTL_TSAD ( tx_idx ) );
811  writel ( ( RTL_TSD_ERTXTH_DEFAULT | iob_len ( iobuf ) ),
812  rtl->regs + RTL_TSD ( tx_idx ) );
813 
814  } else {
815 
816  /* Populate transmit descriptor */
817  address = virt_to_bus ( iobuf->data );
818  is_last = ( tx_idx == ( RTL_NUM_TX_DESC - 1 ) );
819  tx = &rtl->tx.desc[tx_idx];
820  tx->address = cpu_to_le64 ( address );
821  tx->length = cpu_to_le16 ( iob_len ( iobuf ) );
822  wmb();
823  tx->flags = ( cpu_to_le16 ( RTL_DESC_OWN | RTL_DESC_FS |
824  RTL_DESC_LS ) |
825  ( is_last ? cpu_to_le16 ( RTL_DESC_EOR ) : 0 ) );
826  wmb();
827 
828  /* Notify card that there are packets ready to transmit */
829  writeb ( RTL_TPPOLL_NPQ, rtl->regs + rtl->tppoll );
830  }
831 
832  DBGC2 ( rtl, "REALTEK %p TX %d is [%llx,%llx)\n", rtl, tx_idx,
833  ( ( unsigned long long ) virt_to_bus ( iobuf->data ) ),
834  ( ( ( unsigned long long ) virt_to_bus ( iobuf->data ) ) +
835  iob_len ( iobuf ) ) );
836 
837  return 0;
838 }
#define RTL_TPPOLL_NPQ
Normal Priority Queue Polling.
Definition: realtek.h:122
struct realtek_descriptor * desc
Descriptors.
Definition: realtek.h:249
wmb()
void netdev_tx_defer(struct net_device *netdev, struct io_buffer *iobuf)
Defer transmitted packet.
Definition: netdevice.c:344
A packet descriptor.
Definition: realtek.h:21
unsigned int prod
Producer index.
Definition: realtek.h:251
uint64_t address
Base address.
Definition: ena.h:24
#define DBGC(...)
Definition: compiler.h:505
void * regs
Registers.
Definition: realtek.h:278
#define cpu_to_le64(value)
Definition: byteswap.h:108
#define RTL_TSD_ERTXTH_DEFAULT
Definition: realtek.h:80
void writeb(uint8_t data, volatile uint8_t *io_addr)
Write byte to memory-mapped device.
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
#define RTL_NUM_TX_DESC
Number of transmit descriptors.
Definition: realtek.h:93
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:183
void * priv
Driver private data.
Definition: netdevice.h:425
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
static struct net_device * netdev
Definition: gdbudp.c:52
Descriptor is owned by NIC.
Definition: realtek.h:38
A Realtek network card.
Definition: realtek.h:276
uint32_t tx
Maximum number of transmit queues.
Definition: intelvf.h:14
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:151
unsigned int cons
Consumer index.
Definition: realtek.h:253
#define ETH_ZLEN
Definition: if_ether.h:10
End of descriptor ring.
Definition: realtek.h:40
unsigned long physaddr_t
Definition: stdint.h:20
#define RTL_TSD(n)
Transmit Status of Descriptor N (dword, 8139 only)
Definition: realtek.h:78
int legacy
Legacy datapath mode.
Definition: realtek.h:291
#define DBGC2(...)
Definition: compiler.h:522
void * data
Start of data.
Definition: iobuf.h:44
unsigned int tppoll
TPPoll register offset.
Definition: realtek.h:295
#define cpu_to_le16(value)
Definition: byteswap.h:106
Last segment descriptor.
Definition: realtek.h:44
First segment descriptor.
Definition: realtek.h:42
struct realtek_ring tx
Transmit descriptor ring.
Definition: realtek.h:298
void iob_pad(struct io_buffer *iobuf, size_t min_len)
Pad I/O buffer.
Definition: iobpad.c:49
#define RTL_TSAD(n)
Transmit Start Address of Descriptor N (dword, 8139 only)
Definition: realtek.h:84

References address, realtek_ring::cons, cpu_to_le16, cpu_to_le64, io_buffer::data, DBGC, DBGC2, realtek_ring::desc, ENOTSUP, ETH_ZLEN, iob_len(), iob_pad(), realtek_nic::legacy, netdev, netdev_tx_defer(), net_device::priv, realtek_ring::prod, 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_bus(), wmb(), writeb(), and writel().

◆ realtek_poll_tx()

static void realtek_poll_tx ( struct net_device netdev)
static

Poll for completed packets.

Parameters
netdevNetwork device

Definition at line 845 of file realtek.c.

845  {
846  struct realtek_nic *rtl = netdev->priv;
847  struct realtek_descriptor *tx;
848  unsigned int tx_idx;
849 
850  /* Check for completed packets */
851  while ( rtl->tx.cons != rtl->tx.prod ) {
852 
853  /* Get next transmit descriptor */
854  tx_idx = ( rtl->tx.cons % RTL_NUM_TX_DESC );
855 
856  /* Stop if descriptor is still in use */
857  if ( rtl->legacy ) {
858 
859  /* Check ownership bit in transmit status register */
860  if ( ! ( readl ( rtl->regs + RTL_TSD ( tx_idx ) ) &
861  RTL_TSD_OWN ) )
862  return;
863 
864  } else {
865 
866  /* Check ownership bit in descriptor */
867  tx = &rtl->tx.desc[tx_idx];
868  if ( tx->flags & cpu_to_le16 ( RTL_DESC_OWN ) )
869  return;
870  }
871 
872  DBGC2 ( rtl, "REALTEK %p TX %d complete\n", rtl, tx_idx );
873 
874  /* Complete TX descriptor */
875  rtl->tx.cons++;
877  }
878 }
struct realtek_descriptor * desc
Descriptors.
Definition: realtek.h:249
A packet descriptor.
Definition: realtek.h:21
unsigned int prod
Producer index.
Definition: realtek.h:251
static void netdev_tx_complete_next(struct net_device *netdev)
Complete network transmission.
Definition: netdevice.h:758
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
void * regs
Registers.
Definition: realtek.h:278
#define RTL_TSD_OWN
Ownership.
Definition: realtek.h:81
#define RTL_NUM_TX_DESC
Number of transmit descriptors.
Definition: realtek.h:93
void * priv
Driver private data.
Definition: netdevice.h:425
static struct net_device * netdev
Definition: gdbudp.c:52
Descriptor is owned by NIC.
Definition: realtek.h:38
A Realtek network card.
Definition: realtek.h:276
uint32_t tx
Maximum number of transmit queues.
Definition: intelvf.h:14
unsigned int cons
Consumer index.
Definition: realtek.h:253
#define RTL_TSD(n)
Transmit Status of Descriptor N (dword, 8139 only)
Definition: realtek.h:78
int legacy
Legacy datapath mode.
Definition: realtek.h:291
#define DBGC2(...)
Definition: compiler.h:522
#define cpu_to_le16(value)
Definition: byteswap.h:106
struct realtek_ring tx
Transmit descriptor ring.
Definition: realtek.h:298

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().

◆ realtek_legacy_poll_rx()

static void realtek_legacy_poll_rx ( struct net_device netdev)
static

Poll for received packets (legacy mode)

Parameters
netdevNetwork device

Definition at line 885 of file realtek.c.

885  {
886  struct realtek_nic *rtl = netdev->priv;
887  struct realtek_legacy_header *rx;
888  struct io_buffer *iobuf;
889  size_t len;
890 
891  /* Check for received packets */
892  while ( ! ( readb ( rtl->regs + RTL_CR ) & RTL_CR_BUFE ) ) {
893 
894  /* Extract packet from receive buffer */
895  rx = ( rtl->rx_buffer + rtl->rx_offset );
896  len = le16_to_cpu ( rx->length );
897  if ( rx->status & cpu_to_le16 ( RTL_STAT_ROK ) ) {
898 
899  DBGC2 ( rtl, "REALTEK %p RX offset %x+%zx\n",
900  rtl, rtl->rx_offset, len );
901 
902  /* Allocate I/O buffer */
903  iobuf = alloc_iob ( len );
904  if ( ! iobuf ) {
906  /* Leave packet for next poll */
907  break;
908  }
909 
910  /* Copy data to I/O buffer */
911  memcpy ( iob_put ( iobuf, len ), rx->data, len );
912  iob_unput ( iobuf, 4 /* strip CRC */ );
913 
914  /* Hand off to network stack */
915  netdev_rx ( netdev, iobuf );
916 
917  } else {
918 
919  DBGC ( rtl, "REALTEK %p RX offset %x+%zx error %04x\n",
920  rtl, rtl->rx_offset, len,
921  le16_to_cpu ( rx->status ) );
922  netdev_rx_err ( netdev, NULL, -EIO );
923  }
924 
925  /* Update buffer offset */
926  rtl->rx_offset = ( rtl->rx_offset + sizeof ( *rx ) + len );
927  rtl->rx_offset = ( ( rtl->rx_offset + 3 ) & ~3 );
928  rtl->rx_offset = ( rtl->rx_offset % RTL_RXBUF_LEN );
929  writew ( ( rtl->rx_offset - 16 ), rtl->regs + RTL_CAPR );
930 
931  /* Give chip time to react before rechecking RTL_CR */
932  readw ( rtl->regs + RTL_CAPR );
933  }
934 }
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
#define iob_put(iobuf, len)
Definition: iobuf.h:116
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:501
#define RTL_CAPR
Current Address of Packet Read (word, 8139 only)
Definition: realtek.h:118
uint16_t readw(volatile uint16_t *io_addr)
Read 16-bit word from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
unsigned int rx_offset
Offset within receive buffer (legacy mode)
Definition: realtek.h:306
void * regs
Registers.
Definition: realtek.h:278
A legacy mode receive packet header.
Definition: realtek.h:53
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:128
#define ENOMEM
Not enough space.
Definition: errno.h:534
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void * priv
Driver private data.
Definition: netdevice.h:425
static struct net_device * netdev
Definition: gdbudp.c:52
A Realtek network card.
Definition: realtek.h:276
#define RTL_CR_BUFE
Receive buffer empty.
Definition: realtek.h:112
uint32_t rx
Maximum number of receive queues.
Definition: intelvf.h:16
#define RTL_CR
Command Register (byte)
Definition: realtek.h:108
#define iob_unput(iobuf, len)
Definition: iobuf.h:131
#define le16_to_cpu(value)
Definition: byteswap.h:112
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition: netdevice.c:470
void * rx_buffer
Receive buffer (legacy mode)
Definition: realtek.h:304
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
#define writew
Definition: w89c840.c:159
#define RTL_RXBUF_LEN
Receive buffer length.
Definition: realtek.h:99
#define EIO
Input/output error.
Definition: errno.h:433
#define cpu_to_le16(value)
Definition: byteswap.h:106
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
Received OK.
Definition: realtek.h:65
A persistent I/O buffer.
Definition: iobuf.h:32

References alloc_iob(), cpu_to_le16, DBGC, DBGC2, EIO, ENOMEM, iob_put, iob_unput, le16_to_cpu, len, memcpy(), netdev, netdev_rx(), netdev_rx_err(), NULL, net_device::priv, readb(), readw(), realtek_nic::regs, RTL_CAPR, RTL_CR, RTL_CR_BUFE, RTL_RXBUF_LEN, RTL_STAT_ROK, rx, realtek_nic::rx_buffer, realtek_nic::rx_offset, and writew.

Referenced by realtek_poll_rx().

◆ realtek_poll_rx()

static void realtek_poll_rx ( struct net_device netdev)
static

Poll for received packets.

Parameters
netdevNetwork device

Definition at line 941 of file realtek.c.

941  {
942  struct realtek_nic *rtl = netdev->priv;
943  struct realtek_descriptor *rx;
944  struct io_buffer *iobuf;
945  unsigned int rx_idx;
946  size_t len;
947 
948  /* Poll receive buffer if in legacy mode */
949  if ( rtl->legacy ) {
951  return;
952  }
953 
954  /* Check for received packets */
955  while ( rtl->rx.cons != rtl->rx.prod ) {
956 
957  /* Get next receive descriptor */
958  rx_idx = ( rtl->rx.cons % RTL_NUM_RX_DESC );
959  rx = &rtl->rx.desc[rx_idx];
960 
961  /* Stop if descriptor is still in use */
962  if ( rx->flags & cpu_to_le16 ( RTL_DESC_OWN ) )
963  return;
964 
965  /* Populate I/O buffer */
966  iobuf = rtl->rx_iobuf[rx_idx];
967  rtl->rx_iobuf[rx_idx] = NULL;
968  len = ( le16_to_cpu ( rx->length ) & RTL_DESC_SIZE_MASK );
969  iob_put ( iobuf, ( len - 4 /* strip CRC */ ) );
970 
971  /* Hand off to network stack */
972  if ( rx->flags & cpu_to_le16 ( RTL_DESC_RES ) ) {
973  DBGC ( rtl, "REALTEK %p RX %d error (length %zd, "
974  "flags %04x)\n", rtl, rx_idx, len,
975  le16_to_cpu ( rx->flags ) );
976  netdev_rx_err ( netdev, iobuf, -EIO );
977  } else {
978  DBGC2 ( rtl, "REALTEK %p RX %d complete (length "
979  "%zd)\n", rtl, rx_idx, len );
980  netdev_rx ( netdev, iobuf );
981  }
982  rtl->rx.cons++;
983  }
984 }
struct realtek_descriptor * desc
Descriptors.
Definition: realtek.h:249
#define iob_put(iobuf, len)
Definition: iobuf.h:116
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:501
A packet descriptor.
Definition: realtek.h:21
unsigned int prod
Producer index.
Definition: realtek.h:251
#define DBGC(...)
Definition: compiler.h:505
void * priv
Driver private data.
Definition: netdevice.h:425
struct realtek_ring rx
Receive descriptor ring.
Definition: realtek.h:300
static struct net_device * netdev
Definition: gdbudp.c:52
Descriptor is owned by NIC.
Definition: realtek.h:38
A Realtek network card.
Definition: realtek.h:276
uint32_t rx
Maximum number of receive queues.
Definition: intelvf.h:16
unsigned int cons
Consumer index.
Definition: realtek.h:253
#define le16_to_cpu(value)
Definition: byteswap.h:112
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition: netdevice.c:470
int legacy
Legacy datapath mode.
Definition: realtek.h:291
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
#define EIO
Input/output error.
Definition: errno.h:433
#define cpu_to_le16(value)
Definition: byteswap.h:106
#define RTL_DESC_SIZE_MASK
Descriptor buffer size mask.
Definition: realtek.h:33
Receive error summary.
Definition: realtek.h:46
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct io_buffer * rx_iobuf[RTL_NUM_RX_DESC]
Receive I/O buffers.
Definition: realtek.h:302
#define RTL_NUM_RX_DESC
Number of receive descriptors.
Definition: realtek.h:240
static void realtek_legacy_poll_rx(struct net_device *netdev)
Poll for received packets (legacy mode)
Definition: realtek.c:885
A persistent I/O buffer.
Definition: iobuf.h:32

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().

◆ realtek_poll()

static void realtek_poll ( struct net_device netdev)
static

Poll for completed and received packets.

Parameters
netdevNetwork device

Definition at line 991 of file realtek.c.

991  {
992  struct realtek_nic *rtl = netdev->priv;
993  uint16_t isr;
994 
995  /* Check for and acknowledge interrupts */
996  isr = readw ( rtl->regs + RTL_ISR );
997  if ( ! isr )
998  return;
999  writew ( isr, rtl->regs + RTL_ISR );
1000 
1001  /* Poll for TX completions, if applicable */
1002  if ( isr & ( RTL_IRQ_TER | RTL_IRQ_TOK ) )
1003  realtek_poll_tx ( netdev );
1004 
1005  /* Poll for RX completionsm, if applicable */
1006  if ( isr & ( RTL_IRQ_RER | RTL_IRQ_ROK ) )
1007  realtek_poll_rx ( netdev );
1008 
1009  /* Check link state, if applicable */
1010  if ( isr & RTL_IRQ_PUN_LINKCHG )
1012 
1013  /* Refill RX ring */
1014  realtek_refill_rx ( rtl );
1015 }
unsigned short uint16_t
Definition: stdint.h:11
#define RTL_IRQ_RER
Receive error.
Definition: realtek.h:129
uint16_t readw(volatile uint16_t *io_addr)
Read 16-bit word from memory-mapped device.
#define RTL_ISR
Interrupt Status Register (word)
Definition: realtek.h:133
void * regs
Registers.
Definition: realtek.h:278
static void realtek_poll_rx(struct net_device *netdev)
Poll for received packets.
Definition: realtek.c:941
void * priv
Driver private data.
Definition: netdevice.h:425
static struct net_device * netdev
Definition: gdbudp.c:52
static void realtek_poll_tx(struct net_device *netdev)
Poll for completed packets.
Definition: realtek.c:845
A Realtek network card.
Definition: realtek.h:276
Definition: sis900.h:26
#define RTL_IRQ_PUN_LINKCHG
Packet underrun / link change.
Definition: realtek.h:126
static void realtek_check_link(struct net_device *netdev)
Check link state.
Definition: realtek.c:444
static void realtek_refill_rx(struct realtek_nic *rtl)
Refill receive descriptor ring.
Definition: realtek.c:635
#define RTL_IRQ_ROK
Receive OK.
Definition: realtek.h:130
#define RTL_IRQ_TOK
Transmit OK.
Definition: realtek.h:128
#define writew
Definition: w89c840.c:159
#define RTL_IRQ_TER
Transmit error.
Definition: realtek.h:127

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.

◆ realtek_irq()

static void realtek_irq ( struct net_device netdev,
int  enable 
)
static

Enable or disable interrupts.

Parameters
netdevNetwork device
enableInterrupts should be enabled

Definition at line 1023 of file realtek.c.

1023  {
1024  struct realtek_nic *rtl = netdev->priv;
1025  uint16_t imr;
1026 
1027  /* Set interrupt mask */
1028  imr = ( enable ? ( RTL_IRQ_PUN_LINKCHG | RTL_IRQ_TER | RTL_IRQ_TOK |
1029  RTL_IRQ_RER | RTL_IRQ_ROK ) : 0 );
1030  writew ( imr, rtl->regs + RTL_IMR );
1031 }
unsigned short uint16_t
Definition: stdint.h:11
#define RTL_IRQ_RER
Receive error.
Definition: realtek.h:129
Definition: sis900.h:27
void * regs
Registers.
Definition: realtek.h:278
#define RTL_IMR
Interrupt Mask Register (word)
Definition: realtek.h:125
void * priv
Driver private data.
Definition: netdevice.h:425
static struct net_device * netdev
Definition: gdbudp.c:52
A Realtek network card.
Definition: realtek.h:276
#define RTL_IRQ_PUN_LINKCHG
Packet underrun / link change.
Definition: realtek.h:126
#define RTL_IRQ_ROK
Receive OK.
Definition: realtek.h:130
#define RTL_IRQ_TOK
Transmit OK.
Definition: realtek.h:128
#define writew
Definition: w89c840.c:159
#define RTL_IRQ_TER
Transmit error.
Definition: realtek.h:127

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.

◆ realtek_detect()

static void realtek_detect ( struct realtek_nic rtl)
static

Detect device type.

Parameters
rtlRealtek device

Definition at line 1054 of file realtek.c.

1054  {
1055  uint16_t rms;
1056  uint16_t check_rms;
1057  uint16_t cpcr;
1058  uint16_t check_cpcr;
1059 
1060  /* The RX Packet Maximum Size register is present only on
1061  * 8169. Try to set to our intended MTU.
1062  */
1063  rms = RTL_RX_MAX_LEN;
1064  writew ( rms, rtl->regs + RTL_RMS );
1065  check_rms = readw ( rtl->regs + RTL_RMS );
1066 
1067  /* The C+ Command register is present only on 8169 and 8139C+.
1068  * Try to enable C+ mode and PCI Dual Address Cycle (for
1069  * 64-bit systems), if supported.
1070  *
1071  * Note that enabling DAC seems to cause bizarre behaviour
1072  * (lockups, garbage data on the wire) on some systems, even
1073  * if only 32-bit addresses are used.
1074  */
1075  cpcr = readw ( rtl->regs + RTL_CPCR );
1076  cpcr |= ( RTL_CPCR_MULRW | RTL_CPCR_CPRX | RTL_CPCR_CPTX );
1077  if ( sizeof ( physaddr_t ) > sizeof ( uint32_t ) )
1078  cpcr |= RTL_CPCR_DAC;
1079  writew ( cpcr, rtl->regs + RTL_CPCR );
1080  check_cpcr = readw ( rtl->regs + RTL_CPCR );
1081 
1082  /* Detect device type */
1083  if ( check_rms == rms ) {
1084  DBGC ( rtl, "REALTEK %p appears to be an RTL8169\n", rtl );
1085  rtl->have_phy_regs = 1;
1086  rtl->tppoll = RTL_TPPOLL_8169;
1087  } else {
1088  if ( ( check_cpcr == cpcr ) && ( cpcr != 0xffff ) ) {
1089  DBGC ( rtl, "REALTEK %p appears to be an RTL8139C+\n",
1090  rtl );
1091  rtl->tppoll = RTL_TPPOLL_8139CP;
1092  } else {
1093  DBGC ( rtl, "REALTEK %p appears to be an RTL8139\n",
1094  rtl );
1095  rtl->legacy = 1;
1096  }
1097  rtl->eeprom.bus = &rtl->spibit.bus;
1098  }
1099 }
unsigned short uint16_t
Definition: stdint.h:11
uint16_t readw(volatile uint16_t *io_addr)
Read 16-bit word from memory-mapped device.
#define RTL_RX_MAX_LEN
Receive buffer length.
Definition: realtek.h:243
int have_phy_regs
PHYAR and PHYSTATUS registers are present.
Definition: realtek.h:293
#define DBGC(...)
Definition: compiler.h:505
void * regs
Registers.
Definition: realtek.h:278
#define RTL_CPCR_CPTX
C+ transmit enable.
Definition: realtek.h:234
#define RTL_CPCR
C+ Command Register (word)
Definition: realtek.h:230
#define RTL_CPCR_CPRX
C+ receive enable.
Definition: realtek.h:233
unsigned int uint32_t
Definition: stdint.h:12
struct spi_bus bus
SPI bus.
Definition: spi_bit.h:18
unsigned long physaddr_t
Definition: stdint.h:20
int legacy
Legacy datapath mode.
Definition: realtek.h:291
#define RTL_RMS
RX Packet Maximum Size Register (word)
Definition: realtek.h:227
#define writew
Definition: w89c840.c:159
struct spi_bus * bus
SPI bus to which device is attached.
Definition: spi.h:90
#define RTL_TPPOLL_8169
Transmit Priority Polling Register (byte, 8169 only)
Definition: realtek.h:121
unsigned int tppoll
TPPoll register offset.
Definition: realtek.h:295
#define RTL_CPCR_DAC
PCI Dual Address Cycle Enable.
Definition: realtek.h:231
#define RTL_TPPOLL_8139CP
Transmit Priority Polling Register (byte, 8139C+ only)
Definition: realtek.h:224
#define RTL_CPCR_MULRW
PCI Multiple Read/Write Enable.
Definition: realtek.h:232
struct spi_bit_basher spibit
SPI bit-bashing interface.
Definition: realtek.h:280
struct spi_device eeprom
EEPROM.
Definition: realtek.h:282

References spi_bit_basher::bus, spi_device::bus, DBGC, 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_RMS, RTL_RX_MAX_LEN, RTL_TPPOLL_8139CP, RTL_TPPOLL_8169, realtek_nic::spibit, realtek_nic::tppoll, and writew.

Referenced by realtek_probe().

◆ realtek_probe()

static int realtek_probe ( struct pci_device pci)
static

Probe PCI device.

Parameters
pciPCI device
Return values
rcReturn status code

Definition at line 1107 of file realtek.c.

1107  {
1108  struct net_device *netdev;
1109  struct realtek_nic *rtl;
1110  unsigned int i;
1111  int rc;
1112 
1113  /* Allocate and initialise net device */
1114  netdev = alloc_etherdev ( sizeof ( *rtl ) );
1115  if ( ! netdev ) {
1116  rc = -ENOMEM;
1117  goto err_alloc;
1118  }
1120  rtl = netdev->priv;
1121  pci_set_drvdata ( pci, netdev );
1122  netdev->dev = &pci->dev;
1123  memset ( rtl, 0, sizeof ( *rtl ) );
1126 
1127  /* Fix up PCI device */
1128  adjust_pci_device ( pci );
1129 
1130  /* Map registers */
1131  rtl->regs = ioremap ( pci->membase, RTL_BAR_SIZE );
1132  if ( ! rtl->regs ) {
1133  rc = -ENODEV;
1134  goto err_ioremap;
1135  }
1136 
1137  /* Reset the NIC */
1138  if ( ( rc = realtek_reset ( rtl ) ) != 0 )
1139  goto err_reset;
1140 
1141  /* Detect device type */
1142  realtek_detect ( rtl );
1143 
1144  /* Initialise EEPROM */
1145  if ( rtl->eeprom.bus &&
1146  ( ( rc = realtek_init_eeprom ( netdev ) ) == 0 ) ) {
1147 
1148  /* Read MAC address from EEPROM */
1149  if ( ( rc = nvs_read ( &rtl->eeprom.nvs, RTL_EEPROM_MAC,
1150  netdev->hw_addr, ETH_ALEN ) ) != 0 ) {
1151  DBGC ( rtl, "REALTEK %p could not read MAC address: "
1152  "%s\n", rtl, strerror ( rc ) );
1153  goto err_nvs_read;
1154  }
1155 
1156  } else {
1157 
1158  /* EEPROM not present. Fall back to reading the
1159  * current ID register value, which will hopefully
1160  * have been programmed by the platform firmware.
1161  */
1162  for ( i = 0 ; i < ETH_ALEN ; i++ )
1163  netdev->hw_addr[i] = readb ( rtl->regs + RTL_IDR0 + i );
1164  }
1165 
1166  /* Initialise and reset MII interface */
1168  mii_init ( &rtl->mii, &rtl->mdio, 0 );
1169  if ( ( rc = realtek_phy_reset ( rtl ) ) != 0 )
1170  goto err_phy_reset;
1171 
1172  /* Register network device */
1173  if ( ( rc = register_netdev ( netdev ) ) != 0 )
1174  goto err_register_netdev;
1175 
1176  /* Set initial link state */
1178 
1179  /* Register non-volatile options, if applicable */
1180  if ( rtl->nvo.nvs ) {
1181  if ( ( rc = register_nvo ( &rtl->nvo,
1182  netdev_settings ( netdev ) ) ) != 0)
1183  goto err_register_nvo;
1184  }
1185 
1186  return 0;
1187 
1188  err_register_nvo:
1190  err_register_netdev:
1191  err_phy_reset:
1192  err_nvs_read:
1193  realtek_reset ( rtl );
1194  err_reset:
1195  iounmap ( rtl->regs );
1196  err_ioremap:
1197  netdev_nullify ( netdev );
1198  netdev_put ( netdev );
1199  err_alloc:
1200  return rc;
1201 }
unsigned long membase
Memory base.
Definition: pci.h:194
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
#define RTL_EEPROM_MAC
Word offset of MAC address within EEPROM.
Definition: realtek.h:177
static void realtek_detect(struct realtek_nic *rtl)
Detect device type.
Definition: realtek.c:1054
int register_nvo(struct nvo_block *nvo, struct settings *parent)
Register non-volatile stored options.
Definition: nvo.c:293
struct nvo_block nvo
Non-volatile options.
Definition: realtek.h:284
#define DBGC(...)
Definition: compiler.h:505
#define RTL_IDR0
ID Register 0 (6 bytes)
Definition: realtek.h:69
void * regs
Registers.
Definition: realtek.h:278
#define RTL_BAR_SIZE
PCI memory BAR size.
Definition: realtek.h:18
static int realtek_init_eeprom(struct net_device *netdev)
Initialise EEPROM.
Definition: realtek.c:183
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition: pci.c:149
struct device dev
Generic device.
Definition: pci.h:189
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition: netdevice.h:577
static void mdio_init(struct mii_interface *mdio, struct mii_operations *op)
Initialise MII interface.
Definition: mii.h:63
#define RTL_NUM_TX_DESC
Number of transmit descriptors.
Definition: realtek.h:93
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition: netdevice.h:498
struct mii_device mii
MII device.
Definition: realtek.h:288
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition: pci.h:338
#define ENOMEM
Not enough space.
Definition: errno.h:534
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:555
static int realtek_reset(struct realtek_nic *rtl)
Reset hardware.
Definition: realtek.c:341
void * priv
Driver private data.
Definition: netdevice.h:425
struct realtek_ring rx
Receive descriptor ring.
Definition: realtek.h:300
static int realtek_phy_reset(struct realtek_nic *rtl)
Reset PHY.
Definition: realtek.c:399
static struct net_device * netdev
Definition: gdbudp.c:52
A Realtek network card.
Definition: realtek.h:276
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:844
static void realtek_init_ring(struct realtek_ring *ring, unsigned int count, unsigned int reg)
Initialise descriptor ring.
Definition: realtek.h:269
struct nvs_device * nvs
Underlying non-volatile storage device.
Definition: nvo.h:26
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void realtek_check_link(struct net_device *netdev)
Check link state.
Definition: realtek.c:444
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:667
A network device.
Definition: netdevice.h:348
#define ENODEV
No such device.
Definition: errno.h:509
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:511
#define ETH_ALEN
Definition: if_ether.h:8
struct device * dev
Underlying hardware device.
Definition: netdevice.h:360
static void mii_init(struct mii_device *mii, struct mii_interface *mdio, unsigned int address)
Initialise MII device.
Definition: mii.h:75
static struct mii_operations realtek_mii_operations
Realtek MII operations.
Definition: realtek.c:323
#define RTL_TNPDS
Transmit Normal Priority Descriptors (qword)
Definition: realtek.h:87
struct nvs_device nvs
NVS device.
Definition: spi.h:88
struct mii_interface mdio
MII interface.
Definition: realtek.h:286
struct spi_bus * bus
SPI bus to which device is attached.
Definition: spi.h:90
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition: ethernet.c:264
void iounmap(volatile const void *io_addr)
Unmap I/O address.
static struct net_device_operations realtek_operations
Realtek network device operations.
Definition: realtek.c:1034
int nvs_read(struct nvs_device *nvs, unsigned int address, void *data, size_t len)
Read from non-volatile storage device.
Definition: nvs.c:75
#define RTL_RDSAR
Receive Descriptor Start Address Register (qword)
Definition: realtek.h:237
void * ioremap(unsigned long bus_addr, size_t len)
Map bus address as an I/O address.
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:375
struct realtek_ring tx
Transmit descriptor ring.
Definition: realtek.h:298
#define RTL_NUM_RX_DESC
Number of receive descriptors.
Definition: realtek.h:240
void * memset(void *dest, int character, size_t len) __nonnull
struct spi_device eeprom
EEPROM.
Definition: realtek.h:282

References adjust_pci_device(), alloc_etherdev(), spi_device::bus, DBGC, pci_device::dev, net_device::dev, realtek_nic::eeprom, ENODEV, ENOMEM, ETH_ALEN, net_device::hw_addr, ioremap(), 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_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().

◆ realtek_remove()

static void realtek_remove ( struct pci_device pci)
static

Remove PCI device.

Parameters
pciPCI device

Definition at line 1208 of file realtek.c.

1208  {
1209  struct net_device *netdev = pci_get_drvdata ( pci );
1210  struct realtek_nic *rtl = netdev->priv;
1211 
1212  /* Unregister non-volatile options, if applicable */
1213  if ( rtl->nvo.nvs )
1214  unregister_nvo ( &rtl->nvo );
1215 
1216  /* Unregister network device */
1218 
1219  /* Reset card */
1220  realtek_reset ( rtl );
1221 
1222  /* Free network device */
1223  iounmap ( rtl->regs );
1224  netdev_nullify ( netdev );
1225  netdev_put ( netdev );
1226 }
struct nvo_block nvo
Non-volatile options.
Definition: realtek.h:284
void * regs
Registers.
Definition: realtek.h:278
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:555
static int realtek_reset(struct realtek_nic *rtl)
Reset hardware.
Definition: realtek.c:341
void * priv
Driver private data.
Definition: netdevice.h:425
static struct net_device * netdev
Definition: gdbudp.c:52
A Realtek network card.
Definition: realtek.h:276
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:844
void unregister_nvo(struct nvo_block *nvo)
Unregister non-volatile stored options.
Definition: nvo.c:324
struct nvs_device * nvs
Underlying non-volatile storage device.
Definition: nvo.h:26
A network device.
Definition: netdevice.h:348
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:511
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
Definition: pci.h:348
void iounmap(volatile const void *io_addr)
Unmap I/O address.

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().

Variable Documentation

◆ realtek_eeprom_bits

const uint8_t realtek_eeprom_bits[]
static
Initial value:
= {
}
#define RTL_9346CR_EEDO
Data out.
Definition: realtek.h:168
Master In Slave Out.
Definition: spi_bit.h:39
#define RTL_9346CR_EEDI
Data in.
Definition: realtek.h:167
Master Out Slave In.
Definition: spi_bit.h:37
Serial clock.
Definition: spi_bit.h:35
#define SPI_BIT_SS(slave)
Determine bit index for a particular slave.
Definition: spi_bit.h:50
#define RTL_9346CR_EESK
Clock.
Definition: realtek.h:166
#define RTL_9346CR_EECS
Chip select.
Definition: realtek.h:165

Pin mapping for SPI bit-bashing interface.

Definition at line 90 of file realtek.c.

Referenced by realtek_spi_read_bit(), and realtek_spi_write_bit().

◆ realtek_basher_ops

struct bit_basher_operations realtek_basher_ops
static
Initial value:
= {
}
static void realtek_spi_write_bit(struct bit_basher *basher, unsigned int bit_id, unsigned long data)
Set/clear output bit.
Definition: realtek.c:153
static void realtek_spi_open_bit(struct bit_basher *basher)
Open bit-bashing interface.
Definition: realtek.c:102
static int realtek_spi_read_bit(struct bit_basher *basher, unsigned int bit_id)
Read input bit.
Definition: realtek.c:133
static void realtek_spi_close_bit(struct bit_basher *basher)
Close bit-bashing interface.
Definition: realtek.c:116

SPI bit-bashing interface.

Definition at line 170 of file realtek.c.

Referenced by realtek_init_eeprom().

◆ realtek_mii_operations

struct mii_operations realtek_mii_operations
static
Initial value:
= {
}
static int realtek_mii_read(struct mii_interface *mdio, unsigned int phy __unused, unsigned int reg)
Read from MII register.
Definition: realtek.c:250
static int realtek_mii_write(struct mii_interface *mdio, unsigned int phy __unused, unsigned int reg, unsigned int data)
Write to MII register.
Definition: realtek.c:291

Realtek MII operations.

Definition at line 323 of file realtek.c.

Referenced by realtek_probe().

◆ realtek_operations

struct net_device_operations realtek_operations
static
Initial value:
= {
.open = realtek_open,
.close = realtek_close,
.transmit = realtek_transmit,
.poll = realtek_poll,
.irq = realtek_irq,
}
static void realtek_close(struct net_device *netdev)
Close network device.
Definition: realtek.c:749
static void realtek_poll(struct net_device *netdev)
Poll for completed and received packets.
Definition: realtek.c:991
static void realtek_irq(struct net_device *netdev, int enable)
Enable or disable interrupts.
Definition: realtek.c:1023
static int realtek_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition: realtek.c:780
static int realtek_open(struct net_device *netdev)
Open network device.
Definition: realtek.c:685

Realtek network device operations.

Definition at line 1034 of file realtek.c.

Referenced by realtek_probe().

◆ realtek_nics

struct pci_device_id realtek_nics[]
static

Realtek PCI device IDs.

Definition at line 1229 of file realtek.c.

◆ __pci_driver

struct pci_driver realtek_driver __pci_driver
Initial value:
= {
.ids = realtek_nics,
.id_count = ( sizeof ( realtek_nics ) / sizeof ( realtek_nics[0] ) ),
.probe = realtek_probe,
}
static struct pci_device_id realtek_nics[]
Realtek PCI device IDs.
Definition: realtek.c:1229
static void realtek_remove(struct pci_device *pci)
Remove PCI device.
Definition: realtek.c:1208
static struct xen_remove_from_physmap * remove
Definition: xenmem.h:39
static int realtek_probe(struct pci_device *pci)
Probe PCI device.
Definition: realtek.c:1107

Realtek PCI driver.

Definition at line 1264 of file realtek.c.