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

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

                                                                               {
        uint8_t regs[256];
        unsigned int i;

        /* Do nothing unless debug output is enabled */
        if ( ! DBG_LOG )
                return;

        /* Dump registers (via byte accesses; may not work for all registers) */
        for ( i = 0 ; i < sizeof ( regs ) ; i++ )
                regs[i] = readb ( rtl->regs + i );
        DBGC ( rtl, "REALTEK %p register dump:\n", rtl );
        DBGC_HDA ( rtl, 0, regs, sizeof ( regs ) );
}
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.

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

                                                               {
        struct realtek_nic *rtl = container_of ( basher, struct realtek_nic,
                                                 spibit.basher );

        /* Enable EEPROM access */
        writeb ( RTL_9346CR_EEM_EEPROM, rtl->regs + RTL_9346CR );
        readb ( rtl->regs + RTL_9346CR ); /* Ensure write reaches chip */
}
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.

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

                                                                {
        struct realtek_nic *rtl = container_of ( basher, struct realtek_nic,
                                                 spibit.basher );

        /* Disable EEPROM access */
        writeb ( RTL_9346CR_EEM_NORMAL, rtl->regs + RTL_9346CR );
        readb ( rtl->regs + RTL_9346CR ); /* Ensure write reaches chip */
}
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.

References spi_bit_basher::basher, container_of, DBG_DISABLE, DBG_ENABLE, DBGLVL_IO, readb(), reg, realtek_nic::regs, RTL_9346CR, and realtek_nic::spibit.

                                                        {
        struct realtek_nic *rtl = container_of ( basher, struct realtek_nic,
                                                 spibit.basher );
        uint8_t mask = realtek_eeprom_bits[bit_id];
        uint8_t reg;

        DBG_DISABLE ( DBGLVL_IO );
        reg = readb ( rtl->regs + RTL_9346CR );
        DBG_ENABLE ( DBGLVL_IO );
        return ( reg & mask );
}
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.

References spi_bit_basher::basher, container_of, DBG_DISABLE, DBG_ENABLE, DBGLVL_IO, readb(), reg, realtek_nic::regs, RTL_9346CR, realtek_nic::spibit, and writeb().

                                                                              {
        struct realtek_nic *rtl = container_of ( basher, struct realtek_nic,
                                                 spibit.basher );
        uint8_t mask = realtek_eeprom_bits[bit_id];
        uint8_t reg;

        DBG_DISABLE ( DBGLVL_IO );
        reg = readb ( rtl->regs + RTL_9346CR );
        reg &= ~mask;
        reg |= ( data & mask );
        writeb ( reg, rtl->regs + RTL_9346CR );
        readb ( rtl->regs + RTL_9346CR ); /* Ensure write reaches chip */
        DBG_ENABLE ( DBGLVL_IO );
}
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.

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

                                                             {
        struct realtek_nic *rtl = netdev->priv;
        uint16_t id;
        int rc;

        /* Initialise SPI bit-bashing interface */
        rtl->spibit.basher.op = &realtek_basher_ops;
        rtl->spibit.bus.mode = SPI_MODE_THREEWIRE;
        init_spi_bit_basher ( &rtl->spibit );

        /* Detect EEPROM type and initialise three-wire device */
        if ( readl ( rtl->regs + RTL_RCR ) & RTL_RCR_9356SEL ) {
                DBGC ( rtl, "REALTEK %p EEPROM is a 93C56\n", rtl );
                init_at93c56 ( &rtl->eeprom, 16 );
        } else {
                DBGC ( rtl, "REALTEK %p EEPROM is a 93C46\n", rtl );
                init_at93c46 ( &rtl->eeprom, 16 );
        }

        /* Check for EEPROM presence.  Some onboard NICs will have no
         * EEPROM connected, with the BIOS being responsible for
         * programming the initial register values.
         */
        if ( ( rc = nvs_read ( &rtl->eeprom.nvs, RTL_EEPROM_ID,
                               &id, sizeof ( id ) ) ) != 0 ) {
                DBGC ( rtl, "REALTEK %p could not read EEPROM ID: %s\n",
                       rtl, strerror ( rc ) );
                return rc;
        }
        if ( id != cpu_to_le16 ( RTL_EEPROM_ID_MAGIC ) ) {
                DBGC ( rtl, "REALTEK %p EEPROM ID incorrect (%#04x); assuming "
                       "no EEPROM\n", rtl, le16_to_cpu ( id ) );
                return -ENODEV;
        }

        /* Initialise space for non-volatile options, if available
         *
         * We use offset 0x40 (i.e. address 0x20), length 0x40.  This
         * block is marked as VPD in the Realtek datasheets, so we use
         * it only if we detect that the card is not supporting VPD.
         */
        if ( readb ( rtl->regs + RTL_CONFIG1 ) & RTL_CONFIG1_VPD ) {
                DBGC ( rtl, "REALTEK %p EEPROM in use for VPD; cannot use "
                       "for options\n", rtl );
        } else {
                nvo_init ( &rtl->nvo, &rtl->eeprom.nvs, RTL_EEPROM_VPD,
                           RTL_EEPROM_VPD_LEN, NULL, &netdev->refcnt );
        }

        return 0;
}
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.

