iPXE
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/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)
 FILE_SECBOOT (PERMITTED)
static void realtek_dump (struct realtek_nic *rtl)
 Dump all registers (for debugging)
static void realtek_spi_open_bit (struct bit_basher *basher)
 Open bit-bashing interface.
static void realtek_spi_close_bit (struct bit_basher *basher)
 Close bit-bashing interface.
static int realtek_spi_read_bit (struct bit_basher *basher, unsigned int bit_id)
 Read input bit.
static void realtek_spi_write_bit (struct bit_basher *basher, unsigned int bit_id, unsigned long data)
 Set/clear output bit.
static int realtek_init_eeprom (struct net_device *netdev)
 Initialise EEPROM.
static int realtek_mii_read (struct mii_interface *mdio, unsigned int phy __unused, unsigned int reg)
 Read from MII register.
static int realtek_mii_write (struct mii_interface *mdio, unsigned int phy __unused, unsigned int reg, unsigned int data)
 Write to MII register.
static int realtek_reset (struct realtek_nic *rtl)
 Reset hardware.
static int realtek_phy_speed (struct realtek_nic *rtl)
 Configure PHY for Gigabit operation.
static int realtek_phy_reset (struct realtek_nic *rtl)
 Reset PHY.
static void realtek_check_link (struct net_device *netdev)
 Check link state.
static int realtek_create_buffer (struct realtek_nic *rtl)
 Create receive buffer (legacy mode)
static void realtek_destroy_buffer (struct realtek_nic *rtl)
 Destroy receive buffer (legacy mode)
static int realtek_create_ring (struct realtek_nic *rtl, struct realtek_ring *ring)
 Create descriptor ring.
static void realtek_destroy_ring (struct realtek_nic *rtl, struct realtek_ring *ring)
 Destroy descriptor ring.
static void realtek_refill_rx (struct realtek_nic *rtl)
 Refill receive descriptor ring.
static int realtek_open (struct net_device *netdev)
 Open network device.
static void realtek_close (struct net_device *netdev)
 Close network device.
static int realtek_transmit (struct net_device *netdev, struct io_buffer *iobuf)
 Transmit packet.
static void realtek_poll_tx (struct net_device *netdev)
 Poll for completed packets.
static void realtek_legacy_poll_rx (struct net_device *netdev)
 Poll for received packets (legacy mode)
static void realtek_poll_rx (struct net_device *netdev)
 Poll for received packets.
static void realtek_poll (struct net_device *netdev)
 Poll for completed and received packets.
static void realtek_irq (struct net_device *netdev, int enable)
 Enable or disable interrupts.
static void realtek_detect (struct realtek_nic *rtl)
 Detect device type.
static int realtek_probe (struct pci_device *pci)
 Probe PCI device.
static void realtek_remove (struct pci_device *pci)
 Remove PCI device.

Variables

static const uint8_t realtek_eeprom_bits []
 Pin mapping for SPI bit-bashing interface.
static struct bit_basher_operations realtek_basher_ops
 SPI bit-bashing interface.
static struct mii_operations realtek_mii_operations
 Realtek MII operations.
static struct net_device_operations realtek_operations
 Realtek network device operations.
static struct pci_device_id realtek_nics []
 Realtek PCI device IDs.
struct pci_driver realtek_driver __pci_driver
 Realtek PCI driver.

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 )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ realtek_dump()

void realtek_dump ( struct realtek_nic * rtl)
static

Dump all registers (for debugging)

Parameters
rtlRealtek device

Definition at line 69 of file realtek.c.

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

References DBG_LOG, DBGC, DBGC_HDA, readb, realtek_nic::regs, regs, and unused.

◆ realtek_spi_open_bit()

void realtek_spi_open_bit ( struct bit_basher * basher)
static

Open bit-bashing interface.

Parameters
basherBit-bashing interface

Definition at line 104 of file realtek.c.

104 {
105 struct realtek_nic *rtl = container_of ( basher, struct realtek_nic,
106 spibit.basher );
107
108 /* Enable EEPROM access */
110 readb ( rtl->regs + RTL_9346CR ); /* Ensure write reaches chip */
111}
#define RTL_9346CR_EEM_EEPROM
EEPROM mode.
Definition realtek.h:164
#define RTL_9346CR
93C46 (93C56) Command Register (byte)
Definition realtek.h:162
#define container_of(ptr, type, field)
Get containing structure.
Definition stddef.h:36
A Realtek network card.
Definition realtek.h:290
struct spi_bit_basher spibit
SPI bit-bashing interface.
Definition realtek.h:296
struct bit_basher basher
Bit-bashing interface.
Definition spi_bit.h:21
#define writeb
Definition w89c840.c:158

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

void realtek_spi_close_bit ( struct bit_basher * basher)
static

Close bit-bashing interface.

Parameters
basherBit-bashing interface

Definition at line 118 of file realtek.c.

118 {
119 struct realtek_nic *rtl = container_of ( basher, struct realtek_nic,
120 spibit.basher );
121
122 /* Disable EEPROM access */
124 readb ( rtl->regs + RTL_9346CR ); /* Ensure write reaches chip */
125}
#define RTL_9346CR_EEM_NORMAL
Normal mode.
Definition realtek.h:165

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

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 135 of file realtek.c.

136 {
137 struct realtek_nic *rtl = container_of ( basher, struct realtek_nic,
138 spibit.basher );
139 uint8_t mask = realtek_eeprom_bits[bit_id];
140 uint8_t reg;
141
143 reg = readb ( rtl->regs + RTL_9346CR );
145 return ( reg & mask );
146}
#define DBGLVL_IO
Definition compiler.h:322
#define DBG_DISABLE(level)
Definition compiler.h:312
#define DBG_ENABLE(level)
Definition compiler.h:313
static unsigned int unsigned int reg
Definition myson.h:162
static const uint8_t realtek_eeprom_bits[]
Pin mapping for SPI bit-bashing interface.
Definition realtek.c:92

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

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 155 of file realtek.c.

156 {
157 struct realtek_nic *rtl = container_of ( basher, struct realtek_nic,
158 spibit.basher );
159 uint8_t mask = realtek_eeprom_bits[bit_id];
160 uint8_t reg;
161
163 reg = readb ( rtl->regs + RTL_9346CR );
164 reg &= ~mask;
165 reg |= ( data & mask );
166 writeb ( reg, rtl->regs + RTL_9346CR );
167 readb ( rtl->regs + RTL_9346CR ); /* Ensure write reaches chip */
169}
uint8_t data[48]
Additional event data.
Definition ena.h:11

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

int realtek_init_eeprom ( struct net_device * netdev)
static

Initialise EEPROM.

Parameters
netdevNetwork device
Return values
rcReturn status code

Definition at line 185 of file realtek.c.

