linux/drivers/net/ethernet/realtek/8139too.c

/*

	8139too.c: A RealTek RTL-8139 Fast Ethernet driver for Linux.

	Maintained by Jeff Garzik <[email protected]>
	Copyright 2000-2002 Jeff Garzik

	Much code comes from Donald Becker's rtl8139.c driver,
	versions 1.13 and older.  This driver was originally based
	on rtl8139.c version 1.07.  Header of rtl8139.c version 1.13:

	-----<snip>-----

		Written 1997-2001 by Donald Becker.
		This software may be used and distributed according to the
		terms of the GNU General Public License (GPL), incorporated
		herein by reference.  Drivers based on or derived from this
		code fall under the GPL and must retain the authorship,
		copyright and license notice.  This file is not a complete
		program and may only be used when the entire operating
		system is licensed under the GPL.

		This driver is for boards based on the RTL8129 and RTL8139
		PCI ethernet chips.

		The author may be reached as [email protected], or C/O Scyld
		Computing Corporation 410 Severn Ave., Suite 210 Annapolis
		MD 21403

		Support and updates available at
		http://www.scyld.com/network/rtl8139.html

		Twister-tuning table provided by Kinston
		<[email protected]>.

	-----<snip>-----

	This software may be used and distributed according to the terms
	of the GNU General Public License, incorporated herein by reference.

	Contributors:

		Donald Becker - he wrote the original driver, kudos to him!
		(but please don't e-mail him for support, this isn't his driver)

		Tigran Aivazian - bug fixes, skbuff free cleanup

		Martin Mares - suggestions for PCI cleanup

		David S. Miller - PCI DMA and softnet updates

		Ernst Gill - fixes ported from BSD driver

		Daniel Kobras - identified specific locations of
			posted MMIO write bugginess

		Gerard Sharp - bug fix, testing and feedback

		David Ford - Rx ring wrap fix

		Dan DeMaggio - swapped RTL8139 cards with me, and allowed me
		to find and fix a crucial bug on older chipsets.

		Donald Becker/Chris Butterworth/Marcus Westergren -
		Noticed various Rx packet size-related buglets.

		Santiago Garcia Mantinan - testing and feedback

		Jens David - 2.2.x kernel backports

		Martin Dennett - incredibly helpful insight on undocumented
		features of the 8139 chips

		Jean-Jacques Michel - bug fix

		Tobias Ringström - Rx interrupt status checking suggestion

		Andrew Morton - Clear blocked signals, avoid
		buffer overrun setting current->comm.

		Kalle Olavi Niemitalo - Wake-on-LAN ioctls

		Robert Kuebel - Save kernel thread from dying on any signal.

	Submitting bug reports:

		"rtl8139-diag -mmmaaavvveefN" output
		enable RTL8139_DEBUG below, and look at 'dmesg' or kernel log

*/

#define pr_fmt(fmt)

#define DRV_NAME
#define DRV_VERSION


#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/compiler.h>
#include <linux/pci.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/rtnetlink.h>
#include <linux/delay.h>
#include <linux/ethtool.h>
#include <linux/mii.h>
#include <linux/completion.h>
#include <linux/crc32.h>
#include <linux/io.h>
#include <linux/uaccess.h>
#include <linux/gfp.h>
#include <linux/if_vlan.h>
#include <asm/irq.h>

#define RTL8139_DRIVER_NAME

/* Default Message level */
#define RTL8139_DEF_MSG_ENABLE


/* define to 1, 2 or 3 to enable copious debugging info */
#define RTL8139_DEBUG

/* define to 1 to disable lightweight runtime debugging checks */
#undef RTL8139_NDEBUG


#ifdef RTL8139_NDEBUG
#define assert
#else
#define assert(expr)
#endif


/* A few user-configurable values. */
/* media options */
#define MAX_UNITS
static int media[MAX_UNITS] =;
static int full_duplex[MAX_UNITS] =;

/* Whether to use MMIO or PIO. Default to MMIO. */
#ifdef CONFIG_8139TOO_PIO
static bool use_io =;
#else
static bool use_io = false;
#endif

/* Maximum number of multicast addresses to filter (vs. Rx-all-multicast).
   The RTL chips use a 64 element hash table based on the Ethernet CRC.  */
static int multicast_filter_limit =;

/* bitmapped message enable number */
static int debug =;

/*
 * Receive ring size
 * Warning: 64K ring has hardware issues and may lock up.
 */
#if defined(CONFIG_SH_DREAMCAST)
#define RX_BUF_IDX
#else
#define RX_BUF_IDX
#endif
#define RX_BUF_LEN
#define RX_BUF_PAD
#define RX_BUF_WRAP_PAD

#if RX_BUF_LEN == 65536
#define RX_BUF_TOT_LEN
#else
#define RX_BUF_TOT_LEN
#endif