References container_of, DBGC, ENOTSUP, ETIMEDOUT, realtek_nic::have_phy_regs, readl(), realtek_nic::regs, RTL_MII_MAX_WAIT_US, RTL_PHYAR, RTL_PHYAR_DATA, RTL_PHYAR_FLAG, RTL_PHYAR_VALUE, udelay(), value, and writel().

                                                                            {
        struct realtek_nic *rtl =
                container_of ( mdio, struct realtek_nic, mdio );
        unsigned int i;
        uint32_t value;

        /* Fail if PHYAR register is not present */
        if ( ! rtl->have_phy_regs )
                return -ENOTSUP;

        /* Initiate read */
        writel ( RTL_PHYAR_VALUE ( 0, reg, 0 ), rtl->regs + RTL_PHYAR );

        /* Wait for read to complete */
        for ( i = 0 ; i < RTL_MII_MAX_WAIT_US ; i++ ) {

                /* If read is not complete, delay 1us and retry */
                value = readl ( rtl->regs + RTL_PHYAR );
                if ( ! ( value & RTL_PHYAR_FLAG ) ) {
                        udelay ( 1 );
                        continue;
                }

                /* Return register value */
                return ( RTL_PHYAR_DATA ( value ) );
        }

        DBGC ( rtl, "REALTEK %p timed out waiting for MII read\n", rtl );
        return -ETIMEDOUT;
}
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.

References container_of, DBGC, ENOTSUP, ETIMEDOUT, realtek_nic::have_phy_regs, readl(), realtek_nic::regs, RTL_MII_MAX_WAIT_US, RTL_PHYAR, RTL_PHYAR_FLAG, RTL_PHYAR_VALUE, udelay(), and writel().

                                                   {
        struct realtek_nic *rtl =
                container_of ( mdio, struct realtek_nic, mdio );
        unsigned int i;

        /* Fail if PHYAR register is not present */
        if ( ! rtl->have_phy_regs )
                return -ENOTSUP;

        /* Initiate write */
        writel ( RTL_PHYAR_VALUE ( RTL_PHYAR_FLAG, reg, data ),
                 rtl->regs + RTL_PHYAR );

        /* Wait for write to complete */
        for ( i = 0 ; i < RTL_MII_MAX_WAIT_US ; i++ ) {

                /* If write is not complete, delay 1us and retry */
                if ( readl ( rtl->regs + RTL_PHYAR ) & RTL_PHYAR_FLAG ) {
                        udelay ( 1 );
                        continue;
                }

                return 0;
        }

        DBGC ( rtl, "REALTEK %p timed out waiting for MII write\n", rtl );
        return -ETIMEDOUT;
}
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.

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

                                                     {
        unsigned int i;

        /* Issue reset */
        writeb ( RTL_CR_RST, rtl->regs + RTL_CR );

        /* Wait for reset to complete */
        for ( i = 0 ; i < RTL_RESET_MAX_WAIT_MS ; i++ ) {

                /* If reset is not complete, delay 1ms and retry */
                if ( readb ( rtl->regs + RTL_CR ) & RTL_CR_RST ) {
                        mdelay ( 1 );
                        continue;
                }

                return 0;
        }

        DBGC ( rtl, "REALTEK %p timed out waiting for reset\n", rtl );
        return -ETIMEDOUT;
}
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.

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

Referenced by realtek_phy_reset().

                                                         {
        int ctrl1000;
        int rc;

        /* Read CTRL1000 register */
        ctrl1000 = mii_read ( &rtl->mii, MII_CTRL1000 );
        if ( ctrl1000 < 0 ) {
                rc = ctrl1000;
                DBGC ( rtl, "REALTEK %p could not read CTRL1000: %s\n",
                       rtl, strerror ( rc ) );
                return rc;
        }

        /* Advertise 1000Mbps speeds */
        ctrl1000 |= ( ADVERTISE_1000FULL | ADVERTISE_1000HALF );
        if ( ( rc = mii_write ( &rtl->mii, MII_CTRL1000, ctrl1000 ) ) != 0 ) {
                DBGC ( rtl, "REALTEK %p could not write CTRL1000: %s\n",
                       rtl, strerror ( rc ) );
                return rc;
        }

        return 0;
}
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.

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