185 {
186 struct realtek_nic *rtl = netdev->priv;
187 uint16_t id;
188 int rc;
189
190 /* Initialise SPI bit-bashing interface */
193 init_spi_bit_basher ( &rtl->spibit );
194
195 /* Detect EEPROM type and initialise three-wire device */
196 if ( readl ( rtl->regs + RTL_RCR ) & RTL_RCR_9356SEL ) {
197 DBGC ( rtl, "REALTEK %p EEPROM is a 93C56\n", rtl );
198 init_at93c56 ( &rtl->eeprom, 16 );
199 } else {
200 DBGC ( rtl, "REALTEK %p EEPROM is a 93C46\n", rtl );
201 init_at93c46 ( &rtl->eeprom, 16 );
202 }
203
204 /* Check for EEPROM presence. Some onboard NICs will have no
205 * EEPROM connected, with the BIOS being responsible for
206 * programming the initial register values.
207 */
208 if ( ( rc = nvs_read ( &rtl->eeprom.nvs, RTL_EEPROM_ID,
209 &id, sizeof ( id ) ) ) != 0 ) {
210 DBGC ( rtl, "REALTEK %p could not read EEPROM ID: %s\n",
211 rtl, strerror ( rc ) );
212 return rc;
213 }
214 if ( id != cpu_to_le16 ( RTL_EEPROM_ID_MAGIC ) ) {
215 DBGC ( rtl, "REALTEK %p EEPROM ID incorrect (%#04x); assuming "
216 "no EEPROM\n", rtl, le16_to_cpu ( id ) );
217 return -ENODEV;
218 }
219
220 /* Initialise space for non-volatile options, if available
221 *
222 * We use offset 0x40 (i.e. address 0x20), length 0x40. This
223 * block is marked as VPD in the Realtek datasheets, so we use
224 * it only if we detect that the card is not supporting VPD.
225 */
226 if ( readb ( rtl->regs + RTL_CONFIG1 ) & RTL_CONFIG1_VPD ) {
227 DBGC ( rtl, "REALTEK %p EEPROM in use for VPD; cannot use "
228 "for options\n", rtl );
229 } else {
230 nvo_init ( &rtl->nvo, &rtl->eeprom.nvs, RTL_EEPROM_VPD,
231 RTL_EEPROM_VPD_LEN, NULL, &netdev->refcnt );
232 }
233
234 return 0;
235}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
unsigned short uint16_t
Definition stdint.h:11
uint8_t id
Request identifier.
Definition ena.h:1
static struct net_device * netdev
Definition gdbudp.c:53
#define ENODEV
No such device.
Definition errno.h:510
#define le16_to_cpu(value)
Definition byteswap.h:113
#define cpu_to_le16(value)
Definition byteswap.h:107
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:274
int nvs_read(struct nvs_device *nvs, unsigned int address, void *data, size_t len)
Read from non-volatile storage device.
Definition nvs.c:76
static struct bit_basher_operations realtek_basher_ops
SPI bit-bashing interface.
Definition realtek.c:172
#define RTL_EEPROM_ID_MAGIC
EEPROM code word magic value.
Definition realtek.h:175
#define RTL_CONFIG1_VPD
Vital Product Data enabled.
Definition realtek.h:188
#define RTL_EEPROM_VPD
Word offset of VPD / non-volatile options within EEPROM.
Definition realtek.h:181
#define RTL_EEPROM_ID
Word offset of ID code word within EEPROM.
Definition realtek.h:172
#define RTL_CONFIG1
Configuration Register 1 (byte)
Definition realtek.h:187
#define RTL_RCR_9356SEL
EEPROM is a 93C56.
Definition realtek.h:155
#define RTL_RCR
Receive (Rx) Configuration Register (dword)
Definition realtek.h:143
#define RTL_EEPROM_VPD_LEN
Length of VPD / non-volatile options within EEPROM.
Definition realtek.h:184
#define SPI_MODE_THREEWIRE
Threewire-compatible mode.
Definition spi.h:200
void init_spi_bit_basher(struct spi_bit_basher *spibit)
Initialise SPI bit-bashing interface.
Definition spi_bit.c:236
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
struct bit_basher_operations * op
Bit-bashing operations.
Definition bitbash.h:58
struct nvo_block nvo
Non-volatile options.
Definition realtek.h:300
struct spi_device eeprom
EEPROM.
Definition realtek.h:298
struct spi_bus bus
SPI bus.
Definition spi_bit.h:19
unsigned int mode
SPI interface mode.
Definition spi.h:137
struct nvs_device nvs
NVS device.
Definition spi.h:89
#define readl
Definition w89c840.c:157

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, rc, readb, readl, realtek_basher_ops, 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()

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 252 of file realtek.c.

253 {
254 struct realtek_nic *rtl =
255 container_of ( mdio, struct realtek_nic, mdio );
256 unsigned int i;
258
259 /* Fail if PHYAR register is not present */
260 if ( ! rtl->have_phy_regs )
261 return -ENOTSUP;
262
263 /* Initiate read */
264 writel ( RTL_PHYAR_VALUE ( 0, reg, 0 ), rtl->regs + RTL_PHYAR );
265
266 /* Wait for read to complete */
267 for ( i = 0 ; i < RTL_MII_MAX_WAIT_US ; i++ ) {
268
269 /* If read is not complete, delay 1us and retry */
270 value = readl ( rtl->regs + RTL_PHYAR );
271 if ( ! ( value & RTL_PHYAR_FLAG ) ) {
272 udelay ( 1 );
273 continue;
274 }
275
276 /* Return register value */
277 return ( RTL_PHYAR_DATA ( value ) );
278 }
279
280 DBGC ( rtl, "REALTEK %p timed out waiting for MII read\n", rtl );
281 return -ETIMEDOUT;
282}
pseudo_bit_t value[0x00020]
Definition arbel.h:2
unsigned int uint32_t
Definition stdint.h:12
#define ETIMEDOUT
Connection timed out.
Definition errno.h:670
#define ENOTSUP
Operation not supported.
Definition errno.h:590
#define RTL_PHYAR
PHY Access Register (dword, 8169 only)
Definition realtek.h:201
#define RTL_PHYAR_FLAG
Read/write flag.
Definition realtek.h:202
#define RTL_MII_MAX_WAIT_US
Maximum time to wait for PHY access, in microseconds.
Definition realtek.h:211
#define RTL_PHYAR_DATA(value)
Extract PHY Access Register data.
Definition realtek.h:208
#define RTL_PHYAR_VALUE(flag, reg, data)
Construct PHY Access Register value.
Definition realtek.h:205
int have_phy_regs
PHYAR and PHYSTATUS registers are present.
Definition realtek.h:309
struct mii_interface mdio
MII interface.
Definition realtek.h:302
void udelay(unsigned long usecs)
Delay for a fixed number of microseconds.
Definition timer.c:61
#define writel
Definition w89c840.c:160

References __unused, 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()

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 293 of file realtek.c.

295 {
296 struct realtek_nic *rtl =
297 container_of ( mdio, struct realtek_nic, mdio );
298 unsigned int i;
299
300 /* Fail if PHYAR register is not present */
301 if ( ! rtl->have_phy_regs )
302 return -ENOTSUP;
303
304 /* Initiate write */
306 rtl->regs + RTL_PHYAR );
307
308 /* Wait for write to complete */
309 for ( i = 0 ; i < RTL_MII_MAX_WAIT_US ; i++ ) {
310
311 /* If write is not complete, delay 1us and retry */
312 if ( readl ( rtl->regs + RTL_PHYAR ) & RTL_PHYAR_FLAG ) {
313 udelay ( 1 );
314 continue;
315 }
316
317 return 0;
318 }
319
320 DBGC ( rtl, "REALTEK %p timed out waiting for MII write\n", rtl );
321 return -ETIMEDOUT;
322}

References __unused, 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()

int realtek_reset ( struct realtek_nic * rtl)
static

Reset hardware.

Parameters
rtlRealtek device
Return values
rcReturn status code

Definition at line 343 of file realtek.c.

343 {
344 unsigned int i;
345
346 /* Issue reset */
347 writeb ( RTL_CR_RST, rtl->regs + RTL_CR );
348
349 /* Wait for reset to complete */
350 for ( i = 0 ; i < RTL_RESET_MAX_WAIT_MS ; i++ ) {
351
352 /* If reset is not complete, delay 1ms and retry */
353 if ( readb ( rtl->regs + RTL_CR ) & RTL_CR_RST ) {
354 mdelay ( 1 );
355 continue;
356 }
357
358 return 0;
359 }
360
361 DBGC ( rtl, "REALTEK %p timed out waiting for reset\n", rtl );
362 return -ETIMEDOUT;
363}
#define RTL_RESET_MAX_WAIT_MS
Maximum time to wait for a reset, in milliseconds.
Definition realtek.h:116
#define RTL_CR_RST
Reset.
Definition realtek.h:110
#define RTL_CR
Command Register (byte)
Definition realtek.h:109
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition timer.c:79

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

◆ realtek_phy_speed()

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 371 of file realtek.c.

371 {
372 int ctrl1000;
373 int rc;
374
375 /* Read CTRL1000 register */
376 ctrl1000 = mii_read ( &rtl->mii, MII_CTRL1000 );
377 if ( ctrl1000 < 0 ) {
378 rc = ctrl1000;
379 DBGC ( rtl, "REALTEK %p could not read CTRL1000: %s\n",
380 rtl, strerror ( rc ) );
381 return rc;
382 }
383
384 /* Advertise 1000Mbps speeds */
385 ctrl1000 |= ( ADVERTISE_1000FULL | ADVERTISE_1000HALF );
386 if ( ( rc = mii_write ( &rtl->mii, MII_CTRL1000, ctrl1000 ) ) != 0 ) {
387 DBGC ( rtl, "REALTEK %p could not write CTRL1000: %s\n",
388 rtl, strerror ( rc ) );
389 return rc;
390 }
391
392 return 0;
393}
static int mii_read(int phy_id, int location)
Definition epic100.c:500
static int mii_write(struct mii_device *mii, unsigned int reg, unsigned int data)
Write to MII register.
Definition mii.h:105
#define ADVERTISE_1000HALF
Definition mii.h:135
#define MII_CTRL1000
Definition mii.h:25
#define ADVERTISE_1000FULL
Definition mii.h:134
struct mii_device mii
MII device.
Definition realtek.h:304

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

int realtek_phy_reset ( struct realtek_nic * rtl)
static

Reset PHY.

Parameters
rtlRealtek device
Return values
rcReturn status code

Definition at line 401 of file realtek.c.

