linux/drivers/net/ethernet/via/via-rhine.c

/* via-rhine.c: A Linux Ethernet device driver for VIA Rhine family chips. */
/*
	Written 1998-2001 by Donald Becker.

	Current Maintainer: Kevin Brace <[email protected]>

	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 designed for the VIA VT86C100A Rhine-I.
	It also works with the Rhine-II (6102) and Rhine-III (6105/6105L/6105LOM
	and management NIC 6105M).

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


	This driver contains some changes from the original Donald Becker
	version. He may or may not be interested in bug reports on this
	code. You can find his versions at:
	http://www.scyld.com/network/via-rhine.html
	[link no longer provides useful info -jgarzik]

*/

#define pr_fmt(fmt)

#define DRV_NAME

#include <linux/types.h>

/* A few user-configurable values.
   These may be modified when a driver module is loaded. */
static int debug =;
#define RHINE_MSG_DEFAULT

/* Set the copy breakpoint for the copy-only-tiny-frames scheme.
   Setting to > 1518 effectively disables this feature. */
#if defined(__alpha__) || defined(__arm__) || defined(__hppa__) || \
	defined(CONFIG_SPARC) || defined(__ia64__) ||		   \
	defined(__sh__) || defined(__mips__)
static int rx_copybreak = 1518;
#else
static int rx_copybreak;
#endif

/* Work-around for broken BIOSes: they are unable to get the chip back out of
   power state D3 so PXE booting fails. bootparam(7): via-rhine.avoid_D3=1 */
static bool avoid_D3;

/*
 * In case you are looking for 'options[]' or 'full_duplex[]', they
 * are gone. Use ethtool(8) instead.
 */

/* Maximum number of multicast addresses to filter (vs. rx-all-multicast).
   The Rhine has a 64 element 8390-like hash table. */
static const int multicast_filter_limit =;


/* Operational parameters that are set at compile time. */

/* Keep the ring sizes a power of two for compile efficiency.
 * The compiler will convert <unsigned>'%'<2^N> into a bit mask.
 * Making the Tx ring too large decreases the effectiveness of channel
 * bonding and packet priority.
 * With BQL support, we can increase TX ring safely.
 * There are no ill effects from too-large receive rings.
 */
#define TX_RING_SIZE
#define TX_QUEUE_LEN
#define RX_RING_SIZE

/* Operational parameters that usually are not changed. */

/* Time in jiffies before concluding the transmitter is hung. */
#define TX_TIMEOUT

#define PKT_BUF_SZ

#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/timer.h>
#include <linux/errno.h>
#include <linux/ioport.h>
#include <linux/interrupt.h>
#include <linux/pci.h>
#include <linux/of.h>
#include <linux/of_irq.h>
#include <linux/platform_device.h>
#include <linux/dma-mapping.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/skbuff.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/mii.h>
#include <linux/ethtool.h>
#include <linux/crc32.h>
#include <linux/if_vlan.h>
#include <linux/bitops.h>
#include <linux/workqueue.h>
#include <asm/processor.h>	/* Processor type for cache alignment. */
#include <asm/io.h>
#include <asm/irq.h>
#include <linux/uaccess.h>
#include <linux/dmi.h>

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

module_param(debug, int, 0);
module_param(rx_copybreak, int, 0);
module_param(avoid_D3, bool, 0);
MODULE_PARM_DESC();
MODULE_PARM_DESC();
MODULE_PARM_DESC();

#define MCAM_SIZE
#define VCAM_SIZE

