2005-04-17 06:20:36 +08:00
|
|
|
/* epic100.c: A SMC 83c170 EPIC/100 Fast Ethernet driver for Linux. */
|
|
|
|
/*
|
|
|
|
Written/copyright 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 the SMC83c170/175 "EPIC" series, as used on the
|
|
|
|
SMC EtherPower II 9432 PCI adapter, and several CardBus cards.
|
|
|
|
|
|
|
|
The author may be reached as becker@scyld.com, or C/O
|
|
|
|
Scyld Computing Corporation
|
|
|
|
410 Severn Ave., Suite 210
|
|
|
|
Annapolis MD 21403
|
|
|
|
|
|
|
|
Information and updates available at
|
|
|
|
http://www.scyld.com/network/epic100.html
|
2006-06-27 19:38:33 +08:00
|
|
|
[this link no longer provides anything useful -jgarzik]
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
---------------------------------------------------------------------
|
2006-05-27 09:39:03 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define DRV_NAME "epic100"
|
2006-09-12 05:39:18 +08:00
|
|
|
#define DRV_VERSION "2.1"
|
|
|
|
#define DRV_RELDATE "Sept 11, 2006"
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* The user-configurable values.
|
|
|
|
These may be modified when a driver module is loaded.*/
|
|
|
|
|
|
|
|
static int debug = 1; /* 1 normal messages, 0 quiet .. 7 verbose. */
|
|
|
|
|
|
|
|
/* Used to pass the full-duplex flag, etc. */
|
|
|
|
#define MAX_UNITS 8 /* More are supported, limit only on options */
|
|
|
|
static int options[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
|
|
|
|
static int full_duplex[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
|
|
|
|
|
|
|
|
/* Set the copy breakpoint for the copy-only-tiny-frames scheme.
|
|
|
|
Setting to > 1518 effectively disables this feature. */
|
|
|
|
static int rx_copybreak;
|
|
|
|
|
|
|
|
/* Operational parameters that are set at compile time. */
|
|
|
|
|
|
|
|
/* Keep the ring sizes a power of two for operational 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.
|
|
|
|
There are no ill effects from too-large receive rings. */
|
|
|
|
#define TX_RING_SIZE 256
|
|
|
|
#define TX_QUEUE_LEN 240 /* Limit ring entries actually used. */
|
|
|
|
#define RX_RING_SIZE 256
|
|
|
|
#define TX_TOTAL_SIZE TX_RING_SIZE*sizeof(struct epic_tx_desc)
|
|
|
|
#define RX_TOTAL_SIZE RX_RING_SIZE*sizeof(struct epic_rx_desc)
|
|
|
|
|
|
|
|
/* Operational parameters that usually are not changed. */
|
|
|
|
/* Time in jiffies before concluding the transmitter is hung. */
|
|
|
|
#define TX_TIMEOUT (2*HZ)
|
|
|
|
|
|
|
|
#define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer.*/
|
|
|
|
|
|
|
|
/* Bytes transferred to chip before transmission starts. */
|
|
|
|
/* Initial threshold, increased on underflow, rounded down to 4 byte units. */
|
|
|
|
#define TX_FIFO_THRESH 256
|
|
|
|
#define RX_FIFO_THRESH 1 /* 0-3, 0==32, 64,96, or 3==128 bytes */
|
|
|
|
|
|
|
|
#include <linux/module.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/delay.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/ethtool.h>
|
|
|
|
#include <linux/mii.h>
|
|
|
|
#include <linux/crc32.h>
|
|
|
|
#include <linux/bitops.h>
|
|
|
|
#include <asm/io.h>
|
2016-12-25 03:46:01 +08:00
|
|
|
#include <linux/uaccess.h>
|
2010-06-02 18:36:53 +08:00
|
|
|
#include <asm/byteorder.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* These identify the driver base version and may not be removed. */
|
2012-12-03 22:23:42 +08:00
|
|
|
static char version[] =
|
2013-11-01 20:53:30 +08:00
|
|
|
DRV_NAME ".c:v1.11 1/7/2001 Written by Donald Becker <becker@scyld.com>";
|
2012-12-03 22:23:42 +08:00
|
|
|
static char version2[] =
|
2013-11-01 20:53:30 +08:00
|
|
|
" (unofficial 2.4.x kernel port, version " DRV_VERSION ", " DRV_RELDATE ")";
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Donald Becker <becker@scyld.com>");
|
|
|
|
MODULE_DESCRIPTION("SMC 83c170 EPIC series Ethernet driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
module_param(debug, int, 0);
|
|
|
|
module_param(rx_copybreak, int, 0);
|
|
|
|
module_param_array(options, int, NULL, 0);
|
|
|
|
module_param_array(full_duplex, int, NULL, 0);
|
|
|
|
MODULE_PARM_DESC(debug, "EPIC/100 debug level (0-5)");
|
|
|
|
MODULE_PARM_DESC(options, "EPIC/100: Bits 0-3: media type, bit 4: full duplex");
|
|
|
|
MODULE_PARM_DESC(rx_copybreak, "EPIC/100 copy breakpoint for copy-only-tiny-frames");
|
|
|
|
MODULE_PARM_DESC(full_duplex, "EPIC/100 full duplex setting(s) (1)");
|
|
|
|
|
|
|
|
/*
|
|
|
|
Theory of Operation
|
|
|
|
|
|
|
|
I. Board Compatibility
|
|
|
|
|
|
|
|
This device driver is designed for the SMC "EPIC/100", the SMC
|
|
|
|
single-chip Ethernet controllers for PCI. This chip is used on
|
|
|
|
the SMC EtherPower II boards.
|
|
|
|
|
|
|
|
II. Board-specific settings
|
|
|
|
|
|
|
|
PCI bus devices are configured by the system at boot time, so no jumpers
|
|
|
|
need to be set on the board. The system BIOS will assign the
|
|
|
|
PCI INTA signal to a (preferably otherwise unused) system IRQ line.
|
|
|
|
Note: Kernel versions earlier than 1.3.73 do not support shared PCI
|
|
|
|
interrupt lines.
|
|
|
|
|
|
|
|
III. Driver operation
|
|
|
|
|
|
|
|
IIIa. Ring buffers
|
|
|
|
|
|
|
|
IVb. References
|
|
|
|
|
2010-10-18 17:03:14 +08:00
|
|
|
http://www.smsc.com/media/Downloads_Public/discontinued/83c171.pdf
|
|
|
|
http://www.smsc.com/media/Downloads_Public/discontinued/83c175.pdf
|
2005-04-17 06:20:36 +08:00
|
|
|
http://scyld.com/expert/NWay.html
|
|
|
|
http://www.national.com/pf/DP/DP83840A.html
|
|
|
|
|
|
|
|
IVc. Errata
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
enum chip_capability_flags { MII_PWRDWN=1, TYPE2_INTR=2, NO_MII=4 };
|
|
|
|
|
|
|
|
#define EPIC_TOTAL_SIZE 0x100
|
|
|
|
#define USE_IO_OPS 1
|
|
|
|
|
2012-03-13 19:04:26 +08:00
|
|
|
#ifdef USE_IO_OPS
|
|
|
|
#define EPIC_BAR 0
|
|
|
|
#else
|
|
|
|
#define EPIC_BAR 1
|
|
|
|
#endif
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
typedef enum {
|
|
|
|
SMSC_83C170_0,
|
|
|
|
SMSC_83C170,
|
|
|
|
SMSC_83C175,
|
|
|
|
} chip_t;
|
|
|
|
|
|
|
|
|
|
|
|
struct epic_chip_info {
|
|
|
|
const char *name;
|
|
|
|
int drv_flags; /* Driver use, intended as capability flags. */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* indexed by chip_t */
|
2006-03-04 10:33:57 +08:00
|
|
|
static const struct epic_chip_info pci_id_tbl[] = {
|
2006-06-27 19:38:33 +08:00
|
|
|
{ "SMSC EPIC/100 83c170", TYPE2_INTR | NO_MII | MII_PWRDWN },
|
|
|
|
{ "SMSC EPIC/100 83c170", TYPE2_INTR },
|
|
|
|
{ "SMSC EPIC/C 83c175", TYPE2_INTR | MII_PWRDWN },
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-08-08 21:56:03 +08:00
|
|
|
static const struct pci_device_id epic_pci_tbl[] = {
|
2005-04-17 06:20:36 +08:00
|
|
|
{ 0x10B8, 0x0005, 0x1092, 0x0AB4, 0, 0, SMSC_83C170_0 },
|
|
|
|
{ 0x10B8, 0x0005, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SMSC_83C170 },
|
|
|
|
{ 0x10B8, 0x0006, PCI_ANY_ID, PCI_ANY_ID,
|
|
|
|
PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, SMSC_83C175 },
|
|
|
|
{ 0,}
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE (pci, epic_pci_tbl);
|
|
|
|
|
2012-03-13 19:04:26 +08:00
|
|
|
#define ew16(reg, val) iowrite16(val, ioaddr + (reg))
|
|
|
|
#define ew32(reg, val) iowrite32(val, ioaddr + (reg))
|
|
|
|
#define er8(reg) ioread8(ioaddr + (reg))
|
|
|
|
#define er16(reg) ioread16(ioaddr + (reg))
|
|
|
|
#define er32(reg) ioread32(ioaddr + (reg))
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Offsets to registers, using the (ugh) SMC names. */
|
|
|
|
enum epic_registers {
|
|
|
|
COMMAND=0, INTSTAT=4, INTMASK=8, GENCTL=0x0C, NVCTL=0x10, EECTL=0x14,
|
|
|
|
PCIBurstCnt=0x18,
|
|
|
|
TEST1=0x1C, CRCCNT=0x20, ALICNT=0x24, MPCNT=0x28, /* Rx error counters. */
|
|
|
|
MIICtrl=0x30, MIIData=0x34, MIICfg=0x38,
|
|
|
|
LAN0=64, /* MAC address. */
|
|
|
|
MC0=80, /* Multicast filter table. */
|
|
|
|
RxCtrl=96, TxCtrl=112, TxSTAT=0x74,
|
|
|
|
PRxCDAR=0x84, RxSTAT=0xA4, EarlyRx=0xB0, PTxCDAR=0xC4, TxThresh=0xDC,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Interrupt register bits, using my own meaningful names. */
|
|
|
|
enum IntrStatus {
|
|
|
|
TxIdle=0x40000, RxIdle=0x20000, IntrSummary=0x010000,
|
|
|
|
PCIBusErr170=0x7000, PCIBusErr175=0x1000, PhyEvent175=0x8000,
|
|
|
|
RxStarted=0x0800, RxEarlyWarn=0x0400, CntFull=0x0200, TxUnderrun=0x0100,
|
|
|
|
TxEmpty=0x0080, TxDone=0x0020, RxError=0x0010,
|
|
|
|
RxOverflow=0x0008, RxFull=0x0004, RxHeader=0x0002, RxDone=0x0001,
|
|
|
|
};
|
|
|
|
enum CommandBits {
|
|
|
|
StopRx=1, StartRx=2, TxQueued=4, RxQueued=8,
|
|
|
|
StopTxDMA=0x20, StopRxDMA=0x40, RestartTx=0x80,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define EpicRemoved 0xffffffff /* Chip failed or removed (CardBus) */
|
|
|
|
|
|
|
|
#define EpicNapiEvent (TxEmpty | TxDone | \
|
|
|
|
RxDone | RxStarted | RxEarlyWarn | RxOverflow | RxFull)
|
|
|
|
#define EpicNormalEvent (0x0000ffff & ~EpicNapiEvent)
|
|
|
|
|
2006-03-04 10:33:57 +08:00
|
|
|
static const u16 media2miictl[16] = {
|
2005-04-17 06:20:36 +08:00
|
|
|
0, 0x0C00, 0x0C00, 0x2000, 0x0100, 0x2100, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0 };
|
|
|
|
|
2008-03-17 06:22:04 +08:00
|
|
|
/*
|
|
|
|
* The EPIC100 Rx and Tx buffer descriptors. Note that these
|
|
|
|
* really ARE host-endian; it's not a misannotation. We tell
|
|
|
|
* the card to byteswap them internally on big-endian hosts -
|
2010-06-02 18:36:53 +08:00
|
|
|
* look for #ifdef __BIG_ENDIAN in epic_open().
|
2008-03-17 06:22:04 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
struct epic_tx_desc {
|
|
|
|
u32 txstatus;
|
|
|
|
u32 bufaddr;
|
|
|
|
u32 buflength;
|
|
|
|
u32 next;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct epic_rx_desc {
|
|
|
|
u32 rxstatus;
|
|
|
|
u32 bufaddr;
|
|
|
|
u32 buflength;
|
|
|
|
u32 next;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum desc_status_bits {
|
|
|
|
DescOwn=0x8000,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define PRIV_ALIGN 15 /* Required alignment mask */
|
|
|
|
struct epic_private {
|
|
|
|
struct epic_rx_desc *rx_ring;
|
|
|
|
struct epic_tx_desc *tx_ring;
|
|
|
|
/* The saved address of a sent-in-place packet/buffer, for skfree(). */
|
|
|
|
struct sk_buff* tx_skbuff[TX_RING_SIZE];
|
|
|
|
/* The addresses of receive-in-place skbuffs. */
|
|
|
|
struct sk_buff* rx_skbuff[RX_RING_SIZE];
|
|
|
|
|
|
|
|
dma_addr_t tx_ring_dma;
|
|
|
|
dma_addr_t rx_ring_dma;
|
|
|
|
|
|
|
|
/* Ring pointers. */
|
|
|
|
spinlock_t lock; /* Group with Tx control cache line. */
|
|
|
|
spinlock_t napi_lock;
|
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net
device, and some have a single interrupt doorbell for several
queues.
In either case, it's easier to support layouts like that if the
structure representing the poll is independant from the net
device itself.
The signature of the ->poll() call back goes from:
int foo_poll(struct net_device *dev, int *budget)
to
int foo_poll(struct napi_struct *napi, int budget)
The caller is returned the number of RX packets processed (or
the number of "NAPI credits" consumed if you want to get
abstract). The callee no longer messes around bumping
dev->quota, *budget, etc. because that is all handled in the
caller upon return.
The napi_struct is to be embedded in the device driver private data
structures.
Furthermore, it is the driver's responsibility to disable all NAPI
instances in it's ->stop() device close handler. Since the
napi_struct is privatized into the driver's private data structures,
only the driver knows how to get at all of the napi_struct instances
it may have per-device.
With lots of help and suggestions from Rusty Russell, Roland Dreier,
Michael Chan, Jeff Garzik, and Jamal Hadi Salim.
Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra,
Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan.
[ Ported to current tree and all drivers converted. Integrated
Stephen's follow-on kerneldoc additions, and restored poll_list
handling to the old style to fix mutual exclusion issues. -DaveM ]
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-10-04 07:41:36 +08:00
|
|
|
struct napi_struct napi;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned int cur_tx, dirty_tx;
|
|
|
|
|
|
|
|
unsigned int cur_rx, dirty_rx;
|
|
|
|
u32 irq_mask;
|
|
|
|
unsigned int rx_buf_sz; /* Based on MTU+slack. */
|
|
|
|
|
2012-03-13 19:04:26 +08:00
|
|
|
void __iomem *ioaddr;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct pci_dev *pci_dev; /* PCI bus location. */
|
|
|
|
int chip_id, chip_flags;
|
|
|
|
|
|
|
|
struct timer_list timer; /* Media selection timer. */
|
|
|
|
int tx_threshold;
|
|
|
|
unsigned char mc_filter[8];
|
|
|
|
signed char phys[4]; /* MII device addresses. */
|
|
|
|
u16 advertising; /* NWay media advertisement */
|
|
|
|
int mii_phy_cnt;
|
|
|
|
struct mii_if_info mii;
|
|
|
|
unsigned int tx_full:1; /* The Tx queue is full. */
|
|
|
|
unsigned int default_port:4; /* Last dev->if_port value. */
|
|
|
|
};
|
|
|
|
|
|
|
|
static int epic_open(struct net_device *dev);
|
2012-03-13 19:04:26 +08:00
|
|
|
static int read_eeprom(struct epic_private *, int);
|
2005-04-17 06:20:36 +08:00
|
|
|
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 loc, int val);
|
|
|
|
static void epic_restart(struct net_device *dev);
|
2017-10-27 13:55:42 +08:00
|
|
|
static void epic_timer(struct timer_list *t);
|
2005-04-17 06:20:36 +08:00
|
|
|
static void epic_tx_timeout(struct net_device *dev);
|
|
|
|
static void epic_init_ring(struct net_device *dev);
|
2009-09-01 03:50:58 +08:00
|
|
|
static netdev_tx_t epic_start_xmit(struct sk_buff *skb,
|
|
|
|
struct net_device *dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
static int epic_rx(struct net_device *dev, int budget);
|
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net
device, and some have a single interrupt doorbell for several
queues.
In either case, it's easier to support layouts like that if the
structure representing the poll is independant from the net
device itself.
The signature of the ->poll() call back goes from:
int foo_poll(struct net_device *dev, int *budget)
to
int foo_poll(struct napi_struct *napi, int budget)
The caller is returned the number of RX packets processed (or
the number of "NAPI credits" consumed if you want to get
abstract). The callee no longer messes around bumping
dev->quota, *budget, etc. because that is all handled in the
caller upon return.
The napi_struct is to be embedded in the device driver private data
structures.
Furthermore, it is the driver's responsibility to disable all NAPI
instances in it's ->stop() device close handler. Since the
napi_struct is privatized into the driver's private data structures,
only the driver knows how to get at all of the napi_struct instances
it may have per-device.
With lots of help and suggestions from Rusty Russell, Roland Dreier,
Michael Chan, Jeff Garzik, and Jamal Hadi Salim.
Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra,
Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan.
[ Ported to current tree and all drivers converted. Integrated
Stephen's follow-on kerneldoc additions, and restored poll_list
handling to the old style to fix mutual exclusion issues. -DaveM ]
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-10-04 07:41:36 +08:00
|
|
|
static int epic_poll(struct napi_struct *napi, int budget);
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
static irqreturn_t epic_interrupt(int irq, void *dev_instance);
|
2005-04-17 06:20:36 +08:00
|
|
|
static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
|
2006-09-14 02:30:00 +08:00
|
|
|
static const struct ethtool_ops netdev_ethtool_ops;
|
2005-04-17 06:20:36 +08:00
|
|
|
static int epic_close(struct net_device *dev);
|
|
|
|
static struct net_device_stats *epic_get_stats(struct net_device *dev);
|
|
|
|
static void set_rx_mode(struct net_device *dev);
|
|
|
|
|
2009-01-08 09:27:39 +08:00
|
|
|
static const struct net_device_ops epic_netdev_ops = {
|
|
|
|
.ndo_open = epic_open,
|
|
|
|
.ndo_stop = epic_close,
|
|
|
|
.ndo_start_xmit = epic_start_xmit,
|
|
|
|
.ndo_tx_timeout = epic_tx_timeout,
|
|
|
|
.ndo_get_stats = epic_get_stats,
|
2011-08-16 14:29:01 +08:00
|
|
|
.ndo_set_rx_mode = set_rx_mode,
|
2009-01-08 09:27:39 +08:00
|
|
|
.ndo_do_ioctl = netdev_ioctl,
|
|
|
|
.ndo_set_mac_address = eth_mac_addr,
|
|
|
|
.ndo_validate_addr = eth_validate_addr,
|
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-12-06 22:30:56 +08:00
|
|
|
static int epic_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
static int card_idx = -1;
|
2012-03-13 19:04:26 +08:00
|
|
|
void __iomem *ioaddr;
|
2005-04-17 06:20:36 +08:00
|
|
|
int chip_idx = (int) ent->driver_data;
|
|
|
|
int irq;
|
|
|
|
struct net_device *dev;
|
|
|
|
struct epic_private *ep;
|
|
|
|
int i, ret, option = 0, duplex = 0;
|
|
|
|
void *ring_space;
|
|
|
|
dma_addr_t ring_dma;
|
|
|
|
|
|
|
|
/* when built into the kernel, we only print version if device is found */
|
|
|
|
#ifndef MODULE
|
2013-11-01 20:53:30 +08:00
|
|
|
pr_info_once("%s%s\n", version, version2);
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
2006-05-27 09:39:03 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
card_idx++;
|
2006-05-27 09:39:03 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
ret = pci_enable_device(pdev);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
irq = pdev->irq;
|
|
|
|
|
2006-06-27 19:38:33 +08:00
|
|
|
if (pci_resource_len(pdev, 0) < EPIC_TOTAL_SIZE) {
|
2006-06-27 23:39:50 +08:00
|
|
|
dev_err(&pdev->dev, "no PCI region space\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
ret = -ENODEV;
|
|
|
|
goto err_out_disable;
|
|
|
|
}
|
2006-05-27 09:39:03 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
pci_set_master(pdev);
|
|
|
|
|
|
|
|
ret = pci_request_regions(pdev, DRV_NAME);
|
|
|
|
if (ret < 0)
|
|
|
|
goto err_out_disable;
|
|
|
|
|
|
|
|
ret = -ENOMEM;
|
|
|
|
|
|
|
|
dev = alloc_etherdev(sizeof (*ep));
|
2012-01-29 21:47:52 +08:00
|
|
|
if (!dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
goto err_out_free_res;
|
2012-01-29 21:47:52 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
SET_NETDEV_DEV(dev, &pdev->dev);
|
|
|
|
|
2012-03-13 19:04:26 +08:00
|
|
|
ioaddr = pci_iomap(pdev, EPIC_BAR, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!ioaddr) {
|
2006-06-27 23:39:50 +08:00
|
|
|
dev_err(&pdev->dev, "ioremap failed\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
goto err_out_free_netdev;
|
|
|
|
}
|
|
|
|
|
|
|
|
pci_set_drvdata(pdev, dev);
|
2008-11-13 15:38:14 +08:00
|
|
|
ep = netdev_priv(dev);
|
2012-03-13 19:04:26 +08:00
|
|
|
ep->ioaddr = ioaddr;
|
2005-04-17 06:20:36 +08:00
|
|
|
ep->mii.dev = dev;
|
|
|
|
ep->mii.mdio_read = mdio_read;
|
|
|
|
ep->mii.mdio_write = mdio_write;
|
|
|
|
ep->mii.phy_id_mask = 0x1f;
|
|
|
|
ep->mii.reg_num_mask = 0x1f;
|
|
|
|
|
|
|
|
ring_space = pci_alloc_consistent(pdev, TX_TOTAL_SIZE, &ring_dma);
|
|
|
|
if (!ring_space)
|
|
|
|
goto err_out_iounmap;
|
2011-06-17 03:08:06 +08:00
|
|
|
ep->tx_ring = ring_space;
|
2005-04-17 06:20:36 +08:00
|
|
|
ep->tx_ring_dma = ring_dma;
|
|
|
|
|
|
|
|
ring_space = pci_alloc_consistent(pdev, RX_TOTAL_SIZE, &ring_dma);
|
|
|
|
if (!ring_space)
|
|
|
|
goto err_out_unmap_tx;
|
2011-06-17 03:08:06 +08:00
|
|
|
ep->rx_ring = ring_space;
|
2005-04-17 06:20:36 +08:00
|
|
|
ep->rx_ring_dma = ring_dma;
|
|
|
|
|
|
|
|
if (dev->mem_start) {
|
|
|
|
option = dev->mem_start;
|
|
|
|
duplex = (dev->mem_start & 16) ? 1 : 0;
|
|
|
|
} else if (card_idx >= 0 && card_idx < MAX_UNITS) {
|
|
|
|
if (options[card_idx] >= 0)
|
|
|
|
option = options[card_idx];
|
|
|
|
if (full_duplex[card_idx] >= 0)
|
|
|
|
duplex = full_duplex[card_idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_init(&ep->lock);
|
|
|
|
spin_lock_init(&ep->napi_lock);
|
|
|
|
|
|
|
|
/* Bring the chip out of low-power mode. */
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(GENCTL, 0x4200);
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Magic?! If we don't set this bit the MII interface won't work. */
|
|
|
|
/* This magic is documented in SMSC app note 7.15 */
|
|
|
|
for (i = 16; i > 0; i--)
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(TEST1, 0x0008);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Turn on the MII transceiver. */
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(MIICfg, 0x12);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (chip_idx == 1)
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(NVCTL, (er32(NVCTL) & ~0x003c) | 0x4800);
|
|
|
|
ew32(GENCTL, 0x0200);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Note: the '175 does not have a serial EEPROM. */
|
|
|
|
for (i = 0; i < 3; i++)
|
2012-03-13 19:04:26 +08:00
|
|
|
((__le16 *)dev->dev_addr)[i] = cpu_to_le16(er16(LAN0 + i*4));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (debug > 2) {
|
2013-11-01 20:53:30 +08:00
|
|
|
dev_dbg(&pdev->dev, "EEPROM contents:\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
for (i = 0; i < 64; i++)
|
2013-11-01 20:53:30 +08:00
|
|
|
pr_cont(" %4.4x%s", read_eeprom(ep, i),
|
2005-04-17 06:20:36 +08:00
|
|
|
i % 16 == 15 ? "\n" : "");
|
|
|
|
}
|
|
|
|
|
|
|
|
ep->pci_dev = pdev;
|
|
|
|
ep->chip_id = chip_idx;
|
|
|
|
ep->chip_flags = pci_id_tbl[chip_idx].drv_flags;
|
2006-05-27 09:39:03 +08:00
|
|
|
ep->irq_mask =
|
2005-04-17 06:20:36 +08:00
|
|
|
(ep->chip_flags & TYPE2_INTR ? PCIBusErr175 : PCIBusErr170)
|
|
|
|
| CntFull | TxUnderrun | EpicNapiEvent;
|
|
|
|
|
|
|
|
/* Find the connected MII xcvrs.
|
|
|
|
Doing this in open() would allow detecting external xcvrs later, but
|
|
|
|
takes much time and no cards have external MII. */
|
|
|
|
{
|
|
|
|
int phy, phy_idx = 0;
|
|
|
|
for (phy = 1; phy < 32 && phy_idx < sizeof(ep->phys); phy++) {
|
|
|
|
int mii_status = mdio_read(dev, phy, MII_BMSR);
|
|
|
|
if (mii_status != 0xffff && mii_status != 0x0000) {
|
|
|
|
ep->phys[phy_idx++] = phy;
|
2006-06-27 23:39:50 +08:00
|
|
|
dev_info(&pdev->dev,
|
[netdrvr] Use dev_printk() when ethernet interface isn't available
For messages prior to register_netdev(), prefer dev_printk() because
that prints out both our driver name and our [PCI | whatever] bus id.
Updates: 8139{cp,too}, b44, bnx2, cassini, {eepro,epic}100, fealnx,
hamachi, ne2k-pci, ns83820, pci-skeleton, r8169.
Signed-off-by: Jeff Garzik <jeff@garzik.org>
2006-06-27 22:47:51 +08:00
|
|
|
"MII transceiver #%d control "
|
|
|
|
"%4.4x status %4.4x.\n",
|
|
|
|
phy, mdio_read(dev, phy, 0), mii_status);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ep->mii_phy_cnt = phy_idx;
|
|
|
|
if (phy_idx != 0) {
|
|
|
|
phy = ep->phys[0];
|
|
|
|
ep->mii.advertising = mdio_read(dev, phy, MII_ADVERTISE);
|
2006-06-27 23:39:50 +08:00
|
|
|
dev_info(&pdev->dev,
|
[netdrvr] Use dev_printk() when ethernet interface isn't available
For messages prior to register_netdev(), prefer dev_printk() because
that prints out both our driver name and our [PCI | whatever] bus id.
Updates: 8139{cp,too}, b44, bnx2, cassini, {eepro,epic}100, fealnx,
hamachi, ne2k-pci, ns83820, pci-skeleton, r8169.
Signed-off-by: Jeff Garzik <jeff@garzik.org>
2006-06-27 22:47:51 +08:00
|
|
|
"Autonegotiation advertising %4.4x link "
|
2005-04-17 06:20:36 +08:00
|
|
|
"partner %4.4x.\n",
|
[netdrvr] Use dev_printk() when ethernet interface isn't available
For messages prior to register_netdev(), prefer dev_printk() because
that prints out both our driver name and our [PCI | whatever] bus id.
Updates: 8139{cp,too}, b44, bnx2, cassini, {eepro,epic}100, fealnx,
hamachi, ne2k-pci, ns83820, pci-skeleton, r8169.
Signed-off-by: Jeff Garzik <jeff@garzik.org>
2006-06-27 22:47:51 +08:00
|
|
|
ep->mii.advertising, mdio_read(dev, phy, 5));
|
2005-04-17 06:20:36 +08:00
|
|
|
} else if ( ! (ep->chip_flags & NO_MII)) {
|
2006-06-27 23:39:50 +08:00
|
|
|
dev_warn(&pdev->dev,
|
[netdrvr] Use dev_printk() when ethernet interface isn't available
For messages prior to register_netdev(), prefer dev_printk() because
that prints out both our driver name and our [PCI | whatever] bus id.
Updates: 8139{cp,too}, b44, bnx2, cassini, {eepro,epic}100, fealnx,
hamachi, ne2k-pci, ns83820, pci-skeleton, r8169.
Signed-off-by: Jeff Garzik <jeff@garzik.org>
2006-06-27 22:47:51 +08:00
|
|
|
"***WARNING***: No MII transceiver found!\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Use the known PHY address of the EPII. */
|
|
|
|
ep->phys[0] = 3;
|
|
|
|
}
|
|
|
|
ep->mii.phy_id = ep->phys[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Turn off the MII xcvr (175 only!), leave the chip in low-power mode. */
|
|
|
|
if (ep->chip_flags & MII_PWRDWN)
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(NVCTL, er32(NVCTL) & ~0x483c);
|
|
|
|
ew32(GENCTL, 0x0008);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* The lower four bits are the media type. */
|
|
|
|
if (duplex) {
|
|
|
|
ep->mii.force_media = ep->mii.full_duplex = 1;
|
2006-06-27 23:39:50 +08:00
|
|
|
dev_info(&pdev->dev, "Forced full duplex requested.\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
dev->if_port = ep->default_port = option;
|
|
|
|
|
|
|
|
/* The Epic-specific entries in the device structure. */
|
2009-01-08 09:27:39 +08:00
|
|
|
dev->netdev_ops = &epic_netdev_ops;
|
2005-04-17 06:20:36 +08:00
|
|
|
dev->ethtool_ops = &netdev_ethtool_ops;
|
|
|
|
dev->watchdog_timeo = TX_TIMEOUT;
|
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net
device, and some have a single interrupt doorbell for several
queues.
In either case, it's easier to support layouts like that if the
structure representing the poll is independant from the net
device itself.
The signature of the ->poll() call back goes from:
int foo_poll(struct net_device *dev, int *budget)
to
int foo_poll(struct napi_struct *napi, int budget)
The caller is returned the number of RX packets processed (or
the number of "NAPI credits" consumed if you want to get
abstract). The callee no longer messes around bumping
dev->quota, *budget, etc. because that is all handled in the
caller upon return.
The napi_struct is to be embedded in the device driver private data
structures.
Furthermore, it is the driver's responsibility to disable all NAPI
instances in it's ->stop() device close handler. Since the
napi_struct is privatized into the driver's private data structures,
only the driver knows how to get at all of the napi_struct instances
it may have per-device.
With lots of help and suggestions from Rusty Russell, Roland Dreier,
Michael Chan, Jeff Garzik, and Jamal Hadi Salim.
Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra,
Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan.
[ Ported to current tree and all drivers converted. Integrated
Stephen's follow-on kerneldoc additions, and restored poll_list
handling to the old style to fix mutual exclusion issues. -DaveM ]
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-10-04 07:41:36 +08:00
|
|
|
netif_napi_add(dev, &ep->napi, epic_poll, 64);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
ret = register_netdev(dev);
|
|
|
|
if (ret < 0)
|
|
|
|
goto err_out_unmap_rx;
|
|
|
|
|
2013-11-01 20:53:30 +08:00
|
|
|
netdev_info(dev, "%s at %lx, IRQ %d, %pM\n",
|
|
|
|
pci_id_tbl[chip_idx].name,
|
|
|
|
(long)pci_resource_start(pdev, EPIC_BAR), pdev->irq,
|
|
|
|
dev->dev_addr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
err_out_unmap_rx:
|
|
|
|
pci_free_consistent(pdev, RX_TOTAL_SIZE, ep->rx_ring, ep->rx_ring_dma);
|
|
|
|
err_out_unmap_tx:
|
|
|
|
pci_free_consistent(pdev, TX_TOTAL_SIZE, ep->tx_ring, ep->tx_ring_dma);
|
|
|
|
err_out_iounmap:
|
2012-03-13 19:04:26 +08:00
|
|
|
pci_iounmap(pdev, ioaddr);
|
2005-04-17 06:20:36 +08:00
|
|
|
err_out_free_netdev:
|
|
|
|
free_netdev(dev);
|
|
|
|
err_out_free_res:
|
|
|
|
pci_release_regions(pdev);
|
|
|
|
err_out_disable:
|
|
|
|
pci_disable_device(pdev);
|
|
|
|
goto out;
|
|
|
|
}
|
2006-05-27 09:39:03 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Serial EEPROM section. */
|
|
|
|
|
|
|
|
/* EEPROM_Ctrl bits. */
|
|
|
|
#define EE_SHIFT_CLK 0x04 /* EEPROM shift clock. */
|
|
|
|
#define EE_CS 0x02 /* EEPROM chip select. */
|
|
|
|
#define EE_DATA_WRITE 0x08 /* EEPROM chip data in. */
|
|
|
|
#define EE_WRITE_0 0x01
|
|
|
|
#define EE_WRITE_1 0x09
|
|
|
|
#define EE_DATA_READ 0x10 /* EEPROM chip data out. */
|
|
|
|
#define EE_ENB (0x0001 | EE_CS)
|
|
|
|
|
|
|
|
/* Delay between EEPROM clock transitions.
|
|
|
|
This serves to flush the operation to the PCI bus.
|
|
|
|
*/
|
|
|
|
|
2012-03-13 19:04:26 +08:00
|
|
|
#define eeprom_delay() er32(EECTL)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* The EEPROM commands include the alway-set leading bit. */
|
|
|
|
#define EE_WRITE_CMD (5 << 6)
|
|
|
|
#define EE_READ64_CMD (6 << 6)
|
|
|
|
#define EE_READ256_CMD (6 << 8)
|
|
|
|
#define EE_ERASE_CMD (7 << 6)
|
|
|
|
|
|
|
|
static void epic_disable_int(struct net_device *dev, struct epic_private *ep)
|
|
|
|
{
|
2012-03-13 19:04:26 +08:00
|
|
|
void __iomem *ioaddr = ep->ioaddr;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(INTMASK, 0x00000000);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2012-03-13 19:04:26 +08:00
|
|
|
static inline void __epic_pci_commit(void __iomem *ioaddr)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
#ifndef USE_IO_OPS
|
2012-03-13 19:04:26 +08:00
|
|
|
er32(INTMASK);
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void epic_napi_irq_off(struct net_device *dev,
|
|
|
|
struct epic_private *ep)
|
|
|
|
{
|
2012-03-13 19:04:26 +08:00
|
|
|
void __iomem *ioaddr = ep->ioaddr;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(INTMASK, ep->irq_mask & ~EpicNapiEvent);
|
2005-04-17 06:20:36 +08:00
|
|
|
__epic_pci_commit(ioaddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void epic_napi_irq_on(struct net_device *dev,
|
|
|
|
struct epic_private *ep)
|
|
|
|
{
|
2012-03-13 19:04:26 +08:00
|
|
|
void __iomem *ioaddr = ep->ioaddr;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* No need to commit possible posted write */
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(INTMASK, ep->irq_mask | EpicNapiEvent);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2012-12-03 22:23:42 +08:00
|
|
|
static int read_eeprom(struct epic_private *ep, int location)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-03-13 19:04:26 +08:00
|
|
|
void __iomem *ioaddr = ep->ioaddr;
|
2005-04-17 06:20:36 +08:00
|
|
|
int i;
|
|
|
|
int retval = 0;
|
|
|
|
int read_cmd = location |
|
2012-03-13 19:04:26 +08:00
|
|
|
(er32(EECTL) & 0x40 ? EE_READ64_CMD : EE_READ256_CMD);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(EECTL, EE_ENB & ~EE_CS);
|
|
|
|
ew32(EECTL, EE_ENB);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Shift the read command bits out. */
|
|
|
|
for (i = 12; i >= 0; i--) {
|
|
|
|
short dataval = (read_cmd & (1 << i)) ? EE_WRITE_1 : EE_WRITE_0;
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(EECTL, EE_ENB | dataval);
|
2005-04-17 06:20:36 +08:00
|
|
|
eeprom_delay();
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(EECTL, EE_ENB | dataval | EE_SHIFT_CLK);
|
2005-04-17 06:20:36 +08:00
|
|
|
eeprom_delay();
|
|
|
|
}
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(EECTL, EE_ENB);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
for (i = 16; i > 0; i--) {
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(EECTL, EE_ENB | EE_SHIFT_CLK);
|
2005-04-17 06:20:36 +08:00
|
|
|
eeprom_delay();
|
2012-03-13 19:04:26 +08:00
|
|
|
retval = (retval << 1) | ((er32(EECTL) & EE_DATA_READ) ? 1 : 0);
|
|
|
|
ew32(EECTL, EE_ENB);
|
2005-04-17 06:20:36 +08:00
|
|
|
eeprom_delay();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Terminate the EEPROM access. */
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(EECTL, EE_ENB & ~EE_CS);
|
2005-04-17 06:20:36 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MII_READOP 1
|
|
|
|
#define MII_WRITEOP 2
|
|
|
|
static int mdio_read(struct net_device *dev, int phy_id, int location)
|
|
|
|
{
|
2012-03-13 19:04:26 +08:00
|
|
|
struct epic_private *ep = netdev_priv(dev);
|
|
|
|
void __iomem *ioaddr = ep->ioaddr;
|
2005-04-17 06:20:36 +08:00
|
|
|
int read_cmd = (phy_id << 9) | (location << 4) | MII_READOP;
|
|
|
|
int i;
|
|
|
|
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(MIICtrl, read_cmd);
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Typical operation takes 25 loops. */
|
|
|
|
for (i = 400; i > 0; i--) {
|
|
|
|
barrier();
|
2012-03-13 19:04:26 +08:00
|
|
|
if ((er32(MIICtrl) & MII_READOP) == 0) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Work around read failure bug. */
|
2009-12-03 15:58:21 +08:00
|
|
|
if (phy_id == 1 && location < 6 &&
|
2012-03-13 19:04:26 +08:00
|
|
|
er16(MIIData) == 0xffff) {
|
|
|
|
ew32(MIICtrl, read_cmd);
|
2005-04-17 06:20:36 +08:00
|
|
|
continue;
|
|
|
|
}
|
2012-03-13 19:04:26 +08:00
|
|
|
return er16(MIIData);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0xffff;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mdio_write(struct net_device *dev, int phy_id, int loc, int value)
|
|
|
|
{
|
2012-03-13 19:04:26 +08:00
|
|
|
struct epic_private *ep = netdev_priv(dev);
|
|
|
|
void __iomem *ioaddr = ep->ioaddr;
|
2005-04-17 06:20:36 +08:00
|
|
|
int i;
|
|
|
|
|
2012-03-13 19:04:26 +08:00
|
|
|
ew16(MIIData, value);
|
|
|
|
ew32(MIICtrl, (phy_id << 9) | (loc << 4) | MII_WRITEOP);
|
2006-05-27 09:39:03 +08:00
|
|
|
for (i = 10000; i > 0; i--) {
|
2005-04-17 06:20:36 +08:00
|
|
|
barrier();
|
2012-03-13 19:04:26 +08:00
|
|
|
if ((er32(MIICtrl) & MII_WRITEOP) == 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-27 09:39:03 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static int epic_open(struct net_device *dev)
|
|
|
|
{
|
2008-11-13 15:38:14 +08:00
|
|
|
struct epic_private *ep = netdev_priv(dev);
|
2012-03-13 19:04:26 +08:00
|
|
|
void __iomem *ioaddr = ep->ioaddr;
|
|
|
|
const int irq = ep->pci_dev->irq;
|
|
|
|
int rc, i;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Soft reset the chip. */
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(GENCTL, 0x4001);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net
device, and some have a single interrupt doorbell for several
queues.
In either case, it's easier to support layouts like that if the
structure representing the poll is independant from the net
device itself.
The signature of the ->poll() call back goes from:
int foo_poll(struct net_device *dev, int *budget)
to
int foo_poll(struct napi_struct *napi, int budget)
The caller is returned the number of RX packets processed (or
the number of "NAPI credits" consumed if you want to get
abstract). The callee no longer messes around bumping
dev->quota, *budget, etc. because that is all handled in the
caller upon return.
The napi_struct is to be embedded in the device driver private data
structures.
Furthermore, it is the driver's responsibility to disable all NAPI
instances in it's ->stop() device close handler. Since the
napi_struct is privatized into the driver's private data structures,
only the driver knows how to get at all of the napi_struct instances
it may have per-device.
With lots of help and suggestions from Rusty Russell, Roland Dreier,
Michael Chan, Jeff Garzik, and Jamal Hadi Salim.
Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra,
Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan.
[ Ported to current tree and all drivers converted. Integrated
Stephen's follow-on kerneldoc additions, and restored poll_list
handling to the old style to fix mutual exclusion issues. -DaveM ]
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-10-04 07:41:36 +08:00
|
|
|
napi_enable(&ep->napi);
|
2012-03-13 19:04:26 +08:00
|
|
|
rc = request_irq(irq, epic_interrupt, IRQF_SHARED, dev->name, dev);
|
|
|
|
if (rc) {
|
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net
device, and some have a single interrupt doorbell for several
queues.
In either case, it's easier to support layouts like that if the
structure representing the poll is independant from the net
device itself.
The signature of the ->poll() call back goes from:
int foo_poll(struct net_device *dev, int *budget)
to
int foo_poll(struct napi_struct *napi, int budget)
The caller is returned the number of RX packets processed (or
the number of "NAPI credits" consumed if you want to get
abstract). The callee no longer messes around bumping
dev->quota, *budget, etc. because that is all handled in the
caller upon return.
The napi_struct is to be embedded in the device driver private data
structures.
Furthermore, it is the driver's responsibility to disable all NAPI
instances in it's ->stop() device close handler. Since the
napi_struct is privatized into the driver's private data structures,
only the driver knows how to get at all of the napi_struct instances
it may have per-device.
With lots of help and suggestions from Rusty Russell, Roland Dreier,
Michael Chan, Jeff Garzik, and Jamal Hadi Salim.
Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra,
Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan.
[ Ported to current tree and all drivers converted. Integrated
Stephen's follow-on kerneldoc additions, and restored poll_list
handling to the old style to fix mutual exclusion issues. -DaveM ]
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-10-04 07:41:36 +08:00
|
|
|
napi_disable(&ep->napi);
|
2012-03-13 19:04:26 +08:00
|
|
|
return rc;
|
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net
device, and some have a single interrupt doorbell for several
queues.
In either case, it's easier to support layouts like that if the
structure representing the poll is independant from the net
device itself.
The signature of the ->poll() call back goes from:
int foo_poll(struct net_device *dev, int *budget)
to
int foo_poll(struct napi_struct *napi, int budget)
The caller is returned the number of RX packets processed (or
the number of "NAPI credits" consumed if you want to get
abstract). The callee no longer messes around bumping
dev->quota, *budget, etc. because that is all handled in the
caller upon return.
The napi_struct is to be embedded in the device driver private data
structures.
Furthermore, it is the driver's responsibility to disable all NAPI
instances in it's ->stop() device close handler. Since the
napi_struct is privatized into the driver's private data structures,
only the driver knows how to get at all of the napi_struct instances
it may have per-device.
With lots of help and suggestions from Rusty Russell, Roland Dreier,
Michael Chan, Jeff Garzik, and Jamal Hadi Salim.
Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra,
Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan.
[ Ported to current tree and all drivers converted. Integrated
Stephen's follow-on kerneldoc additions, and restored poll_list
handling to the old style to fix mutual exclusion issues. -DaveM ]
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-10-04 07:41:36 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
epic_init_ring(dev);
|
|
|
|
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(GENCTL, 0x4000);
|
2005-04-17 06:20:36 +08:00
|
|
|
/* This magic is documented in SMSC app note 7.15 */
|
|
|
|
for (i = 16; i > 0; i--)
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(TEST1, 0x0008);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Pull the chip out of low-power mode, enable interrupts, and set for
|
|
|
|
PCI read multiple. The MIIcfg setting and strange write order are
|
|
|
|
required by the details of which bits are reset and the transceiver
|
|
|
|
wiring on the Ositech CardBus card.
|
|
|
|
*/
|
|
|
|
#if 0
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(MIICfg, dev->if_port == 1 ? 0x13 : 0x12);
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
if (ep->chip_flags & MII_PWRDWN)
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(NVCTL, (er32(NVCTL) & ~0x003c) | 0x4800);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-03-17 06:22:04 +08:00
|
|
|
/* Tell the chip to byteswap descriptors on big-endian hosts */
|
2010-06-02 18:36:53 +08:00
|
|
|
#ifdef __BIG_ENDIAN
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(GENCTL, 0x4432 | (RX_FIFO_THRESH << 8));
|
|
|
|
er32(GENCTL);
|
|
|
|
ew32(GENCTL, 0x0432 | (RX_FIFO_THRESH << 8));
|
2005-04-17 06:20:36 +08:00
|
|
|
#else
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(GENCTL, 0x4412 | (RX_FIFO_THRESH << 8));
|
|
|
|
er32(GENCTL);
|
|
|
|
ew32(GENCTL, 0x0412 | (RX_FIFO_THRESH << 8));
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
udelay(20); /* Looks like EPII needs that if you want reliable RX init. FIXME: pci posting bug? */
|
2006-05-27 09:39:03 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
for (i = 0; i < 3; i++)
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(LAN0 + i*4, le16_to_cpu(((__le16*)dev->dev_addr)[i]));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
ep->tx_threshold = TX_FIFO_THRESH;
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(TxThresh, ep->tx_threshold);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (media2miictl[dev->if_port & 15]) {
|
|
|
|
if (ep->mii_phy_cnt)
|
|
|
|
mdio_write(dev, ep->phys[0], MII_BMCR, media2miictl[dev->if_port&15]);
|
|
|
|
if (dev->if_port == 1) {
|
|
|
|
if (debug > 1)
|
2013-11-01 20:53:30 +08:00
|
|
|
netdev_info(dev, "Using the 10base2 transceiver, MII status %4.4x.\n",
|
|
|
|
mdio_read(dev, ep->phys[0], MII_BMSR));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int mii_lpa = mdio_read(dev, ep->phys[0], MII_LPA);
|
|
|
|
if (mii_lpa != 0xffff) {
|
|
|
|
if ((mii_lpa & LPA_100FULL) || (mii_lpa & 0x01C0) == LPA_10FULL)
|
|
|
|
ep->mii.full_duplex = 1;
|
|
|
|
else if (! (mii_lpa & LPA_LPACK))
|
|
|
|
mdio_write(dev, ep->phys[0], MII_BMCR, BMCR_ANENABLE|BMCR_ANRESTART);
|
|
|
|
if (debug > 1)
|
2013-11-01 20:53:30 +08:00
|
|
|
netdev_info(dev, "Setting %s-duplex based on MII xcvr %d register read of %4.4x.\n",
|
|
|
|
ep->mii.full_duplex ? "full"
|
|
|
|
: "half",
|
|
|
|
ep->phys[0], mii_lpa);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(TxCtrl, ep->mii.full_duplex ? 0x7f : 0x79);
|
|
|
|
ew32(PRxCDAR, ep->rx_ring_dma);
|
|
|
|
ew32(PTxCDAR, ep->tx_ring_dma);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Start the chip's Rx process. */
|
|
|
|
set_rx_mode(dev);
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(COMMAND, StartRx | RxQueued);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
netif_start_queue(dev);
|
|
|
|
|
|
|
|
/* Enable interrupts by setting the interrupt mask. */
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(INTMASK, RxError | RxHeader | EpicNapiEvent | CntFull |
|
|
|
|
((ep->chip_flags & TYPE2_INTR) ? PCIBusErr175 : PCIBusErr170) |
|
|
|
|
TxUnderrun);
|
|
|
|
|
|
|
|
if (debug > 1) {
|
2013-11-01 20:53:30 +08:00
|
|
|
netdev_dbg(dev, "epic_open() ioaddr %p IRQ %d status %4.4x %s-duplex.\n",
|
|
|
|
ioaddr, irq, er32(GENCTL),
|
|
|
|
ep->mii.full_duplex ? "full" : "half");
|
2012-03-13 19:04:26 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Set the timer to switch to check for link beat and perhaps switch
|
|
|
|
to an alternate media type. */
|
2017-10-27 13:55:42 +08:00
|
|
|
timer_setup(&ep->timer, epic_timer, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
ep->timer.expires = jiffies + 3*HZ;
|
|
|
|
add_timer(&ep->timer);
|
|
|
|
|
2012-03-13 19:04:26 +08:00
|
|
|
return rc;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset the chip to recover from a PCI transaction error.
|
|
|
|
This may occur at interrupt time. */
|
|
|
|
static void epic_pause(struct net_device *dev)
|
|
|
|
{
|
2012-03-13 19:04:26 +08:00
|
|
|
struct net_device_stats *stats = &dev->stats;
|
|
|
|
struct epic_private *ep = netdev_priv(dev);
|
|
|
|
void __iomem *ioaddr = ep->ioaddr;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
netif_stop_queue (dev);
|
2006-05-27 09:39:03 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Disable interrupts by clearing the interrupt mask. */
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(INTMASK, 0x00000000);
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Stop the chip's Tx and Rx DMA processes. */
|
2012-03-13 19:04:26 +08:00
|
|
|
ew16(COMMAND, StopRx | StopTxDMA | StopRxDMA);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Update the error counts. */
|
2012-03-13 19:04:26 +08:00
|
|
|
if (er16(COMMAND) != 0xffff) {
|
|
|
|
stats->rx_missed_errors += er8(MPCNT);
|
|
|
|
stats->rx_frame_errors += er8(ALICNT);
|
|
|
|
stats->rx_crc_errors += er8(CRCCNT);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove the packets on the Rx queue. */
|
|
|
|
epic_rx(dev, RX_RING_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void epic_restart(struct net_device *dev)
|
|
|
|
{
|
2008-11-13 15:38:14 +08:00
|
|
|
struct epic_private *ep = netdev_priv(dev);
|
2012-03-13 19:04:26 +08:00
|
|
|
void __iomem *ioaddr = ep->ioaddr;
|
2005-04-17 06:20:36 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Soft reset the chip. */
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(GENCTL, 0x4001);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-11-01 20:53:30 +08:00
|
|
|
netdev_dbg(dev, "Restarting the EPIC chip, Rx %d/%d Tx %d/%d.\n",
|
|
|
|
ep->cur_rx, ep->dirty_rx, ep->dirty_tx, ep->cur_tx);
|
2005-04-17 06:20:36 +08:00
|
|
|
udelay(1);
|
|
|
|
|
|
|
|
/* This magic is documented in SMSC app note 7.15 */
|
|
|
|
for (i = 16; i > 0; i--)
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(TEST1, 0x0008);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-06-02 18:36:53 +08:00
|
|
|
#ifdef __BIG_ENDIAN
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(GENCTL, 0x0432 | (RX_FIFO_THRESH << 8));
|
2005-04-17 06:20:36 +08:00
|
|
|
#else
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(GENCTL, 0x0412 | (RX_FIFO_THRESH << 8));
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(MIICfg, dev->if_port == 1 ? 0x13 : 0x12);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (ep->chip_flags & MII_PWRDWN)
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(NVCTL, (er32(NVCTL) & ~0x003c) | 0x4800);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
for (i = 0; i < 3; i++)
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(LAN0 + i*4, le16_to_cpu(((__le16*)dev->dev_addr)[i]));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
ep->tx_threshold = TX_FIFO_THRESH;
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(TxThresh, ep->tx_threshold);
|
|
|
|
ew32(TxCtrl, ep->mii.full_duplex ? 0x7f : 0x79);
|
|
|
|
ew32(PRxCDAR, ep->rx_ring_dma +
|
|
|
|
(ep->cur_rx % RX_RING_SIZE) * sizeof(struct epic_rx_desc));
|
|
|
|
ew32(PTxCDAR, ep->tx_ring_dma +
|
|
|
|
(ep->dirty_tx % TX_RING_SIZE) * sizeof(struct epic_tx_desc));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Start the chip's Rx process. */
|
|
|
|
set_rx_mode(dev);
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(COMMAND, StartRx | RxQueued);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Enable interrupts by setting the interrupt mask. */
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(INTMASK, RxError | RxHeader | EpicNapiEvent | CntFull |
|
|
|
|
((ep->chip_flags & TYPE2_INTR) ? PCIBusErr175 : PCIBusErr170) |
|
|
|
|
TxUnderrun);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-11-01 20:53:30 +08:00
|
|
|
netdev_dbg(dev, "epic_restart() done, cmd status %4.4x, ctl %4.4x interrupt %4.4x.\n",
|
|
|
|
er32(COMMAND), er32(GENCTL), er32(INTSTAT));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void check_media(struct net_device *dev)
|
|
|
|
{
|
2008-11-13 15:38:14 +08:00
|
|
|
struct epic_private *ep = netdev_priv(dev);
|
2012-03-13 19:04:26 +08:00
|
|
|
void __iomem *ioaddr = ep->ioaddr;
|
2005-04-17 06:20:36 +08:00
|
|
|
int mii_lpa = ep->mii_phy_cnt ? mdio_read(dev, ep->phys[0], MII_LPA) : 0;
|
|
|
|
int negotiated = mii_lpa & ep->mii.advertising;
|
|
|
|
int duplex = (negotiated & 0x0100) || (negotiated & 0x01C0) == 0x0040;
|
|
|
|
|
|
|
|
if (ep->mii.force_media)
|
|
|
|
return;
|
|
|
|
if (mii_lpa == 0xffff) /* Bogus read */
|
|
|
|
return;
|
|
|
|
if (ep->mii.full_duplex != duplex) {
|
|
|
|
ep->mii.full_duplex = duplex;
|
2013-11-01 20:53:30 +08:00
|
|
|
netdev_info(dev, "Setting %s-duplex based on MII #%d link partner capability of %4.4x.\n",
|
|
|
|
ep->mii.full_duplex ? "full" : "half",
|
|
|
|
ep->phys[0], mii_lpa);
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(TxCtrl, ep->mii.full_duplex ? 0x7F : 0x79);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-27 13:55:42 +08:00
|
|
|
static void epic_timer(struct timer_list *t)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2017-10-27 13:55:42 +08:00
|
|
|
struct epic_private *ep = from_timer(ep, t, timer);
|
|
|
|
struct net_device *dev = ep->mii.dev;
|
2012-03-13 19:04:26 +08:00
|
|
|
void __iomem *ioaddr = ep->ioaddr;
|
2005-04-17 06:20:36 +08:00
|
|
|
int next_tick = 5*HZ;
|
|
|
|
|
|
|
|
if (debug > 3) {
|
2013-11-01 20:53:30 +08:00
|
|
|
netdev_dbg(dev, "Media monitor tick, Tx status %8.8x.\n",
|
|
|
|
er32(TxSTAT));
|
|
|
|
netdev_dbg(dev, "Other registers are IntMask %4.4x IntStatus %4.4x RxStatus %4.4x.\n",
|
|
|
|
er32(INTMASK), er32(INTSTAT), er32(RxSTAT));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
check_media(dev);
|
|
|
|
|
|
|
|
ep->timer.expires = jiffies + next_tick;
|
|
|
|
add_timer(&ep->timer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void epic_tx_timeout(struct net_device *dev)
|
|
|
|
{
|
2008-11-13 15:38:14 +08:00
|
|
|
struct epic_private *ep = netdev_priv(dev);
|
2012-03-13 19:04:26 +08:00
|
|
|
void __iomem *ioaddr = ep->ioaddr;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (debug > 0) {
|
2013-11-01 20:53:30 +08:00
|
|
|
netdev_warn(dev, "Transmit timeout using MII device, Tx status %4.4x.\n",
|
|
|
|
er16(TxSTAT));
|
2005-04-17 06:20:36 +08:00
|
|
|
if (debug > 1) {
|
2013-11-01 20:53:30 +08:00
|
|
|
netdev_dbg(dev, "Tx indices: dirty_tx %d, cur_tx %d.\n",
|
|
|
|
ep->dirty_tx, ep->cur_tx);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
2012-03-13 19:04:26 +08:00
|
|
|
if (er16(TxSTAT) & 0x10) { /* Tx FIFO underflow. */
|
2010-07-05 10:13:20 +08:00
|
|
|
dev->stats.tx_fifo_errors++;
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(COMMAND, RestartTx);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
|
|
|
epic_restart(dev);
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(COMMAND, TxQueued);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2016-05-03 22:33:13 +08:00
|
|
|
netif_trans_update(dev); /* prevent tx timeout */
|
2010-07-05 10:13:20 +08:00
|
|
|
dev->stats.tx_errors++;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!ep->tx_full)
|
|
|
|
netif_wake_queue(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the Rx and Tx rings, along with various 'dev' bits. */
|
|
|
|
static void epic_init_ring(struct net_device *dev)
|
|
|
|
{
|
2008-11-13 15:38:14 +08:00
|
|
|
struct epic_private *ep = netdev_priv(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
ep->tx_full = 0;
|
|
|
|
ep->dirty_tx = ep->cur_tx = 0;
|
|
|
|
ep->cur_rx = ep->dirty_rx = 0;
|
|
|
|
ep->rx_buf_sz = (dev->mtu <= 1500 ? PKT_BUF_SZ : dev->mtu + 32);
|
|
|
|
|
|
|
|
/* Initialize all Rx descriptors. */
|
|
|
|
for (i = 0; i < RX_RING_SIZE; i++) {
|
|
|
|
ep->rx_ring[i].rxstatus = 0;
|
2008-03-17 06:22:04 +08:00
|
|
|
ep->rx_ring[i].buflength = ep->rx_buf_sz;
|
2006-05-27 09:39:03 +08:00
|
|
|
ep->rx_ring[i].next = ep->rx_ring_dma +
|
2005-04-17 06:20:36 +08:00
|
|
|
(i+1)*sizeof(struct epic_rx_desc);
|
|
|
|
ep->rx_skbuff[i] = NULL;
|
|
|
|
}
|
|
|
|
/* Mark the last entry as wrapping the ring. */
|
|
|
|
ep->rx_ring[i-1].next = ep->rx_ring_dma;
|
|
|
|
|
|
|
|
/* Fill in the Rx buffers. Handle allocation failure gracefully. */
|
|
|
|
for (i = 0; i < RX_RING_SIZE; i++) {
|
2012-02-06 19:16:13 +08:00
|
|
|
struct sk_buff *skb = netdev_alloc_skb(dev, ep->rx_buf_sz + 2);
|
2005-04-17 06:20:36 +08:00
|
|
|
ep->rx_skbuff[i] = skb;
|
|
|
|
if (skb == NULL)
|
|
|
|
break;
|
|
|
|
skb_reserve(skb, 2); /* 16 byte align the IP header. */
|
2006-05-27 09:39:03 +08:00
|
|
|
ep->rx_ring[i].bufaddr = pci_map_single(ep->pci_dev,
|
2005-06-29 06:25:31 +08:00
|
|
|
skb->data, ep->rx_buf_sz, PCI_DMA_FROMDEVICE);
|
2008-03-17 06:22:04 +08:00
|
|
|
ep->rx_ring[i].rxstatus = DescOwn;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
ep->dirty_rx = (unsigned int)(i - RX_RING_SIZE);
|
|
|
|
|
|
|
|
/* The Tx buffer descriptor is filled in as needed, but we
|
|
|
|
do need to clear the ownership bit. */
|
|
|
|
for (i = 0; i < TX_RING_SIZE; i++) {
|
|
|
|
ep->tx_skbuff[i] = NULL;
|
|
|
|
ep->tx_ring[i].txstatus = 0x0000;
|
2006-05-27 09:39:03 +08:00
|
|
|
ep->tx_ring[i].next = ep->tx_ring_dma +
|
2005-04-17 06:20:36 +08:00
|
|
|
(i+1)*sizeof(struct epic_tx_desc);
|
|
|
|
}
|
|
|
|
ep->tx_ring[i-1].next = ep->tx_ring_dma;
|
|
|
|
}
|
|
|
|
|
2009-09-01 03:50:58 +08:00
|
|
|
static netdev_tx_t epic_start_xmit(struct sk_buff *skb, struct net_device *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-11-13 15:38:14 +08:00
|
|
|
struct epic_private *ep = netdev_priv(dev);
|
2012-03-13 19:04:26 +08:00
|
|
|
void __iomem *ioaddr = ep->ioaddr;
|
2005-04-17 06:20:36 +08:00
|
|
|
int entry, free_count;
|
|
|
|
u32 ctrl_word;
|
|
|
|
unsigned long flags;
|
2006-05-27 09:39:03 +08:00
|
|
|
|
2006-06-23 17:06:41 +08:00
|
|
|
if (skb_padto(skb, ETH_ZLEN))
|
2009-06-23 14:03:08 +08:00
|
|
|
return NETDEV_TX_OK;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Caution: the write order is important here, set the field with the
|
|
|
|
"ownership" bit last. */
|
|
|
|
|
|
|
|
/* Calculate the next Tx descriptor entry. */
|
|
|
|
spin_lock_irqsave(&ep->lock, flags);
|
|
|
|
free_count = ep->cur_tx - ep->dirty_tx;
|
|
|
|
entry = ep->cur_tx % TX_RING_SIZE;
|
|
|
|
|
|
|
|
ep->tx_skbuff[entry] = skb;
|
2006-05-27 09:39:03 +08:00
|
|
|
ep->tx_ring[entry].bufaddr = pci_map_single(ep->pci_dev, skb->data,
|
2005-04-17 06:20:36 +08:00
|
|
|
skb->len, PCI_DMA_TODEVICE);
|
|
|
|
if (free_count < TX_QUEUE_LEN/2) {/* Typical path */
|
2008-03-17 06:22:04 +08:00
|
|
|
ctrl_word = 0x100000; /* No interrupt */
|
2005-04-17 06:20:36 +08:00
|
|
|
} else if (free_count == TX_QUEUE_LEN/2) {
|
2008-03-17 06:22:04 +08:00
|
|
|
ctrl_word = 0x140000; /* Tx-done intr. */
|
2005-04-17 06:20:36 +08:00
|
|
|
} else if (free_count < TX_QUEUE_LEN - 1) {
|
2008-03-17 06:22:04 +08:00
|
|
|
ctrl_word = 0x100000; /* No Tx-done intr. */
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
|
|
|
/* Leave room for an additional entry. */
|
2008-03-17 06:22:04 +08:00
|
|
|
ctrl_word = 0x140000; /* Tx-done intr. */
|
2005-04-17 06:20:36 +08:00
|
|
|
ep->tx_full = 1;
|
|
|
|
}
|
2008-03-17 06:22:04 +08:00
|
|
|
ep->tx_ring[entry].buflength = ctrl_word | skb->len;
|
2005-04-17 06:20:36 +08:00
|
|
|
ep->tx_ring[entry].txstatus =
|
|
|
|
((skb->len >= ETH_ZLEN ? skb->len : ETH_ZLEN) << 16)
|
2008-03-17 06:22:04 +08:00
|
|
|
| DescOwn;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
ep->cur_tx++;
|
|
|
|
if (ep->tx_full)
|
|
|
|
netif_stop_queue(dev);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&ep->lock, flags);
|
|
|
|
/* Trigger an immediate transmit demand. */
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(COMMAND, TxQueued);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (debug > 4)
|
2013-11-01 20:53:30 +08:00
|
|
|
netdev_dbg(dev, "Queued Tx packet size %d to slot %d, flag %2.2x Tx status %8.8x.\n",
|
|
|
|
skb->len, entry, ctrl_word, er32(TxSTAT));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-06-23 14:03:08 +08:00
|
|
|
return NETDEV_TX_OK;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void epic_tx_error(struct net_device *dev, struct epic_private *ep,
|
|
|
|
int status)
|
|
|
|
{
|
2010-07-05 10:13:20 +08:00
|
|
|
struct net_device_stats *stats = &dev->stats;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#ifndef final_version
|
|
|
|
/* There was an major error, log it. */
|
|
|
|
if (debug > 1)
|
2013-11-01 20:53:30 +08:00
|
|
|
netdev_dbg(dev, "Transmit error, Tx status %8.8x.\n",
|
|
|
|
status);
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
stats->tx_errors++;
|
|
|
|
if (status & 0x1050)
|
|
|
|
stats->tx_aborted_errors++;
|
|
|
|
if (status & 0x0008)
|
|
|
|
stats->tx_carrier_errors++;
|
|
|
|
if (status & 0x0040)
|
|
|
|
stats->tx_window_errors++;
|
|
|
|
if (status & 0x0010)
|
|
|
|
stats->tx_fifo_errors++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void epic_tx(struct net_device *dev, struct epic_private *ep)
|
|
|
|
{
|
|
|
|
unsigned int dirty_tx, cur_tx;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note: if this lock becomes a problem we can narrow the locked
|
|
|
|
* region at the cost of occasionally grabbing the lock more times.
|
|
|
|
*/
|
|
|
|
cur_tx = ep->cur_tx;
|
|
|
|
for (dirty_tx = ep->dirty_tx; cur_tx - dirty_tx > 0; dirty_tx++) {
|
|
|
|
struct sk_buff *skb;
|
|
|
|
int entry = dirty_tx % TX_RING_SIZE;
|
2008-03-17 06:22:04 +08:00
|
|
|
int txstatus = ep->tx_ring[entry].txstatus;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (txstatus & DescOwn)
|
|
|
|
break; /* It still hasn't been Txed */
|
|
|
|
|
|
|
|
if (likely(txstatus & 0x0001)) {
|
2010-07-05 10:13:20 +08:00
|
|
|
dev->stats.collisions += (txstatus >> 8) & 15;
|
|
|
|
dev->stats.tx_packets++;
|
|
|
|
dev->stats.tx_bytes += ep->tx_skbuff[entry]->len;
|
2005-04-17 06:20:36 +08:00
|
|
|
} else
|
|
|
|
epic_tx_error(dev, ep, txstatus);
|
|
|
|
|
|
|
|
/* Free the original skb. */
|
|
|
|
skb = ep->tx_skbuff[entry];
|
2006-05-27 09:39:03 +08:00
|
|
|
pci_unmap_single(ep->pci_dev, ep->tx_ring[entry].bufaddr,
|
2005-04-17 06:20:36 +08:00
|
|
|
skb->len, PCI_DMA_TODEVICE);
|
|
|
|
dev_kfree_skb_irq(skb);
|
|
|
|
ep->tx_skbuff[entry] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef final_version
|
|
|
|
if (cur_tx - dirty_tx > TX_RING_SIZE) {
|
2013-11-01 20:53:30 +08:00
|
|
|
netdev_warn(dev, "Out-of-sync dirty pointer, %d vs. %d, full=%d.\n",
|
|
|
|
dirty_tx, cur_tx, ep->tx_full);
|
2005-04-17 06:20:36 +08:00
|
|
|
dirty_tx += TX_RING_SIZE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
ep->dirty_tx = dirty_tx;
|
|
|
|
if (ep->tx_full && cur_tx - dirty_tx < TX_QUEUE_LEN - 4) {
|
|
|
|
/* The ring is no longer full, allow new TX entries. */
|
|
|
|
ep->tx_full = 0;
|
|
|
|
netif_wake_queue(dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The interrupt handler does all of the Rx thread work and cleans up
|
|
|
|
after the Tx thread. */
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
static irqreturn_t epic_interrupt(int irq, void *dev_instance)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct net_device *dev = dev_instance;
|
2008-11-13 15:38:14 +08:00
|
|
|
struct epic_private *ep = netdev_priv(dev);
|
2012-03-13 19:04:26 +08:00
|
|
|
void __iomem *ioaddr = ep->ioaddr;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned int handled = 0;
|
|
|
|
int status;
|
|
|
|
|
2012-03-13 19:04:26 +08:00
|
|
|
status = er32(INTSTAT);
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Acknowledge all of the current interrupt sources ASAP. */
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(INTSTAT, status & EpicNormalEvent);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (debug > 4) {
|
2013-11-01 20:53:30 +08:00
|
|
|
netdev_dbg(dev, "Interrupt, status=%#8.8x new intstat=%#8.8x.\n",
|
|
|
|
status, er32(INTSTAT));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((status & IntrSummary) == 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
handled = 1;
|
|
|
|
|
2017-02-05 07:24:53 +08:00
|
|
|
if (status & EpicNapiEvent) {
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_lock(&ep->napi_lock);
|
2009-01-20 08:43:59 +08:00
|
|
|
if (napi_schedule_prep(&ep->napi)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
epic_napi_irq_off(dev, ep);
|
2009-01-20 08:43:59 +08:00
|
|
|
__napi_schedule(&ep->napi);
|
2017-02-05 07:24:53 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock(&ep->napi_lock);
|
|
|
|
}
|
|
|
|
status &= ~EpicNapiEvent;
|
|
|
|
|
|
|
|
/* Check uncommon events all at once. */
|
|
|
|
if (status & (CntFull | TxUnderrun | PCIBusErr170 | PCIBusErr175)) {
|
2012-03-13 19:04:26 +08:00
|
|
|
struct net_device_stats *stats = &dev->stats;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (status == EpicRemoved)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Always update the error counts to avoid overhead later. */
|
2012-03-13 19:04:26 +08:00
|
|
|
stats->rx_missed_errors += er8(MPCNT);
|
|
|
|
stats->rx_frame_errors += er8(ALICNT);
|
|
|
|
stats->rx_crc_errors += er8(CRCCNT);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (status & TxUnderrun) { /* Tx FIFO underflow. */
|
2012-03-13 19:04:26 +08:00
|
|
|
stats->tx_fifo_errors++;
|
|
|
|
ew32(TxThresh, ep->tx_threshold += 128);
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Restart the transmit process. */
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(COMMAND, RestartTx);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
if (status & PCIBusErr170) {
|
2013-11-01 20:53:30 +08:00
|
|
|
netdev_err(dev, "PCI Bus Error! status %4.4x.\n",
|
|
|
|
status);
|
2005-04-17 06:20:36 +08:00
|
|
|
epic_pause(dev);
|
|
|
|
epic_restart(dev);
|
|
|
|
}
|
|
|
|
/* Clear all error sources. */
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(INTSTAT, status & 0x7f18);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (debug > 3) {
|
2013-11-01 20:53:30 +08:00
|
|
|
netdev_dbg(dev, "exit interrupt, intr_status=%#4.4x.\n",
|
|
|
|
status);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return IRQ_RETVAL(handled);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int epic_rx(struct net_device *dev, int budget)
|
|
|
|
{
|
2008-11-13 15:38:14 +08:00
|
|
|
struct epic_private *ep = netdev_priv(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
int entry = ep->cur_rx % RX_RING_SIZE;
|
|
|
|
int rx_work_limit = ep->dirty_rx + RX_RING_SIZE - ep->cur_rx;
|
|
|
|
int work_done = 0;
|
|
|
|
|
|
|
|
if (debug > 4)
|
2013-11-01 20:53:30 +08:00
|
|
|
netdev_dbg(dev, " In epic_rx(), entry %d %8.8x.\n", entry,
|
2005-04-17 06:20:36 +08:00
|
|
|
ep->rx_ring[entry].rxstatus);
|
|
|
|
|
|
|
|
if (rx_work_limit > budget)
|
|
|
|
rx_work_limit = budget;
|
|
|
|
|
|
|
|
/* If we own the next entry, it's a new packet. Send it up. */
|
2008-03-17 06:22:04 +08:00
|
|
|
while ((ep->rx_ring[entry].rxstatus & DescOwn) == 0) {
|
|
|
|
int status = ep->rx_ring[entry].rxstatus;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (debug > 4)
|
2013-11-01 20:53:30 +08:00
|
|
|
netdev_dbg(dev, " epic_rx() status was %8.8x.\n",
|
|
|
|
status);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (--rx_work_limit < 0)
|
|
|
|
break;
|
|
|
|
if (status & 0x2006) {
|
|
|
|
if (debug > 2)
|
2013-11-01 20:53:30 +08:00
|
|
|
netdev_dbg(dev, "epic_rx() error status was %8.8x.\n",
|
|
|
|
status);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (status & 0x2000) {
|
2013-11-01 20:53:30 +08:00
|
|
|
netdev_warn(dev, "Oversized Ethernet frame spanned multiple buffers, status %4.4x!\n",
|
|
|
|
status);
|
2010-07-05 10:13:20 +08:00
|
|
|
dev->stats.rx_length_errors++;
|
2005-04-17 06:20:36 +08:00
|
|
|
} else if (status & 0x0006)
|
|
|
|
/* Rx Frame errors are counted in hardware. */
|
2010-07-05 10:13:20 +08:00
|
|
|
dev->stats.rx_errors++;
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
|
|
|
/* Malloc up new buffer, compatible with net-2e. */
|
|
|
|
/* Omit the four octet CRC from the length. */
|
|
|
|
short pkt_len = (status >> 16) - 4;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
|
|
|
|
if (pkt_len > PKT_BUF_SZ - 4) {
|
2013-11-01 20:53:30 +08:00
|
|
|
netdev_err(dev, "Oversized Ethernet frame, status %x %d bytes.\n",
|
|
|
|
status, pkt_len);
|
2005-04-17 06:20:36 +08:00
|
|
|
pkt_len = 1514;
|
|
|
|
}
|
|
|
|
/* Check if the packet is long enough to accept without copying
|
|
|
|
to a minimally-sized skbuff. */
|
2009-12-03 15:58:21 +08:00
|
|
|
if (pkt_len < rx_copybreak &&
|
2012-02-06 19:16:13 +08:00
|
|
|
(skb = netdev_alloc_skb(dev, pkt_len + 2)) != NULL) {
|
2005-04-17 06:20:36 +08:00
|
|
|
skb_reserve(skb, 2); /* 16 byte align the IP header */
|
|
|
|
pci_dma_sync_single_for_cpu(ep->pci_dev,
|
|
|
|
ep->rx_ring[entry].bufaddr,
|
|
|
|
ep->rx_buf_sz,
|
|
|
|
PCI_DMA_FROMDEVICE);
|
2007-07-11 13:08:12 +08:00
|
|
|
skb_copy_to_linear_data(skb, ep->rx_skbuff[entry]->data, pkt_len);
|
2005-04-17 06:20:36 +08:00
|
|
|
skb_put(skb, pkt_len);
|
|
|
|
pci_dma_sync_single_for_device(ep->pci_dev,
|
|
|
|
ep->rx_ring[entry].bufaddr,
|
|
|
|
ep->rx_buf_sz,
|
|
|
|
PCI_DMA_FROMDEVICE);
|
|
|
|
} else {
|
2006-05-27 09:39:03 +08:00
|
|
|
pci_unmap_single(ep->pci_dev,
|
|
|
|
ep->rx_ring[entry].bufaddr,
|
2005-04-17 06:20:36 +08:00
|
|
|
ep->rx_buf_sz, PCI_DMA_FROMDEVICE);
|
|
|
|
skb_put(skb = ep->rx_skbuff[entry], pkt_len);
|
|
|
|
ep->rx_skbuff[entry] = NULL;
|
|
|
|
}
|
|
|
|
skb->protocol = eth_type_trans(skb, dev);
|
|
|
|
netif_receive_skb(skb);
|
2010-07-05 10:13:20 +08:00
|
|
|
dev->stats.rx_packets++;
|
|
|
|
dev->stats.rx_bytes += pkt_len;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
work_done++;
|
|
|
|
entry = (++ep->cur_rx) % RX_RING_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Refill the Rx ring buffers. */
|
|
|
|
for (; ep->cur_rx - ep->dirty_rx > 0; ep->dirty_rx++) {
|
|
|
|
entry = ep->dirty_rx % RX_RING_SIZE;
|
|
|
|
if (ep->rx_skbuff[entry] == NULL) {
|
|
|
|
struct sk_buff *skb;
|
2012-02-06 19:16:13 +08:00
|
|
|
skb = ep->rx_skbuff[entry] = netdev_alloc_skb(dev, ep->rx_buf_sz + 2);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (skb == NULL)
|
|
|
|
break;
|
|
|
|
skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
|
2006-05-27 09:39:03 +08:00
|
|
|
ep->rx_ring[entry].bufaddr = pci_map_single(ep->pci_dev,
|
2005-06-29 06:25:31 +08:00
|
|
|
skb->data, ep->rx_buf_sz, PCI_DMA_FROMDEVICE);
|
2005-04-17 06:20:36 +08:00
|
|
|
work_done++;
|
|
|
|
}
|
2008-03-17 06:22:04 +08:00
|
|
|
/* AV: shouldn't we add a barrier here? */
|
|
|
|
ep->rx_ring[entry].rxstatus = DescOwn;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
return work_done;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void epic_rx_err(struct net_device *dev, struct epic_private *ep)
|
|
|
|
{
|
2012-03-13 19:04:26 +08:00
|
|
|
void __iomem *ioaddr = ep->ioaddr;
|
2005-04-17 06:20:36 +08:00
|
|
|
int status;
|
|
|
|
|
2012-03-13 19:04:26 +08:00
|
|
|
status = er32(INTSTAT);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (status == EpicRemoved)
|
|
|
|
return;
|
|
|
|
if (status & RxOverflow) /* Missed a Rx frame. */
|
2010-07-05 10:13:20 +08:00
|
|
|
dev->stats.rx_errors++;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (status & (RxOverflow | RxFull))
|
2012-03-13 19:04:26 +08:00
|
|
|
ew16(COMMAND, RxQueued);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net
device, and some have a single interrupt doorbell for several
queues.
In either case, it's easier to support layouts like that if the
structure representing the poll is independant from the net
device itself.
The signature of the ->poll() call back goes from:
int foo_poll(struct net_device *dev, int *budget)
to
int foo_poll(struct napi_struct *napi, int budget)
The caller is returned the number of RX packets processed (or
the number of "NAPI credits" consumed if you want to get
abstract). The callee no longer messes around bumping
dev->quota, *budget, etc. because that is all handled in the
caller upon return.
The napi_struct is to be embedded in the device driver private data
structures.
Furthermore, it is the driver's responsibility to disable all NAPI
instances in it's ->stop() device close handler. Since the
napi_struct is privatized into the driver's private data structures,
only the driver knows how to get at all of the napi_struct instances
it may have per-device.
With lots of help and suggestions from Rusty Russell, Roland Dreier,
Michael Chan, Jeff Garzik, and Jamal Hadi Salim.
Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra,
Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan.
[ Ported to current tree and all drivers converted. Integrated
Stephen's follow-on kerneldoc additions, and restored poll_list
handling to the old style to fix mutual exclusion issues. -DaveM ]
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-10-04 07:41:36 +08:00
|
|
|
static int epic_poll(struct napi_struct *napi, int budget)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net
device, and some have a single interrupt doorbell for several
queues.
In either case, it's easier to support layouts like that if the
structure representing the poll is independant from the net
device itself.
The signature of the ->poll() call back goes from:
int foo_poll(struct net_device *dev, int *budget)
to
int foo_poll(struct napi_struct *napi, int budget)
The caller is returned the number of RX packets processed (or
the number of "NAPI credits" consumed if you want to get
abstract). The callee no longer messes around bumping
dev->quota, *budget, etc. because that is all handled in the
caller upon return.
The napi_struct is to be embedded in the device driver private data
structures.
Furthermore, it is the driver's responsibility to disable all NAPI
instances in it's ->stop() device close handler. Since the
napi_struct is privatized into the driver's private data structures,
only the driver knows how to get at all of the napi_struct instances
it may have per-device.
With lots of help and suggestions from Rusty Russell, Roland Dreier,
Michael Chan, Jeff Garzik, and Jamal Hadi Salim.
Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra,
Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan.
[ Ported to current tree and all drivers converted. Integrated
Stephen's follow-on kerneldoc additions, and restored poll_list
handling to the old style to fix mutual exclusion issues. -DaveM ]
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-10-04 07:41:36 +08:00
|
|
|
struct epic_private *ep = container_of(napi, struct epic_private, napi);
|
|
|
|
struct net_device *dev = ep->mii.dev;
|
2012-03-13 19:04:26 +08:00
|
|
|
void __iomem *ioaddr = ep->ioaddr;
|
2017-02-05 07:24:53 +08:00
|
|
|
int work_done;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
epic_tx(dev, ep);
|
|
|
|
|
2017-02-05 07:24:53 +08:00
|
|
|
work_done = epic_rx(dev, budget);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
epic_rx_err(dev, ep);
|
|
|
|
|
2017-02-05 07:24:53 +08:00
|
|
|
if (work_done < budget && napi_complete_done(napi, work_done)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&ep->napi_lock, flags);
|
|
|
|
|
2017-02-05 07:24:53 +08:00
|
|
|
ew32(INTSTAT, EpicNapiEvent);
|
|
|
|
epic_napi_irq_on(dev, ep);
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock_irqrestore(&ep->napi_lock, flags);
|
|
|
|
}
|
|
|
|
|
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net
device, and some have a single interrupt doorbell for several
queues.
In either case, it's easier to support layouts like that if the
structure representing the poll is independant from the net
device itself.
The signature of the ->poll() call back goes from:
int foo_poll(struct net_device *dev, int *budget)
to
int foo_poll(struct napi_struct *napi, int budget)
The caller is returned the number of RX packets processed (or
the number of "NAPI credits" consumed if you want to get
abstract). The callee no longer messes around bumping
dev->quota, *budget, etc. because that is all handled in the
caller upon return.
The napi_struct is to be embedded in the device driver private data
structures.
Furthermore, it is the driver's responsibility to disable all NAPI
instances in it's ->stop() device close handler. Since the
napi_struct is privatized into the driver's private data structures,
only the driver knows how to get at all of the napi_struct instances
it may have per-device.
With lots of help and suggestions from Rusty Russell, Roland Dreier,
Michael Chan, Jeff Garzik, and Jamal Hadi Salim.
Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra,
Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan.
[ Ported to current tree and all drivers converted. Integrated
Stephen's follow-on kerneldoc additions, and restored poll_list
handling to the old style to fix mutual exclusion issues. -DaveM ]
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-10-04 07:41:36 +08:00
|
|
|
return work_done;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int epic_close(struct net_device *dev)
|
|
|
|
{
|
2008-11-13 15:38:14 +08:00
|
|
|
struct epic_private *ep = netdev_priv(dev);
|
2012-03-13 19:04:26 +08:00
|
|
|
struct pci_dev *pdev = ep->pci_dev;
|
|
|
|
void __iomem *ioaddr = ep->ioaddr;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct sk_buff *skb;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
netif_stop_queue(dev);
|
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net
device, and some have a single interrupt doorbell for several
queues.
In either case, it's easier to support layouts like that if the
structure representing the poll is independant from the net
device itself.
The signature of the ->poll() call back goes from:
int foo_poll(struct net_device *dev, int *budget)
to
int foo_poll(struct napi_struct *napi, int budget)
The caller is returned the number of RX packets processed (or
the number of "NAPI credits" consumed if you want to get
abstract). The callee no longer messes around bumping
dev->quota, *budget, etc. because that is all handled in the
caller upon return.
The napi_struct is to be embedded in the device driver private data
structures.
Furthermore, it is the driver's responsibility to disable all NAPI
instances in it's ->stop() device close handler. Since the
napi_struct is privatized into the driver's private data structures,
only the driver knows how to get at all of the napi_struct instances
it may have per-device.
With lots of help and suggestions from Rusty Russell, Roland Dreier,
Michael Chan, Jeff Garzik, and Jamal Hadi Salim.
Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra,
Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan.
[ Ported to current tree and all drivers converted. Integrated
Stephen's follow-on kerneldoc additions, and restored poll_list
handling to the old style to fix mutual exclusion issues. -DaveM ]
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-10-04 07:41:36 +08:00
|
|
|
napi_disable(&ep->napi);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (debug > 1)
|
2013-11-01 20:53:30 +08:00
|
|
|
netdev_dbg(dev, "Shutting down ethercard, status was %2.2x.\n",
|
|
|
|
er32(INTSTAT));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
del_timer_sync(&ep->timer);
|
|
|
|
|
|
|
|
epic_disable_int(dev, ep);
|
|
|
|
|
2012-03-13 19:04:26 +08:00
|
|
|
free_irq(pdev->irq, dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
epic_pause(dev);
|
|
|
|
|
|
|
|
/* Free all the skbuffs in the Rx queue. */
|
|
|
|
for (i = 0; i < RX_RING_SIZE; i++) {
|
|
|
|
skb = ep->rx_skbuff[i];
|
|
|
|
ep->rx_skbuff[i] = NULL;
|
|
|
|
ep->rx_ring[i].rxstatus = 0; /* Not owned by Epic chip. */
|
|
|
|
ep->rx_ring[i].buflength = 0;
|
|
|
|
if (skb) {
|
2012-03-13 19:04:26 +08:00
|
|
|
pci_unmap_single(pdev, ep->rx_ring[i].bufaddr,
|
2013-11-01 20:53:30 +08:00
|
|
|
ep->rx_buf_sz, PCI_DMA_FROMDEVICE);
|
2005-04-17 06:20:36 +08:00
|
|
|
dev_kfree_skb(skb);
|
|
|
|
}
|
|
|
|
ep->rx_ring[i].bufaddr = 0xBADF00D0; /* An invalid address. */
|
|
|
|
}
|
|
|
|
for (i = 0; i < TX_RING_SIZE; i++) {
|
|
|
|
skb = ep->tx_skbuff[i];
|
|
|
|
ep->tx_skbuff[i] = NULL;
|
|
|
|
if (!skb)
|
|
|
|
continue;
|
2012-03-13 19:04:26 +08:00
|
|
|
pci_unmap_single(pdev, ep->tx_ring[i].bufaddr, skb->len,
|
|
|
|
PCI_DMA_TODEVICE);
|
2005-04-17 06:20:36 +08:00
|
|
|
dev_kfree_skb(skb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Green! Leave the chip in low-power mode. */
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(GENCTL, 0x0008);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct net_device_stats *epic_get_stats(struct net_device *dev)
|
|
|
|
{
|
2012-03-13 19:04:26 +08:00
|
|
|
struct epic_private *ep = netdev_priv(dev);
|
|
|
|
void __iomem *ioaddr = ep->ioaddr;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (netif_running(dev)) {
|
2012-03-13 19:04:26 +08:00
|
|
|
struct net_device_stats *stats = &dev->stats;
|
|
|
|
|
|
|
|
stats->rx_missed_errors += er8(MPCNT);
|
|
|
|
stats->rx_frame_errors += er8(ALICNT);
|
|
|
|
stats->rx_crc_errors += er8(CRCCNT);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2010-07-05 10:13:20 +08:00
|
|
|
return &dev->stats;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set or clear the multicast filter for this adaptor.
|
|
|
|
Note that we only use exclusion around actually queueing the
|
|
|
|
new frame, not around filling ep->setup_frame. This is non-deterministic
|
|
|
|
when re-entered but still correct. */
|
|
|
|
|
|
|
|
static void set_rx_mode(struct net_device *dev)
|
|
|
|
{
|
2008-11-13 15:38:14 +08:00
|
|
|
struct epic_private *ep = netdev_priv(dev);
|
2012-03-13 19:04:26 +08:00
|
|
|
void __iomem *ioaddr = ep->ioaddr;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned char mc_filter[8]; /* Multicast hash filter */
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(RxCtrl, 0x002c);
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Unconditionally log net taps. */
|
|
|
|
memset(mc_filter, 0xff, sizeof(mc_filter));
|
2010-02-08 12:30:35 +08:00
|
|
|
} else if ((!netdev_mc_empty(dev)) || (dev->flags & IFF_ALLMULTI)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* There is apparently a chip bug, so the multicast filter
|
|
|
|
is never enabled. */
|
|
|
|
/* Too many to filter perfectly -- accept all multicasts. */
|
|
|
|
memset(mc_filter, 0xff, sizeof(mc_filter));
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(RxCtrl, 0x000c);
|
2010-02-08 12:30:35 +08:00
|
|
|
} else if (netdev_mc_empty(dev)) {
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(RxCtrl, 0x0004);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
} else { /* Never executed, for now. */
|
2010-04-02 05:22:57 +08:00
|
|
|
struct netdev_hw_addr *ha;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
memset(mc_filter, 0, sizeof(mc_filter));
|
2010-04-02 05:22:57 +08:00
|
|
|
netdev_for_each_mc_addr(ha, dev) {
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned int bit_nr =
|
2010-04-02 05:22:57 +08:00
|
|
|
ether_crc_le(ETH_ALEN, ha->addr) & 0x3f;
|
2005-04-17 06:20:36 +08:00
|
|
|
mc_filter[bit_nr >> 3] |= (1 << bit_nr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* ToDo: perhaps we need to stop the Tx and Rx process here? */
|
|
|
|
if (memcmp(mc_filter, ep->mc_filter, sizeof(mc_filter))) {
|
|
|
|
for (i = 0; i < 4; i++)
|
2012-03-13 19:04:26 +08:00
|
|
|
ew16(MC0 + i*4, ((u16 *)mc_filter)[i]);
|
2005-04-17 06:20:36 +08:00
|
|
|
memcpy(ep->mc_filter, mc_filter, sizeof(mc_filter));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void netdev_get_drvinfo (struct net_device *dev, struct ethtool_drvinfo *info)
|
|
|
|
{
|
2008-11-13 15:38:14 +08:00
|
|
|
struct epic_private *np = netdev_priv(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-11-07 21:29:27 +08:00
|
|
|
strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
|
|
|
|
strlcpy(info->version, DRV_VERSION, sizeof(info->version));
|
|
|
|
strlcpy(info->bus_info, pci_name(np->pci_dev), sizeof(info->bus_info));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2017-02-28 06:43:14 +08:00
|
|
|
static int netdev_get_link_ksettings(struct net_device *dev,
|
|
|
|
struct ethtool_link_ksettings *cmd)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-11-13 15:38:14 +08:00
|
|
|
struct epic_private *np = netdev_priv(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
spin_lock_irq(&np->lock);
|
2017-06-05 01:22:00 +08:00
|
|
|
mii_ethtool_get_link_ksettings(&np->mii, cmd);
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock_irq(&np->lock);
|
|
|
|
|
2017-06-05 01:22:00 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2017-02-28 06:43:14 +08:00
|
|
|
static int netdev_set_link_ksettings(struct net_device *dev,
|
|
|
|
const struct ethtool_link_ksettings *cmd)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-11-13 15:38:14 +08:00
|
|
|
struct epic_private *np = netdev_priv(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
spin_lock_irq(&np->lock);
|
2017-02-28 06:43:14 +08:00
|
|
|
rc = mii_ethtool_set_link_ksettings(&np->mii, cmd);
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock_irq(&np->lock);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int netdev_nway_reset(struct net_device *dev)
|
|
|
|
{
|
2008-11-13 15:38:14 +08:00
|
|
|
struct epic_private *np = netdev_priv(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
return mii_nway_restart(&np->mii);
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 netdev_get_link(struct net_device *dev)
|
|
|
|
{
|
2008-11-13 15:38:14 +08:00
|
|
|
struct epic_private *np = netdev_priv(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
return mii_link_ok(&np->mii);
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 netdev_get_msglevel(struct net_device *dev)
|
|
|
|
{
|
|
|
|
return debug;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void netdev_set_msglevel(struct net_device *dev, u32 value)
|
|
|
|
{
|
|
|
|
debug = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ethtool_begin(struct net_device *dev)
|
|
|
|
{
|
2012-03-13 19:04:26 +08:00
|
|
|
struct epic_private *ep = netdev_priv(dev);
|
|
|
|
void __iomem *ioaddr = ep->ioaddr;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* power-up, if interface is down */
|
2012-03-13 19:04:26 +08:00
|
|
|
if (!netif_running(dev)) {
|
|
|
|
ew32(GENCTL, 0x0200);
|
|
|
|
ew32(NVCTL, (er32(NVCTL) & ~0x003c) | 0x4800);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ethtool_complete(struct net_device *dev)
|
|
|
|
{
|
2012-03-13 19:04:26 +08:00
|
|
|
struct epic_private *ep = netdev_priv(dev);
|
|
|
|
void __iomem *ioaddr = ep->ioaddr;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* power-down, if interface is down */
|
2012-03-13 19:04:26 +08:00
|
|
|
if (!netif_running(dev)) {
|
|
|
|
ew32(GENCTL, 0x0008);
|
|
|
|
ew32(NVCTL, (er32(NVCTL) & ~0x483c) | 0x0000);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-14 02:30:00 +08:00
|
|
|
static const struct ethtool_ops netdev_ethtool_ops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.get_drvinfo = netdev_get_drvinfo,
|
|
|
|
.nway_reset = netdev_nway_reset,
|
|
|
|
.get_link = netdev_get_link,
|
|
|
|
.get_msglevel = netdev_get_msglevel,
|
|
|
|
.set_msglevel = netdev_set_msglevel,
|
|
|
|
.begin = ethtool_begin,
|
2017-02-28 06:43:14 +08:00
|
|
|
.complete = ethtool_complete,
|
|
|
|
.get_link_ksettings = netdev_get_link_ksettings,
|
|
|
|
.set_link_ksettings = netdev_set_link_ksettings,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
|
|
|
|
{
|
2008-11-13 15:38:14 +08:00
|
|
|
struct epic_private *np = netdev_priv(dev);
|
2012-03-13 19:04:26 +08:00
|
|
|
void __iomem *ioaddr = np->ioaddr;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct mii_ioctl_data *data = if_mii(rq);
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* power-up, if interface is down */
|
|
|
|
if (! netif_running(dev)) {
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(GENCTL, 0x0200);
|
|
|
|
ew32(NVCTL, (er32(NVCTL) & ~0x003c) | 0x4800);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* all non-ethtool ioctls (the SIOC[GS]MIIxxx ioctls) */
|
|
|
|
spin_lock_irq(&np->lock);
|
|
|
|
rc = generic_mii_ioctl(&np->mii, data, cmd, NULL);
|
|
|
|
spin_unlock_irq(&np->lock);
|
|
|
|
|
|
|
|
/* power-down, if interface is down */
|
|
|
|
if (! netif_running(dev)) {
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(GENCTL, 0x0008);
|
|
|
|
ew32(NVCTL, (er32(NVCTL) & ~0x483c) | 0x0000);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-03 22:23:42 +08:00
|
|
|
static void epic_remove_one(struct pci_dev *pdev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct net_device *dev = pci_get_drvdata(pdev);
|
2008-11-13 15:38:14 +08:00
|
|
|
struct epic_private *ep = netdev_priv(dev);
|
2006-05-27 09:39:03 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
pci_free_consistent(pdev, TX_TOTAL_SIZE, ep->tx_ring, ep->tx_ring_dma);
|
|
|
|
pci_free_consistent(pdev, RX_TOTAL_SIZE, ep->rx_ring, ep->rx_ring_dma);
|
|
|
|
unregister_netdev(dev);
|
2012-03-13 19:04:26 +08:00
|
|
|
pci_iounmap(pdev, ep->ioaddr);
|
2005-04-17 06:20:36 +08:00
|
|
|
pci_release_regions(pdev);
|
|
|
|
free_netdev(dev);
|
|
|
|
pci_disable_device(pdev);
|
|
|
|
/* pci_power_off(pdev, -1); */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM
|
|
|
|
|
|
|
|
static int epic_suspend (struct pci_dev *pdev, pm_message_t state)
|
|
|
|
{
|
|
|
|
struct net_device *dev = pci_get_drvdata(pdev);
|
2012-03-13 19:04:26 +08:00
|
|
|
struct epic_private *ep = netdev_priv(dev);
|
|
|
|
void __iomem *ioaddr = ep->ioaddr;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (!netif_running(dev))
|
|
|
|
return 0;
|
|
|
|
epic_pause(dev);
|
|
|
|
/* Put the chip into low-power mode. */
|
2012-03-13 19:04:26 +08:00
|
|
|
ew32(GENCTL, 0x0008);
|
2005-04-17 06:20:36 +08:00
|
|
|
/* pci_power_off(pdev, -1); */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int epic_resume (struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
struct net_device *dev = pci_get_drvdata(pdev);
|
|
|
|
|
|
|
|
if (!netif_running(dev))
|
|
|
|
return 0;
|
|
|
|
epic_restart(dev);
|
|
|
|
/* pci_power_on(pdev); */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_PM */
|
|
|
|
|
|
|
|
|
|
|
|
static struct pci_driver epic_driver = {
|
|
|
|
.name = DRV_NAME,
|
|
|
|
.id_table = epic_pci_tbl,
|
|
|
|
.probe = epic_init_one,
|
2012-12-03 22:23:42 +08:00
|
|
|
.remove = epic_remove_one,
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef CONFIG_PM
|
|
|
|
.suspend = epic_suspend,
|
|
|
|
.resume = epic_resume,
|
|
|
|
#endif /* CONFIG_PM */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int __init epic_init (void)
|
|
|
|
{
|
|
|
|
/* when a module, this is printed whether or not devices are found in probe */
|
|
|
|
#ifdef MODULE
|
2013-11-01 20:53:30 +08:00
|
|
|
pr_info("%s%s\n", version, version2);
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
2006-08-20 05:48:59 +08:00
|
|
|
return pci_register_driver(&epic_driver);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void __exit epic_cleanup (void)
|
|
|
|
{
|
|
|
|
pci_unregister_driver (&epic_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module_init(epic_init);
|
|
|
|
module_exit(epic_cleanup);
|