401 {
402 int rc;
403
404 /* Do nothing if we have no separate PHY register access */
405 if ( ! rtl->have_phy_regs )
406 return 0;
407
408 /* Perform MII reset */
409 if ( ( rc = mii_reset ( &rtl->mii ) ) != 0 ) {
410 DBGC ( rtl, "REALTEK %p could not reset MII: %s\n",
411 rtl, strerror ( rc ) );
412 return rc;
413 }
414
415 /* Some cards (e.g. RTL8169SC) do not advertise Gigabit by
416 * default. Try to enable advertisement of Gigabit speeds.
417 */
418 if ( ( rc = realtek_phy_speed ( rtl ) ) != 0 ) {
419 /* Ignore failures, since the register may not be
420 * present on non-Gigabit PHYs (e.g. RTL8101).
421 */
422 }
423
424 /* Some cards (e.g. RTL8211B) have a hardware errata that
425 * requires the MII_MMD_DATA register to be cleared before the
426 * link will come up.
427 */
428 if ( ( rc = mii_write ( &rtl->mii, MII_MMD_DATA, 0 ) ) != 0 ) {
429 /* Ignore failures, since the register may not be
430 * present on all PHYs.
431 */
432 }
433
434 /* Restart autonegotiation */
435 if ( ( rc = mii_restart ( &rtl->mii ) ) != 0 ) {
436 DBGC ( rtl, "REALTEK %p could not restart MII: %s\n",
437 rtl, strerror ( rc ) );
438 return rc;
439 }
440
441 return 0;
442}
int mii_reset(struct mii_device *mii)
Reset MII device.
Definition mii.c:75
int mii_restart(struct mii_device *mii)
Restart autonegotiation.
Definition mii.c:44
#define MII_MMD_DATA
Definition mii.h:28
static int realtek_phy_speed(struct realtek_nic *rtl)
Configure PHY for Gigabit operation.
Definition realtek.c:371

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

◆ realtek_check_link()

void realtek_check_link ( struct net_device * netdev)
static

Check link state.

Parameters
netdevNetwork device

Definition at line 456 of file realtek.c.

456 {
457 struct realtek_nic *rtl = netdev->priv;
458 uint8_t phystatus;
459 uint8_t msr;
460 int link_up;
461
462 /* Determine link state */
463 if ( rtl->have_phy_regs ) {
464 mii_dump ( &rtl->mii );
465 phystatus = readb ( rtl->regs + RTL_PHYSTATUS );
466 link_up = ( phystatus & RTL_PHYSTATUS_LINKSTS );
467 DBGC ( rtl, "REALTEK %p PHY status is %02x (%s%s%s%s%s%s, "
468 "Link%s, %sDuplex)\n", rtl, phystatus,
469 ( ( phystatus & RTL_PHYSTATUS_ENTBI ) ? "TBI" : "GMII" ),
470 ( ( phystatus & RTL_PHYSTATUS_TXFLOW ) ?
471 ", TxFlow" : "" ),
472 ( ( phystatus & RTL_PHYSTATUS_RXFLOW ) ?
473 ", RxFlow" : "" ),
474 ( ( phystatus & RTL_PHYSTATUS_1000MF ) ?
475 ", 1000Mbps" : "" ),
476 ( ( phystatus & RTL_PHYSTATUS_100M ) ?
477 ", 100Mbps" : "" ),
478 ( ( phystatus & RTL_PHYSTATUS_10M ) ?
479 ", 10Mbps" : "" ),
480 ( ( phystatus & RTL_PHYSTATUS_LINKSTS ) ?
481 "Up" : "Down" ),
482 ( ( phystatus & RTL_PHYSTATUS_FULLDUP ) ?
483 "Full" : "Half" ) );
484 } else {
485 msr = readb ( rtl->regs + RTL_MSR );
486 link_up = ( ! ( msr & RTL_MSR_LINKB ) );
487 DBGC ( rtl, "REALTEK %p media status is %02x (Link%s, "
488 "%dMbps%s%s%s%s%s)\n", rtl, msr,
489 ( ( msr & RTL_MSR_LINKB ) ? "Down" : "Up" ),
490 ( ( msr & RTL_MSR_SPEED_10 ) ? 10 : 100 ),
491 ( ( msr & RTL_MSR_TXFCE ) ? ", TxFlow" : "" ),
492 ( ( msr & RTL_MSR_RXFCE ) ? ", RxFlow" : "" ),
493 ( ( msr & RTL_MSR_AUX_STATUS ) ? ", AuxPwr" : "" ),
494 ( ( msr & RTL_MSR_TXPF ) ? ", TxPause" : "" ),
495 ( ( msr & RTL_MSR_RXPF ) ? ", RxPause" : "" ) );
496 }
497
498 /* Report link state */
499 if ( link_up ) {
501 } else {
503 }
504}
static void mii_dump(struct mii_device *mii)
Dump MII registers (for debugging)
Definition mii.h:117
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
Definition netdevice.c:231
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition netdevice.h:789
#define RTL_PHYSTATUS_FULLDUP
Full duplex.
Definition realtek.h:222
#define RTL_MSR
Media Status Register (byte, 8139 only)
Definition realtek.h:191
#define RTL_PHYSTATUS_10M
10Mbps
Definition realtek.h:220
#define RTL_MSR_TXFCE
TX flow control enabled.
Definition realtek.h:192
#define RTL_MSR_RXFCE
RX flow control enabled.
Definition realtek.h:193
#define RTL_PHYSTATUS_ENTBI
TBI / GMII mode.
Definition realtek.h:215
#define RTL_PHYSTATUS_LINKSTS
Link ok.
Definition realtek.h:221
#define RTL_MSR_RXPF
RX pause flag.
Definition realtek.h:198
#define RTL_PHYSTATUS_100M
100Mbps
Definition realtek.h:219
#define RTL_PHYSTATUS_TXFLOW
TX flow control enabled.
Definition realtek.h:216
#define RTL_MSR_LINKB
Inverse of link status.
Definition realtek.h:196
#define RTL_MSR_SPEED_10
10Mbps
Definition realtek.h:195
#define RTL_PHYSTATUS_RXFLOW
RX flow control enabled.
Definition realtek.h:217
#define RTL_MSR_TXPF
TX pause flag.
Definition realtek.h:197
#define RTL_MSR_AUX_STATUS
Aux power present.
Definition realtek.h:194
#define RTL_PHYSTATUS_1000MF
1000Mbps full-duplex
Definition realtek.h:218
#define RTL_PHYSTATUS
PHY (GMII, MII, or TBI) Status Register (byte, 8169 only)
Definition realtek.h:214

References DBGC, realtek_nic::have_phy_regs, realtek_nic::mii, mii_dump(), netdev, netdev_link_down(), netdev_link_up(), 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()

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 519 of file realtek.c.