/*
		Theory of Operation

I. Board Compatibility

This driver is designed for the VIA 86c100A Rhine-II PCI Fast Ethernet
controller.

II. Board-specific settings

Boards with this chip are functional only in a bus-master PCI slot.

Many operational settings are loaded from the EEPROM to the Config word at
offset 0x78. For most of these settings, this driver assumes that they are
correct.
If this driver is compiled to use PCI memory space operations the EEPROM
must be configured to enable memory ops.

III. Driver operation

IIIa. Ring buffers

This driver uses two statically allocated fixed-size descriptor lists
formed into rings by a branch from the final descriptor to the beginning of
the list. The ring sizes are set at compile time by RX/TX_RING_SIZE.

IIIb/c. Transmit/Receive Structure

This driver attempts to use a zero-copy receive and transmit scheme.

Alas, all data buffers are required to start on a 32 bit boundary, so
the driver must often copy transmit packets into bounce buffers.

The driver allocates full frame size skbuffs for the Rx ring buffers at
open() time and passes the skb->data field to the chip as receive data
buffers. When an incoming frame is less than RX_COPYBREAK bytes long,
a fresh skbuff is allocated and the frame is copied to the new skbuff.
When the incoming frame is larger, the skbuff is passed directly up the
protocol stack. Buffers consumed this way are replaced by newly allocated
skbuffs in the last phase of rhine_rx().

The RX_COPYBREAK value is chosen to trade-off the memory wasted by
using a full-sized skbuff for small frames vs. the copying costs of larger
frames. New boards are typically used in generously configured machines
and the underfilled buffers have negligible impact compared to the benefit of
a single allocation size, so the default value of zero results in never
copying packets. When copying is done, the cost is usually mitigated by using
a combined copy/checksum routine. Copying also preloads the cache, which is
most useful with small frames.

Since the VIA chips are only able to transfer data to buffers on 32 bit
boundaries, the IP header at offset 14 in an ethernet frame isn't
longword aligned for further processing. Copying these unaligned buffers
has the beneficial effect of 16-byte aligning the IP header.

IIId. Synchronization

The driver runs as two independent, single-threaded flows of control. One
is the send-packet routine, which enforces single-threaded use by the
netdev_priv(dev)->lock spinlock. The other thread is the interrupt handler,
which is single threaded by the hardware and interrupt handling software.

The send packet thread has partial control over the Tx ring. It locks the
netdev_priv(dev)->lock whenever it's queuing a Tx packet. If the next slot in
the ring is not available it stops the transmit queue by
calling netif_stop_queue.

The interrupt handler has exclusive control over the Rx ring and records stats
from the Tx ring. After reaping the stats, it marks the Tx queue entry as
empty by incrementing the dirty_tx mark. If at least half of the entries in
the Rx ring are available the transmit queue is woken up if it was stopped.

IV. Notes

IVb. References

Preliminary VT86C100A manual from http://www.via.com.tw/
http://www.scyld.com/expert/100mbps.html
http://www.scyld.com/expert/NWay.html
ftp://ftp.via.com.tw/public/lan/Products/NIC/VT86C100A/Datasheet/VT86C100A03.pdf
ftp://ftp.via.com.tw/public/lan/Products/NIC/VT6102/Datasheet/VT6102_021.PDF


IVc. Errata

The VT86C100A manual is not reliable information.
The 3043 chip does not handle unaligned transmit or receive buffers, resulting
in significant performance degradation for bounce buffer copies on transmit
and unaligned IP headers on receive.
The chip does not pad to minimum transmit length.

*/


/* This table drives the PCI probe routines. It's mostly boilerplate in all
   of the drivers, and will likely be provided by some future kernel.
   Note the matching code -- the first table entry matchs all 56** cards but
   second only the 1234 card.
*/

enum rhine_revs {};

enum rhine_quirks {};
/*
 * rqRhineI: VT86C100A (aka Rhine-I) uses different bits to enable
 * MMIO as well as for the collision counter and the Tx FIFO underflow
 * indicator. In addition, Tx and Rx buffers need to 4 byte aligned.
 */

/* Beware of PCI posted writes */
#define IOSYNC

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

/* OpenFirmware identifiers for platform-bus devices
 * The .data field is currently only used to store quirks
 */
static u32 vt8500_quirks =;
static const struct of_device_id rhine_of_tbl[] =;
MODULE_DEVICE_TABLE(of, rhine_of_tbl);

/* Offsets to the device registers. */
enum register_offsets {};

/* Bits in ConfigD */
enum backoff_bits {};

/* Bits in the TxConfig (TCR) register */
enum tcr_bits {};

/* Bits in the CamCon (CAMC) register */
enum camcon_bits {};

/* Bits in the PCIBusConfig1 (BCR1) register */
enum bcr1_bits {};

/* Registers we check that mmio and reg are the same. */
static const int mmio_verify_registers[] =;

/* Bits in the interrupt status/mask registers. */
enum intr_status_bits {};

/* Bits in WOLcrSet/WOLcrClr and PwrcsrSet/PwrcsrClr */
enum wol_bits {};

/* The Rx and Tx buffer descriptors. */
struct rx_desc {};
struct tx_desc {};

/* Initial value for tx_desc.desc_length, Buffer size goes to bits 0-10 */
#define TXDESC

enum rx_status_bits {};

/* Bits in *_desc.*_status */
enum desc_status_bits {};

/* Bits in *_desc.*_length */
enum desc_length_bits {};

/* Bits in ChipCmd. */
enum chip_cmd_bits {};

struct rhine_stats {};

struct rhine_private {};

#define BYTE_REG_BITS_ON(x, p)
#define WORD_REG_BITS_ON(x, p)
#define DWORD_REG_BITS_ON(x, p)

#define BYTE_REG_BITS_IS_ON(x, p)
#define WORD_REG_BITS_IS_ON(x, p)
#define DWORD_REG_BITS_IS_ON(x, p)

#define BYTE_REG_BITS_OFF(x, p)
#define WORD_REG_BITS_OFF(x, p)
#define DWORD_REG_BITS_OFF(x, p)