Referenced by realtek_probe().

                                                         {
        int rc;

        /* Do nothing if we have no separate PHY register access */
        if ( ! rtl->have_phy_regs )
                return 0;

        /* Perform MII reset */
        if ( ( rc = mii_reset ( &rtl->mii ) ) != 0 ) {
                DBGC ( rtl, "REALTEK %p could not reset MII: %s\n",
                       rtl, strerror ( rc ) );
                return rc;
        }

        /* Some cards (e.g. RTL8169SC) do not advertise Gigabit by
         * default.  Try to enable advertisement of Gigabit speeds.
         */
        if ( ( rc = realtek_phy_speed ( rtl ) ) != 0 ) {
                /* Ignore failures, since the register may not be
                 * present on non-Gigabit PHYs (e.g. RTL8101).
                 */
        }

        /* Restart autonegotiation */
        if ( ( rc = mii_restart ( &rtl->mii ) ) != 0 ) {
                DBGC ( rtl, "REALTEK %p could not restart MII: %s\n",
                       rtl, strerror ( rc ) );
                return rc;
        }

        return 0;
}
static void realtek_check_link ( struct net_device netdev) [static]

Check link state.

Parameters:
netdevNetwork device

Definition at line 444 of file realtek.c.

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

                                                             {
        struct realtek_nic *rtl = netdev->priv;
        uint8_t phystatus;
        uint8_t msr;
        int link_up;

        /* Determine link state */
        if ( rtl->have_phy_regs ) {
                mii_dump ( &rtl->mii );
                phystatus = readb ( rtl->regs + RTL_PHYSTATUS );
                link_up = ( phystatus & RTL_PHYSTATUS_LINKSTS );
                DBGC ( rtl, "REALTEK %p PHY status is %02x (%s%s%s%s%s%s, "
                       "Link%s, %sDuplex)\n", rtl, phystatus,
                       ( ( phystatus & RTL_PHYSTATUS_ENTBI ) ? "TBI" : "GMII" ),
                       ( ( phystatus & RTL_PHYSTATUS_TXFLOW ) ?
                         ", TxFlow" : "" ),
                       ( ( phystatus & RTL_PHYSTATUS_RXFLOW ) ?
                         ", RxFlow" : "" ),
                       ( ( phystatus & RTL_PHYSTATUS_1000MF ) ?
                         ", 1000Mbps" : "" ),
                       ( ( phystatus & RTL_PHYSTATUS_100M ) ?
                         ", 100Mbps" : "" ),
                       ( ( phystatus & RTL_PHYSTATUS_10M ) ?
                         ", 10Mbps" : "" ),
                       ( ( phystatus & RTL_PHYSTATUS_LINKSTS ) ?
                         "Up" : "Down" ),
                       ( ( phystatus & RTL_PHYSTATUS_FULLDUP ) ?
                         "Full" : "Half" ) );
        } else {
                msr = readb ( rtl->regs + RTL_MSR );
                link_up = ( ! ( msr & RTL_MSR_LINKB ) );
                DBGC ( rtl, "REALTEK %p media status is %02x (Link%s, "
                       "%dMbps%s%s%s%s%s)\n", rtl, msr,
                       ( ( msr & RTL_MSR_LINKB ) ? "Down" : "Up" ),
                       ( ( msr & RTL_MSR_SPEED_10 ) ? 10 : 100 ),
                       ( ( msr & RTL_MSR_TXFCE ) ? ", TxFlow" : "" ),
                       ( ( msr & RTL_MSR_RXFCE ) ? ", RxFlow" : "" ),
                       ( ( msr & RTL_MSR_AUX_STATUS ) ? ", AuxPwr" : "" ),
                       ( ( msr & RTL_MSR_TXPF ) ? ", TxPause" : "" ),
                       ( ( msr & RTL_MSR_RXPF ) ? ", RxPause" : "" ) );
        }

        /* Report link state */
        if ( link_up ) {
                netdev_link_up ( netdev );
        } else {
                netdev_link_down ( netdev );
        }
}
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.

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

                                                             {
        size_t len = ( RTL_RXBUF_LEN + RTL_RXBUF_PAD );
        physaddr_t address;
        int rc;

        /* Do nothing unless in legacy mode */
        if ( ! rtl->legacy )
                return 0;

        /* Allocate buffer */
        rtl->rx_buffer = malloc_dma ( len, RTL_RXBUF_ALIGN );
        if ( ! rtl->rx_buffer ) {
                rc = -ENOMEM;
                goto err_alloc;
        }
        address = virt_to_bus ( rtl->rx_buffer );

        /* Check that card can support address */
        if ( address & ~0xffffffffULL ) {
                DBGC ( rtl, "REALTEK %p cannot support 64-bit RX buffer "
                       "address\n", rtl );
                rc = -ENOTSUP;
                goto err_64bit;
        }

        /* Program buffer address */
        writel ( address, rtl->regs + RTL_RBSTART );
        DBGC ( rtl, "REALTEK %p receive buffer is at [%08llx,%08llx,%08llx)\n",
               rtl, ( ( unsigned long long ) address ),
               ( ( unsigned long long ) address + RTL_RXBUF_LEN ),
               ( ( unsigned long long ) address + len ) );

        return 0;

 err_64bit:
        free_dma ( rtl->rx_buffer, len );
        rtl->rx_buffer = NULL;
 err_alloc:
        return rc;
}
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.

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

                                                               {
        size_t len = ( RTL_RXBUF_LEN + RTL_RXBUF_PAD );

        /* Do nothing unless in legacy mode */
        if ( ! rtl->legacy )
                return;

        /* Clear buffer address */
        writel ( 0, rtl->regs + RTL_RBSTART );

        /* Free buffer */
        free_dma ( rtl->rx_buffer, len );
        rtl->rx_buffer = NULL;
        rtl->rx_offset = 0;
}
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.

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

                                                             {
        physaddr_t address;

        /* Do nothing in legacy mode */
        if ( rtl->legacy )
                return 0;

        /* Allocate descriptor ring */
        ring->desc = malloc_dma ( ring->len, RTL_RING_ALIGN );
        if ( ! ring->desc )
                return -ENOMEM;

        /* Initialise descriptor ring */
        memset ( ring->desc, 0, ring->len );

        /* Program ring address */
        address = virt_to_bus ( ring->desc );
        writel ( ( ( ( uint64_t ) address ) >> 32 ),
                 rtl->regs + ring->reg + 4 );
        writel ( ( address & 0xffffffffUL ), rtl->regs + ring->reg );
        DBGC ( rtl, "REALTEK %p ring %02x is at [%08llx,%08llx)\n",
               rtl, ring->reg, ( ( unsigned long long ) address ),
               ( ( unsigned long long ) address + ring->len ) );

        return 0;
}
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.

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

                                                               {

        /* Reset producer and consumer counters */
        ring->prod = 0;
        ring->cons = 0;

        /* Do nothing more if in legacy mode */
        if ( rtl->legacy )
                return;

        /* Clear ring address */
        writel ( 0, rtl->regs + ring->reg );
        writel ( 0, rtl->regs + ring->reg + 4 );

        /* Free descriptor ring */
        free_dma ( ring->desc, ring->len );
        ring->desc = NULL;
}
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.