519 {
520 struct realtek_rx_buffer *rxbuf = &rtl->rxbuf;
521 size_t len = ( RTL_RXBUF_LEN + RTL_RXBUF_PAD );
522
523 /* Do nothing unless in legacy mode */
524 if ( ! rtl->legacy )
525 return 0;
526
527 /* Allocate buffer */
528 rxbuf->data = dma_alloc ( rtl->dma, &rxbuf->map, len,
530 if ( ! rxbuf->data )
531 return -ENOMEM;
532
533 /* Program buffer address */
534 writel ( dma ( &rxbuf->map, rxbuf->data ), rtl->regs + RTL_RBSTART );
535 DBGC ( rtl, "REALTEK %p receive buffer is at [%08lx,%08lx,%08lx)\n",
536 rtl, virt_to_phys ( rxbuf->data ),
537 ( virt_to_phys ( rxbuf->data ) + RTL_RXBUF_LEN ),
538 ( virt_to_phys ( rxbuf->data ) + len ) );
539
540 return 0;
541}
ring len
Length.
Definition dwmac.h:226
#define ENOMEM
Not enough space.
Definition errno.h:535
void * dma_alloc(struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align)
Allocate and map DMA-coherent buffer.
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
#define RTL_RXBUF_LEN
Receive buffer length.
Definition realtek.h:100
#define RTL_RXBUF_ALIGN
Receive buffer alignment.
Definition realtek.h:106
#define RTL_RXBUF_PAD
Receive buffer padding.
Definition realtek.h:103
#define RTL_RBSTART
Receive Buffer Start Address (dword, 8139 only)
Definition realtek.h:97
struct realtek_rx_buffer rxbuf
Receive buffer (legacy mode)
Definition realtek.h:320
int legacy
Legacy datapath mode.
Definition realtek.h:307
struct dma_device * dma
DMA device.
Definition realtek.h:294
Receive buffer (legacy mode *)
Definition realtek.h:280
struct dma_mapping map
Buffer DMA mapping.
Definition realtek.h:284
void * data
Buffer.
Definition realtek.h:282

References realtek_rx_buffer::data, DBGC, dma(), realtek_nic::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, and writel.

Referenced by realtek_open().

◆ realtek_destroy_buffer()

void realtek_destroy_buffer ( struct realtek_nic * rtl)
static

Destroy receive buffer (legacy mode)

Parameters
rtlRealtek device

Definition at line 548 of file realtek.c.

548 {
549 struct realtek_rx_buffer *rxbuf = &rtl->rxbuf;
550 size_t len = ( RTL_RXBUF_LEN + RTL_RXBUF_PAD );
551
552 /* Do nothing unless in legacy mode */
553 if ( ! rtl->legacy )
554 return;
555
556 /* Clear buffer address */
557 writel ( 0, rtl->regs + RTL_RBSTART );
558
559 /* Free buffer */
560 dma_free ( &rxbuf->map, rxbuf->data, len );
561 rxbuf->data = NULL;
562 rxbuf->offset = 0;
563}
void dma_free(struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer.
unsigned int offset
Offset within buffer.
Definition realtek.h:286

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

◆ realtek_create_ring()

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 572 of file realtek.c.

573 {
575
576 /* Do nothing in legacy mode */
577 if ( rtl->legacy )
578 return 0;
579
580 /* Allocate descriptor ring */
581 ring->desc = dma_alloc ( rtl->dma, &ring->map, ring->len,
583 if ( ! ring->desc )
584 return -ENOMEM;
585
586 /* Initialise descriptor ring */
587 memset ( ring->desc, 0, ring->len );
588
589 /* Program ring address */
590 address = dma ( &ring->map, ring->desc );
591 writel ( ( ( ( uint64_t ) address ) >> 32 ),
592 rtl->regs + ring->reg + 4 );
593 writel ( ( address & 0xffffffffUL ), rtl->regs + ring->reg );
594 DBGC ( rtl, "REALTEK %p ring %02x is at [%08lx,%08lx)\n",
595 rtl, ring->reg, virt_to_phys ( ring->desc ),
596 ( virt_to_phys ( ring->desc ) + ring->len ) );
597
598 return 0;
599}
unsigned long physaddr_t
Definition stdint.h:20
unsigned long long uint64_t
Definition stdint.h:13
uint64_t address
Base address.
Definition ena.h:13
void * memset(void *dest, int character, size_t len) __nonnull
#define RTL_RING_ALIGN
Descriptor ring alignment.
Definition realtek.h:51
size_t len
Length (in bytes)
Definition realtek.h:262
struct dma_mapping map
Descriptor ring DMA mapping.
Definition realtek.h:253
unsigned int reg
Descriptor start address register.
Definition realtek.h:260
struct realtek_descriptor * desc
Descriptors.
Definition realtek.h:251

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

Referenced by realtek_open().

◆ realtek_destroy_ring()

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

Destroy descriptor ring.

Parameters
rtlRealtek device
ringDescriptor ring

Definition at line 607 of file realtek.c.

608 {
609
610 /* Reset producer and consumer counters */
611 ring->prod = 0;
612 ring->cons = 0;
613
614 /* Do nothing more if in legacy mode */
615 if ( rtl->legacy )
616 return;
617
618 /* Clear ring address */
619 writel ( 0, rtl->regs + ring->reg );
620 writel ( 0, rtl->regs + ring->reg + 4 );
621
622 /* Free descriptor ring */
623 dma_free ( &ring->map, ring->desc, ring->len );
624 ring->desc = NULL;
625}
unsigned int prod
Producer index.
Definition realtek.h:255
unsigned int cons
Consumer index.
Definition realtek.h:257

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

◆ realtek_refill_rx()

void realtek_refill_rx ( struct realtek_nic * rtl)
static

Refill receive descriptor ring.

Parameters
rtlRealtek device

Definition at line 632 of file realtek.c.

632 {
633 struct realtek_descriptor *rx;
634 struct io_buffer *iobuf;
635 unsigned int rx_idx;
636 int is_last;
637
638 /* Do nothing in legacy mode */
639 if ( rtl->legacy )
640 return;
641
642 while ( ( rtl->rx.prod - rtl->rx.cons ) < RTL_NUM_RX_DESC ) {
643
644 /* Allocate I/O buffer */
645 iobuf = alloc_rx_iob ( RTL_RX_MAX_LEN, rtl->dma );
646 if ( ! iobuf ) {
647 /* Wait for next refill */
648 return;
649 }
650
651 /* Get next receive descriptor */
652 rx_idx = ( rtl->rx.prod++ % RTL_NUM_RX_DESC );
653 is_last = ( rx_idx == ( RTL_NUM_RX_DESC - 1 ) );
654 rx = &rtl->rx.desc[rx_idx];
655
656 /* Populate receive descriptor */
657 rx->address = cpu_to_le64 ( iob_dma ( iobuf ) );
658 rx->length = cpu_to_le16 ( RTL_RX_MAX_LEN );
659 wmb();
660 rx->flags = ( cpu_to_le16 ( RTL_DESC_OWN ) |
661 ( is_last ? cpu_to_le16 ( RTL_DESC_EOR ) : 0 ) );
662 wmb();
663
664 /* Record I/O buffer */
665 assert ( rtl->rx_iobuf[rx_idx] == NULL );
666 rtl->rx_iobuf[rx_idx] = iobuf;
667
668 DBGC2 ( rtl, "REALTEK %p RX %d is [%lx,%lx)\n",
669 rtl, rx_idx, virt_to_phys ( iobuf->data ),
670 ( virt_to_phys ( iobuf->data ) + RTL_RX_MAX_LEN ) );
671 }
672}
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
#define DBGC2(...)
Definition compiler.h:522
#define cpu_to_le64(value)
Definition byteswap.h:109
#define wmb()
Definition io.h:546
struct io_buffer * alloc_rx_iob(size_t len, struct dma_device *dma)
Allocate and map I/O buffer for receive DMA.
Definition iobuf.c:188
static __always_inline physaddr_t iob_dma(struct io_buffer *iobuf)
Get I/O buffer DMA address.
Definition iobuf.h:268
@ RTL_DESC_OWN
Descriptor is owned by NIC.
Definition realtek.h:39
@ RTL_DESC_EOR
End of descriptor ring.
Definition realtek.h:41
#define RTL_RX_MAX_LEN
Receive buffer length.
Definition realtek.h:245
#define RTL_NUM_RX_DESC
Number of receive descriptors.
Definition realtek.h:242
A persistent I/O buffer.
Definition iobuf.h:38
void * data
Start of data.
Definition iobuf.h:53
A packet descriptor.
Definition realtek.h:22
struct io_buffer * rx_iobuf[RTL_NUM_RX_DESC]
Receive I/O buffers.
Definition realtek.h:318
struct realtek_ring rx
Receive descriptor ring.
Definition realtek.h:316
u8 rx[WPA_TKIP_MIC_KEY_LEN]
MIC key for packets from the AP.
Definition wpa.h:1

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, realtek_nic::rx, rx, realtek_nic::rx_iobuf, and wmb.

Referenced by realtek_open(), and realtek_poll().

◆ realtek_open()

int realtek_open ( struct net_device * netdev)
static

Open network device.

Parameters
netdevNetwork device
Return values
rcReturn status code

Definition at line 680 of file realtek.c.

680 {
681 struct realtek_nic *rtl = netdev->priv;
682 uint32_t tcr;
683 uint32_t rcr;
684 int rc;
685
686 /* Create transmit descriptor ring */
687 if ( ( rc = realtek_create_ring ( rtl, &rtl->tx ) ) != 0 )
688 goto err_create_tx;
689
690 /* Create receive descriptor ring */
691 if ( ( rc = realtek_create_ring ( rtl, &rtl->rx ) ) != 0 )
692 goto err_create_rx;
693
694 /* Create receive buffer */
695 if ( ( rc = realtek_create_buffer ( rtl ) ) != 0 )
696 goto err_create_buffer;
697
698 /* Accept all packets */
699 writel ( 0xffffffffUL, rtl->regs + RTL_MAR0 );
700 writel ( 0xffffffffUL, rtl->regs + RTL_MAR4 );
701
702 /* Enable transmitter and receiver. RTL8139 requires that
703 * this happens before writing to RCR.
704 */
705 writeb ( ( RTL_CR_TE | RTL_CR_RE ), rtl->regs + RTL_CR );
706
707 /* Configure transmitter */
708 tcr = readl ( rtl->regs + RTL_TCR );
709 tcr &= ~RTL_TCR_MXDMA_MASK;
711 writel ( tcr, rtl->regs + RTL_TCR );
712
713 /* Configure receiver */
714 rcr = readl ( rtl->regs + RTL_RCR );
720 writel ( rcr, rtl->regs + RTL_RCR );
721
722 /* Fill receive ring */
723 realtek_refill_rx ( rtl );
724
725 /* Update link state */
727
728 return 0;
729
731 err_create_buffer:
732 realtek_destroy_ring ( rtl, &rtl->rx );
733 err_create_rx:
734 realtek_destroy_ring ( rtl, &rtl->tx );
735 err_create_tx:
736 return rc;
737}
static void realtek_destroy_buffer(struct realtek_nic *rtl)
Destroy receive buffer (legacy mode)
Definition realtek.c:548
static int realtek_create_ring(struct realtek_nic *rtl, struct realtek_ring *ring)
Create descriptor ring.
Definition realtek.c:572
static void realtek_refill_rx(struct realtek_nic *rtl)
Refill receive descriptor ring.
Definition realtek.c:632
static void realtek_check_link(struct net_device *netdev)
Check link state.
Definition realtek.c:456
static void realtek_destroy_ring(struct realtek_nic *rtl, struct realtek_ring *ring)
Destroy descriptor ring.
Definition realtek.c:607
static int realtek_create_buffer(struct realtek_nic *rtl)
Create receive buffer (legacy mode)
Definition realtek.c:519
#define RTL_RCR_WRAP
Overrun receive buffer.
Definition realtek.h:154
#define RTL_RCR_AAP
Accept all packets.
Definition realtek.h:159
#define RTL_RCR_RBLEN_MASK
Definition realtek.h:149
#define RTL_RCR_MXDMA_DEFAULT
Definition realtek.h:153
#define RTL_RCR_MXDMA_MASK
Definition realtek.h:152
#define RTL_RCR_RXFTH_MASK
Definition realtek.h:146
#define RTL_RCR_APM
Accept physical match.
Definition realtek.h:158
#define RTL_TCR_MXDMA_DEFAULT
Definition realtek.h:140
#define RTL_RCR_RXFTH_DEFAULT
Definition realtek.h:147
#define RTL_RCR_AM
Accept multicast packets.
Definition realtek.h:157
#define RTL_TCR_MXDMA_MASK
Definition realtek.h:139
#define RTL_CR_RE
Receiver Enable.
Definition realtek.h:111
#define RTL_MAR0
Multicast Register 0 (dword)
Definition realtek.h:73
#define RTL_RCR_RBLEN_DEFAULT
Definition realtek.h:150
#define RTL_RCR_STOP_WORKING
Here be dragons.
Definition realtek.h:144
#define RTL_CR_TE
Transmit Enable.
Definition realtek.h:112
#define RTL_RCR_AB
Accept broadcast packets.
Definition realtek.h:156
#define RTL_TCR
Transmit (Tx) Configuration Register (dword)
Definition realtek.h:137
#define RTL_MAR4
Multicast Register 4 (dword)
Definition realtek.h:76
struct realtek_ring tx
Transmit descriptor ring.
Definition realtek.h:314

References netdev, 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()

void realtek_close ( struct net_device * netdev)
static

Close network device.

Parameters
netdevNetwork device

Definition at line 744 of file realtek.c.

744 {
745 struct realtek_nic *rtl = netdev->priv;
746 unsigned int i;
747
748 /* Disable receiver and transmitter */
749 writeb ( 0, rtl->regs + RTL_CR );
750
751 /* Destroy receive buffer */
753
754 /* Destroy receive descriptor ring */
755 realtek_destroy_ring ( rtl, &rtl->rx );
756
757 /* Discard any unused receive buffers */
758 for ( i = 0 ; i < RTL_NUM_RX_DESC ; i++ ) {
759 if ( rtl->rx_iobuf[i] )
760 free_rx_iob ( rtl->rx_iobuf[i] );
761 rtl->rx_iobuf[i] = NULL;
762 }
763
764 /* Destroy transmit descriptor ring */
765 realtek_destroy_ring ( rtl, &rtl->tx );
766
767 /* Reset legacy transmit descriptor index, if applicable */
768 if ( rtl->legacy )
769 realtek_reset ( rtl );
770}
void free_rx_iob(struct io_buffer *iobuf)
Unmap and free I/O buffer for receive DMA.
Definition iobuf.c:215
static int realtek_reset(struct realtek_nic *rtl)
Reset hardware.
Definition realtek.c:343

References free_rx_iob(), realtek_nic::legacy, netdev, NULL, 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.

◆ realtek_transmit()

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 779 of file realtek.c.

780 {
781 struct realtek_nic *rtl = netdev->priv;
782 struct realtek_descriptor *tx;
783 unsigned int tx_idx;
784 int is_last;
785 int rc;
786
787 /* Get next transmit descriptor */
788 if ( ( rtl->tx.prod - rtl->tx.cons ) >= RTL_NUM_TX_DESC ) {
789 netdev_tx_defer ( netdev, iobuf );
790 return 0;
791 }
792 tx_idx = ( rtl->tx.prod % RTL_NUM_TX_DESC );
793
794 /* Pad and align packet, if needed */
795 if ( rtl->legacy )
796 iob_pad ( iobuf, ETH_ZLEN );
797
798 /* Map I/O buffer */
799 if ( ( rc = iob_map_tx ( iobuf, rtl->dma ) ) != 0 )
800 return rc;
801
802 /* Update producer index */
803 rtl->tx.prod++;
804
805 /* Transmit packet */
806 if ( rtl->legacy ) {
807
808 /* Add to transmit ring */
809 writel ( iob_dma ( iobuf ), rtl->regs + RTL_TSAD ( tx_idx ) );
810 writel ( ( RTL_TSD_ERTXTH_DEFAULT | iob_len ( iobuf ) ),
811 rtl->regs + RTL_TSD ( tx_idx ) );
812
813 } else {
814
815 /* Populate transmit descriptor */
816 is_last = ( tx_idx == ( RTL_NUM_TX_DESC - 1 ) );
817 tx = &rtl->tx.desc[tx_idx];
818 tx->address = cpu_to_le64 ( iob_dma ( iobuf ) );
819 tx->length = cpu_to_le16 ( iob_len ( iobuf ) );
820 wmb();
821 tx->flags = ( cpu_to_le16 ( RTL_DESC_OWN | RTL_DESC_FS |
822 RTL_DESC_LS ) |
823 ( is_last ? cpu_to_le16 ( RTL_DESC_EOR ) : 0 ) );
824 wmb();
825
826 /* Notify card that there are packets ready to transmit */
827 writeb ( RTL_TPPOLL_NPQ, rtl->regs + rtl->tppoll );
828 }
829
830 DBGC2 ( rtl, "REALTEK %p TX %d is [%lx,%lx)\n",
831 rtl, tx_idx, virt_to_phys ( iobuf->data ),
832 virt_to_phys ( iobuf->data ) + iob_len ( iobuf ) );
833
834 return 0;
835}
#define ETH_ZLEN
Definition if_ether.h:11
void iob_pad(struct io_buffer *iobuf, size_t min_len)
Pad I/O buffer.
Definition iobpad.c:50
static __always_inline int iob_map_tx(struct io_buffer *iobuf, struct dma_device *dma)
Map I/O buffer for transmit DMA.
Definition iobuf.h:244
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition iobuf.h:160
void netdev_tx_defer(struct net_device *netdev, struct io_buffer *iobuf)
Defer transmitted packet.
Definition netdevice.c:413
#define RTL_NUM_TX_DESC
Number of transmit descriptors.
Definition realtek.h:94
#define RTL_TSAD(n)
Transmit Start Address of Descriptor N (dword, 8139 only)
Definition realtek.h:85
@ RTL_DESC_LS
Last segment descriptor.
Definition realtek.h:45
@ RTL_DESC_FS
First segment descriptor.
Definition realtek.h:43
#define RTL_TSD(n)
Transmit Status of Descriptor N (dword, 8139 only)
Definition realtek.h:79
#define RTL_TPPOLL_NPQ
Normal Priority Queue Polling.
Definition realtek.h:123
#define RTL_TSD_ERTXTH_DEFAULT
Definition realtek.h:81
unsigned int tppoll
TPPoll register offset.
Definition realtek.h:311
u8 tx[WPA_TKIP_MIC_KEY_LEN]
MIC key for packets to the AP.
Definition wpa.h:4

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(), 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, realtek_nic::tx, tx, wmb, writeb, and writel.

◆ realtek_poll_tx()

void realtek_poll_tx ( struct net_device * netdev)
static

Poll for completed packets.

Parameters
netdevNetwork device

Definition at line 842 of file realtek.c.

842 {
843 struct realtek_nic *rtl = netdev->priv;
844 struct realtek_descriptor *tx;
845 unsigned int tx_idx;
846
847 /* Check for completed packets */
848 while ( rtl->tx.cons != rtl->tx.prod ) {
849
850 /* Get next transmit descriptor */
851 tx_idx = ( rtl->tx.cons % RTL_NUM_TX_DESC );
852
853 /* Stop if descriptor is still in use */
854 if ( rtl->legacy ) {
855
856 /* Check ownership bit in transmit status register */
857 if ( ! ( readl ( rtl->regs + RTL_TSD ( tx_idx ) ) &
858 RTL_TSD_OWN ) )
859 return;
860
861 } else {
862
863 /* Check ownership bit in descriptor */
864 tx = &rtl->tx.desc[tx_idx];
865 if ( tx->flags & cpu_to_le16 ( RTL_DESC_OWN ) )
866 return;
867 }
868
869 DBGC2 ( rtl, "REALTEK %p TX %d complete\n", rtl, tx_idx );
870
871 /* Complete TX descriptor */
872 rtl->tx.cons++;
874 }
875}
static void netdev_tx_complete_next(struct net_device *netdev)
Complete network transmission.
Definition netdevice.h:779
#define RTL_TSD_OWN
Ownership.
Definition realtek.h:82

References realtek_ring::cons, cpu_to_le16, DBGC2, realtek_ring::desc, realtek_nic::legacy, netdev, netdev_tx_complete_next(), realtek_ring::prod, readl, realtek_nic::regs, RTL_DESC_OWN, RTL_NUM_TX_DESC, RTL_TSD, RTL_TSD_OWN, realtek_nic::tx, and tx.

Referenced by realtek_poll().

◆ realtek_legacy_poll_rx()

void realtek_legacy_poll_rx ( struct net_device * netdev)
static

Poll for received packets (legacy mode)

Parameters
netdevNetwork device

Definition at line 882 of file realtek.c.

882 {
883 struct realtek_nic *rtl = netdev->priv;
885 struct io_buffer *iobuf;
886 size_t len;
887
888 /* Check for received packets */
889 while ( ! ( readb ( rtl->regs + RTL_CR ) & RTL_CR_BUFE ) ) {
890
891 /* Extract packet from receive buffer */
892 rx = ( rtl->rxbuf.data + rtl->rxbuf.offset );
893 len = le16_to_cpu ( rx->length );
894 if ( rx->status & cpu_to_le16 ( RTL_STAT_ROK ) ) {
895
896 DBGC2 ( rtl, "REALTEK %p RX offset %x+%zx\n",
897 rtl, rtl->rxbuf.offset, len );
898
899 /* Allocate I/O buffer */
900 iobuf = alloc_iob ( len );
901 if ( ! iobuf ) {
903 /* Leave packet for next poll */
904 break;
905 }
906
907 /* Copy data to I/O buffer */
908 memcpy ( iob_put ( iobuf, len ), rx->data, len );
909 iob_unput ( iobuf, 4 /* strip CRC */ );
910
911 /* Hand off to network stack */
912 netdev_rx ( netdev, iobuf );
913
914 } else {
915
916 DBGC ( rtl, "REALTEK %p RX offset %x+%zx error %04x\n",
917 rtl, rtl->rxbuf.offset, len,
918 le16_to_cpu ( rx->status ) );
920 }
921
922 /* Update buffer offset */
923 rtl->rxbuf.offset += ( sizeof ( *rx ) + len );
924 rtl->rxbuf.offset = ( ( rtl->rxbuf.offset + 3 ) & ~3 );
925 rtl->rxbuf.offset = ( rtl->rxbuf.offset % RTL_RXBUF_LEN );
926 writew ( ( rtl->rxbuf.offset - 16 ), rtl->regs + RTL_CAPR );
927
928 /* Give chip time to react before rechecking RTL_CR */
929 readw ( rtl->regs + RTL_CAPR );
930 }
931}
#define EIO
Input/output error.
Definition errno.h:434
void * memcpy(void *dest, const void *src, size_t len) __nonnull
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition iobuf.c:131
#define iob_put(iobuf, len)
Definition iobuf.h:125
#define iob_unput(iobuf, len)
Definition iobuf.h:140
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition netdevice.c:549
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition netdevice.c:587
#define RTL_CAPR
Current Address of Packet Read (word, 8139 only)
Definition realtek.h:119
@ RTL_STAT_ROK
Received OK.
Definition realtek.h:66
#define RTL_CR_BUFE
Receive buffer empty.
Definition realtek.h:113
A legacy mode receive packet header.
Definition realtek.h:54
#define writew
Definition w89c840.c:159
#define readw
Definition w89c840.c:156

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

◆ realtek_poll_rx()

void realtek_poll_rx ( struct net_device * netdev)
static

Poll for received packets.

Parameters
netdevNetwork device

Definition at line 938 of file realtek.c.

938 {
939 struct realtek_nic *rtl = netdev->priv;
940 struct realtek_descriptor *rx;
941 struct io_buffer *iobuf;
942 unsigned int rx_idx;
943 size_t len;
944
945 /* Poll receive buffer if in legacy mode */
946 if ( rtl->legacy ) {
948 return;
949 }
950
951 /* Check for received packets */
952 while ( rtl->rx.cons != rtl->rx.prod ) {
953
954 /* Get next receive descriptor */
955 rx_idx = ( rtl->rx.cons % RTL_NUM_RX_DESC );
956 rx = &rtl->rx.desc[rx_idx];
957
958 /* Stop if descriptor is still in use */
959 if ( rx->flags & cpu_to_le16 ( RTL_DESC_OWN ) )
960 return;
961
962 /* Populate I/O buffer */
963 iobuf = rtl->rx_iobuf[rx_idx];
964 rtl->rx_iobuf[rx_idx] = NULL;
965 len = ( le16_to_cpu ( rx->length ) & RTL_DESC_SIZE_MASK );
966 iob_put ( iobuf, ( len - 4 /* strip CRC */ ) );
967
968 /* Hand off to network stack */
969 if ( rx->flags & cpu_to_le16 ( RTL_DESC_RES ) ) {
970 DBGC ( rtl, "REALTEK %p RX %d error (length %zd, "
971 "flags %04x)\n", rtl, rx_idx, len,
972 le16_to_cpu ( rx->flags ) );
973 netdev_rx_err ( netdev, iobuf, -EIO );
974 } else {
975 DBGC2 ( rtl, "REALTEK %p RX %d complete (length "
976 "%zd)\n", rtl, rx_idx, len );
977 netdev_rx ( netdev, iobuf );
978 }
979 rtl->rx.cons++;
980 }
981}
static void realtek_legacy_poll_rx(struct net_device *netdev)
Poll for received packets (legacy mode)
Definition realtek.c:882
#define RTL_DESC_SIZE_MASK
Descriptor buffer size mask.
Definition realtek.h:34
@ RTL_DESC_RES
Receive error summary.
Definition realtek.h:47

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, realtek_ring::prod, realtek_legacy_poll_rx(), RTL_DESC_OWN, RTL_DESC_RES, RTL_DESC_SIZE_MASK, RTL_NUM_RX_DESC, realtek_nic::rx, rx, and realtek_nic::rx_iobuf.

Referenced by realtek_poll().

◆ realtek_poll()

void realtek_poll ( struct net_device * netdev)
static

Poll for completed and received packets.

Parameters
netdevNetwork device

Definition at line 988 of file realtek.c.

988 {
989 struct realtek_nic *rtl = netdev->priv;
991
992 /* Check for and acknowledge interrupts */
993 isr = readw ( rtl->regs + RTL_ISR );
994 if ( ! isr )
995 return;
996 writew ( isr, rtl->regs + RTL_ISR );
997
998 /* Poll for TX completions, if applicable */
999 if ( isr & ( RTL_IRQ_TER | RTL_IRQ_TOK ) )
1001
1002 /* Poll for RX completionsm, if applicable */
1003 if ( isr & ( RTL_IRQ_RER | RTL_IRQ_ROK ) )
1005
1006 /* Check link state, if applicable */
1007 if ( isr & RTL_IRQ_PUN_LINKCHG )
1009
1010 /* Refill RX ring */
1011 realtek_refill_rx ( rtl );
1012}
static void realtek_poll_tx(struct net_device *netdev)
Poll for completed packets.
Definition realtek.c:842
static void realtek_poll_rx(struct net_device *netdev)
Poll for received packets.
Definition realtek.c:938
#define RTL_IRQ_ROK
Receive OK.
Definition realtek.h:131
#define RTL_IRQ_PUN_LINKCHG
Packet underrun / link change.
Definition realtek.h:127
#define RTL_IRQ_TER
Transmit error.
Definition realtek.h:128
#define RTL_IRQ_RER
Receive error.
Definition realtek.h:130
#define RTL_IRQ_TOK
Transmit OK.
Definition realtek.h:129
#define RTL_ISR
Interrupt Status Register (word)
Definition realtek.h:134
@ isr
Definition sis900.h:26

References isr, netdev, 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()

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

Enable or disable interrupts.

Parameters
netdevNetwork device
enableInterrupts should be enabled

Definition at line 1020 of file realtek.c.

1020 {
1021 struct realtek_nic *rtl = netdev->priv;
1022 uint16_t imr;
1023
1024 /* Set interrupt mask */
1025 imr = ( enable ? ( RTL_IRQ_PUN_LINKCHG | RTL_IRQ_TER | RTL_IRQ_TOK |
1026 RTL_IRQ_RER | RTL_IRQ_ROK ) : 0 );
1027 writew ( imr, rtl->regs + RTL_IMR );
1028}
#define RTL_IMR
Interrupt Mask Register (word)
Definition realtek.h:126
@ imr
Definition sis900.h:27

References imr, netdev, 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()

void realtek_detect ( struct realtek_nic * rtl)
static

Detect device type.

Parameters
rtlRealtek device

Definition at line 1051 of file realtek.c.

1051 {
1052 uint16_t rms;
1053 uint16_t check_rms;
1054 uint16_t cpcr;
1055 uint16_t check_cpcr;
1056
1057 /* The RX Packet Maximum Size register is present only on
1058 * 8169. Try to set to our intended MTU.
1059 */
1060 rms = RTL_RX_MAX_LEN;
1061 writew ( rms, rtl->regs + RTL_RMS );
1062 check_rms = readw ( rtl->regs + RTL_RMS );
1063
1064 /* The C+ Command register is present only on 8169 and 8139C+.
1065 * Try to enable C+ mode and PCI Dual Address Cycle (for
1066 * 64-bit systems), if supported.
1067 *
1068 * Note that enabling DAC seems to cause bizarre behaviour
1069 * (lockups, garbage data on the wire) on some systems, even
1070 * if only 32-bit addresses are used.
1071 *
1072 * Disable VLAN offload, since some cards seem to have it
1073 * enabled by default.
1074 */
1075 cpcr = readw ( rtl->regs + RTL_CPCR );
1077 if ( sizeof ( physaddr_t ) > sizeof ( uint32_t ) )
1078 cpcr |= RTL_CPCR_DAC;
1079 cpcr &= ~RTL_CPCR_VLAN;
1080 writew ( cpcr, rtl->regs + RTL_CPCR );
1081 check_cpcr = readw ( rtl->regs + RTL_CPCR );
1082
1083 /* Detect device type */
1084 if ( check_rms == rms ) {
1085 DBGC ( rtl, "REALTEK %p appears to be an RTL8169\n", rtl );
1086 rtl->have_phy_regs = 1;
1087 rtl->tppoll = RTL_TPPOLL_8169;
1088 dma_set_mask_64bit ( rtl->dma );
1089 } else {
1090 if ( ( check_cpcr == cpcr ) && ( cpcr != 0xffff ) ) {
1091 DBGC ( rtl, "REALTEK %p appears to be an RTL8139C+\n",
1092 rtl );
1094 dma_set_mask_64bit ( rtl->dma );
1095 } else {
1096 DBGC ( rtl, "REALTEK %p appears to be an RTL8139\n",
1097 rtl );
1098 rtl->legacy = 1;
1099 }
1100 rtl->eeprom.bus = &rtl->spibit.bus;
1101 }
1102}
static __always_inline void dma_set_mask_64bit(struct dma_device *dma)
Set 64-bit addressable space mask.
Definition dma.h:467
#define RTL_TPPOLL_8139CP
Transmit Priority Polling Register (byte, 8139C+ only)
Definition realtek.h:225
#define RTL_CPCR_CPRX
C+ receive enable.
Definition realtek.h:235
#define RTL_CPCR_CPTX
C+ transmit enable.
Definition realtek.h:236
#define RTL_CPCR_DAC
PCI Dual Address Cycle enable.
Definition realtek.h:233
#define RTL_CPCR
C+ Command Register (word)
Definition realtek.h:231
#define RTL_RMS
RX Packet Maximum Size Register (word)
Definition realtek.h:228
#define RTL_CPCR_VLAN
VLAN tag stripping enable.
Definition realtek.h:232
#define RTL_TPPOLL_8169
Transmit Priority Polling Register (byte, 8169 only)
Definition realtek.h:122
#define RTL_CPCR_MULRW
PCI Multiple Read/Write enable.
Definition realtek.h:234
struct spi_bus * bus
SPI bus to which device is attached.
Definition spi.h:91

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

◆ realtek_probe()

int realtek_probe ( struct pci_device * pci)
static

Probe PCI device.

Parameters
pciPCI device
Return values
rcReturn status code

Definition at line 1110 of file realtek.c.

1110 {
1111 struct net_device *netdev;
1112 struct realtek_nic *rtl;
1113 unsigned int i;
1114 int rc;
1115
1116 /* Allocate and initialise net device */
1117 netdev = alloc_etherdev ( sizeof ( *rtl ) );
1118 if ( ! netdev ) {
1119 rc = -ENOMEM;
1120 goto err_alloc;
1121 }
1123 rtl = netdev->priv;
1124 pci_set_drvdata ( pci, netdev );
1125 netdev->dev = &pci->dev;
1126 memset ( rtl, 0, sizeof ( *rtl ) );
1129
1130 /* Fix up PCI device */
1131 adjust_pci_device ( pci );
1132
1133 /* Map registers */
1134 rtl->regs = pci_ioremap ( pci, pci->membase, RTL_BAR_SIZE );
1135 if ( ! rtl->regs ) {
1136 rc = -ENODEV;
1137 goto err_ioremap;
1138 }
1139
1140 /* Configure DMA */
1141 rtl->dma = &pci->dma;
1142
1143 /* Reset the NIC */
1144 if ( ( rc = realtek_reset ( rtl ) ) != 0 )
1145 goto err_reset;
1146
1147 /* Detect device type */
1148 realtek_detect ( rtl );
1149
1150 /* Initialise EEPROM */
1151 if ( rtl->eeprom.bus &&
1152 ( ( rc = realtek_init_eeprom ( netdev ) ) == 0 ) ) {
1153
1154 /* Read MAC address from EEPROM */
1155 if ( ( rc = nvs_read ( &rtl->eeprom.nvs, RTL_EEPROM_MAC,
1156 netdev->hw_addr, ETH_ALEN ) ) != 0 ) {
1157 DBGC ( rtl, "REALTEK %p could not read MAC address: "
1158 "%s\n", rtl, strerror ( rc ) );
1159 goto err_nvs_read;
1160 }
1161
1162 } else {
1163
1164 /* EEPROM not present. Fall back to reading the
1165 * current ID register value, which will hopefully
1166 * have been programmed by the platform firmware.
1167 */
1168 for ( i = 0 ; i < ETH_ALEN ; i++ )
1169 netdev->hw_addr[i] = readb ( rtl->regs + RTL_IDR0 + i );
1170 }
1171
1172 /* Initialise and reset MII interface */
1174 mii_init ( &rtl->mii, &rtl->mdio, 0 );
1175 if ( ( rc = realtek_phy_reset ( rtl ) ) != 0 )
1176 goto err_phy_reset;
1177
1178 /* Register network device */
1179 if ( ( rc = register_netdev ( netdev ) ) != 0 )
1180 goto err_register_netdev;
1181
1182 /* Set initial link state */
1184
1185 /* Register non-volatile options, if applicable */
1186 if ( rtl->nvo.nvs ) {
1187 if ( ( rc = register_nvo ( &rtl->nvo,
1188 netdev_settings ( netdev ) ) ) != 0)
1189 goto err_register_nvo;
1190 }
1191
1192 return 0;
1193
1194 err_register_nvo:
1196 err_register_netdev:
1197 err_phy_reset:
1198 err_nvs_read:
1199 realtek_reset ( rtl );
1200 err_reset:
1201 iounmap ( rtl->regs );
1202 err_ioremap:
1204 netdev_put ( netdev );
1205 err_alloc:
1206 return rc;
1207}
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition ethernet.c:265
#define ETH_ALEN
Definition if_ether.h:9
void iounmap(volatile const void *io_addr)
Unmap I/O address.
void * pci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
static void mdio_init(struct mii_interface *mdio, struct mii_operations *op)
Initialise MII interface.
Definition mii.h:64
static void mii_init(struct mii_device *mii, struct mii_interface *mdio, unsigned int address)
Initialise MII device.
Definition mii.h:76
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition netdevice.c:942
int register_netdev(struct net_device *netdev)
Register network device.
Definition netdevice.c:760
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition netdevice.h:519
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition netdevice.h:532
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition netdevice.h:576
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition netdevice.h:587
int register_nvo(struct nvo_block *nvo, struct settings *parent)
Register non-volatile stored options.
Definition nvo.c:294
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition pci.c:241
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition pci.h:366
static struct net_device_operations realtek_operations
Realtek network device operations.
Definition realtek.c:1031
static int realtek_init_eeprom(struct net_device *netdev)
Initialise EEPROM.
Definition realtek.c:185
static int realtek_phy_reset(struct realtek_nic *rtl)
Reset PHY.
Definition realtek.c:401
static struct mii_operations realtek_mii_operations
Realtek MII operations.
Definition realtek.c:325
static void realtek_detect(struct realtek_nic *rtl)
Detect device type.
Definition realtek.c:1051
#define RTL_BAR_SIZE
PCI memory BAR size.
Definition realtek.h:19
static void realtek_init_ring(struct realtek_ring *ring, unsigned int count, unsigned int reg)
Initialise descriptor ring.
Definition realtek.h:273
#define RTL_RDSAR
Receive Descriptor Start Address Register (qword)
Definition realtek.h:239
#define RTL_IDR0
ID Register 0 (6 bytes)
Definition realtek.h:70
#define RTL_TNPDS
Transmit Normal Priority Descriptors (qword)
Definition realtek.h:88
#define RTL_EEPROM_MAC
Word offset of MAC address within EEPROM.
Definition realtek.h:178
A network device.
Definition netdevice.h:353
struct nvs_device * nvs
Underlying non-volatile storage device.
Definition nvo.h:27
unsigned long membase
Memory base.
Definition pci.h:220
struct device dev
Generic device.
Definition pci.h:213
struct dma_device dma
DMA device.
Definition pci.h:215

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

void realtek_remove ( struct pci_device * pci)
static

Remove PCI device.

Parameters
pciPCI device

Definition at line 1214 of file realtek.c.

1214 {
1215 struct net_device *netdev = pci_get_drvdata ( pci );
1216 struct realtek_nic *rtl = netdev->priv;
1217
1218 /* Unregister non-volatile options, if applicable */
1219 if ( rtl->nvo.nvs )
1220 unregister_nvo ( &rtl->nvo );
1221
1222 /* Unregister network device */
1224
1225 /* Reset card */
1226 realtek_reset ( rtl );
1227
1228 /* Free network device */
1229 iounmap ( rtl->regs );
1231 netdev_put ( netdev );
1232}
void unregister_nvo(struct nvo_block *nvo)
Unregister non-volatile stored options.
Definition nvo.c:325
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
Definition pci.h:376

References iounmap(), netdev, netdev_nullify(), netdev_put(), realtek_nic::nvo, nvo_block::nvs, pci_get_drvdata(), 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:169
#define RTL_9346CR_EEDI
Data in.
Definition realtek.h:168
#define RTL_9346CR_EECS
Chip select.
Definition realtek.h:166
#define RTL_9346CR_EESK
Clock.
Definition realtek.h:167
@ SPI_BIT_MOSI
Master Out Slave In.
Definition spi_bit.h:38
@ SPI_BIT_MISO
Master In Slave Out.
Definition spi_bit.h:40
@ SPI_BIT_SCLK
Serial clock.
Definition spi_bit.h:36
#define SPI_BIT_SS(slave)
Determine bit index for a particular slave.
Definition spi_bit.h:51

Pin mapping for SPI bit-bashing interface.

Definition at line 92 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_close_bit(struct bit_basher *basher)
Close bit-bashing interface.
Definition realtek.c:118
static int realtek_spi_read_bit(struct bit_basher *basher, unsigned int bit_id)
Read input bit.
Definition realtek.c:135
static void realtek_spi_write_bit(struct bit_basher *basher, unsigned int bit_id, unsigned long data)
Set/clear output bit.
Definition realtek.c:155
static void realtek_spi_open_bit(struct bit_basher *basher)
Open bit-bashing interface.
Definition realtek.c:104

SPI bit-bashing interface.

Definition at line 172 of file realtek.c.

172 {
173 .open = realtek_spi_open_bit,
174 .close = realtek_spi_close_bit,
175 .read = realtek_spi_read_bit,
176 .write = realtek_spi_write_bit,
177};

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:252
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:293

Realtek MII operations.

Definition at line 325 of file realtek.c.

325 {
326 .read = realtek_mii_read,
327 .write = realtek_mii_write,
328};

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_poll(struct net_device *netdev)
Poll for completed and received packets.
Definition realtek.c:988
static int realtek_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition realtek.c:779
static void realtek_irq(struct net_device *netdev, int enable)
Enable or disable interrupts.
Definition realtek.c:1020
static int realtek_open(struct net_device *netdev)
Open network device.
Definition realtek.c:680
static void realtek_close(struct net_device *netdev)
Close network device.
Definition realtek.c:744

Realtek network device operations.

Definition at line 1031 of file realtek.c.

1031 {
1032 .open = realtek_open,
1033 .close = realtek_close,
1034 .transmit = realtek_transmit,
1035 .poll = realtek_poll,
1036 .irq = realtek_irq,
1037};

Referenced by realtek_probe().

◆ realtek_nics

struct pci_device_id realtek_nics[]
static

Realtek PCI device IDs.

Definition at line 1235 of file realtek.c.

1235 {
1236 PCI_ROM ( 0x0001, 0x8168, "clone8169", "Cloned 8169", 0 ),
1237 PCI_ROM ( 0x018a, 0x0106, "fpc0106tx", "LevelOne FPC-0106TX", 0 ),
1238 PCI_ROM ( 0x021b, 0x8139, "hne300", "Compaq HNE-300", 0 ),
1239 PCI_ROM ( 0x02ac, 0x1012, "s1012", "SpeedStream 1012", 0 ),
1240 PCI_ROM ( 0x0357, 0x000a, "ttpmon", "TTTech TTP-Monitoring", 0 ),
1241 PCI_ROM ( 0x10ec, 0x8129, "rtl8129", "RTL-8129", 0 ),
1242 PCI_ROM ( 0x10ec, 0x8136, "rtl8136", "RTL8101E/RTL8102E", 0 ),
1243 PCI_ROM ( 0x10ec, 0x8138, "rtl8138", "RT8139 (B/C)", 0 ),
1244 PCI_ROM ( 0x10ec, 0x8139, "rtl8139", "RTL-8139/8139C/8139C+", 0 ),
1245 PCI_ROM ( 0x10ec, 0x8167, "rtl8167", "RTL-8110SC/8169SC", 0 ),
1246 PCI_ROM ( 0x10ec, 0x8168, "rtl8168", "RTL8111/8168B", 0 ),
1247 PCI_ROM ( 0x10ec, 0x8169, "rtl8169", "RTL-8169", 0 ),
1248 PCI_ROM ( 0x1113, 0x1211, "smc1211", "SMC2-1211TX", 0 ),
1249 PCI_ROM ( 0x1186, 0x1300, "dfe538", "DFE530TX+/DFE538TX", 0 ),
1250 PCI_ROM ( 0x1186, 0x1340, "dfe690", "DFE-690TXD", 0 ),
1251 PCI_ROM ( 0x1186, 0x4300, "dge528t", "DGE-528T", 0 ),
1252 PCI_ROM ( 0x11db, 0x1234, "sega8139", "Sega Enterprises 8139", 0 ),
1253 PCI_ROM ( 0x1259, 0xa117, "allied8139", "Allied Telesyn 8139", 0 ),
1254 PCI_ROM ( 0x1259, 0xa11e, "allied81xx", "Allied Telesyn 81xx", 0 ),
1255 PCI_ROM ( 0x1259, 0xc107, "allied8169", "Allied Telesyn 8169", 0 ),
1256 PCI_ROM ( 0x126c, 0x1211, "northen8139","Northern Telecom 8139", 0 ),
1257 PCI_ROM ( 0x13d1, 0xab06, "fe2000vx", "Abocom FE2000VX", 0 ),
1258 PCI_ROM ( 0x1432, 0x9130, "edi8139", "Edimax 8139", 0 ),
1259 PCI_ROM ( 0x14ea, 0xab06, "fnw3603tx", "Planex FNW-3603-TX", 0 ),
1260 PCI_ROM ( 0x14ea, 0xab07, "fnw3800tx", "Planex FNW-3800-TX", 0 ),
1261 PCI_ROM ( 0x1500, 0x1360, "delta8139", "Delta Electronics 8139", 0 ),
1262 PCI_ROM ( 0x16ec, 0x0116, "usr997902", "USR997902", 0 ),
1263 PCI_ROM ( 0x1737, 0x1032, "linksys8169","Linksys 8169", 0 ),
1264 PCI_ROM ( 0x1743, 0x8139, "rolf100", "Peppercorn ROL/F-100", 0 ),
1265 PCI_ROM ( 0x4033, 0x1360, "addron8139", "Addtron 8139", 0 ),
1266 PCI_ROM ( 0xffff, 0x8139, "clonse8139", "Cloned 8139", 0 ),
1267};
#define PCI_ROM(_vendor, _device, _name, _description, _data)
Definition pci.h:308

◆ __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:1235
static int realtek_probe(struct pci_device *pci)
Probe PCI device.
Definition realtek.c:1110
static void realtek_remove(struct pci_device *pci)
Remove PCI device.
Definition realtek.c:1214
static struct xen_remove_from_physmap * remove
Definition xenmem.h:40

Realtek PCI driver.

Definition at line 1270 of file realtek.c.

1270 {
1271 .ids = realtek_nics,
1272 .id_count = ( sizeof ( realtek_nics ) / sizeof ( realtek_nics[0] ) ),
1273 .probe = realtek_probe,
1275};