1 |
1626 |
jcastillo |
/* epic100.c: A SMC 83c170 EPIC/100 Fast Ethernet driver for Linux. */
|
2 |
|
|
/*
|
3 |
|
|
Written/copyright 1997-1998 by Donald Becker.
|
4 |
|
|
|
5 |
|
|
This software may be used and distributed according to the terms
|
6 |
|
|
of the GNU Public License, incorporated herein by reference.
|
7 |
|
|
All other rights reserved.
|
8 |
|
|
|
9 |
|
|
This driver is for the SMC83c170/175 "EPIC" series, as used on the
|
10 |
|
|
SMC EtherPower II 9432 PCI adapter, and several CardBus cards.
|
11 |
|
|
|
12 |
|
|
The author may be reached as becker@CESDIS.gsfc.nasa.gov, or C/O
|
13 |
|
|
USRA Center of Excellence in Space Data and Information Sciences
|
14 |
|
|
Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771
|
15 |
|
|
|
16 |
|
|
Information and updates available at
|
17 |
|
|
http://cesdis.gsfc.nasa.gov/linux/drivers/epic100.html
|
18 |
|
|
*/
|
19 |
|
|
|
20 |
|
|
static const char *version =
|
21 |
|
|
"epic100.c:v1.04 8/23/98 Donald Becker http://cesdis.gsfc.nasa.gov/linux/drivers/epic100.html\n";
|
22 |
|
|
|
23 |
|
|
/* A few user-configurable values. */
|
24 |
|
|
|
25 |
|
|
/* Keep the ring sizes a power of two for efficiency.
|
26 |
|
|
Making the Tx ring too large decreases the effectiveness of channel
|
27 |
|
|
bonding and packet priority.
|
28 |
|
|
There are no ill effects from too-large receive rings. */
|
29 |
|
|
#define TX_RING_SIZE 16
|
30 |
|
|
#define RX_RING_SIZE 32
|
31 |
|
|
|
32 |
|
|
/* Set the copy breakpoint for the copy-only-tiny-frames scheme.
|
33 |
|
|
Setting to > 1518 effectively disables this feature. */
|
34 |
|
|
static int rx_copybreak = 200;
|
35 |
|
|
|
36 |
|
|
/* Maximum events (Rx packets, etc.) to handle at each interrupt. */
|
37 |
|
|
static int max_interrupt_work = 10;
|
38 |
|
|
|
39 |
|
|
/* Operational parameters that usually are not changed. */
|
40 |
|
|
/* Time in jiffies before concluding the transmitter is hung. */
|
41 |
|
|
#define TX_TIMEOUT ((2000*HZ)/1000)
|
42 |
|
|
|
43 |
|
|
#define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer.*/
|
44 |
|
|
|
45 |
|
|
/* Bytes transferred to chip before transmission starts. */
|
46 |
|
|
#define TX_FIFO_THRESH 256 /* Rounded down to 4 byte units. */
|
47 |
|
|
#define RX_FIFO_THRESH 1 /* 0-3, 0==32, 64,96, or 3==128 bytes */
|
48 |
|
|
|
49 |
|
|
#include <linux/config.h>
|
50 |
|
|
#include <linux/version.h> /* Evil, but neccessary */
|
51 |
|
|
#ifdef MODULE
|
52 |
|
|
#ifdef MODVERSIONS
|
53 |
|
|
#include <linux/modversions.h>
|
54 |
|
|
#endif
|
55 |
|
|
#include <linux/module.h>
|
56 |
|
|
#else
|
57 |
|
|
#define MOD_INC_USE_COUNT
|
58 |
|
|
#define MOD_DEC_USE_COUNT
|
59 |
|
|
#endif
|
60 |
|
|
|
61 |
|
|
#include <linux/kernel.h>
|
62 |
|
|
#include <linux/sched.h>
|
63 |
|
|
#include <linux/string.h>
|
64 |
|
|
#include <linux/timer.h>
|
65 |
|
|
#include <linux/ptrace.h>
|
66 |
|
|
#include <linux/errno.h>
|
67 |
|
|
#include <linux/ioport.h>
|
68 |
|
|
#include <linux/malloc.h>
|
69 |
|
|
#include <linux/interrupt.h>
|
70 |
|
|
#include <linux/pci.h>
|
71 |
|
|
#if LINUX_VERSION_CODE >= 0x20155
|
72 |
|
|
#define PCI_SUPPORT_VER2
|
73 |
|
|
#else
|
74 |
|
|
#include <linux/bios32.h>
|
75 |
|
|
#endif
|
76 |
|
|
#include <linux/delay.h>
|
77 |
|
|
|
78 |
|
|
#include <asm/processor.h> /* Processor type for cache alignment. */
|
79 |
|
|
#include <asm/bitops.h>
|
80 |
|
|
#include <asm/io.h>
|
81 |
|
|
#include <asm/dma.h>
|
82 |
|
|
|
83 |
|
|
#include <linux/netdevice.h>
|
84 |
|
|
#include <linux/etherdevice.h>
|
85 |
|
|
#include <linux/skbuff.h>
|
86 |
|
|
|
87 |
|
|
/* Kernel compatibility defines, common to David Hind's PCMCIA package.
|
88 |
|
|
This is only in the support-all-kernels source code. */
|
89 |
|
|
|
90 |
|
|
#if ! defined (LINUX_VERSION_CODE) || LINUX_VERSION_CODE < 0x20000
|
91 |
|
|
#warning This driver version is only for kernel versions 2.0.0 and later.
|
92 |
|
|
#endif
|
93 |
|
|
|
94 |
|
|
#define RUN_AT(x) (jiffies + (x))
|
95 |
|
|
|
96 |
|
|
#if defined(MODULE) && (LINUX_VERSION_CODE >= 0x20115)
|
97 |
|
|
MODULE_AUTHOR("Donald Becker <becker@cesdis.gsfc.nasa.gov>");
|
98 |
|
|
MODULE_DESCRIPTION("SMC 83c170 EPIC series Ethernet driver");
|
99 |
|
|
MODULE_PARM(debug, "i");
|
100 |
|
|
MODULE_PARM(options, "1-" __MODULE_STRING(8) "i");
|
101 |
|
|
MODULE_PARM(full_duplex, "1-" __MODULE_STRING(8) "i");
|
102 |
|
|
MODULE_PARM(rx_copybreak, "i");
|
103 |
|
|
MODULE_PARM(max_interrupt_work, "i");
|
104 |
|
|
#endif
|
105 |
|
|
#if LINUX_VERSION_CODE < 0x20123
|
106 |
|
|
#define test_and_set_bit(val, addr) set_bit(val, addr)
|
107 |
|
|
#endif
|
108 |
|
|
#if LINUX_VERSION_CODE <= 0x20139
|
109 |
|
|
#define net_device_stats enet_statistics
|
110 |
|
|
#define NETSTATS_VER2
|
111 |
|
|
#endif
|
112 |
|
|
#if LINUX_VERSION_CODE < 0x20159
|
113 |
|
|
#define DEV_FREE_SKB(skb) dev_kfree_skb(skb, FREE_WRITE);
|
114 |
|
|
#else /* Grrr, unneeded incompatible change. */
|
115 |
|
|
#define DEV_FREE_SKB(skb) dev_kfree_skb(skb);
|
116 |
|
|
#endif
|
117 |
|
|
|
118 |
|
|
/* The I/O extent. */
|
119 |
|
|
#define EPIC_TOTAL_SIZE 0x100
|
120 |
|
|
|
121 |
|
|
#define epic_debug debug
|
122 |
|
|
static int epic_debug = 1;
|
123 |
|
|
|
124 |
|
|
/*
|
125 |
|
|
Theory of Operation
|
126 |
|
|
|
127 |
|
|
I. Board Compatibility
|
128 |
|
|
|
129 |
|
|
This device driver is designed for the SMC "EPCI/100", the SMC
|
130 |
|
|
single-chip Ethernet controllers for PCI. This chip is used on
|
131 |
|
|
the SMC EtherPower II boards.
|
132 |
|
|
|
133 |
|
|
|
134 |
|
|
II. Board-specific settings
|
135 |
|
|
|
136 |
|
|
PCI bus devices are configured by the system at boot time, so no jumpers
|
137 |
|
|
need to be set on the board. The system BIOS will assign the
|
138 |
|
|
PCI INTA signal to a (preferably otherwise unused) system IRQ line.
|
139 |
|
|
Note: Kernel versions earlier than 1.3.73 do not support shared PCI
|
140 |
|
|
interrupt lines.
|
141 |
|
|
|
142 |
|
|
III. Driver operation
|
143 |
|
|
|
144 |
|
|
IIIa. Ring buffers
|
145 |
|
|
|
146 |
|
|
IVb. References
|
147 |
|
|
|
148 |
|
|
http://www.smc.com/components/catalog/smc83c170.html
|
149 |
|
|
http://cesdis.gsfc.nasa.gov/linux/misc/NWay.html
|
150 |
|
|
http://www.national.com/pf/DP/DP83840.html
|
151 |
|
|
|
152 |
|
|
IVc. Errata
|
153 |
|
|
|
154 |
|
|
*/
|
155 |
|
|
|
156 |
|
|
/* The rest of these values should never change. */
|
157 |
|
|
|
158 |
|
|
static struct device *epic_probe1(int pci_bus, int pci_devfn,
|
159 |
|
|
struct device *dev, long ioaddr, int irq,
|
160 |
|
|
int chip_id, int card_idx);
|
161 |
|
|
|
162 |
|
|
enum pci_flags_bit {
|
163 |
|
|
PCI_USES_IO=1, PCI_USES_MEM=2, PCI_USES_MASTER=4,
|
164 |
|
|
PCI_ADDR0=0x10<<0, PCI_ADDR1=0x10<<1, PCI_ADDR2=0x10<<2, PCI_ADDR3=0x10<<3,
|
165 |
|
|
};
|
166 |
|
|
struct chip_info {
|
167 |
|
|
const char *name;
|
168 |
|
|
u16 vendor_id, device_id, device_id_mask, pci_flags;
|
169 |
|
|
int io_size, min_latency;
|
170 |
|
|
struct device *(*probe1)(int pci_bus, int pci_devfn, struct device *dev,
|
171 |
|
|
long ioaddr, int irq, int chip_idx, int fnd_cnt);
|
172 |
|
|
} chip_tbl[] = {
|
173 |
|
|
{"SMSC EPIC/100 83c170", 0x10B8, 0x0005, 0x7fff,
|
174 |
|
|
PCI_USES_IO|PCI_USES_MASTER|PCI_ADDR0, EPIC_TOTAL_SIZE, 32, epic_probe1},
|
175 |
|
|
{"SMSC EPIC/C 83c175", 0x10B8, 0x0006, 0x7fff,
|
176 |
|
|
PCI_USES_IO|PCI_USES_MASTER|PCI_ADDR0, EPIC_TOTAL_SIZE, 32, epic_probe1},
|
177 |
|
|
{0,},
|
178 |
|
|
};
|
179 |
|
|
|
180 |
|
|
/* Offsets to registers, using the (ugh) SMC names. */
|
181 |
|
|
enum epic_registers {
|
182 |
|
|
COMMAND=0, INTSTAT=4, INTMASK=8, GENCTL=0x0C, NVCTL=0x10, EECTL=0x14,
|
183 |
|
|
PCIBurstCnt=0x18,
|
184 |
|
|
TEST1=0x1C, CRCCNT=0x20, ALICNT=0x24, MPCNT=0x28, /* Rx error counters. */
|
185 |
|
|
MIICtrl=0x30, MIIData=0x34, MIICfg=0x38,
|
186 |
|
|
LAN0=64, /* MAC address. */
|
187 |
|
|
MC0=80, /* Multicast filter table. */
|
188 |
|
|
RxCtrl=96, TxCtrl=112, TxSTAT=0x74,
|
189 |
|
|
PRxCDAR=0x84, RxSTAT=0xA4, EarlyRx=0xB0, PTxCDAR=0xC4, TxThresh=0xDC,
|
190 |
|
|
};
|
191 |
|
|
|
192 |
|
|
/* Interrupt register bits, using my own meaningful names. */
|
193 |
|
|
enum IntrStatus {
|
194 |
|
|
TxIdle=0x40000, RxIdle=0x20000, IntrSummary=0x010000,
|
195 |
|
|
PCIBusErr170=0x7000, PCIBusErr175=0x1000, PhyEvent175=0x8000,
|
196 |
|
|
RxStarted=0x0800, RxEarlyWarn=0x0400, CntFull=0x0200, TxUnderrun=0x0100,
|
197 |
|
|
TxEmpty=0x0080, TxDone=0x0020, RxError=0x0010,
|
198 |
|
|
RxOverflow=0x0008, RxFull=0x0004, RxHeader=0x0002, RxDone=0x0001,
|
199 |
|
|
};
|
200 |
|
|
|
201 |
|
|
/* The EPIC100 Rx and Tx buffer descriptors. */
|
202 |
|
|
|
203 |
|
|
struct epic_tx_desc {
|
204 |
|
|
s16 status;
|
205 |
|
|
u16 txlength;
|
206 |
|
|
u32 bufaddr;
|
207 |
|
|
u16 buflength;
|
208 |
|
|
u16 control;
|
209 |
|
|
u32 next;
|
210 |
|
|
};
|
211 |
|
|
|
212 |
|
|
struct epic_rx_desc {
|
213 |
|
|
s16 status;
|
214 |
|
|
u16 rxlength;
|
215 |
|
|
u32 bufaddr;
|
216 |
|
|
u32 buflength;
|
217 |
|
|
u32 next;
|
218 |
|
|
};
|
219 |
|
|
|
220 |
|
|
struct epic_private {
|
221 |
|
|
char devname[8]; /* Used only for kernel debugging. */
|
222 |
|
|
const char *product_name;
|
223 |
|
|
struct device *next_module;
|
224 |
|
|
|
225 |
|
|
/* Rx and Rx rings here so that they remain paragraph aligned. */
|
226 |
|
|
struct epic_rx_desc rx_ring[RX_RING_SIZE];
|
227 |
|
|
struct epic_tx_desc tx_ring[TX_RING_SIZE];
|
228 |
|
|
/* The saved address of a sent-in-place packet/buffer, for skfree(). */
|
229 |
|
|
struct sk_buff* tx_skbuff[TX_RING_SIZE];
|
230 |
|
|
/* The addresses of receive-in-place skbuffs. */
|
231 |
|
|
struct sk_buff* rx_skbuff[RX_RING_SIZE];
|
232 |
|
|
|
233 |
|
|
/* Ring pointers. */
|
234 |
|
|
unsigned int cur_rx, cur_tx; /* The next free ring entry */
|
235 |
|
|
unsigned int dirty_rx, dirty_tx; /* The ring entries to be free()ed. */
|
236 |
|
|
|
237 |
|
|
u8 pci_bus, pci_dev_fn; /* PCI bus location. */
|
238 |
|
|
u16 chip_id;
|
239 |
|
|
|
240 |
|
|
struct net_device_stats stats;
|
241 |
|
|
struct timer_list timer; /* Media selection timer. */
|
242 |
|
|
unsigned char mc_filter[8];
|
243 |
|
|
signed char phys[4]; /* MII device addresses. */
|
244 |
|
|
unsigned int tx_full:1; /* The Tx queue is full. */
|
245 |
|
|
unsigned int full_duplex:1; /* Current duplex setting. */
|
246 |
|
|
unsigned int force_fd:1; /* Full-duplex operation requested. */
|
247 |
|
|
unsigned int default_port:4; /* Last dev->if_port value. */
|
248 |
|
|
unsigned int media2:4; /* Secondary monitored media port. */
|
249 |
|
|
unsigned int medialock:1; /* Don't sense media type. */
|
250 |
|
|
unsigned int mediasense:1; /* Media sensing in progress. */
|
251 |
|
|
int pad0, pad1; /* Used for 8-byte alignment */
|
252 |
|
|
};
|
253 |
|
|
|
254 |
|
|
/* Used to pass the full-duplex flag, etc. */
|
255 |
|
|
#define MAX_UNITS 8
|
256 |
|
|
static int full_duplex[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
|
257 |
|
|
static int options[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
|
258 |
|
|
|
259 |
|
|
static int epic_open(struct device *dev);
|
260 |
|
|
static int read_eeprom(long ioaddr, int location);
|
261 |
|
|
static int mdio_read(long ioaddr, int phy_id, int location);
|
262 |
|
|
static void mdio_write(long ioaddr, int phy_id, int location, int value);
|
263 |
|
|
static void epic_restart(struct device *dev);
|
264 |
|
|
static void epic_timer(unsigned long data);
|
265 |
|
|
static void epic_tx_timeout(struct device *dev);
|
266 |
|
|
static void epic_init_ring(struct device *dev);
|
267 |
|
|
static int epic_start_xmit(struct sk_buff *skb, struct device *dev);
|
268 |
|
|
static int epic_rx(struct device *dev);
|
269 |
|
|
static void epic_interrupt(int irq, void *dev_instance, struct pt_regs *regs);
|
270 |
|
|
static int mii_ioctl(struct device *dev, struct ifreq *rq, int cmd);
|
271 |
|
|
static int epic_close(struct device *dev);
|
272 |
|
|
static struct net_device_stats *epic_get_stats(struct device *dev);
|
273 |
|
|
static void set_rx_mode(struct device *dev);
|
274 |
|
|
|
275 |
|
|
|
276 |
|
|
/* A list of all installed EPIC devices, for removing the driver module. */
|
277 |
|
|
static struct device *root_epic_dev = NULL;
|
278 |
|
|
|
279 |
|
|
#ifndef CARDBUS
|
280 |
|
|
int epic100_probe(struct device *dev)
|
281 |
|
|
{
|
282 |
|
|
int cards_found = 0;
|
283 |
|
|
int chip_idx, irq;
|
284 |
|
|
u16 pci_command, new_command;
|
285 |
|
|
unsigned char pci_bus, pci_device_fn;
|
286 |
|
|
|
287 |
|
|
#ifdef PCI_SUPPORT_VER2
|
288 |
|
|
struct pci_dev *pcidev = NULL;
|
289 |
|
|
while ((pcidev = pci_find_class(PCI_CLASS_NETWORK_ETHERNET << 8, pcidev))
|
290 |
|
|
!= NULL) {
|
291 |
|
|
long pci_ioaddr = pcidev->base_address[0] & ~3;
|
292 |
|
|
int vendor = pcidev->vendor;
|
293 |
|
|
int device = pcidev->device;
|
294 |
|
|
|
295 |
|
|
for (chip_idx = 0; chip_tbl[chip_idx].vendor_id; chip_idx++)
|
296 |
|
|
if (vendor == chip_tbl[chip_idx].vendor_id
|
297 |
|
|
&& (device & chip_tbl[chip_idx].device_id_mask) ==
|
298 |
|
|
chip_tbl[chip_idx].device_id)
|
299 |
|
|
break;
|
300 |
|
|
if (chip_tbl[chip_idx].vendor_id == 0 /* Compiled out! */
|
301 |
|
|
|| check_region(pci_ioaddr, chip_tbl[chip_idx].io_size))
|
302 |
|
|
continue;
|
303 |
|
|
pci_bus = pcidev->bus->number;
|
304 |
|
|
pci_device_fn = pcidev->devfn;
|
305 |
|
|
irq = pcidev->irq;
|
306 |
|
|
#else
|
307 |
|
|
int pci_index;
|
308 |
|
|
|
309 |
|
|
if ( ! pcibios_present())
|
310 |
|
|
return -ENODEV;
|
311 |
|
|
|
312 |
|
|
for (pci_index = 0; pci_index < 0xff; pci_index++) {
|
313 |
|
|
u8 pci_irq_line;
|
314 |
|
|
u16 vendor, device;
|
315 |
|
|
u32 pci_ioaddr;
|
316 |
|
|
|
317 |
|
|
if (pcibios_find_class (PCI_CLASS_NETWORK_ETHERNET << 8,
|
318 |
|
|
pci_index, &pci_bus, &pci_device_fn)
|
319 |
|
|
!= PCIBIOS_SUCCESSFUL)
|
320 |
|
|
break;
|
321 |
|
|
pcibios_read_config_word(pci_bus, pci_device_fn,
|
322 |
|
|
PCI_VENDOR_ID, &vendor);
|
323 |
|
|
pcibios_read_config_word(pci_bus, pci_device_fn,
|
324 |
|
|
PCI_DEVICE_ID, &device);
|
325 |
|
|
|
326 |
|
|
for (chip_idx = 0; chip_tbl[chip_idx].vendor_id; chip_idx++)
|
327 |
|
|
if (vendor == chip_tbl[chip_idx].vendor_id
|
328 |
|
|
&& (device & chip_tbl[chip_idx].device_id_mask) ==
|
329 |
|
|
chip_tbl[chip_idx].device_id)
|
330 |
|
|
break;
|
331 |
|
|
if (chip_tbl[chip_idx].vendor_id == 0) /* Compiled out! */
|
332 |
|
|
continue;
|
333 |
|
|
|
334 |
|
|
pcibios_read_config_dword(pci_bus, pci_device_fn,
|
335 |
|
|
PCI_BASE_ADDRESS_0, &pci_ioaddr);
|
336 |
|
|
pcibios_read_config_byte(pci_bus, pci_device_fn,
|
337 |
|
|
PCI_INTERRUPT_LINE, &pci_irq_line);
|
338 |
|
|
/* Remove I/O space marker in bit 0. */
|
339 |
|
|
pci_ioaddr &= ~3;
|
340 |
|
|
irq = pci_irq_line;
|
341 |
|
|
|
342 |
|
|
if (check_region(pci_ioaddr, chip_tbl[chip_idx].io_size))
|
343 |
|
|
continue;
|
344 |
|
|
#endif
|
345 |
|
|
|
346 |
|
|
/* EPIC-specific code: Soft-reset the chip ere setting as master. */
|
347 |
|
|
outl(0x0001, pci_ioaddr + GENCTL);
|
348 |
|
|
|
349 |
|
|
/* Activate the card: fix for brain-damaged Win98 BIOSes. */
|
350 |
|
|
pcibios_read_config_word(pci_bus, pci_device_fn,
|
351 |
|
|
PCI_COMMAND, &pci_command);
|
352 |
|
|
new_command = pci_command | PCI_COMMAND_MASTER|PCI_COMMAND_IO;
|
353 |
|
|
if (pci_command != new_command) {
|
354 |
|
|
printk(KERN_INFO " The PCI BIOS has not enabled Ethernet"
|
355 |
|
|
" device %4.4x-%4.4x."
|
356 |
|
|
" Updating PCI command %4.4x->%4.4x.\n",
|
357 |
|
|
vendor, device, pci_command, new_command);
|
358 |
|
|
pcibios_write_config_word(pci_bus, pci_device_fn,
|
359 |
|
|
PCI_COMMAND, new_command);
|
360 |
|
|
}
|
361 |
|
|
|
362 |
|
|
dev = chip_tbl[chip_idx].probe1(pci_bus, pci_device_fn, dev, pci_ioaddr,
|
363 |
|
|
irq, chip_idx, cards_found);
|
364 |
|
|
|
365 |
|
|
/* Check the latency timer. */
|
366 |
|
|
if (dev) {
|
367 |
|
|
u8 pci_latency;
|
368 |
|
|
pcibios_read_config_byte(pci_bus, pci_device_fn,
|
369 |
|
|
PCI_LATENCY_TIMER, &pci_latency);
|
370 |
|
|
if (pci_latency < chip_tbl[chip_idx].min_latency) {
|
371 |
|
|
printk(KERN_INFO " PCI latency timer (CFLT) value of %d is "
|
372 |
|
|
"unreasonably low, setting to %d.\n", pci_latency,
|
373 |
|
|
chip_tbl[chip_idx].min_latency);
|
374 |
|
|
pcibios_write_config_byte(pci_bus, pci_device_fn,
|
375 |
|
|
PCI_LATENCY_TIMER,
|
376 |
|
|
chip_tbl[chip_idx].min_latency);
|
377 |
|
|
}
|
378 |
|
|
dev = 0;
|
379 |
|
|
cards_found++;
|
380 |
|
|
}
|
381 |
|
|
}
|
382 |
|
|
|
383 |
|
|
return cards_found ? 0 : -ENODEV;
|
384 |
|
|
}
|
385 |
|
|
#endif /* not CARDBUS */
|
386 |
|
|
|
387 |
|
|
static struct device *epic_probe1(int pci_bus, int pci_devfn,
|
388 |
|
|
struct device *dev, long ioaddr, int irq,
|
389 |
|
|
int chip_idx, int card_idx)
|
390 |
|
|
{
|
391 |
|
|
struct epic_private *ep;
|
392 |
|
|
int i, option = 0, duplex = 0;
|
393 |
|
|
|
394 |
|
|
if (dev && dev->mem_start) {
|
395 |
|
|
option = dev->mem_start;
|
396 |
|
|
duplex = (dev->mem_start & 16) ? 1 : 0;
|
397 |
|
|
} else if (card_idx >= 0 && card_idx < MAX_UNITS) {
|
398 |
|
|
if (options[card_idx] >= 0)
|
399 |
|
|
option = options[card_idx];
|
400 |
|
|
if (full_duplex[card_idx] >= 0)
|
401 |
|
|
duplex = full_duplex[card_idx];
|
402 |
|
|
}
|
403 |
|
|
|
404 |
|
|
dev = init_etherdev(dev, 0);
|
405 |
|
|
|
406 |
|
|
dev->base_addr = ioaddr;
|
407 |
|
|
dev->irq = irq;
|
408 |
|
|
printk(KERN_INFO "%s: SMC EPIC/100 at %#lx, IRQ %d, ",
|
409 |
|
|
dev->name, ioaddr, dev->irq);
|
410 |
|
|
|
411 |
|
|
/* Bring the chip out of low-power mode. */
|
412 |
|
|
outl(0x4200, ioaddr + GENCTL);
|
413 |
|
|
/* Magic?! If we don't set this bit the MII interface won't work. */
|
414 |
|
|
outl(0x0008, ioaddr + TEST1);
|
415 |
|
|
|
416 |
|
|
/* Turn on the MII transceiver. */
|
417 |
|
|
outl(0x12, ioaddr + MIICfg);
|
418 |
|
|
if (chip_idx == 1)
|
419 |
|
|
outl((inl(ioaddr + NVCTL) & ~0x003C) | 0x4800, ioaddr + NVCTL);
|
420 |
|
|
outl(0x0200, ioaddr + GENCTL);
|
421 |
|
|
|
422 |
|
|
/* This could also be read from the EEPROM. */
|
423 |
|
|
for (i = 0; i < 3; i++)
|
424 |
|
|
((u16 *)dev->dev_addr)[i] = inw(ioaddr + LAN0 + i*4);
|
425 |
|
|
|
426 |
|
|
for (i = 0; i < 5; i++)
|
427 |
|
|
printk("%2.2x:", dev->dev_addr[i]);
|
428 |
|
|
printk("%2.2x.\n", dev->dev_addr[i]);
|
429 |
|
|
|
430 |
|
|
if (epic_debug > 1) {
|
431 |
|
|
printk(KERN_DEBUG "%s: EEPROM contents\n", dev->name);
|
432 |
|
|
for (i = 0; i < 64; i++)
|
433 |
|
|
printk(" %4.4x%s", read_eeprom(ioaddr, i),
|
434 |
|
|
i % 16 == 15 ? "\n" : "");
|
435 |
|
|
}
|
436 |
|
|
|
437 |
|
|
/* We do a request_region() to register /proc/ioports info. */
|
438 |
|
|
request_region(ioaddr, EPIC_TOTAL_SIZE, dev->name);
|
439 |
|
|
|
440 |
|
|
/* The data structures must be quadword aligned. */
|
441 |
|
|
ep = kmalloc(sizeof(*ep), GFP_KERNEL | GFP_DMA);
|
442 |
|
|
memset(ep, 0, sizeof(*ep));
|
443 |
|
|
dev->priv = ep;
|
444 |
|
|
|
445 |
|
|
ep->next_module = root_epic_dev;
|
446 |
|
|
root_epic_dev = dev;
|
447 |
|
|
|
448 |
|
|
ep->pci_bus = pci_bus;
|
449 |
|
|
ep->pci_dev_fn = pci_devfn;
|
450 |
|
|
#if defined(PCI_SUPPORT_VER2)
|
451 |
|
|
ep->chip_id = pci_find_slot(pci_bus, pci_devfn)->device;
|
452 |
|
|
#else
|
453 |
|
|
ep->chip_id = chip_tbl[chip_idx].device_id;
|
454 |
|
|
#endif
|
455 |
|
|
|
456 |
|
|
/* Find the connected MII xcvrs.
|
457 |
|
|
Doing this in open() would allow detecting external xcvrs later, but
|
458 |
|
|
takes too much time. */
|
459 |
|
|
{
|
460 |
|
|
int phy, phy_idx;
|
461 |
|
|
for (phy = 1, phy_idx = 0; phy < 32 && phy_idx < sizeof(ep->phys);
|
462 |
|
|
phy++) {
|
463 |
|
|
int mii_status = mdio_read(ioaddr, phy, 1);
|
464 |
|
|
if (mii_status != 0xffff && mii_status != 0x0000) {
|
465 |
|
|
ep->phys[phy_idx++] = phy;
|
466 |
|
|
printk(KERN_INFO "%s: MII transceiver #%d control "
|
467 |
|
|
"%4.4x status %4.4x.\n"
|
468 |
|
|
KERN_INFO "%s: Autonegotiation advertising %4.4x "
|
469 |
|
|
"link partner %4.4x.\n",
|
470 |
|
|
dev->name, phy, mdio_read(ioaddr, phy, 0), mii_status,
|
471 |
|
|
dev->name, mdio_read(ioaddr, phy, 4),
|
472 |
|
|
mdio_read(ioaddr, phy, 5));
|
473 |
|
|
}
|
474 |
|
|
}
|
475 |
|
|
if (phy_idx == 0) {
|
476 |
|
|
printk(KERN_WARNING "%s: ***WARNING***: No MII transceiver found!\n",
|
477 |
|
|
dev->name);
|
478 |
|
|
/* Use the known PHY address of the EPII. */
|
479 |
|
|
ep->phys[0] = 3;
|
480 |
|
|
}
|
481 |
|
|
}
|
482 |
|
|
|
483 |
|
|
/* Turn off the MII xcvr (175 only!), leave the chip in low-power mode. */
|
484 |
|
|
if (ep->chip_id == 6)
|
485 |
|
|
outl(inl(ioaddr + NVCTL) & ~0x483C, ioaddr + NVCTL);
|
486 |
|
|
outl(0x0008, ioaddr + GENCTL);
|
487 |
|
|
|
488 |
|
|
/* The lower four bits are the media type. */
|
489 |
|
|
ep->force_fd = duplex;
|
490 |
|
|
ep->default_port = option;
|
491 |
|
|
if (ep->default_port)
|
492 |
|
|
ep->medialock = 1;
|
493 |
|
|
|
494 |
|
|
/* The Epic-specific entries in the device structure. */
|
495 |
|
|
dev->open = &epic_open;
|
496 |
|
|
dev->hard_start_xmit = &epic_start_xmit;
|
497 |
|
|
dev->stop = &epic_close;
|
498 |
|
|
dev->get_stats = &epic_get_stats;
|
499 |
|
|
dev->set_multicast_list = &set_rx_mode;
|
500 |
|
|
dev->do_ioctl = &mii_ioctl;
|
501 |
|
|
|
502 |
|
|
return dev;
|
503 |
|
|
}
|
504 |
|
|
|
505 |
|
|
/* Serial EEPROM section. */
|
506 |
|
|
|
507 |
|
|
/* EEPROM_Ctrl bits. */
|
508 |
|
|
#define EE_SHIFT_CLK 0x04 /* EEPROM shift clock. */
|
509 |
|
|
#define EE_CS 0x02 /* EEPROM chip select. */
|
510 |
|
|
#define EE_DATA_WRITE 0x08 /* EEPROM chip data in. */
|
511 |
|
|
#define EE_WRITE_0 0x01
|
512 |
|
|
#define EE_WRITE_1 0x09
|
513 |
|
|
#define EE_DATA_READ 0x10 /* EEPROM chip data out. */
|
514 |
|
|
#define EE_ENB (0x0001 | EE_CS)
|
515 |
|
|
|
516 |
|
|
/* Delay between EEPROM clock transitions.
|
517 |
|
|
No extra delay is needed with 33Mhz PCI, but 66Mhz is untested.
|
518 |
|
|
*/
|
519 |
|
|
|
520 |
|
|
#ifdef _LINUX_DELAY_H
|
521 |
|
|
#define eeprom_delay(nanosec) udelay(1)
|
522 |
|
|
#else
|
523 |
|
|
#define eeprom_delay(nanosec) do { ; } while (0)
|
524 |
|
|
#endif
|
525 |
|
|
|
526 |
|
|
/* The EEPROM commands include the alway-set leading bit. */
|
527 |
|
|
#define EE_WRITE_CMD (5 << 6)
|
528 |
|
|
#define EE_READ64_CMD (6 << 6)
|
529 |
|
|
#define EE_READ256_CMD (6 << 8)
|
530 |
|
|
#define EE_ERASE_CMD (7 << 6)
|
531 |
|
|
|
532 |
|
|
static int read_eeprom(long ioaddr, int location)
|
533 |
|
|
{
|
534 |
|
|
int i;
|
535 |
|
|
int retval = 0;
|
536 |
|
|
long ee_addr = ioaddr + EECTL;
|
537 |
|
|
int read_cmd = location |
|
538 |
|
|
(inl(ee_addr) & 0x40) ? EE_READ64_CMD : EE_READ256_CMD;
|
539 |
|
|
|
540 |
|
|
outl(EE_ENB & ~EE_CS, ee_addr);
|
541 |
|
|
outl(EE_ENB, ee_addr);
|
542 |
|
|
|
543 |
|
|
/* Shift the read command bits out. */
|
544 |
|
|
for (i = 12; i >= 0; i--) {
|
545 |
|
|
short dataval = (read_cmd & (1 << i)) ? EE_WRITE_1 : EE_WRITE_0;
|
546 |
|
|
outl(EE_ENB | dataval, ee_addr);
|
547 |
|
|
eeprom_delay(100);
|
548 |
|
|
outl(EE_ENB | dataval | EE_SHIFT_CLK, ee_addr);
|
549 |
|
|
eeprom_delay(150);
|
550 |
|
|
}
|
551 |
|
|
outl(EE_ENB, ee_addr);
|
552 |
|
|
|
553 |
|
|
for (i = 16; i > 0; i--) {
|
554 |
|
|
outl(EE_ENB | EE_SHIFT_CLK, ee_addr);
|
555 |
|
|
eeprom_delay(100);
|
556 |
|
|
retval = (retval << 1) | ((inl(ee_addr) & EE_DATA_READ) ? 1 : 0);
|
557 |
|
|
outl(EE_ENB, ee_addr);
|
558 |
|
|
eeprom_delay(100);
|
559 |
|
|
}
|
560 |
|
|
|
561 |
|
|
/* Terminate the EEPROM access. */
|
562 |
|
|
outl(EE_ENB & ~EE_CS, ee_addr);
|
563 |
|
|
return retval;
|
564 |
|
|
}
|
565 |
|
|
|
566 |
|
|
#define MII_READOP 1
|
567 |
|
|
#define MII_WRITEOP 2
|
568 |
|
|
static int mdio_read(long ioaddr, int phy_id, int location)
|
569 |
|
|
{
|
570 |
|
|
int i;
|
571 |
|
|
|
572 |
|
|
outl((phy_id << 9) | (location << 4) | MII_READOP, ioaddr + MIICtrl);
|
573 |
|
|
/* Typical operation takes < 50 ticks. */
|
574 |
|
|
for (i = 4000; i > 0; i--)
|
575 |
|
|
if ((inl(ioaddr + MIICtrl) & MII_READOP) == 0)
|
576 |
|
|
return inw(ioaddr + MIIData);
|
577 |
|
|
return 0xffff;
|
578 |
|
|
}
|
579 |
|
|
|
580 |
|
|
static void mdio_write(long ioaddr, int phy_id, int location, int value)
|
581 |
|
|
{
|
582 |
|
|
int i;
|
583 |
|
|
|
584 |
|
|
outw(value, ioaddr + MIIData);
|
585 |
|
|
outl((phy_id << 9) | (location << 4) | MII_WRITEOP, ioaddr + MIICtrl);
|
586 |
|
|
for (i = 10000; i > 0; i--) {
|
587 |
|
|
if ((inl(ioaddr + MIICtrl) & MII_WRITEOP) == 0)
|
588 |
|
|
break;
|
589 |
|
|
}
|
590 |
|
|
return;
|
591 |
|
|
}
|
592 |
|
|
|
593 |
|
|
|
594 |
|
|
static int
|
595 |
|
|
epic_open(struct device *dev)
|
596 |
|
|
{
|
597 |
|
|
struct epic_private *ep = (struct epic_private *)dev->priv;
|
598 |
|
|
long ioaddr = dev->base_addr;
|
599 |
|
|
int i;
|
600 |
|
|
int mii_reg5;
|
601 |
|
|
ep->full_duplex = ep->force_fd;
|
602 |
|
|
|
603 |
|
|
/* Soft reset the chip. */
|
604 |
|
|
outl(0x4001, ioaddr + GENCTL);
|
605 |
|
|
|
606 |
|
|
if (request_irq(dev->irq, &epic_interrupt, SA_SHIRQ, "SMC EPIC/100", dev))
|
607 |
|
|
return -EAGAIN;
|
608 |
|
|
|
609 |
|
|
MOD_INC_USE_COUNT;
|
610 |
|
|
|
611 |
|
|
epic_init_ring(dev);
|
612 |
|
|
|
613 |
|
|
outl(0x4000, ioaddr + GENCTL);
|
614 |
|
|
/* This next magic! line by Ken Yamaguchi.. ?? */
|
615 |
|
|
outl(0x0008, ioaddr + TEST1);
|
616 |
|
|
|
617 |
|
|
/* Pull the chip out of low-power mode, enable interrupts, and set for
|
618 |
|
|
PCI read multiple. The MIIcfg setting and strange write order are
|
619 |
|
|
required by the details of which bits are reset and the transceiver
|
620 |
|
|
wiring on the Ositech CardBus card.
|
621 |
|
|
*/
|
622 |
|
|
outl(0x12, ioaddr + MIICfg);
|
623 |
|
|
if (ep->chip_id == 6)
|
624 |
|
|
outl((inl(ioaddr + NVCTL) & ~0x003C) | 0x4800, ioaddr + NVCTL);
|
625 |
|
|
|
626 |
|
|
#if defined(__powerpc__) || defined(__sparc__) /* Big endian */
|
627 |
|
|
outl(0x0432 | (RX_FIFO_THRESH<<8), ioaddr + GENCTL);
|
628 |
|
|
#else
|
629 |
|
|
outl(0x0412 | (RX_FIFO_THRESH<<8), ioaddr + GENCTL);
|
630 |
|
|
#endif
|
631 |
|
|
|
632 |
|
|
for (i = 0; i < 3; i++)
|
633 |
|
|
outl(((u16*)dev->dev_addr)[i], ioaddr + LAN0 + i*4);
|
634 |
|
|
|
635 |
|
|
outl(TX_FIFO_THRESH, ioaddr + TxThresh);
|
636 |
|
|
|
637 |
|
|
mii_reg5 = mdio_read(ioaddr, ep->phys[0], 5);
|
638 |
|
|
if (mii_reg5 != 0xffff) {
|
639 |
|
|
if ((mii_reg5 & 0x0100) || (mii_reg5 & 0x01C0) == 0x0040)
|
640 |
|
|
ep->full_duplex = 1;
|
641 |
|
|
else if (! (mii_reg5 & 0x4000))
|
642 |
|
|
mdio_write(ioaddr, ep->phys[0], 0, 0x1200);
|
643 |
|
|
if (epic_debug > 1)
|
644 |
|
|
printk(KERN_INFO "%s: Setting %s-duplex based on MII xcvr %d"
|
645 |
|
|
" register read of %4.4x.\n", dev->name,
|
646 |
|
|
ep->full_duplex ? "full" : "half", ep->phys[0], mii_reg5);
|
647 |
|
|
}
|
648 |
|
|
|
649 |
|
|
outl(ep->full_duplex ? 0x7F : 0x79, ioaddr + TxCtrl);
|
650 |
|
|
outl(virt_to_bus(ep->rx_ring), ioaddr + PRxCDAR);
|
651 |
|
|
outl(virt_to_bus(ep->tx_ring), ioaddr + PTxCDAR);
|
652 |
|
|
|
653 |
|
|
/* Start the chip's Rx process. */
|
654 |
|
|
set_rx_mode(dev);
|
655 |
|
|
outl(0x000A, ioaddr + COMMAND);
|
656 |
|
|
|
657 |
|
|
dev->tbusy = 0;
|
658 |
|
|
dev->interrupt = 0;
|
659 |
|
|
dev->start = 1;
|
660 |
|
|
|
661 |
|
|
/* Enable interrupts by setting the interrupt mask. */
|
662 |
|
|
outl((ep->chip_id == 6 ? PCIBusErr175 : PCIBusErr170)
|
663 |
|
|
| CntFull | TxUnderrun | TxDone
|
664 |
|
|
| RxError | RxOverflow | RxFull | RxHeader | RxDone,
|
665 |
|
|
ioaddr + INTMASK);
|
666 |
|
|
|
667 |
|
|
if (epic_debug > 1)
|
668 |
|
|
printk(KERN_DEBUG "%s: epic_open() ioaddr %lx IRQ %d status %4.4x "
|
669 |
|
|
"%s-duplex.\n",
|
670 |
|
|
dev->name, ioaddr, dev->irq, inl(ioaddr + GENCTL),
|
671 |
|
|
ep->full_duplex ? "full" : "half");
|
672 |
|
|
|
673 |
|
|
/* Set the timer to switch to check for link beat and perhaps switch
|
674 |
|
|
to an alternate media type. */
|
675 |
|
|
init_timer(&ep->timer);
|
676 |
|
|
ep->timer.expires = RUN_AT((24*HZ)/10); /* 2.4 sec. */
|
677 |
|
|
ep->timer.data = (unsigned long)dev;
|
678 |
|
|
ep->timer.function = &epic_timer; /* timer handler */
|
679 |
|
|
add_timer(&ep->timer);
|
680 |
|
|
|
681 |
|
|
return 0;
|
682 |
|
|
}
|
683 |
|
|
|
684 |
|
|
/* Reset the chip to recover from a PCI transaction error.
|
685 |
|
|
This may occur at interrupt time. */
|
686 |
|
|
static void epic_pause(struct device *dev)
|
687 |
|
|
{
|
688 |
|
|
long ioaddr = dev->base_addr;
|
689 |
|
|
struct epic_private *ep = (struct epic_private *)dev->priv;
|
690 |
|
|
|
691 |
|
|
/* Disable interrupts by clearing the interrupt mask. */
|
692 |
|
|
outl(0x00000000, ioaddr + INTMASK);
|
693 |
|
|
/* Stop the chip's Tx and Rx DMA processes. */
|
694 |
|
|
outw(0x0061, ioaddr + COMMAND);
|
695 |
|
|
|
696 |
|
|
/* Update the error counts. */
|
697 |
|
|
if (inw(ioaddr + COMMAND) != 0xffff) {
|
698 |
|
|
ep->stats.rx_missed_errors += inb(ioaddr + MPCNT);
|
699 |
|
|
ep->stats.rx_frame_errors += inb(ioaddr + ALICNT);
|
700 |
|
|
ep->stats.rx_crc_errors += inb(ioaddr + CRCCNT);
|
701 |
|
|
}
|
702 |
|
|
|
703 |
|
|
/* Remove the packets on the Rx queue. */
|
704 |
|
|
epic_rx(dev);
|
705 |
|
|
}
|
706 |
|
|
|
707 |
|
|
static void epic_restart(struct device *dev)
|
708 |
|
|
{
|
709 |
|
|
long ioaddr = dev->base_addr;
|
710 |
|
|
struct epic_private *ep = (struct epic_private *)dev->priv;
|
711 |
|
|
int i;
|
712 |
|
|
|
713 |
|
|
printk(KERN_DEBUG "%s: Restarting the EPIC chip, Rx %d/%d Tx %d/%d.\n",
|
714 |
|
|
dev->name, ep->cur_rx, ep->dirty_rx, ep->dirty_tx, ep->cur_tx);
|
715 |
|
|
/* Soft reset the chip. */
|
716 |
|
|
outl(0x0001, ioaddr + GENCTL);
|
717 |
|
|
|
718 |
|
|
udelay(1);
|
719 |
|
|
/* Duplicate code from epic_open(). */
|
720 |
|
|
outl(0x0008, ioaddr + TEST1);
|
721 |
|
|
|
722 |
|
|
#if defined(__powerpc__) /* Big endian */
|
723 |
|
|
outl(0x0432 | (RX_FIFO_THRESH<<8), ioaddr + GENCTL);
|
724 |
|
|
#else
|
725 |
|
|
outl(0x0412 | (RX_FIFO_THRESH<<8), ioaddr + GENCTL);
|
726 |
|
|
#endif
|
727 |
|
|
outl(0x12, ioaddr + MIICfg);
|
728 |
|
|
if (ep->chip_id == 6)
|
729 |
|
|
outl((inl(ioaddr + NVCTL) & ~0x003C) | 0x4800, ioaddr + NVCTL);
|
730 |
|
|
|
731 |
|
|
for (i = 0; i < 3; i++)
|
732 |
|
|
outl(((u16*)dev->dev_addr)[i], ioaddr + LAN0 + i*4);
|
733 |
|
|
|
734 |
|
|
outl(TX_FIFO_THRESH, ioaddr + TxThresh);
|
735 |
|
|
outl(ep->full_duplex ? 0x7F : 0x79, ioaddr + TxCtrl);
|
736 |
|
|
outl(virt_to_bus(&ep->rx_ring[ep->cur_rx%RX_RING_SIZE]), ioaddr + PRxCDAR);
|
737 |
|
|
outl(virt_to_bus(&ep->tx_ring[ep->dirty_tx%TX_RING_SIZE]),
|
738 |
|
|
ioaddr + PTxCDAR);
|
739 |
|
|
|
740 |
|
|
/* Start the chip's Rx process. */
|
741 |
|
|
set_rx_mode(dev);
|
742 |
|
|
outl(0x000A, ioaddr + COMMAND);
|
743 |
|
|
|
744 |
|
|
/* Enable interrupts by setting the interrupt mask. */
|
745 |
|
|
outl((ep->chip_id == 6 ? PCIBusErr175 : PCIBusErr170)
|
746 |
|
|
| CntFull | TxUnderrun | TxDone
|
747 |
|
|
| RxError | RxOverflow | RxFull | RxHeader | RxDone,
|
748 |
|
|
ioaddr + INTMASK);
|
749 |
|
|
printk(KERN_DEBUG "%s: epic_restart() done, cmd status %4.4x, ctl %4.4x"
|
750 |
|
|
" interrupt %4.4x.\n",
|
751 |
|
|
dev->name, inl(ioaddr + COMMAND), inl(ioaddr + GENCTL),
|
752 |
|
|
inl(ioaddr + INTSTAT));
|
753 |
|
|
return;
|
754 |
|
|
}
|
755 |
|
|
|
756 |
|
|
static void epic_timer(unsigned long data)
|
757 |
|
|
{
|
758 |
|
|
struct device *dev = (struct device *)data;
|
759 |
|
|
struct epic_private *ep = (struct epic_private *)dev->priv;
|
760 |
|
|
long ioaddr = dev->base_addr;
|
761 |
|
|
int next_tick = 0;
|
762 |
|
|
int mii_reg5 = mdio_read(ioaddr, ep->phys[0], 5);
|
763 |
|
|
|
764 |
|
|
if (epic_debug > 3) {
|
765 |
|
|
printk(KERN_DEBUG "%s: Media selection tick, Tx status %8.8x.\n",
|
766 |
|
|
dev->name, inl(ioaddr + TxSTAT));
|
767 |
|
|
printk(KERN_DEBUG "%s: Other registers are IntMask %4.4x "
|
768 |
|
|
"IntStatus %4.4x RxStatus %4.4x.\n",
|
769 |
|
|
dev->name, inl(ioaddr + INTMASK), inl(ioaddr + INTSTAT),
|
770 |
|
|
inl(ioaddr + RxSTAT));
|
771 |
|
|
}
|
772 |
|
|
if (! ep->force_fd && mii_reg5 != 0xffff) {
|
773 |
|
|
int duplex = (mii_reg5&0x0100) || (mii_reg5 & 0x01C0) == 0x0040;
|
774 |
|
|
if (ep->full_duplex != duplex) {
|
775 |
|
|
ep->full_duplex = duplex;
|
776 |
|
|
printk(KERN_INFO "%s: Setting %s-duplex based on MII #%d link"
|
777 |
|
|
" partner capability of %4.4x.\n", dev->name,
|
778 |
|
|
ep->full_duplex ? "full" : "half", ep->phys[0], mii_reg5);
|
779 |
|
|
outl(ep->full_duplex ? 0x7F : 0x79, ioaddr + TxCtrl);
|
780 |
|
|
}
|
781 |
|
|
next_tick = 60*HZ;
|
782 |
|
|
}
|
783 |
|
|
|
784 |
|
|
if (next_tick) {
|
785 |
|
|
ep->timer.expires = RUN_AT(next_tick);
|
786 |
|
|
add_timer(&ep->timer);
|
787 |
|
|
}
|
788 |
|
|
}
|
789 |
|
|
|
790 |
|
|
static void epic_tx_timeout(struct device *dev)
|
791 |
|
|
{
|
792 |
|
|
struct epic_private *ep = (struct epic_private *)dev->priv;
|
793 |
|
|
long ioaddr = dev->base_addr;
|
794 |
|
|
|
795 |
|
|
if (epic_debug > 0) {
|
796 |
|
|
printk(KERN_WARNING "%s: Transmit timeout using MII device, "
|
797 |
|
|
"Tx status %4.4x.\n",
|
798 |
|
|
dev->name, inw(ioaddr + TxSTAT));
|
799 |
|
|
if (epic_debug > 1) {
|
800 |
|
|
printk(KERN_DEBUG "%s: Tx indices: dirty_tx %d, cur_tx %d.\n",
|
801 |
|
|
dev->name, ep->dirty_tx, ep->cur_tx);
|
802 |
|
|
}
|
803 |
|
|
}
|
804 |
|
|
if (inw(ioaddr + TxSTAT) & 0x10) { /* Tx FIFO underflow. */
|
805 |
|
|
ep->stats.tx_fifo_errors++;
|
806 |
|
|
/* Restart the transmit process. */
|
807 |
|
|
outl(0x0080, ioaddr + COMMAND);
|
808 |
|
|
}
|
809 |
|
|
|
810 |
|
|
/* Perhaps stop and restart the chip's Tx processes . */
|
811 |
|
|
/* Trigger a transmit demand. */
|
812 |
|
|
outl(0x0004, dev->base_addr + COMMAND);
|
813 |
|
|
|
814 |
|
|
dev->trans_start = jiffies;
|
815 |
|
|
ep->stats.tx_errors++;
|
816 |
|
|
return;
|
817 |
|
|
}
|
818 |
|
|
|
819 |
|
|
/* Initialize the Rx and Tx rings, along with various 'dev' bits. */
|
820 |
|
|
static void
|
821 |
|
|
epic_init_ring(struct device *dev)
|
822 |
|
|
{
|
823 |
|
|
struct epic_private *ep = (struct epic_private *)dev->priv;
|
824 |
|
|
int i;
|
825 |
|
|
|
826 |
|
|
ep->tx_full = 0;
|
827 |
|
|
ep->cur_rx = ep->cur_tx = 0;
|
828 |
|
|
ep->dirty_rx = ep->dirty_tx = 0;
|
829 |
|
|
|
830 |
|
|
for (i = 0; i < RX_RING_SIZE; i++) {
|
831 |
|
|
ep->rx_ring[i].status = 0x8000; /* Owned by Epic chip */
|
832 |
|
|
ep->rx_ring[i].buflength = PKT_BUF_SZ;
|
833 |
|
|
{
|
834 |
|
|
/* Note the receive buffer must be longword aligned.
|
835 |
|
|
dev_alloc_skb() provides 16 byte alignment. But do *not*
|
836 |
|
|
use skb_reserve() to align the IP header! */
|
837 |
|
|
struct sk_buff *skb;
|
838 |
|
|
skb = dev_alloc_skb(PKT_BUF_SZ);
|
839 |
|
|
ep->rx_skbuff[i] = skb;
|
840 |
|
|
if (skb == NULL)
|
841 |
|
|
break; /* Bad news! */
|
842 |
|
|
skb->dev = dev; /* Mark as being used by this device. */
|
843 |
|
|
skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
|
844 |
|
|
ep->rx_ring[i].bufaddr = virt_to_bus(skb->tail);
|
845 |
|
|
}
|
846 |
|
|
ep->rx_ring[i].next = virt_to_bus(&ep->rx_ring[i+1]);
|
847 |
|
|
}
|
848 |
|
|
/* Mark the last entry as wrapping the ring. */
|
849 |
|
|
ep->rx_ring[i-1].next = virt_to_bus(&ep->rx_ring[0]);
|
850 |
|
|
|
851 |
|
|
/* The Tx buffer descriptor is filled in as needed, but we
|
852 |
|
|
do need to clear the ownership bit. */
|
853 |
|
|
for (i = 0; i < TX_RING_SIZE; i++) {
|
854 |
|
|
ep->tx_skbuff[i] = 0;
|
855 |
|
|
ep->tx_ring[i].status = 0x0000;
|
856 |
|
|
ep->tx_ring[i].next = virt_to_bus(&ep->tx_ring[i+1]);
|
857 |
|
|
}
|
858 |
|
|
ep->tx_ring[i-1].next = virt_to_bus(&ep->tx_ring[0]);
|
859 |
|
|
}
|
860 |
|
|
|
861 |
|
|
static int
|
862 |
|
|
epic_start_xmit(struct sk_buff *skb, struct device *dev)
|
863 |
|
|
{
|
864 |
|
|
struct epic_private *ep = (struct epic_private *)dev->priv;
|
865 |
|
|
int entry;
|
866 |
|
|
u32 flag;
|
867 |
|
|
|
868 |
|
|
/* Block a timer-based transmit from overlapping. This could better be
|
869 |
|
|
done with atomic_swap(1, dev->tbusy), but set_bit() works as well. */
|
870 |
|
|
if (test_and_set_bit(0, (void*)&dev->tbusy) != 0) {
|
871 |
|
|
if (jiffies - dev->trans_start < TX_TIMEOUT)
|
872 |
|
|
return 1;
|
873 |
|
|
epic_tx_timeout(dev);
|
874 |
|
|
return 1;
|
875 |
|
|
}
|
876 |
|
|
|
877 |
|
|
/* Caution: the write order is important here, set the base address
|
878 |
|
|
with the "ownership" bits last. */
|
879 |
|
|
|
880 |
|
|
/* Calculate the next Tx descriptor entry. */
|
881 |
|
|
entry = ep->cur_tx % TX_RING_SIZE;
|
882 |
|
|
|
883 |
|
|
ep->tx_skbuff[entry] = skb;
|
884 |
|
|
ep->tx_ring[entry].txlength = (skb->len >= ETH_ZLEN ? skb->len : ETH_ZLEN);
|
885 |
|
|
ep->tx_ring[entry].bufaddr = virt_to_bus(skb->data);
|
886 |
|
|
ep->tx_ring[entry].buflength = skb->len;
|
887 |
|
|
|
888 |
|
|
if (ep->cur_tx - ep->dirty_tx < TX_RING_SIZE/2) {/* Typical path */
|
889 |
|
|
flag = 0x10; /* No interrupt */
|
890 |
|
|
clear_bit(0, (void*)&dev->tbusy);
|
891 |
|
|
} else if (ep->cur_tx - ep->dirty_tx == TX_RING_SIZE/2) {
|
892 |
|
|
flag = 0x14; /* Tx-done intr. */
|
893 |
|
|
clear_bit(0, (void*)&dev->tbusy);
|
894 |
|
|
} else if (ep->cur_tx - ep->dirty_tx < TX_RING_SIZE - 2) {
|
895 |
|
|
flag = 0x10; /* No Tx-done intr. */
|
896 |
|
|
clear_bit(0, (void*)&dev->tbusy);
|
897 |
|
|
} else {
|
898 |
|
|
/* Leave room for two additional entries. */
|
899 |
|
|
flag = 0x14; /* Tx-done intr. */
|
900 |
|
|
ep->tx_full = 1;
|
901 |
|
|
}
|
902 |
|
|
|
903 |
|
|
ep->tx_ring[entry].control = flag;
|
904 |
|
|
ep->tx_ring[entry].status = 0x8000; /* Pass ownership to the chip. */
|
905 |
|
|
ep->cur_tx++;
|
906 |
|
|
/* Trigger an immediate transmit demand. */
|
907 |
|
|
outl(0x0004, dev->base_addr + COMMAND);
|
908 |
|
|
|
909 |
|
|
dev->trans_start = jiffies;
|
910 |
|
|
if (epic_debug > 4)
|
911 |
|
|
printk(KERN_DEBUG "%s: Queued Tx packet size %d to slot %d, "
|
912 |
|
|
"flag %2.2x Tx status %8.8x.\n",
|
913 |
|
|
dev->name, (int)skb->len, entry, flag,
|
914 |
|
|
inl(dev->base_addr + TxSTAT));
|
915 |
|
|
|
916 |
|
|
return 0;
|
917 |
|
|
}
|
918 |
|
|
|
919 |
|
|
/* The interrupt handler does all of the Rx thread work and cleans up
|
920 |
|
|
after the Tx thread. */
|
921 |
|
|
static void epic_interrupt(int irq, void *dev_instance, struct pt_regs *regs)
|
922 |
|
|
{
|
923 |
|
|
struct device *dev = (struct device *)dev_instance;
|
924 |
|
|
struct epic_private *ep = (struct epic_private *)dev->priv;
|
925 |
|
|
long ioaddr = dev->base_addr;
|
926 |
|
|
int status, boguscnt = max_interrupt_work;
|
927 |
|
|
|
928 |
|
|
#if defined(__i386__)
|
929 |
|
|
/* A lock to prevent simultaneous entry bug on Intel SMP machines. */
|
930 |
|
|
if (test_and_set_bit(0, (void*)&dev->interrupt)) {
|
931 |
|
|
printk(KERN_ERR"%s: SMP simultaneous entry of an interrupt handler.\n",
|
932 |
|
|
dev->name);
|
933 |
|
|
dev->interrupt = 0; /* Avoid halting machine. */
|
934 |
|
|
return;
|
935 |
|
|
}
|
936 |
|
|
#else
|
937 |
|
|
if (dev->interrupt) {
|
938 |
|
|
printk(KERN_ERR "%s: Re-entering the interrupt handler.\n", dev->name);
|
939 |
|
|
return;
|
940 |
|
|
}
|
941 |
|
|
dev->interrupt = 1;
|
942 |
|
|
#endif
|
943 |
|
|
|
944 |
|
|
do {
|
945 |
|
|
status = inl(ioaddr + INTSTAT);
|
946 |
|
|
/* Acknowledge all of the current interrupt sources ASAP. */
|
947 |
|
|
outl(status & 0x00007fff, ioaddr + INTSTAT);
|
948 |
|
|
|
949 |
|
|
if (epic_debug > 4)
|
950 |
|
|
printk("%s: interrupt interrupt=%#8.8x new intstat=%#8.8x.\n",
|
951 |
|
|
dev->name, status, inl(ioaddr + INTSTAT));
|
952 |
|
|
|
953 |
|
|
if ((status & IntrSummary) == 0)
|
954 |
|
|
break;
|
955 |
|
|
|
956 |
|
|
if (status & (RxDone | RxStarted | RxEarlyWarn))
|
957 |
|
|
epic_rx(dev);
|
958 |
|
|
|
959 |
|
|
if (status & (TxEmpty | TxDone)) {
|
960 |
|
|
int dirty_tx;
|
961 |
|
|
|
962 |
|
|
for (dirty_tx = ep->dirty_tx; dirty_tx < ep->cur_tx; dirty_tx++) {
|
963 |
|
|
int entry = dirty_tx % TX_RING_SIZE;
|
964 |
|
|
int txstatus = ep->tx_ring[entry].status;
|
965 |
|
|
|
966 |
|
|
if (txstatus < 0)
|
967 |
|
|
break; /* It still hasn't been Txed */
|
968 |
|
|
|
969 |
|
|
if ( ! (txstatus & 0x0001)) {
|
970 |
|
|
/* There was an major error, log it. */
|
971 |
|
|
#ifndef final_version
|
972 |
|
|
if (epic_debug > 1)
|
973 |
|
|
printk("%s: Transmit error, Tx status %8.8x.\n",
|
974 |
|
|
dev->name, txstatus);
|
975 |
|
|
#endif
|
976 |
|
|
ep->stats.tx_errors++;
|
977 |
|
|
if (txstatus & 0x1050) ep->stats.tx_aborted_errors++;
|
978 |
|
|
if (txstatus & 0x0008) ep->stats.tx_carrier_errors++;
|
979 |
|
|
if (txstatus & 0x0040) ep->stats.tx_window_errors++;
|
980 |
|
|
if (txstatus & 0x0010) ep->stats.tx_fifo_errors++;
|
981 |
|
|
#ifdef ETHER_STATS
|
982 |
|
|
if (txstatus & 0x1000) ep->stats.collisions16++;
|
983 |
|
|
#endif
|
984 |
|
|
} else {
|
985 |
|
|
#ifdef ETHER_STATS
|
986 |
|
|
if ((txstatus & 0x0002) != 0) ep->stats.tx_deferred++;
|
987 |
|
|
#endif
|
988 |
|
|
ep->stats.collisions += (txstatus >> 8) & 15;
|
989 |
|
|
ep->stats.tx_packets++;
|
990 |
|
|
}
|
991 |
|
|
|
992 |
|
|
/* Free the original skb. */
|
993 |
|
|
DEV_FREE_SKB(ep->tx_skbuff[entry]);
|
994 |
|
|
ep->tx_skbuff[entry] = 0;
|
995 |
|
|
}
|
996 |
|
|
|
997 |
|
|
#ifndef final_version
|
998 |
|
|
if (ep->cur_tx - dirty_tx > TX_RING_SIZE) {
|
999 |
|
|
printk("%s: Out-of-sync dirty pointer, %d vs. %d, full=%d.\n",
|
1000 |
|
|
dev->name, dirty_tx, ep->cur_tx, ep->tx_full);
|
1001 |
|
|
dirty_tx += TX_RING_SIZE;
|
1002 |
|
|
}
|
1003 |
|
|
#endif
|
1004 |
|
|
|
1005 |
|
|
if (ep->tx_full && dev->tbusy
|
1006 |
|
|
&& dirty_tx > ep->cur_tx - TX_RING_SIZE + 2) {
|
1007 |
|
|
/* The ring is no longer full, clear tbusy. */
|
1008 |
|
|
ep->tx_full = 0;
|
1009 |
|
|
clear_bit(0, (void*)&dev->tbusy);
|
1010 |
|
|
mark_bh(NET_BH);
|
1011 |
|
|
}
|
1012 |
|
|
|
1013 |
|
|
ep->dirty_tx = dirty_tx;
|
1014 |
|
|
}
|
1015 |
|
|
|
1016 |
|
|
/* Check uncommon events all at once. */
|
1017 |
|
|
if (status & (CntFull | TxUnderrun | RxOverflow |
|
1018 |
|
|
PCIBusErr170 | PCIBusErr175)) {
|
1019 |
|
|
if (status == 0xffffffff) /* Chip failed or removed (CardBus). */
|
1020 |
|
|
break;
|
1021 |
|
|
/* Always update the error counts to avoid overhead later. */
|
1022 |
|
|
ep->stats.rx_missed_errors += inb(ioaddr + MPCNT);
|
1023 |
|
|
ep->stats.rx_frame_errors += inb(ioaddr + ALICNT);
|
1024 |
|
|
ep->stats.rx_crc_errors += inb(ioaddr + CRCCNT);
|
1025 |
|
|
|
1026 |
|
|
if (status & TxUnderrun) { /* Tx FIFO underflow. */
|
1027 |
|
|
ep->stats.tx_fifo_errors++;
|
1028 |
|
|
outl(1536, ioaddr + TxThresh);
|
1029 |
|
|
/* Restart the transmit process. */
|
1030 |
|
|
outl(0x0080, ioaddr + COMMAND);
|
1031 |
|
|
}
|
1032 |
|
|
if (status & RxOverflow) { /* Missed a Rx frame. */
|
1033 |
|
|
ep->stats.rx_errors++;
|
1034 |
|
|
}
|
1035 |
|
|
if (status & PCIBusErr170) {
|
1036 |
|
|
printk(KERN_ERR "%s: PCI Bus Error! EPIC status %4.4x.\n",
|
1037 |
|
|
dev->name, status);
|
1038 |
|
|
epic_pause(dev);
|
1039 |
|
|
epic_restart(dev);
|
1040 |
|
|
}
|
1041 |
|
|
/* Clear all error sources. */
|
1042 |
|
|
outl(status & 0x7f18, ioaddr + INTSTAT);
|
1043 |
|
|
}
|
1044 |
|
|
if (--boguscnt < 0) {
|
1045 |
|
|
printk(KERN_ERR "%s: Too much work at interrupt, "
|
1046 |
|
|
"IntrStatus=0x%8.8x.\n",
|
1047 |
|
|
dev->name, status);
|
1048 |
|
|
/* Clear all interrupt sources. */
|
1049 |
|
|
outl(0x0001ffff, ioaddr + INTSTAT);
|
1050 |
|
|
break;
|
1051 |
|
|
}
|
1052 |
|
|
} while (1);
|
1053 |
|
|
|
1054 |
|
|
if (epic_debug > 3)
|
1055 |
|
|
printk(KERN_DEBUG "%s: exiting interrupt, intr_status=%#4.4x.\n",
|
1056 |
|
|
dev->name, inl(ioaddr + INTSTAT));
|
1057 |
|
|
|
1058 |
|
|
#if defined(__i386__)
|
1059 |
|
|
clear_bit(0, (void*)&dev->interrupt);
|
1060 |
|
|
#else
|
1061 |
|
|
dev->interrupt = 0;
|
1062 |
|
|
#endif
|
1063 |
|
|
return;
|
1064 |
|
|
}
|
1065 |
|
|
|
1066 |
|
|
static int epic_rx(struct device *dev)
|
1067 |
|
|
{
|
1068 |
|
|
struct epic_private *ep = (struct epic_private *)dev->priv;
|
1069 |
|
|
int entry = ep->cur_rx % RX_RING_SIZE;
|
1070 |
|
|
int work_done = 0;
|
1071 |
|
|
|
1072 |
|
|
if (epic_debug > 4)
|
1073 |
|
|
printk(KERN_DEBUG " In epic_rx(), entry %d %8.8x.\n", entry,
|
1074 |
|
|
ep->rx_ring[entry].status);
|
1075 |
|
|
/* If we own the next entry, it's a new packet. Send it up. */
|
1076 |
|
|
while (ep->rx_ring[entry].status >= 0 && ep->rx_skbuff[entry]) {
|
1077 |
|
|
int status = ep->rx_ring[entry].status;
|
1078 |
|
|
|
1079 |
|
|
if (epic_debug > 4)
|
1080 |
|
|
printk(KERN_DEBUG " epic_rx() status was %8.8x.\n", status);
|
1081 |
|
|
if (status & 0x2006) {
|
1082 |
|
|
if (status & 0x2000) {
|
1083 |
|
|
printk(KERN_WARNING "%s: Oversized Ethernet frame spanned "
|
1084 |
|
|
"multiple buffers, status %4.4x!\n", dev->name, status);
|
1085 |
|
|
ep->stats.rx_length_errors++;
|
1086 |
|
|
} else if (status & 0x0006)
|
1087 |
|
|
/* Rx Frame errors are counted in hardware. */
|
1088 |
|
|
ep->stats.rx_errors++;
|
1089 |
|
|
} else {
|
1090 |
|
|
/* Malloc up new buffer, compatible with net-2e. */
|
1091 |
|
|
/* Omit the four octet CRC from the length. */
|
1092 |
|
|
short pkt_len = ep->rx_ring[entry].rxlength - 4;
|
1093 |
|
|
struct sk_buff *skb;
|
1094 |
|
|
|
1095 |
|
|
/* Check if the packet is long enough to accept without copying
|
1096 |
|
|
to a minimally-sized skbuff. */
|
1097 |
|
|
if (pkt_len < rx_copybreak
|
1098 |
|
|
&& (skb = dev_alloc_skb(pkt_len + 2)) != NULL) {
|
1099 |
|
|
skb->dev = dev;
|
1100 |
|
|
skb_reserve(skb, 2); /* 16 byte align the IP header */
|
1101 |
|
|
#if 1 /* USE_IP_COPYSUM */
|
1102 |
|
|
eth_copy_and_sum(skb, bus_to_virt(ep->rx_ring[entry].bufaddr),
|
1103 |
|
|
pkt_len, 0);
|
1104 |
|
|
skb_put(skb, pkt_len);
|
1105 |
|
|
#else
|
1106 |
|
|
memcpy(skb_put(skb, pkt_len),
|
1107 |
|
|
bus_to_virt(ep->rx_ring[entry].bufaddr), pkt_len);
|
1108 |
|
|
#endif
|
1109 |
|
|
} else {
|
1110 |
|
|
skb_put(skb = ep->rx_skbuff[entry], pkt_len);
|
1111 |
|
|
ep->rx_skbuff[entry] = NULL;
|
1112 |
|
|
}
|
1113 |
|
|
skb->protocol = eth_type_trans(skb, dev);
|
1114 |
|
|
netif_rx(skb);
|
1115 |
|
|
ep->stats.rx_packets++;
|
1116 |
|
|
}
|
1117 |
|
|
work_done++;
|
1118 |
|
|
entry = (++ep->cur_rx) % RX_RING_SIZE;
|
1119 |
|
|
}
|
1120 |
|
|
|
1121 |
|
|
/* Refill the Rx ring buffers. */
|
1122 |
|
|
for (; ep->cur_rx - ep->dirty_rx > 0; ep->dirty_rx++) {
|
1123 |
|
|
entry = ep->dirty_rx % RX_RING_SIZE;
|
1124 |
|
|
if (ep->rx_skbuff[entry] == NULL) {
|
1125 |
|
|
struct sk_buff *skb;
|
1126 |
|
|
skb = ep->rx_skbuff[entry] = dev_alloc_skb(PKT_BUF_SZ);
|
1127 |
|
|
if (skb == NULL)
|
1128 |
|
|
break;
|
1129 |
|
|
skb->dev = dev; /* Mark as being used by this device. */
|
1130 |
|
|
skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
|
1131 |
|
|
ep->rx_ring[entry].bufaddr = virt_to_bus(skb->tail);
|
1132 |
|
|
work_done++;
|
1133 |
|
|
}
|
1134 |
|
|
ep->rx_ring[entry].status = 0x8000;
|
1135 |
|
|
}
|
1136 |
|
|
return work_done;
|
1137 |
|
|
}
|
1138 |
|
|
|
1139 |
|
|
static int epic_close(struct device *dev)
|
1140 |
|
|
{
|
1141 |
|
|
long ioaddr = dev->base_addr;
|
1142 |
|
|
struct epic_private *ep = (struct epic_private *)dev->priv;
|
1143 |
|
|
int i;
|
1144 |
|
|
|
1145 |
|
|
dev->start = 0;
|
1146 |
|
|
dev->tbusy = 1;
|
1147 |
|
|
|
1148 |
|
|
if (epic_debug > 1)
|
1149 |
|
|
printk(KERN_DEBUG "%s: Shutting down ethercard, status was %2.2x.\n",
|
1150 |
|
|
dev->name, inl(ioaddr + INTSTAT));
|
1151 |
|
|
|
1152 |
|
|
/* Disable interrupts by clearing the interrupt mask. */
|
1153 |
|
|
outl(0x00000000, ioaddr + INTMASK);
|
1154 |
|
|
/* Stop the chip's Tx and Rx DMA processes. */
|
1155 |
|
|
outw(0x0061, ioaddr + COMMAND);
|
1156 |
|
|
|
1157 |
|
|
/* Update the error counts. */
|
1158 |
|
|
ep->stats.rx_missed_errors += inb(ioaddr + MPCNT);
|
1159 |
|
|
ep->stats.rx_frame_errors += inb(ioaddr + ALICNT);
|
1160 |
|
|
ep->stats.rx_crc_errors += inb(ioaddr + CRCCNT);
|
1161 |
|
|
|
1162 |
|
|
del_timer(&ep->timer);
|
1163 |
|
|
|
1164 |
|
|
free_irq(dev->irq, dev);
|
1165 |
|
|
|
1166 |
|
|
/* Free all the skbuffs in the Rx queue. */
|
1167 |
|
|
for (i = 0; i < RX_RING_SIZE; i++) {
|
1168 |
|
|
struct sk_buff *skb = ep->rx_skbuff[i];
|
1169 |
|
|
ep->rx_skbuff[i] = 0;
|
1170 |
|
|
ep->rx_ring[i].status = 0; /* Not owned by Epic chip. */
|
1171 |
|
|
ep->rx_ring[i].buflength = 0;
|
1172 |
|
|
ep->rx_ring[i].bufaddr = 0xBADF00D0; /* An invalid address. */
|
1173 |
|
|
if (skb) {
|
1174 |
|
|
#if LINUX_VERSION_CODE < 0x20100
|
1175 |
|
|
skb->free = 1;
|
1176 |
|
|
#endif
|
1177 |
|
|
DEV_FREE_SKB(skb);
|
1178 |
|
|
}
|
1179 |
|
|
}
|
1180 |
|
|
for (i = 0; i < TX_RING_SIZE; i++) {
|
1181 |
|
|
if (ep->tx_skbuff[i])
|
1182 |
|
|
DEV_FREE_SKB(ep->tx_skbuff[i]);
|
1183 |
|
|
ep->tx_skbuff[i] = 0;
|
1184 |
|
|
}
|
1185 |
|
|
|
1186 |
|
|
|
1187 |
|
|
/* Green! Leave the chip in low-power mode. */
|
1188 |
|
|
outl(0x0008, ioaddr + GENCTL);
|
1189 |
|
|
|
1190 |
|
|
MOD_DEC_USE_COUNT;
|
1191 |
|
|
|
1192 |
|
|
return 0;
|
1193 |
|
|
}
|
1194 |
|
|
|
1195 |
|
|
static struct net_device_stats *epic_get_stats(struct device *dev)
|
1196 |
|
|
{
|
1197 |
|
|
struct epic_private *ep = (struct epic_private *)dev->priv;
|
1198 |
|
|
long ioaddr = dev->base_addr;
|
1199 |
|
|
|
1200 |
|
|
if (dev->start) {
|
1201 |
|
|
/* Update the error counts. */
|
1202 |
|
|
ep->stats.rx_missed_errors += inb(ioaddr + MPCNT);
|
1203 |
|
|
ep->stats.rx_frame_errors += inb(ioaddr + ALICNT);
|
1204 |
|
|
ep->stats.rx_crc_errors += inb(ioaddr + CRCCNT);
|
1205 |
|
|
}
|
1206 |
|
|
|
1207 |
|
|
return &ep->stats;
|
1208 |
|
|
}
|
1209 |
|
|
|
1210 |
|
|
/* Set or clear the multicast filter for this adaptor.
|
1211 |
|
|
Note that we only use exclusion around actually queueing the
|
1212 |
|
|
new frame, not around filling ep->setup_frame. This is non-deterministic
|
1213 |
|
|
when re-entered but still correct. */
|
1214 |
|
|
|
1215 |
|
|
/* The little-endian AUTODIN II ethernet CRC calculation.
|
1216 |
|
|
N.B. Do not use for bulk data, use a table-based routine instead.
|
1217 |
|
|
This is common code and should be moved to net/core/crc.c */
|
1218 |
|
|
static unsigned const ethernet_polynomial_le = 0xedb88320U;
|
1219 |
|
|
static inline unsigned ether_crc_le(int length, unsigned char *data)
|
1220 |
|
|
{
|
1221 |
|
|
unsigned int crc = 0xffffffff; /* Initial value. */
|
1222 |
|
|
while(--length >= 0) {
|
1223 |
|
|
unsigned char current_octet = *data++;
|
1224 |
|
|
int bit;
|
1225 |
|
|
for (bit = 8; --bit >= 0; current_octet >>= 1) {
|
1226 |
|
|
if ((crc ^ current_octet) & 1) {
|
1227 |
|
|
crc >>= 1;
|
1228 |
|
|
crc ^= ethernet_polynomial_le;
|
1229 |
|
|
} else
|
1230 |
|
|
crc >>= 1;
|
1231 |
|
|
}
|
1232 |
|
|
}
|
1233 |
|
|
return crc;
|
1234 |
|
|
}
|
1235 |
|
|
|
1236 |
|
|
|
1237 |
|
|
static void set_rx_mode(struct device *dev)
|
1238 |
|
|
{
|
1239 |
|
|
long ioaddr = dev->base_addr;
|
1240 |
|
|
struct epic_private *ep = (struct epic_private *)dev->priv;
|
1241 |
|
|
unsigned char mc_filter[8]; /* Multicast hash filter */
|
1242 |
|
|
int i;
|
1243 |
|
|
|
1244 |
|
|
if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */
|
1245 |
|
|
outl(0x002C, ioaddr + RxCtrl);
|
1246 |
|
|
/* Unconditionally log net taps. */
|
1247 |
|
|
printk(KERN_INFO "%s: Promiscuous mode enabled.\n", dev->name);
|
1248 |
|
|
memset(mc_filter, 0xff, sizeof(mc_filter));
|
1249 |
|
|
} else if ((dev->mc_count > 0) || (dev->flags & IFF_ALLMULTI)) {
|
1250 |
|
|
/* There is apparently a chip bug, so the multicast filter
|
1251 |
|
|
is never enabled. */
|
1252 |
|
|
/* Too many to filter perfectly -- accept all multicasts. */
|
1253 |
|
|
memset(mc_filter, 0xff, sizeof(mc_filter));
|
1254 |
|
|
outl(0x000C, ioaddr + RxCtrl);
|
1255 |
|
|
} else if (dev->mc_count == 0) {
|
1256 |
|
|
outl(0x0004, ioaddr + RxCtrl);
|
1257 |
|
|
return;
|
1258 |
|
|
} else { /* Never executed, for now. */
|
1259 |
|
|
struct dev_mc_list *mclist;
|
1260 |
|
|
|
1261 |
|
|
memset(mc_filter, 0, sizeof(mc_filter));
|
1262 |
|
|
for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
|
1263 |
|
|
i++, mclist = mclist->next)
|
1264 |
|
|
set_bit(ether_crc_le(ETH_ALEN, mclist->dmi_addr) & 0x3f,
|
1265 |
|
|
mc_filter);
|
1266 |
|
|
}
|
1267 |
|
|
/* ToDo: perhaps we need to stop the Tx and Rx process here? */
|
1268 |
|
|
if (memcmp(mc_filter, ep->mc_filter, sizeof(mc_filter))) {
|
1269 |
|
|
for (i = 0; i < 4; i++)
|
1270 |
|
|
outw(((u16 *)mc_filter)[i], ioaddr + MC0 + i*4);
|
1271 |
|
|
memcpy(ep->mc_filter, mc_filter, sizeof(mc_filter));
|
1272 |
|
|
}
|
1273 |
|
|
return;
|
1274 |
|
|
}
|
1275 |
|
|
|
1276 |
|
|
static int mii_ioctl(struct device *dev, struct ifreq *rq, int cmd)
|
1277 |
|
|
{
|
1278 |
|
|
long ioaddr = dev->base_addr;
|
1279 |
|
|
u16 *data = (u16 *)&rq->ifr_data;
|
1280 |
|
|
|
1281 |
|
|
switch(cmd) {
|
1282 |
|
|
case SIOCDEVPRIVATE: /* Get the address of the PHY in use. */
|
1283 |
|
|
data[0] = ((struct epic_private *)dev->priv)->phys[0] & 0x1f;
|
1284 |
|
|
/* Fall Through */
|
1285 |
|
|
case SIOCDEVPRIVATE+1: /* Read the specified MII register. */
|
1286 |
|
|
if (! dev->start) {
|
1287 |
|
|
outl(0x0200, ioaddr + GENCTL);
|
1288 |
|
|
outl((inl(ioaddr + NVCTL) & ~0x003C) | 0x4800, ioaddr + NVCTL);
|
1289 |
|
|
}
|
1290 |
|
|
data[3] = mdio_read(ioaddr, data[0] & 0x1f, data[1] & 0x1f);
|
1291 |
|
|
if (! dev->start) {
|
1292 |
|
|
#ifdef notdef
|
1293 |
|
|
outl(0x0008, ioaddr + GENCTL);
|
1294 |
|
|
outl((inl(ioaddr + NVCTL) & ~0x483C) | 0x0000, ioaddr + NVCTL);
|
1295 |
|
|
#endif
|
1296 |
|
|
}
|
1297 |
|
|
return 0;
|
1298 |
|
|
case SIOCDEVPRIVATE+2: /* Write the specified MII register */
|
1299 |
|
|
if (!suser())
|
1300 |
|
|
return -EPERM;
|
1301 |
|
|
if (! dev->start) {
|
1302 |
|
|
outl(0x0200, ioaddr + GENCTL);
|
1303 |
|
|
outl((inl(ioaddr + NVCTL) & ~0x003C) | 0x4800, ioaddr + NVCTL);
|
1304 |
|
|
}
|
1305 |
|
|
mdio_write(ioaddr, data[0] & 0x1f, data[1] & 0x1f, data[2]);
|
1306 |
|
|
if (! dev->start) {
|
1307 |
|
|
#ifdef notdef
|
1308 |
|
|
outl(0x0008, ioaddr + GENCTL);
|
1309 |
|
|
outl((inl(ioaddr + NVCTL) & ~0x483C) | 0x0000, ioaddr + NVCTL);
|
1310 |
|
|
#endif
|
1311 |
|
|
}
|
1312 |
|
|
return 0;
|
1313 |
|
|
default:
|
1314 |
|
|
return -EOPNOTSUPP;
|
1315 |
|
|
}
|
1316 |
|
|
}
|
1317 |
|
|
|
1318 |
|
|
|
1319 |
|
|
#ifdef CARDBUS
|
1320 |
|
|
|
1321 |
|
|
#include <pcmcia/driver_ops.h>
|
1322 |
|
|
|
1323 |
|
|
static dev_node_t *epic_attach(dev_locator_t *loc)
|
1324 |
|
|
{
|
1325 |
|
|
struct device *dev;
|
1326 |
|
|
u16 dev_id;
|
1327 |
|
|
u32 io;
|
1328 |
|
|
u8 bus, devfn, irq;
|
1329 |
|
|
|
1330 |
|
|
if (loc->bus != LOC_PCI) return NULL;
|
1331 |
|
|
bus = loc->b.pci.bus; devfn = loc->b.pci.devfn;
|
1332 |
|
|
printk(KERN_DEBUG "epic_attach(bus %d, function %d)\n", bus, devfn);
|
1333 |
|
|
pcibios_read_config_dword(bus, devfn, PCI_BASE_ADDRESS_0, &io);
|
1334 |
|
|
pcibios_read_config_byte(bus, devfn, PCI_INTERRUPT_LINE, &irq);
|
1335 |
|
|
pcibios_read_config_word(bus, devfn, PCI_DEVICE_ID, &dev_id);
|
1336 |
|
|
io &= ~3;
|
1337 |
|
|
if (io == 0 || irq == 0) {
|
1338 |
|
|
printk(KERN_ERR "The EPIC/C CardBus Ethernet interface was not "
|
1339 |
|
|
"assigned an %s.\n" KERN_ERR " It will not be activated.\n",
|
1340 |
|
|
io == 0 ? "I/O address" : "IRQ");
|
1341 |
|
|
return NULL;
|
1342 |
|
|
}
|
1343 |
|
|
dev = epic_probe1(bus, devfn, NULL, io, irq, 2, -1);
|
1344 |
|
|
if (dev) {
|
1345 |
|
|
dev_node_t *node = kmalloc(sizeof(dev_node_t), GFP_KERNEL);
|
1346 |
|
|
strcpy(node->dev_name, dev->name);
|
1347 |
|
|
node->major = node->minor = 0;
|
1348 |
|
|
node->next = NULL;
|
1349 |
|
|
MOD_INC_USE_COUNT;
|
1350 |
|
|
return node;
|
1351 |
|
|
}
|
1352 |
|
|
return NULL;
|
1353 |
|
|
}
|
1354 |
|
|
|
1355 |
|
|
static void epic_suspend(dev_node_t *node)
|
1356 |
|
|
{
|
1357 |
|
|
struct device **devp, **next;
|
1358 |
|
|
printk(KERN_INFO "epic_suspend(%s)\n", node->dev_name);
|
1359 |
|
|
for (devp = &root_epic_dev; *devp; devp = next) {
|
1360 |
|
|
next = &((struct epic_private *)(*devp)->priv)->next_module;
|
1361 |
|
|
if (strcmp((*devp)->name, node->dev_name) == 0) break;
|
1362 |
|
|
}
|
1363 |
|
|
if (*devp) {
|
1364 |
|
|
long ioaddr = (*devp)->base_addr;
|
1365 |
|
|
epic_pause(*devp);
|
1366 |
|
|
/* Put the chip into low-power mode. */
|
1367 |
|
|
outl(0x0008, ioaddr + GENCTL);
|
1368 |
|
|
}
|
1369 |
|
|
}
|
1370 |
|
|
static void epic_resume(dev_node_t *node)
|
1371 |
|
|
{
|
1372 |
|
|
struct device **devp, **next;
|
1373 |
|
|
printk(KERN_INFO "epic_resume(%s)\n", node->dev_name);
|
1374 |
|
|
for (devp = &root_epic_dev; *devp; devp = next) {
|
1375 |
|
|
next = &((struct epic_private *)(*devp)->priv)->next_module;
|
1376 |
|
|
if (strcmp((*devp)->name, node->dev_name) == 0) break;
|
1377 |
|
|
}
|
1378 |
|
|
if (*devp) {
|
1379 |
|
|
epic_restart(*devp);
|
1380 |
|
|
}
|
1381 |
|
|
}
|
1382 |
|
|
static void epic_detach(dev_node_t *node)
|
1383 |
|
|
{
|
1384 |
|
|
struct device **devp, **next;
|
1385 |
|
|
printk(KERN_INFO "epic_detach(%s)\n", node->dev_name);
|
1386 |
|
|
for (devp = &root_epic_dev; *devp; devp = next) {
|
1387 |
|
|
next = &((struct epic_private *)(*devp)->priv)->next_module;
|
1388 |
|
|
if (strcmp((*devp)->name, node->dev_name) == 0) break;
|
1389 |
|
|
}
|
1390 |
|
|
if (*devp) {
|
1391 |
|
|
unregister_netdev(*devp);
|
1392 |
|
|
kfree(*devp);
|
1393 |
|
|
*devp = *next;
|
1394 |
|
|
kfree(node);
|
1395 |
|
|
MOD_DEC_USE_COUNT;
|
1396 |
|
|
}
|
1397 |
|
|
}
|
1398 |
|
|
|
1399 |
|
|
struct driver_operations epic_ops = {
|
1400 |
|
|
"epic_cb", epic_attach, epic_suspend, epic_resume, epic_detach
|
1401 |
|
|
};
|
1402 |
|
|
|
1403 |
|
|
#endif /* Cardbus support */
|
1404 |
|
|
|
1405 |
|
|
|
1406 |
|
|
#ifdef MODULE
|
1407 |
|
|
|
1408 |
|
|
int init_module(void)
|
1409 |
|
|
{
|
1410 |
|
|
if (epic_debug)
|
1411 |
|
|
printk(KERN_INFO "%s", version);
|
1412 |
|
|
|
1413 |
|
|
#ifdef CARDBUS
|
1414 |
|
|
register_driver(&epic_ops);
|
1415 |
|
|
return 0;
|
1416 |
|
|
#else
|
1417 |
|
|
return epic100_probe(0);
|
1418 |
|
|
#endif
|
1419 |
|
|
}
|
1420 |
|
|
|
1421 |
|
|
void cleanup_module(void)
|
1422 |
|
|
{
|
1423 |
|
|
struct device *next_dev;
|
1424 |
|
|
|
1425 |
|
|
#ifdef CARDBUS
|
1426 |
|
|
unregister_driver(&epic_ops);
|
1427 |
|
|
#endif
|
1428 |
|
|
|
1429 |
|
|
/* No need to check MOD_IN_USE, as sys_delete_module() checks. */
|
1430 |
|
|
while (root_epic_dev) {
|
1431 |
|
|
struct epic_private *ep = (struct epic_private *)root_epic_dev->priv;
|
1432 |
|
|
next_dev = ep->next_module;
|
1433 |
|
|
unregister_netdev(root_epic_dev);
|
1434 |
|
|
release_region(root_epic_dev->base_addr, EPIC_TOTAL_SIZE);
|
1435 |
|
|
kfree(root_epic_dev);
|
1436 |
|
|
root_epic_dev = next_dev;
|
1437 |
|
|
kfree(ep);
|
1438 |
|
|
}
|
1439 |
|
|
}
|
1440 |
|
|
|
1441 |
|
|
#endif /* MODULE */
|
1442 |
|
|
|
1443 |
|
|
/*
|
1444 |
|
|
* Local variables:
|
1445 |
|
|
* compile-command: "gcc -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -c epic100.c `[ -f /usr/include/linux/modversions.h ] && echo -DMODVERSIONS`"
|
1446 |
|
|
* cardbus-compile-command: "gcc -DCARDBUS -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -c epic100.c -o epic_cb.o -I/usr/src/pcmcia-cs-3.0.5/include/"
|
1447 |
|
|
* c-indent-level: 4
|
1448 |
|
|
* c-basic-offset: 4
|
1449 |
|
|
* tab-width: 4
|
1450 |
|
|
* End:
|
1451 |
|
|
*/
|