References realtek_descriptor::address, address, alloc_iob(), assert, realtek_ring::cons, cpu_to_le16, cpu_to_le64, io_buffer::data, DBGC2, realtek_ring::desc, realtek_descriptor::flags, realtek_nic::legacy, realtek_descriptor::length, 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().

                                                          {
        struct realtek_descriptor *rx;
        struct io_buffer *iobuf;
        unsigned int rx_idx;
        physaddr_t address;
        int is_last;

        /* Do nothing in legacy mode */
        if ( rtl->legacy )
                return;

        while ( ( rtl->rx.prod - rtl->rx.cons ) < RTL_NUM_RX_DESC ) {

                /* Allocate I/O buffer */
                iobuf = alloc_iob ( RTL_RX_MAX_LEN );
                if ( ! iobuf ) {
                        /* Wait for next refill */
                        return;
                }

                /* Get next receive descriptor */
                rx_idx = ( rtl->rx.prod++ % RTL_NUM_RX_DESC );
                is_last = ( rx_idx == ( RTL_NUM_RX_DESC - 1 ) );
                rx = &rtl->rx.desc[rx_idx];

                /* Populate receive descriptor */
                address = virt_to_bus ( iobuf->data );
                rx->address = cpu_to_le64 ( address );
                rx->length = cpu_to_le16 ( RTL_RX_MAX_LEN );
                wmb();
                rx->flags = ( cpu_to_le16 ( RTL_DESC_OWN ) |
                              ( is_last ? cpu_to_le16 ( RTL_DESC_EOR ) : 0 ) );
                wmb();

                /* Record I/O buffer */
                assert ( rtl->rx_iobuf[rx_idx] == NULL );
                rtl->rx_iobuf[rx_idx] = iobuf;

                DBGC2 ( rtl, "REALTEK %p RX %d is [%llx,%llx)\n", rtl, rx_idx,
                        ( ( unsigned long long ) address ),
                        ( ( unsigned long long ) address + RTL_RX_MAX_LEN ) );
        }
}
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.

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

                                                      {
        struct realtek_nic *rtl = netdev->priv;
        uint32_t tcr;
        uint32_t rcr;
        int rc;

        /* Create transmit descriptor ring */
        if ( ( rc = realtek_create_ring ( rtl, &rtl->tx ) ) != 0 )
                goto err_create_tx;

        /* Create receive descriptor ring */
        if ( ( rc = realtek_create_ring ( rtl, &rtl->rx ) ) != 0 )
                goto err_create_rx;

        /* Create receive buffer */
        if ( ( rc = realtek_create_buffer ( rtl ) ) != 0 )
                goto err_create_buffer;

        /* Accept all packets */
        writel ( 0xffffffffUL, rtl->regs + RTL_MAR0 );
        writel ( 0xffffffffUL, rtl->regs + RTL_MAR4 );

        /* Enable transmitter and receiver.  RTL8139 requires that
         * this happens before writing to RCR.
         */
        writeb ( ( RTL_CR_TE | RTL_CR_RE ), rtl->regs + RTL_CR );

        /* Configure transmitter */
        tcr = readl ( rtl->regs + RTL_TCR );
        tcr &= ~RTL_TCR_MXDMA_MASK;
        tcr |= RTL_TCR_MXDMA_DEFAULT;
        writel ( tcr, rtl->regs + RTL_TCR );

        /* Configure receiver */
        rcr = readl ( rtl->regs + RTL_RCR );
        rcr &= ~( RTL_RCR_STOP_WORKING | RTL_RCR_RXFTH_MASK |
                  RTL_RCR_RBLEN_MASK | RTL_RCR_MXDMA_MASK );
        rcr |= ( RTL_RCR_RXFTH_DEFAULT | RTL_RCR_RBLEN_DEFAULT |
                 RTL_RCR_MXDMA_DEFAULT | RTL_RCR_WRAP | RTL_RCR_AB |
                 RTL_RCR_AM | RTL_RCR_APM | RTL_RCR_AAP );
        writel ( rcr, rtl->regs + RTL_RCR );

        /* Fill receive ring */
        realtek_refill_rx ( rtl );

        /* Update link state */
        realtek_check_link ( netdev );

        return 0;

        realtek_destroy_buffer ( rtl );
 err_create_buffer:
        realtek_destroy_ring ( rtl, &rtl->rx );
 err_create_rx:
        realtek_destroy_ring ( rtl, &rtl->tx );
 err_create_tx:
        return rc;
}
static void realtek_close ( struct net_device netdev) [static]