/* Number of Tx descriptor registers. */
#define NUM_TX_DESC

/* max supported ethernet frame size -- must be at least (dev->mtu+18+4).*/
#define MAX_ETH_FRAME_SIZE

/* max supported payload size */
#define MAX_ETH_DATA_SIZE

/* Size of the Tx bounce buffers -- must be at least (dev->mtu+18+4). */
#define TX_BUF_SIZE
#define TX_BUF_TOT_LEN

/* PCI Tuning Parameters
   Threshold is bytes transferred to chip before transmission starts. */
#define TX_FIFO_THRESH

/* The following settings are log_2(bytes)-4:  0 == 16 bytes .. 6==1024, 7==end of packet. */
#define RX_FIFO_THRESH
#define RX_DMA_BURST
#define TX_DMA_BURST
#define TX_RETRY

/* Operational parameters that usually are not changed. */
/* Time in jiffies before concluding the transmitter is hung. */
#define TX_TIMEOUT


enum {};

#define RTL_NUM_STATS
#define RTL_REGS_VER
#define RTL_MIN_IO_SIZE
#define RTL8139B_IO_SIZE

#define RTL8129_CAPS
#define RTL8139_CAPS

board_t;


/* indexed by board_t, above */
static const struct {} board_info[] =;


static const struct pci_device_id rtl8139_pci_tbl[] =;
MODULE_DEVICE_TABLE (pci, rtl8139_pci_tbl);

static struct {} ethtool_stats_keys[] =;

/* The rest of these values should never change. */

/* Symbolic offsets to registers. */
enum RTL8139_registers {};

enum ClearBitMasks {};

enum ChipCmdBits {};

/* Interrupt register bits, using my own meaningful names. */
enum IntrStatusBits {};

enum TxStatusBits {};
enum RxStatusBits {};

/* Bits in RxConfig. */
enum rx_mode_bits {};

/* Bits in TxConfig. */
enum tx_config_bits {};

/* Bits in Config1 */
enum Config1Bits {};

/* Bits in Config3 */
enum Config3Bits {};

/* Bits in Config4 */
enum Config4Bits {};

/* Bits in Config5 */
enum Config5Bits {};

enum RxConfigBits {};

/* Twister tuning parameters from RealTek.
   Completely undocumented, but required to tune bad links on some boards. */
enum CSCRBits {};

enum Cfg9346Bits {};

chip_t;

enum chip_flags {};

#define HW_REVID(b30, b29, b28, b27, b26, b23, b22)
#define HW_REVID_MASK

/* directly indexed by chip_t, above */
static const struct {} rtl_chip_info[] =;

struct rtl_extra_stats {};

struct rtl8139_stats {};

struct rtl8139_private {};

MODULE_AUTHOR();
MODULE_DESCRIPTION();
MODULE_LICENSE();
MODULE_VERSION();

module_param(use_io, bool, 0);
MODULE_PARM_DESC();
module_param(multicast_filter_limit, int, 0);
module_param_array();
module_param_array();
module_param(debug, int, 0);
MODULE_PARM_DESC();
MODULE_PARM_DESC();
MODULE_PARM_DESC();
MODULE_PARM_DESC();

static int read_eeprom (void __iomem *ioaddr, int location, int addr_len);
static int rtl8139_open (struct net_device *dev);
static int mdio_read (struct net_device *dev, int phy_id, int location);
static void mdio_write (struct net_device *dev, int phy_id, int location,
			int val);
static void rtl8139_start_thread(struct rtl8139_private *tp);
static void rtl8139_tx_timeout (struct net_device *dev, unsigned int txqueue);
static void rtl8139_init_ring (struct net_device *dev);
static netdev_tx_t rtl8139_start_xmit (struct sk_buff *skb,
				       struct net_device *dev);
#ifdef CONFIG_NET_POLL_CONTROLLER
static void rtl8139_poll_controller(struct net_device *dev);
#endif
static int rtl8139_set_mac_address(struct net_device *dev, void *p);
static int rtl8139_poll(struct napi_struct *napi, int budget);
static irqreturn_t rtl8139_interrupt (int irq, void *dev_instance);
static int rtl8139_close (struct net_device *dev);
static int netdev_ioctl (struct net_device *dev, struct ifreq *rq, int cmd);
static void rtl8139_get_stats64(struct net_device *dev,
				struct rtnl_link_stats64 *stats);
static void rtl8139_set_rx_mode (struct net_device *dev);
static void __set_rx_mode (struct net_device *dev);
static void rtl8139_hw_start (struct net_device *dev);
static void rtl8139_thread (struct work_struct *work);
static void rtl8139_tx_timeout_task(struct work_struct *work);
static const struct ethtool_ops rtl8139_ethtool_ops;