#define BYTE_REG_BITS_SET(x, m, p)
#define WORD_REG_BITS_SET(x, m, p)
#define DWORD_REG_BITS_SET(x, m, p)


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  rhine_open(struct net_device *dev);
static void rhine_reset_task(struct work_struct *work);
static void rhine_slow_event_task(struct work_struct *work);
static void rhine_tx_timeout(struct net_device *dev, unsigned int txqueue);
static netdev_tx_t rhine_start_tx(struct sk_buff *skb,
				  struct net_device *dev);
static irqreturn_t rhine_interrupt(int irq, void *dev_instance);
static void rhine_tx(struct net_device *dev);
static int rhine_rx(struct net_device *dev, int limit);
static void rhine_set_rx_mode(struct net_device *dev);
static void rhine_get_stats64(struct net_device *dev,
			      struct rtnl_link_stats64 *stats);
static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
static const struct ethtool_ops netdev_ethtool_ops;
static int  rhine_close(struct net_device *dev);
static int rhine_vlan_rx_add_vid(struct net_device *dev,
				 __be16 proto, u16 vid);
static int rhine_vlan_rx_kill_vid(struct net_device *dev,
				  __be16 proto, u16 vid);
static void rhine_restart_tx(struct net_device *dev);

static void rhine_wait_bit(struct rhine_private *rp, u8 reg, u8 mask, bool low)
{}

static void rhine_wait_bit_high(struct rhine_private *rp, u8 reg, u8 mask)
{}

static void rhine_wait_bit_low(struct rhine_private *rp, u8 reg, u8 mask)
{}

static u32 rhine_get_events(struct rhine_private *rp)
{}

static void rhine_ack_events(struct rhine_private *rp, u32 mask)
{}

/*
 * Get power related registers into sane state.
 * Notify user about past WOL event.
 */
static void rhine_power_init(struct net_device *dev)
{}

static void rhine_chip_reset(struct net_device *dev)
{}

static void enable_mmio(long pioaddr, u32 quirks)
{}

static inline int verify_mmio(struct device *hwdev,
			      long pioaddr,
			      void __iomem *ioaddr,
			      u32 quirks)
{}

/*
 * Loads bytes 0x00-0x05, 0x6E-0x6F, 0x78-0x7B from EEPROM
 * (plus 0x6C for Rhine-I/II)
 */
static void rhine_reload_eeprom(long pioaddr, struct net_device *dev)
{}

#ifdef CONFIG_NET_POLL_CONTROLLER
static void rhine_poll(struct net_device *dev)
{}
#endif

static void rhine_kick_tx_threshold(struct rhine_private *rp)
{}

static void rhine_tx_err(struct rhine_private *rp, u32 status)
{}

static void rhine_update_rx_crc_and_missed_errord(struct rhine_private *rp)
{}

#define RHINE_EVENT_NAPI_RX

#define RHINE_EVENT_NAPI_TX_ERR
#define RHINE_EVENT_NAPI_TX

#define RHINE_EVENT_NAPI
#define RHINE_EVENT_SLOW
#define RHINE_EVENT

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

static void rhine_hw_init(struct net_device *dev, long pioaddr)
{}

static const struct net_device_ops rhine_netdev_ops =;

static int rhine_init_one_common(struct device *hwdev, u32 quirks,
				 long pioaddr, void __iomem *ioaddr, int irq)
{}

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

static int rhine_init_one_platform(struct platform_device *pdev)
{}

static int alloc_ring(struct net_device* dev)
{}

static void free_ring(struct net_device* dev)
{}

struct rhine_skb_dma {};

static inline int rhine_skb_dma_init(struct net_device *dev,
				     struct rhine_skb_dma *sd)
{}

static void rhine_reset_rbufs(struct rhine_private *rp)
{}

static inline void rhine_skb_dma_nic_store(struct rhine_private *rp,
					   struct rhine_skb_dma *sd, int entry)
{}

static void free_rbufs(struct net_device* dev);

static int alloc_rbufs(struct net_device *dev)
{}

static void free_rbufs(struct net_device* dev)
{}

static void alloc_tbufs(struct net_device* dev)
{}

static void free_tbufs(struct net_device* dev)
{}

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

/* Called after status of force_media possibly changed */
static void rhine_set_carrier(struct mii_if_info *mii)
{}

/**
 * rhine_set_cam - set CAM multicast filters
 * @ioaddr: register block of this Rhine
 * @idx: multicast CAM index [0..MCAM_SIZE-1]
 * @addr: multicast address (6 bytes)
 *
 * Load addresses into multicast filters.
 */
static void rhine_set_cam(void __iomem *ioaddr, int idx, u8 *addr)
{}