Close network device.

Parameters:
netdevNetwork device

Definition at line 749 of file realtek.c.

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

                                                        {
        struct realtek_nic *rtl = netdev->priv;
        unsigned int i;

        /* Disable receiver and transmitter */
        writeb ( 0, rtl->regs + RTL_CR );

        /* Destroy receive buffer */
        realtek_destroy_buffer ( rtl );

        /* Destroy receive descriptor ring */
        realtek_destroy_ring ( rtl, &rtl->rx );

        /* Discard any unused receive buffers */
        for ( i = 0 ; i < RTL_NUM_RX_DESC ; i++ ) {
                if ( rtl->rx_iobuf[i] )
                        free_iob ( rtl->rx_iobuf[i] );
                rtl->rx_iobuf[i] = NULL;
        }

        /* Destroy transmit descriptor ring */
        realtek_destroy_ring ( rtl, &rtl->tx );
}
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.

References realtek_descriptor::address, address, realtek_ring::cons, cpu_to_le16, cpu_to_le64, io_buffer::data, DBGC, DBGC2, realtek_ring::desc, ENOTSUP, ETH_ZLEN, realtek_descriptor::flags, iob_len(), iob_pad(), realtek_nic::legacy, realtek_descriptor::length, 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().

                                                        {
        struct realtek_nic *rtl = netdev->priv;
        struct realtek_descriptor *tx;
        unsigned int tx_idx;
        physaddr_t address;
        int is_last;

        /* Get next transmit descriptor */
        if ( ( rtl->tx.prod - rtl->tx.cons ) >= RTL_NUM_TX_DESC ) {
                netdev_tx_defer ( netdev, iobuf );
                return 0;
        }
        tx_idx = ( rtl->tx.prod++ % RTL_NUM_TX_DESC );

        /* Transmit packet */
        if ( rtl->legacy ) {

                /* Pad and align packet */
                iob_pad ( iobuf, ETH_ZLEN );
                address = virt_to_bus ( iobuf->data );

                /* Check that card can support address */
                if ( address & ~0xffffffffULL ) {
                        DBGC ( rtl, "REALTEK %p cannot support 64-bit TX "
                               "buffer address\n", rtl );
                        return -ENOTSUP;
                }

                /* Add to transmit ring */
                writel ( address, rtl->regs + RTL_TSAD ( tx_idx ) );
                writel ( ( RTL_TSD_ERTXTH_DEFAULT | iob_len ( iobuf ) ),
                         rtl->regs + RTL_TSD ( tx_idx ) );

        } else {

                /* Populate transmit descriptor */
                address = virt_to_bus ( iobuf->data );
                is_last = ( tx_idx == ( RTL_NUM_TX_DESC - 1 ) );
                tx = &rtl->tx.desc[tx_idx];
                tx->address = cpu_to_le64 ( address );
                tx->length = cpu_to_le16 ( iob_len ( iobuf ) );
                wmb();
                tx->flags = ( cpu_to_le16 ( RTL_DESC_OWN | RTL_DESC_FS |
                                            RTL_DESC_LS ) |
                              ( is_last ? cpu_to_le16 ( RTL_DESC_EOR ) : 0 ) );
                wmb();

                /* Notify card that there are packets ready to transmit */
                writeb ( RTL_TPPOLL_NPQ, rtl->regs + rtl->tppoll );
        }

        DBGC2 ( rtl, "REALTEK %p TX %d is [%llx,%llx)\n", rtl, tx_idx,
                ( ( unsigned long long ) virt_to_bus ( iobuf->data ) ),
                ( ( ( unsigned long long ) virt_to_bus ( iobuf->data ) ) +
                  iob_len ( iobuf ) ) );

        return 0;
}
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.