/* write MMIO register, with flush */
/* Flush avoids rtl8139 bug w/ posted MMIO writes */
#define RTL_W8_F(reg, val8)
#define RTL_W16_F(reg, val16)
#define RTL_W32_F(reg, val32)

/* write MMIO register */
#define RTL_W8(reg, val8)
#define RTL_W16(reg, val16)
#define RTL_W32(reg, val32)

/* read MMIO register */
#define RTL_R8(reg)
#define RTL_R16(reg)
#define RTL_R32(reg)


static const u16 rtl8139_intr_mask =;

static const u16 rtl8139_norx_intr_mask = ;

#if RX_BUF_IDX == 0
static const unsigned int rtl8139_rx_config =
	RxCfgRcv8K | RxNoWrap |
	(RX_FIFO_THRESH << RxCfgFIFOShift) |
	(RX_DMA_BURST << RxCfgDMAShift);
#elif RX_BUF_IDX == 1
static const unsigned int rtl8139_rx_config =
	RxCfgRcv16K | RxNoWrap |
	(RX_FIFO_THRESH << RxCfgFIFOShift) |
	(RX_DMA_BURST << RxCfgDMAShift);
#elif RX_BUF_IDX == 2
static const unsigned int rtl8139_rx_config =;
#elif RX_BUF_IDX == 3
static const unsigned int rtl8139_rx_config =
	RxCfgRcv64K |
	(RX_FIFO_THRESH << RxCfgFIFOShift) |
	(RX_DMA_BURST << RxCfgDMAShift);
#else
#error "Invalid configuration for 8139_RXBUF_IDX"
#endif

static const unsigned int rtl8139_tx_config =;

static void __rtl8139_cleanup_dev (struct net_device *dev)
{}


static void rtl8139_chip_reset (void __iomem *ioaddr)
{}


static struct net_device *rtl8139_init_board(struct pci_dev *pdev)
{}

static int rtl8139_set_features(struct net_device *dev, netdev_features_t features)
{}

static const struct net_device_ops rtl8139_netdev_ops =;

static int rtl8139_init_one(struct pci_dev *pdev,
			    const struct pci_device_id *ent)
{}


static void rtl8139_remove_one(struct pci_dev *pdev)
{}


/* Serial EEPROM section. */

/*  EEPROM_Ctrl bits. */
#define EE_SHIFT_CLK
#define EE_CS
#define EE_DATA_WRITE
#define EE_WRITE_0
#define EE_WRITE_1
#define EE_DATA_READ
#define EE_ENB

/* Delay between EEPROM clock transitions.
   No extra delay is needed with 33Mhz PCI, but 66Mhz may change this.
 */

#define eeprom_delay()

/* The EEPROM commands include the alway-set leading bit. */
#define EE_WRITE_CMD
#define EE_READ_CMD
#define EE_ERASE_CMD

static int read_eeprom(void __iomem *ioaddr, int location, int addr_len)
{}

/* MII serial management: mostly bogus for now. */
/* Read and write the MII management registers using software-generated
   serial MDIO protocol.
   The maximum data clock rate is 2.5 Mhz.  The minimum timing is usually
   met by back-to-back PCI I/O cycles, but we insert a delay to avoid
   "overclocking" issues. */
#define MDIO_DIR
#define MDIO_DATA_OUT
#define MDIO_DATA_IN
#define MDIO_CLK
#define MDIO_WRITE0
#define MDIO_WRITE1

#define mdio_delay()


static const char mii_2_8139_map[8] =;


#ifdef CONFIG_8139TOO_8129
/* Syncronize the MII management interface by shifting 32 one bits out. */
static void mdio_sync (void __iomem *ioaddr)
{}
#endif

static int mdio_read (struct net_device *dev, int phy_id, int location)
{}


static void mdio_write (struct net_device *dev, int phy_id, int location,
			int value)
{}


static int rtl8139_open (struct net_device *dev)
{}


static void rtl_check_media (struct net_device *dev, unsigned int init_media)
{}

/* Start the hardware at open or resume. */
static void rtl8139_hw_start (struct net_device *dev)
{}


/* Initialize the Rx and Tx rings, along with various 'dev' bits. */
static void rtl8139_init_ring (struct net_device *dev)
{}


/* This must be global for CONFIG_8139TOO_TUNE_TWISTER case */
static int next_tick =;

#ifndef CONFIG_8139TOO_TUNE_TWISTER
static inline void rtl8139_tune_twister (struct net_device *dev,
				  struct rtl8139_private *tp) {}
#else
enum TwisterParamVals {};

static const unsigned long param[4][4] =;

static void rtl8139_tune_twister (struct net_device *dev,
				  struct rtl8139_private *tp)
{}
#endif /* CONFIG_8139TOO_TUNE_TWISTER */