/**
 * rhine_set_vlan_cam - set CAM VLAN filters
 * @ioaddr: register block of this Rhine
 * @idx: VLAN CAM index [0..VCAM_SIZE-1]
 * @addr: VLAN ID (2 bytes)
 *
 * Load addresses into VLAN filters.
 */
static void rhine_set_vlan_cam(void __iomem *ioaddr, int idx, u8 *addr)
{}

/**
 * rhine_set_cam_mask - set multicast CAM mask
 * @ioaddr: register block of this Rhine
 * @mask: multicast CAM mask
 *
 * Mask sets multicast filters active/inactive.
 */
static void rhine_set_cam_mask(void __iomem *ioaddr, u32 mask)
{}

/**
 * rhine_set_vlan_cam_mask - set VLAN CAM mask
 * @ioaddr: register block of this Rhine
 * @mask: VLAN CAM mask
 *
 * Mask sets VLAN filters active/inactive.
 */
static void rhine_set_vlan_cam_mask(void __iomem *ioaddr, u32 mask)
{}

/**
 * rhine_init_cam_filter - initialize CAM filters
 * @dev: network device
 *
 * Initialize (disable) hardware VLAN and multicast support on this
 * Rhine.
 */
static void rhine_init_cam_filter(struct net_device *dev)
{}

/**
 * rhine_update_vcam - update VLAN CAM filters
 * @dev: rhine_private data of this Rhine
 *
 * Update VLAN CAM filters to match configuration change.
 */
static void rhine_update_vcam(struct net_device *dev)
{}

static int rhine_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid)
{}

static int rhine_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, u16 vid)
{}

static void init_registers(struct net_device *dev)
{}

/* Enable MII link status auto-polling (required for IntrLinkChange) */
static void rhine_enable_linkmon(struct rhine_private *rp)
{}

/* Disable MII link status auto-polling (required for MDIO access) */
static void rhine_disable_linkmon(struct rhine_private *rp)
{}

/* Read and write over the MII Management Data I/O (MDIO) interface. */

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

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

static void rhine_task_disable(struct rhine_private *rp)
{}

static void rhine_task_enable(struct rhine_private *rp)
{}

static int rhine_open(struct net_device *dev)
{}

static void rhine_reset_task(struct work_struct *work)
{}

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

static inline bool rhine_tx_queue_full(struct rhine_private *rp)
{}

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

static void rhine_irq_disable(struct rhine_private *rp)
{}

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

/* This routine is logically part of the interrupt handler, but isolated
   for clarity. */
static void rhine_tx(struct net_device *dev)
{}

/**
 * rhine_get_vlan_tci - extract TCI from Rx data buffer
 * @skb: pointer to sk_buff
 * @data_size: used data area of the buffer including CRC
 *
 * If hardware VLAN tag extraction is enabled and the chip indicates a 802.1Q
 * packet, the extracted 802.1Q header (2 bytes TPID + 2 bytes TCI) is 4-byte
 * aligned following the CRC.
 */
static inline u16 rhine_get_vlan_tci(struct sk_buff *skb, int data_size)
{}

static inline void rhine_rx_vlan_tag(struct sk_buff *skb, struct rx_desc *desc,
				     int data_size)
{}

/* Process up to limit frames from receive ring */
static int rhine_rx(struct net_device *dev, int limit)
{}

static void rhine_restart_tx(struct net_device *dev) {}

static void rhine_slow_event_task(struct work_struct *work)
{}

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

static void rhine_set_rx_mode(struct net_device *dev)
{}

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

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

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

static int netdev_nway_reset(struct net_device *dev)
{}

static u32 netdev_get_link(struct net_device *dev)
{}

static u32 netdev_get_msglevel(struct net_device *dev)
{}

static void netdev_set_msglevel(struct net_device *dev, u32 value)
{}

static void rhine_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
{}

static int rhine_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
{}

static const struct ethtool_ops netdev_ethtool_ops =;

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

static int rhine_close(struct net_device *dev)
{}


static void rhine_remove_one_pci(struct pci_dev *pdev)
{}

static void rhine_remove_one_platform(struct platform_device *pdev)
{}

static void rhine_shutdown_pci(struct pci_dev *pdev)
{}

#ifdef CONFIG_PM_SLEEP
static int rhine_suspend(struct device *device)
{}

static int rhine_resume(struct device *device)
{}

static SIMPLE_DEV_PM_OPS(rhine_pm_ops, rhine_suspend, rhine_resume);
#define RHINE_PM_OPS

#else

#define RHINE_PM_OPS

#endif /* !CONFIG_PM_SLEEP */

static struct pci_driver rhine_driver_pci =;

static struct platform_driver rhine_driver_platform =;

static const struct dmi_system_id rhine_dmi_table[] __initconst =;

static int __init rhine_init(void)
{}


static void __exit rhine_cleanup(void)
{}


module_init();
module_exit(rhine_cleanup);