References realtek_ring::cons, cpu_to_le16, DBGC2, realtek_ring::desc, realtek_descriptor::flags, realtek_nic::legacy, 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().

                                                          {
        struct realtek_nic *rtl = netdev->priv;
        struct realtek_descriptor *tx;
        unsigned int tx_idx;

        /* Check for completed packets */
        while ( rtl->tx.cons != rtl->tx.prod ) {

                /* Get next transmit descriptor */
                tx_idx = ( rtl->tx.cons % RTL_NUM_TX_DESC );

                /* Stop if descriptor is still in use */
                if ( rtl->legacy ) {

                        /* Check ownership bit in transmit status register */
                        if ( ! ( readl ( rtl->regs + RTL_TSD ( tx_idx ) ) &
                                 RTL_TSD_OWN ) )
                                return;

                } else {

                        /* Check ownership bit in descriptor */
                        tx = &rtl->tx.desc[tx_idx];
                        if ( tx->flags & cpu_to_le16 ( RTL_DESC_OWN ) )
                                return;
                }

                DBGC2 ( rtl, "REALTEK %p TX %d complete\n", rtl, tx_idx );

                /* Complete TX descriptor */
                rtl->tx.cons++;
                netdev_tx_complete_next ( netdev );
        }
}
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.

References alloc_iob(), cpu_to_le16, realtek_legacy_header::data, DBGC, DBGC2, EIO, ENOMEM, iob_put, iob_unput, le16_to_cpu, len, realtek_legacy_header::length, memcpy(), 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, realtek_legacy_header::status, and writew().

Referenced by realtek_poll_rx().

                                                                 {
        struct realtek_nic *rtl = netdev->priv;
        struct realtek_legacy_header *rx;
        struct io_buffer *iobuf;
        size_t len;

        /* Check for received packets */
        while ( ! ( readb ( rtl->regs + RTL_CR ) & RTL_CR_BUFE ) ) {

                /* Extract packet from receive buffer */
                rx = ( rtl->rx_buffer + rtl->rx_offset );
                len = le16_to_cpu ( rx->length );
                if ( rx->status & cpu_to_le16 ( RTL_STAT_ROK ) ) {

                        DBGC2 ( rtl, "REALTEK %p RX offset %x+%zx\n",
                                rtl, rtl->rx_offset, len );

                        /* Allocate I/O buffer */
                        iobuf = alloc_iob ( len );
                        if ( ! iobuf ) {
                                netdev_rx_err ( netdev, NULL, -ENOMEM );
                                /* Leave packet for next poll */
                                break;
                        }

                        /* Copy data to I/O buffer */
                        memcpy ( iob_put ( iobuf, len ), rx->data, len );
                        iob_unput ( iobuf, 4 /* strip CRC */ );

                        /* Hand off to network stack */
                        netdev_rx ( netdev, iobuf );

                } else {

                        DBGC ( rtl, "REALTEK %p RX offset %x+%zx error %04x\n",
                               rtl, rtl->rx_offset, len,
                               le16_to_cpu ( rx->status ) );
                        netdev_rx_err ( netdev, NULL, -EIO );
                }

                /* Update buffer offset */
                rtl->rx_offset = ( rtl->rx_offset + sizeof ( *rx ) + len );
                rtl->rx_offset = ( ( rtl->rx_offset + 3 ) & ~3 );
                rtl->rx_offset = ( rtl->rx_offset % RTL_RXBUF_LEN );
                writew ( ( rtl->rx_offset - 16 ), rtl->regs + RTL_CAPR );

                /* Give chip time to react before rechecking RTL_CR */
                readw ( rtl->regs + RTL_CAPR );
        }
}
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.