static inline void rtl8139_thread_iter (struct net_device *dev,
				 struct rtl8139_private *tp,
				 void __iomem *ioaddr)
{}

static void rtl8139_thread (struct work_struct *work)
{}

static void rtl8139_start_thread(struct rtl8139_private *tp)
{}

static inline void rtl8139_tx_clear (struct rtl8139_private *tp)
{}

static void rtl8139_tx_timeout_task (struct work_struct *work)
{}

static void rtl8139_tx_timeout(struct net_device *dev, unsigned int txqueue)
{}

static netdev_tx_t rtl8139_start_xmit (struct sk_buff *skb,
					     struct net_device *dev)
{}


static void rtl8139_tx_interrupt (struct net_device *dev,
				  struct rtl8139_private *tp,
				  void __iomem *ioaddr)
{}


/* TODO: clean this up!  Rx reset need not be this intensive */
static void rtl8139_rx_err (u32 rx_status, struct net_device *dev,
			    struct rtl8139_private *tp, void __iomem *ioaddr)
{}

#if RX_BUF_IDX == 3
static inline void wrap_copy(struct sk_buff *skb, const unsigned char *ring,
				 u32 offset, unsigned int size)
{
	u32 left = RX_BUF_LEN - offset;

	if (size > left) {
		skb_copy_to_linear_data(skb, ring + offset, left);
		skb_copy_to_linear_data_offset(skb, left, ring, size - left);
	} else
		skb_copy_to_linear_data(skb, ring + offset, size);
}
#endif

static void rtl8139_isr_ack(struct rtl8139_private *tp)
{}

static int rtl8139_rx(struct net_device *dev, struct rtl8139_private *tp,
		      int budget)
{}


static void rtl8139_weird_interrupt (struct net_device *dev,
				     struct rtl8139_private *tp,
				     void __iomem *ioaddr,
				     int status, int link_changed)
{}

static int rtl8139_poll(struct napi_struct *napi, int budget)
{}

/* The interrupt handler does all of the Rx thread work and cleans up
   after the Tx thread. */
static irqreturn_t rtl8139_interrupt (int irq, void *dev_instance)
{}

#ifdef CONFIG_NET_POLL_CONTROLLER
/*
 * Polling receive - used by netconsole and other diagnostic tools
 * to allow network i/o with interrupts disabled.
 */
static void rtl8139_poll_controller(struct net_device *dev)
{}
#endif

static int rtl8139_set_mac_address(struct net_device *dev, void *p)
{}

static int rtl8139_close (struct net_device *dev)
{}


/* Get the ethtool Wake-on-LAN settings.  Assumes that wol points to
   kernel memory, *wol has been initialized as {ETHTOOL_GWOL}, and
   other threads or interrupts aren't messing with the 8139.  */
static void rtl8139_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
{}


/* Set the ethtool Wake-on-LAN settings.  Return 0 or -errno.  Assumes
   that wol points to kernel memory and other threads or interrupts
   aren't messing with the 8139.  */
static int rtl8139_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
{}

static void rtl8139_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
{}

static int rtl8139_get_link_ksettings(struct net_device *dev,
				      struct ethtool_link_ksettings *cmd)
{}

static int rtl8139_set_link_ksettings(struct net_device *dev,
				      const struct ethtool_link_ksettings *cmd)
{}

static int rtl8139_nway_reset(struct net_device *dev)
{}

static u32 rtl8139_get_link(struct net_device *dev)
{}

static u32 rtl8139_get_msglevel(struct net_device *dev)
{}

static void rtl8139_set_msglevel(struct net_device *dev, u32 datum)
{}

static int rtl8139_get_regs_len(struct net_device *dev)
{}

static void rtl8139_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *regbuf)
{}

static int rtl8139_get_sset_count(struct net_device *dev, int sset)
{}

static void rtl8139_get_ethtool_stats(struct net_device *dev, struct ethtool_stats *stats, u64 *data)
{}

static void rtl8139_get_strings(struct net_device *dev, u32 stringset, u8 *data)
{}

static const struct ethtool_ops rtl8139_ethtool_ops =;

static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
{}


static void
rtl8139_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
{}

/* Set or clear the multicast filter for this adaptor.
   This routine is not state sensitive and need not be SMP locked. */

static void __set_rx_mode (struct net_device *dev)
{}

static void rtl8139_set_rx_mode (struct net_device *dev)
{}

static int __maybe_unused rtl8139_suspend(struct device *device)
{}

static int __maybe_unused rtl8139_resume(struct device *device)
{}

static SIMPLE_DEV_PM_OPS(rtl8139_pm_ops, rtl8139_suspend, rtl8139_resume);

static struct pci_driver rtl8139_pci_driver =;


static int __init rtl8139_init_module (void)
{}


static void __exit rtl8139_cleanup_module (void)
{}


module_init();
module_exit(rtl8139_cleanup_module);