References realtek_ring::cons, cpu_to_le16, DBGC, DBGC2, realtek_ring::desc, EIO, realtek_descriptor::flags, iob_put, le16_to_cpu, realtek_nic::legacy, len, realtek_descriptor::length, 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().

                                                          {
        struct realtek_nic *rtl = netdev->priv;
        struct realtek_descriptor *rx;
        struct io_buffer *iobuf;
        unsigned int rx_idx;
        size_t len;

        /* Poll receive buffer if in legacy mode */
        if ( rtl->legacy ) {
                realtek_legacy_poll_rx ( netdev );
                return;
        }

        /* Check for received packets */
        while ( rtl->rx.cons != rtl->rx.prod ) {

                /* Get next receive descriptor */
                rx_idx = ( rtl->rx.cons % RTL_NUM_RX_DESC );
                rx = &rtl->rx.desc[rx_idx];

                /* Stop if descriptor is still in use */
                if ( rx->flags & cpu_to_le16 ( RTL_DESC_OWN ) )
                        return;

                /* Populate I/O buffer */
                iobuf = rtl->rx_iobuf[rx_idx];
                rtl->rx_iobuf[rx_idx] = NULL;
                len = ( le16_to_cpu ( rx->length ) & RTL_DESC_SIZE_MASK );
                iob_put ( iobuf, ( len - 4 /* strip CRC */ ) );

                /* Hand off to network stack */
                if ( rx->flags & cpu_to_le16 ( RTL_DESC_RES ) ) {
                        DBGC ( rtl, "REALTEK %p RX %d error (length %zd, "
                               "flags %04x)\n", rtl, rx_idx, len,
                               le16_to_cpu ( rx->flags ) );
                        netdev_rx_err ( netdev, iobuf, -EIO );
                } else {
                        DBGC2 ( rtl, "REALTEK %p RX %d complete (length "
                                "%zd)\n", rtl, rx_idx, len );
                        netdev_rx ( netdev, iobuf );
                }
                rtl->rx.cons++;
        }
}
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.

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

                                                       {
        struct realtek_nic *rtl = netdev->priv;
        uint16_t isr;

        /* Check for and acknowledge interrupts */
        isr = readw ( rtl->regs + RTL_ISR );
        if ( ! isr )
                return;
        writew ( isr, rtl->regs + RTL_ISR );

        /* Poll for TX completions, if applicable */
        if ( isr & ( RTL_IRQ_TER | RTL_IRQ_TOK ) )
                realtek_poll_tx ( netdev );

        /* Poll for RX completionsm, if applicable */
        if ( isr & ( RTL_IRQ_RER | RTL_IRQ_ROK ) )
                realtek_poll_rx ( netdev );

        /* Check link state, if applicable */
        if ( isr & RTL_IRQ_PUN_LINKCHG )
                realtek_check_link ( netdev );

        /* Refill RX ring */
        realtek_refill_rx ( rtl );
}
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.

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

                                                                  {
        struct realtek_nic *rtl = netdev->priv;
        uint16_t imr;

        /* Set interrupt mask */
        imr = ( enable ? ( RTL_IRQ_PUN_LINKCHG | RTL_IRQ_TER | RTL_IRQ_TOK |
                           RTL_IRQ_RER | RTL_IRQ_ROK ) : 0 );
        writew ( imr, rtl->regs + RTL_IMR );
}
static void realtek_detect ( struct realtek_nic rtl) [static]

Detect device type.

Parameters:
rtlRealtek device

Definition at line 1054 of file realtek.c.

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

                                                       {
        uint16_t rms;
        uint16_t check_rms;
        uint16_t cpcr;
        uint16_t check_cpcr;

        /* The RX Packet Maximum Size register is present only on
         * 8169.  Try to set to our intended MTU.
         */
        rms = RTL_RX_MAX_LEN;
        writew ( rms, rtl->regs + RTL_RMS );
        check_rms = readw ( rtl->regs + RTL_RMS );

        /* The C+ Command register is present only on 8169 and 8139C+.
         * Try to enable C+ mode and PCI Dual Address Cycle (for
         * 64-bit systems), if supported.
         *
         * Note that enabling DAC seems to cause bizarre behaviour
         * (lockups, garbage data on the wire) on some systems, even
         * if only 32-bit addresses are used.
         */
        cpcr = readw ( rtl->regs + RTL_CPCR );
        cpcr |= ( RTL_CPCR_MULRW | RTL_CPCR_CPRX | RTL_CPCR_CPTX );
        if ( sizeof ( physaddr_t ) > sizeof ( uint32_t ) )
                cpcr |= RTL_CPCR_DAC;
        writew ( cpcr, rtl->regs + RTL_CPCR );
        check_cpcr = readw ( rtl->regs + RTL_CPCR );

        /* Detect device type */
        if ( check_rms == rms ) {
                DBGC ( rtl, "REALTEK %p appears to be an RTL8169\n", rtl );
                rtl->have_phy_regs = 1;
                rtl->tppoll = RTL_TPPOLL_8169;
        } else {
                if ( ( check_cpcr == cpcr ) && ( cpcr != 0xffff ) ) {
                        DBGC ( rtl, "REALTEK %p appears to be an RTL8139C+\n",
                               rtl );
                        rtl->tppoll = RTL_TPPOLL_8139CP;
                } else {
                        DBGC ( rtl, "REALTEK %p appears to be an RTL8139\n",
                               rtl );
                        rtl->legacy = 1;
                }
                rtl->eeprom.bus = &rtl->spibit.bus;
        }
}
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.

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

                                                    {
        struct net_device *netdev;
        struct realtek_nic *rtl;
        unsigned int i;
        int rc;

        /* Allocate and initialise net device */
        netdev = alloc_etherdev ( sizeof ( *rtl ) );
        if ( ! netdev ) {
                rc = -ENOMEM;
                goto err_alloc;
        }
        netdev_init ( netdev, &realtek_operations );
        rtl = netdev->priv;
        pci_set_drvdata ( pci, netdev );
        netdev->dev = &pci->dev;
        memset ( rtl, 0, sizeof ( *rtl ) );
        realtek_init_ring ( &rtl->tx, RTL_NUM_TX_DESC, RTL_TNPDS );
        realtek_init_ring ( &rtl->rx, RTL_NUM_RX_DESC, RTL_RDSAR );

        /* Fix up PCI device */
        adjust_pci_device ( pci );

        /* Map registers */
        rtl->regs = ioremap ( pci->membase, RTL_BAR_SIZE );
        if ( ! rtl->regs ) {
                rc = -ENODEV;
                goto err_ioremap;
        }

        /* Reset the NIC */
        if ( ( rc = realtek_reset ( rtl ) ) != 0 )
                goto err_reset;

        /* Detect device type */
        realtek_detect ( rtl );

        /* Initialise EEPROM */
        if ( rtl->eeprom.bus &&
             ( ( rc = realtek_init_eeprom ( netdev ) ) == 0 ) ) {

                /* Read MAC address from EEPROM */
                if ( ( rc = nvs_read ( &rtl->eeprom.nvs, RTL_EEPROM_MAC,
                                       netdev->hw_addr, ETH_ALEN ) ) != 0 ) {
                        DBGC ( rtl, "REALTEK %p could not read MAC address: "
                               "%s\n", rtl, strerror ( rc ) );
                        goto err_nvs_read;
                }

        } else {

                /* EEPROM not present.  Fall back to reading the
                 * current ID register value, which will hopefully
                 * have been programmed by the platform firmware.
                 */
                for ( i = 0 ; i < ETH_ALEN ; i++ )
                        netdev->hw_addr[i] = readb ( rtl->regs + RTL_IDR0 + i );
        }

        /* Initialise and reset MII interface */
        mdio_init ( &rtl->mdio, &realtek_mii_operations );
        mii_init ( &rtl->mii, &rtl->mdio, 0 );
        if ( ( rc = realtek_phy_reset ( rtl ) ) != 0 )
                goto err_phy_reset;

        /* Register network device */
        if ( ( rc = register_netdev ( netdev ) ) != 0 )
                goto err_register_netdev;

        /* Set initial link state */
        realtek_check_link ( netdev );

        /* Register non-volatile options, if applicable */
        if ( rtl->nvo.nvs ) {
                if ( ( rc = register_nvo ( &rtl->nvo,
                                           netdev_settings ( netdev ) ) ) != 0)
                        goto err_register_nvo;
        }

        return 0;

 err_register_nvo:
        unregister_netdev ( netdev );
 err_register_netdev:
 err_phy_reset:
 err_nvs_read:
        realtek_reset ( rtl );
 err_reset:
        iounmap ( rtl->regs );
 err_ioremap:
        netdev_nullify ( netdev );
        netdev_put ( netdev );
 err_alloc:
        return rc;
}
static void realtek_remove ( struct pci_device pci) [static]

Remove PCI device.

Parameters:
pciPCI device

Definition at line 1208 of file realtek.c.

References iounmap(), netdev, netdev_nullify(), netdev_put(), realtek_nic::nvo, nvo_block::nvs, pci_get_drvdata(), net_device::priv, realtek_reset(), realtek_nic::regs, unregister_netdev(), and unregister_nvo().

                                                      {
        struct net_device *netdev = pci_get_drvdata ( pci );
        struct realtek_nic *rtl = netdev->priv;

        /* Unregister non-volatile options, if applicable */
        if ( rtl->nvo.nvs )
                unregister_nvo ( &rtl->nvo );

        /* Unregister network device */
        unregister_netdev ( netdev );

        /* Reset card */
        realtek_reset ( rtl );

        /* Free network device */
        iounmap ( rtl->regs );
        netdev_nullify ( netdev );
        netdev_put ( netdev );
}

Variable Documentation

const uint8_t realtek_eeprom_bits[] [static]
Initial value:

Pin mapping for SPI bit-bashing interface.

Definition at line 90 of file realtek.c.

Initial value:

SPI bit-bashing interface.

Definition at line 170 of file realtek.c.

Referenced by realtek_init_eeprom().

Initial value:
 {
        .read = realtek_mii_read,
        .write = realtek_mii_write,
}

Realtek MII operations.

Definition at line 323 of file realtek.c.

Initial value:
 {
        .open           = realtek_open,
        .close          = realtek_close,
        .transmit       = realtek_transmit,
        .poll           = realtek_poll,
        .irq            = realtek_irq,
}

Realtek network device operations.

Definition at line 1034 of file realtek.c.

struct pci_device_id realtek_nics[] [static]

Realtek PCI device IDs.

Definition at line 1229 of file realtek.c.

struct pci_driver realtek_driver __pci_driver
Initial value:
 {
        .ids = realtek_nics,
        .id_count = ( sizeof ( realtek_nics ) / sizeof ( realtek_nics[0] ) ),
        .probe = realtek_probe,
        .remove = realtek_remove,
}

Realtek PCI driver.

Definition at line 1264 of file realtek.c.