blob: 89f2ef7f16de6e6ad27fbb7b4387bd623b5c25ec [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* cs89x0.c: A Crystal Semiconductor (Now Cirrus Logic) CS89[02]0
2 * driver for linux.
3 */
4
5/*
6 Written 1996 by Russell Nelson, with reference to skeleton.c
7 written 1993-1994 by Donald Becker.
8
9 This software may be used and distributed according to the terms
10 of the GNU General Public License, incorporated herein by reference.
11
12 The author may be reached at nelson@crynwr.com, Crynwr
13 Software, 521 Pleasant Valley Rd., Potsdam, NY 13676
14
15 Changelog:
16
17 Mike Cruse : mcruse@cti-ltd.com
Jeff Garzik6aa20a22006-09-13 13:24:59 -040018 : Changes for Linux 2.0 compatibility.
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 : Added dev_id parameter in net_interrupt(),
20 : request_irq() and free_irq(). Just NULL for now.
21
22 Mike Cruse : Added MOD_INC_USE_COUNT and MOD_DEC_USE_COUNT macros
23 : in net_open() and net_close() so kerneld would know
Jeff Garzik6aa20a22006-09-13 13:24:59 -040024 : that the module is in use and wouldn't eject the
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 : driver prematurely.
26
27 Mike Cruse : Rewrote init_module() and cleanup_module using 8390.c
28 : as an example. Disabled autoprobing in init_module(),
29 : not a good thing to do to other devices while Linux
30 : is running from all accounts.
31
32 Russ Nelson : Jul 13 1998. Added RxOnly DMA support.
33
Jeff Garzik6aa20a22006-09-13 13:24:59 -040034 Melody Lee : Aug 10 1999. Changes for Linux 2.2.5 compatibility.
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 : email: ethernet@crystal.cirrus.com
36
37 Alan Cox : Removed 1.2 support, added 2.1 extra counters.
38
Francois Camie1f8e872008-10-15 22:01:59 -070039 Andrew Morton : Kernel 2.3.48
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 : Handle kmalloc() failures
41 : Other resource allocation fixes
42 : Add SMP locks
43 : Integrate Russ Nelson's ALLOW_DMA functionality back in.
44 : If ALLOW_DMA is true, make DMA runtime selectable
45 : Folded in changes from Cirrus (Melody Lee
46 : <klee@crystal.cirrus.com>)
47 : Don't call netif_wake_queue() in net_send_packet()
48 : Fixed an out-of-mem bug in dma_rx()
49 : Updated Documentation/networking/cs89x0.txt
50
Francois Camie1f8e872008-10-15 22:01:59 -070051 Andrew Morton : Kernel 2.3.99-pre1
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 : Use skb_reserve to longword align IP header (two places)
53 : Remove a delay loop from dma_rx()
54 : Replace '100' with HZ
55 : Clean up a couple of skb API abuses
56 : Added 'cs89x0_dma=N' kernel boot option
57 : Correctly initialise lp->lock in non-module compile
58
Francois Camie1f8e872008-10-15 22:01:59 -070059 Andrew Morton : Kernel 2.3.99-pre4-1
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 : MOD_INC/DEC race fix (see
61 : http://www.uwsg.indiana.edu/hypermail/linux/kernel/0003.3/1532.html)
62
Francois Camie1f8e872008-10-15 22:01:59 -070063 Andrew Morton : Kernel 2.4.0-test7-pre2
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 : Enhanced EEPROM support to cover more devices,
65 : abstracted IRQ mapping to support CONFIG_ARCH_CLPS7500 arch
66 : (Jason Gunthorpe <jgg@ualberta.ca>)
67
68 Andrew Morton : Kernel 2.4.0-test11-pre4
69 : Use dev->name in request_*() (Andrey Panin)
70 : Fix an error-path memleak in init_module()
71 : Preserve return value from request_irq()
72 : Fix type of `media' module parm (Keith Owens)
73 : Use SET_MODULE_OWNER()
74 : Tidied up strange request_irq() abuse in net_open().
75
76 Andrew Morton : Kernel 2.4.3-pre1
77 : Request correct number of pages for DMA (Hugh Dickens)
78 : Select PP_ChipID _after_ unregister_netdev in cleanup_module()
79 : because unregister_netdev() calls get_stats.
80 : Make `version[]' __initdata
81 : Uninlined the read/write reg/word functions.
82
83 Oskar Schirmer : oskar@scara.com
84 : HiCO.SH4 (superh) support added (irq#1, cs89x0_media=)
85
86 Deepak Saxena : dsaxena@plexity.net
87 : Intel IXDP2x01 (XScale ixp2x00 NPU) platform support
88
Lennert Buytenhek032874e2006-01-14 13:21:15 -080089 Dmitry Pervushin : dpervushin@ru.mvista.com
90 : PNX010X platform support
91
Deepak Saxena9c878962006-01-14 13:21:18 -080092 Deepak Saxena : dsaxena@plexity.net
93 : Intel IXDP2351 platform support
94
Lennert Buytenhek5aeebe02006-01-16 22:14:53 -080095 Dmitry Pervushin : dpervushin@ru.mvista.com
96 : PNX010X platform support
97
Linus Torvalds1da177e2005-04-16 15:20:36 -070098*/
99
100/* Always include 'config.h' first in case the user wants to turn on
101 or override something. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102#include <linux/module.h>
103
104/*
105 * Set this to zero to disable DMA code
106 *
107 * Note that even if DMA is turned off we still support the 'dma' and 'use_dma'
108 * module options so we don't break any startup scripts.
109 */
Lennert Buytenhek91e1c462006-01-11 12:17:34 -0800110#ifndef CONFIG_ISA_DMA_API
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111#define ALLOW_DMA 0
112#else
113#define ALLOW_DMA 1
114#endif
115
116/*
117 * Set this to zero to remove all the debug statements via
118 * dead code elimination
119 */
120#define DEBUGGING 1
121
122/*
123 Sources:
124
125 Crynwr packet driver epktisa.
126
127 Crystal Semiconductor data sheets.
128
129*/
130
131#include <linux/errno.h>
132#include <linux/netdevice.h>
133#include <linux/etherdevice.h>
134#include <linux/kernel.h>
135#include <linux/types.h>
136#include <linux/fcntl.h>
137#include <linux/interrupt.h>
138#include <linux/ioport.h>
139#include <linux/in.h>
140#include <linux/skbuff.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141#include <linux/spinlock.h>
142#include <linux/string.h>
143#include <linux/init.h>
144#include <linux/bitops.h>
145#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +0900146#include <linux/gfp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148#include <asm/system.h>
149#include <asm/io.h>
Al Viro7625d482005-09-26 05:25:59 +0100150#include <asm/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151#if ALLOW_DMA
152#include <asm/dma.h>
153#endif
154
155#include "cs89x0.h"
156
157static char version[] __initdata =
Francois Camie1f8e872008-10-15 22:01:59 -0700158"cs89x0.c: v2.4.3-pre1 Russell Nelson <nelson@crynwr.com>, Andrew Morton\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
160#define DRV_NAME "cs89x0"
161
162/* First, a few definitions that the brave might change.
163 A zero-terminated list of I/O addresses to be probed. Some special flags..
164 Addr & 1 = Read back the address port, look for signature and reset
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400165 the page window before probing
166 Addr & 3 = Reset the page window and probe
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 The CLPS eval board has the Cirrus chip at 0x80090300, in ARM IO space,
168 but it is possible that a Cirrus board could be plugged into the ISA
169 slots. */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400170/* The cs8900 has 4 IRQ pins, software selectable. cs8900_irq_map maps
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 them to system IRQ numbers. This mapping is card specific and is set to
172 the configuration of the Cirrus Eval board for this chip. */
Christoph Eggeref3cf9f2010-07-14 13:40:36 -0700173#if defined(CONFIG_MACH_IXDP2351)
Leonardo Potenzaa80763c2008-02-17 18:23:15 +0100174static unsigned int netcard_portlist[] __used __initdata = {IXDP2351_VIRT_CS8900_BASE, 0};
Deepak Saxena9c878962006-01-14 13:21:18 -0800175static unsigned int cs8900_irq_map[] = {IRQ_IXDP2351_CS8900, 0, 0, 0};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176#elif defined(CONFIG_ARCH_IXDP2X01)
Leonardo Potenzaa80763c2008-02-17 18:23:15 +0100177static unsigned int netcard_portlist[] __used __initdata = {IXDP2X01_CS8900_VIRT_BASE, 0};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178static unsigned int cs8900_irq_map[] = {IRQ_IXDP2X01_CS8900, 0, 0, 0};
Lennert Buytenhek277cb102006-01-08 01:01:14 -0800179#elif defined(CONFIG_ARCH_PNX010X)
Russell Kinga09e64f2008-08-05 16:14:15 +0100180#include <mach/gpio.h>
dmitry pervushin0dd3c782005-06-20 15:32:54 -0700181#define CIRRUS_DEFAULT_BASE IO_ADDRESS(EXT_STATIC2_s0_BASE + 0x200000) /* = Physical address 0x48200000 */
182#define CIRRUS_DEFAULT_IRQ VH_INTC_INT_NUM_CASCADED_INTERRUPT_1 /* Event inputs bank 1 - ID 35/bit 3 */
Leonardo Potenzaa80763c2008-02-17 18:23:15 +0100183static unsigned int netcard_portlist[] __used __initdata = {CIRRUS_DEFAULT_BASE, 0};
dmitry pervushin0dd3c782005-06-20 15:32:54 -0700184static unsigned int cs8900_irq_map[] = {CIRRUS_DEFAULT_IRQ, 0, 0, 0};
Gilles Chanteperdrix0ac4ed92008-09-26 15:44:43 +0100185#elif defined(CONFIG_MACH_MX31ADS)
186#include <mach/board-mx31ads.h>
187static unsigned int netcard_portlist[] __used __initdata = {
188 PBC_BASE_ADDRESS + PBC_CS8900A_IOBASE + 0x300, 0
189};
190static unsigned cs8900_irq_map[] = {EXPIO_INT_ENET_INT, 0, 0, 0};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191#else
Leonardo Potenzaa80763c2008-02-17 18:23:15 +0100192static unsigned int netcard_portlist[] __used __initdata =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 { 0x300, 0x320, 0x340, 0x360, 0x200, 0x220, 0x240, 0x260, 0x280, 0x2a0, 0x2c0, 0x2e0, 0};
194static unsigned int cs8900_irq_map[] = {10,11,12,5};
195#endif
196
197#if DEBUGGING
198static unsigned int net_debug = DEBUGGING;
199#else
200#define net_debug 0 /* gcc will remove all the debug code for us */
201#endif
202
203/* The number of low I/O ports used by the ethercard. */
204#define NETCARD_IO_EXTENT 16
205
206/* we allow the user to override various values normally set in the EEPROM */
207#define FORCE_RJ45 0x0001 /* pick one of these three */
208#define FORCE_AUI 0x0002
209#define FORCE_BNC 0x0004
210
211#define FORCE_AUTO 0x0010 /* pick one of these three */
212#define FORCE_HALF 0x0020
213#define FORCE_FULL 0x0030
214
215/* Information that need to be kept for each board. */
216struct net_local {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 int chip_type; /* one of: CS8900, CS8920, CS8920M */
218 char chip_revision; /* revision letter of the chip ('A'...) */
219 int send_cmd; /* the proper send command: TX_NOW, TX_AFTER_381, or TX_AFTER_ALL */
220 int auto_neg_cnf; /* auto-negotiation word from EEPROM */
221 int adapter_cnf; /* adapter configuration from EEPROM */
222 int isa_config; /* ISA configuration from EEPROM */
223 int irq_map; /* IRQ map from EEPROM */
224 int rx_mode; /* what mode are we in? 0, RX_MULTCAST_ACCEPT, or RX_ALL_ACCEPT */
225 int curr_rx_cfg; /* a copy of PP_RxCFG */
226 int linectl; /* either 0 or LOW_RX_SQUELCH, depending on configuration. */
227 int send_underrun; /* keep track of how many underruns in a row we get */
228 int force; /* force various values; see FORCE* above. */
229 spinlock_t lock;
230#if ALLOW_DMA
231 int use_dma; /* Flag: we're using dma */
232 int dma; /* DMA channel */
233 int dmasize; /* 16 or 64 */
234 unsigned char *dma_buff; /* points to the beginning of the buffer */
235 unsigned char *end_dma_buff; /* points to the end of the buffer */
236 unsigned char *rx_dma_ptr; /* points to the next packet */
237#endif
238};
239
240/* Index to functions, as function prototypes. */
241
242static int cs89x0_probe1(struct net_device *dev, int ioaddr, int modular);
243static int net_open(struct net_device *dev);
Stephen Hemminger613573252009-08-31 19:50:58 +0000244static netdev_tx_t net_send_packet(struct sk_buff *skb, struct net_device *dev);
David Howells7d12e782006-10-05 14:55:46 +0100245static irqreturn_t net_interrupt(int irq, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246static void set_multicast_list(struct net_device *dev);
247static void net_timeout(struct net_device *dev);
248static void net_rx(struct net_device *dev);
249static int net_close(struct net_device *dev);
250static struct net_device_stats *net_get_stats(struct net_device *dev);
251static void reset_chip(struct net_device *dev);
252static int get_eeprom_data(struct net_device *dev, int off, int len, int *buffer);
253static int get_eeprom_cksum(int off, int len, int *buffer);
254static int set_mac_address(struct net_device *dev, void *addr);
Kulikov Vasiliy661a16c2010-07-05 02:13:15 +0000255static void count_rx_errors(int status, struct net_device *dev);
Deepak Saxena6f519162005-09-09 13:02:07 -0700256#ifdef CONFIG_NET_POLL_CONTROLLER
257static void net_poll_controller(struct net_device *dev);
258#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259#if ALLOW_DMA
260static void get_dma_channel(struct net_device *dev);
261static void release_dma_buff(struct net_local *lp);
262#endif
263
264/* Example routines you must write ;->. */
265#define tx_done(dev) 1
266
267/*
268 * Permit 'cs89x0_dma=N' in the kernel boot environment
269 */
270#if !defined(MODULE) && (ALLOW_DMA != 0)
271static int g_cs89x0_dma;
272
273static int __init dma_fn(char *str)
274{
275 g_cs89x0_dma = simple_strtol(str,NULL,0);
276 return 1;
277}
278
279__setup("cs89x0_dma=", dma_fn);
280#endif /* !defined(MODULE) && (ALLOW_DMA != 0) */
281
282#ifndef MODULE
283static int g_cs89x0_media__force;
284
285static int __init media_fn(char *str)
286{
287 if (!strcmp(str, "rj45")) g_cs89x0_media__force = FORCE_RJ45;
288 else if (!strcmp(str, "aui")) g_cs89x0_media__force = FORCE_AUI;
289 else if (!strcmp(str, "bnc")) g_cs89x0_media__force = FORCE_BNC;
290 return 1;
291}
292
293__setup("cs89x0_media=", media_fn);
294
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400295
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296/* Check for a network adaptor of this type, and return '0' iff one exists.
297 If dev->base_addr == 0, probe all likely locations.
298 If dev->base_addr == 1, always return failure.
299 If dev->base_addr == 2, allocate space for the device and return success
300 (detachable devices only).
301 Return 0 on success.
302 */
303
304struct net_device * __init cs89x0_probe(int unit)
305{
306 struct net_device *dev = alloc_etherdev(sizeof(struct net_local));
307 unsigned *port;
308 int err = 0;
309 int irq;
310 int io;
311
312 if (!dev)
313 return ERR_PTR(-ENODEV);
314
315 sprintf(dev->name, "eth%d", unit);
316 netdev_boot_setup_check(dev);
317 io = dev->base_addr;
318 irq = dev->irq;
319
320 if (net_debug)
321 printk("cs89x0:cs89x0_probe(0x%x)\n", io);
322
323 if (io > 0x1ff) { /* Check a single specified location. */
324 err = cs89x0_probe1(dev, io, 0);
325 } else if (io != 0) { /* Don't probe at all. */
326 err = -ENXIO;
327 } else {
328 for (port = netcard_portlist; *port; port++) {
329 if (cs89x0_probe1(dev, *port, 0) == 0)
330 break;
331 dev->irq = irq;
332 }
333 if (!*port)
334 err = -ENODEV;
335 }
336 if (err)
337 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 return dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339out:
340 free_netdev(dev);
341 printk(KERN_WARNING "cs89x0: no cs8900 or cs8920 detected. Be sure to disable PnP with SETUP\n");
342 return ERR_PTR(err);
343}
344#endif
345
Deepak Saxena9c878962006-01-14 13:21:18 -0800346#if defined(CONFIG_MACH_IXDP2351)
347static u16
348readword(unsigned long base_addr, int portno)
349{
350 return __raw_readw(base_addr + (portno << 1));
351}
352
353static void
354writeword(unsigned long base_addr, int portno, u16 value)
355{
356 __raw_writew(value, base_addr + (portno << 1));
357}
358#elif defined(CONFIG_ARCH_IXDP2X01)
Lennert Buytenheka07f0db2006-01-14 13:21:17 -0800359static u16
Lennert Buytenhek3b68d702006-01-08 01:01:11 -0800360readword(unsigned long base_addr, int portno)
361{
Lennert Buytenheka07f0db2006-01-14 13:21:17 -0800362 return __raw_readl(base_addr + (portno << 1));
Lennert Buytenhek3b68d702006-01-08 01:01:11 -0800363}
364
365static void
Lennert Buytenheka07f0db2006-01-14 13:21:17 -0800366writeword(unsigned long base_addr, int portno, u16 value)
Lennert Buytenhek3b68d702006-01-08 01:01:11 -0800367{
Lennert Buytenheka07f0db2006-01-14 13:21:17 -0800368 __raw_writel(value, base_addr + (portno << 1));
Lennert Buytenhek3b68d702006-01-08 01:01:11 -0800369}
Lennert Buytenhek580d7b82006-01-14 13:21:16 -0800370#elif defined(CONFIG_ARCH_PNX010X)
Lennert Buytenheka07f0db2006-01-14 13:21:17 -0800371static u16
Lennert Buytenhek3b68d702006-01-08 01:01:11 -0800372readword(unsigned long base_addr, int portno)
373{
374 return inw(base_addr + (portno << 1));
375}
376
377static void
Lennert Buytenheka07f0db2006-01-14 13:21:17 -0800378writeword(unsigned long base_addr, int portno, u16 value)
Lennert Buytenhek3b68d702006-01-08 01:01:11 -0800379{
380 outw(value, base_addr + (portno << 1));
381}
382#else
Lennert Buytenheka07f0db2006-01-14 13:21:17 -0800383static u16
Lennert Buytenhek0d5affc2006-01-08 01:01:09 -0800384readword(unsigned long base_addr, int portno)
385{
386 return inw(base_addr + portno);
387}
388
389static void
Lennert Buytenheka07f0db2006-01-14 13:21:17 -0800390writeword(unsigned long base_addr, int portno, u16 value)
Lennert Buytenhek0d5affc2006-01-08 01:01:09 -0800391{
392 outw(value, base_addr + portno);
393}
Lennert Buytenhek3b68d702006-01-08 01:01:11 -0800394#endif
Lennert Buytenhek0d5affc2006-01-08 01:01:09 -0800395
Lennert Buytenhek084f7462006-01-08 01:01:12 -0800396static void
397readwords(unsigned long base_addr, int portno, void *buf, int length)
398{
399 u8 *buf8 = (u8 *)buf;
400
401 do {
Lennert Buytenheka07f0db2006-01-14 13:21:17 -0800402 u16 tmp16;
Lennert Buytenhek084f7462006-01-08 01:01:12 -0800403
Lennert Buytenheka07f0db2006-01-14 13:21:17 -0800404 tmp16 = readword(base_addr, portno);
405 *buf8++ = (u8)tmp16;
406 *buf8++ = (u8)(tmp16 >> 8);
Lennert Buytenhek084f7462006-01-08 01:01:12 -0800407 } while (--length);
408}
409
410static void
411writewords(unsigned long base_addr, int portno, void *buf, int length)
412{
413 u8 *buf8 = (u8 *)buf;
414
415 do {
Lennert Buytenheka07f0db2006-01-14 13:21:17 -0800416 u16 tmp16;
Lennert Buytenhek084f7462006-01-08 01:01:12 -0800417
Lennert Buytenheka07f0db2006-01-14 13:21:17 -0800418 tmp16 = *buf8++;
419 tmp16 |= (*buf8++) << 8;
420 writeword(base_addr, portno, tmp16);
Lennert Buytenhek084f7462006-01-08 01:01:12 -0800421 } while (--length);
422}
423
Lennert Buytenheka07f0db2006-01-14 13:21:17 -0800424static u16
425readreg(struct net_device *dev, u16 regno)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426{
Lennert Buytenhek3eaa5e72006-01-08 01:01:10 -0800427 writeword(dev->base_addr, ADD_PORT, regno);
428 return readword(dev->base_addr, DATA_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429}
430
431static void
Lennert Buytenheka07f0db2006-01-14 13:21:17 -0800432writereg(struct net_device *dev, u16 regno, u16 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433{
Lennert Buytenhek3eaa5e72006-01-08 01:01:10 -0800434 writeword(dev->base_addr, ADD_PORT, regno);
435 writeword(dev->base_addr, DATA_PORT, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436}
437
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438static int __init
439wait_eeprom_ready(struct net_device *dev)
440{
441 int timeout = jiffies;
442 /* check to see if the EEPROM is ready, a timeout is used -
443 just in case EEPROM is ready when SI_BUSY in the
444 PP_SelfST is clear */
445 while(readreg(dev, PP_SelfST) & SI_BUSY)
446 if (jiffies - timeout >= 40)
447 return -1;
448 return 0;
449}
450
451static int __init
452get_eeprom_data(struct net_device *dev, int off, int len, int *buffer)
453{
454 int i;
455
456 if (net_debug > 3) printk("EEPROM data from %x for %x:\n",off,len);
457 for (i = 0; i < len; i++) {
458 if (wait_eeprom_ready(dev) < 0) return -1;
459 /* Now send the EEPROM read command and EEPROM location to read */
460 writereg(dev, PP_EECMD, (off + i) | EEPROM_READ_CMD);
461 if (wait_eeprom_ready(dev) < 0) return -1;
462 buffer[i] = readreg(dev, PP_EEData);
463 if (net_debug > 3) printk("%04x ", buffer[i]);
464 }
465 if (net_debug > 3) printk("\n");
466 return 0;
467}
468
469static int __init
470get_eeprom_cksum(int off, int len, int *buffer)
471{
472 int i, cksum;
473
474 cksum = 0;
475 for (i = 0; i < len; i++)
476 cksum += buffer[i];
477 cksum &= 0xffff;
478 if (cksum == 0)
479 return 0;
480 return -1;
481}
482
Deepak Saxena6f519162005-09-09 13:02:07 -0700483#ifdef CONFIG_NET_POLL_CONTROLLER
484/*
485 * Polling receive - used by netconsole and other diagnostic tools
486 * to allow network i/o with interrupts disabled.
487 */
488static void net_poll_controller(struct net_device *dev)
489{
490 disable_irq(dev->irq);
David Howells7d12e782006-10-05 14:55:46 +0100491 net_interrupt(dev->irq, dev);
Deepak Saxena6f519162005-09-09 13:02:07 -0700492 enable_irq(dev->irq);
493}
494#endif
495
Stephen Hemminger15d23e72009-03-26 15:11:43 +0000496static const struct net_device_ops net_ops = {
497 .ndo_open = net_open,
498 .ndo_stop = net_close,
499 .ndo_tx_timeout = net_timeout,
500 .ndo_start_xmit = net_send_packet,
501 .ndo_get_stats = net_get_stats,
502 .ndo_set_multicast_list = set_multicast_list,
503 .ndo_set_mac_address = set_mac_address,
504#ifdef CONFIG_NET_POLL_CONTROLLER
505 .ndo_poll_controller = net_poll_controller,
506#endif
507 .ndo_change_mtu = eth_change_mtu,
508 .ndo_validate_addr = eth_validate_addr,
509};
510
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511/* This is the real probe routine. Linux has a history of friendly device
512 probes on the ISA bus. A good device probes avoids doing writes, and
513 verifies that the correct device exists and functions.
514 Return 0 on success.
515 */
516
517static int __init
518cs89x0_probe1(struct net_device *dev, int ioaddr, int modular)
519{
520 struct net_local *lp = netdev_priv(dev);
521 static unsigned version_printed;
522 int i;
Denis Vlasenko01bdc032005-07-31 22:34:50 -0700523 int tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 unsigned rev_type = 0;
525 int eeprom_buff[CHKSUM_LEN];
526 int retval;
527
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 /* Initialize the device structure. */
529 if (!modular) {
530 memset(lp, 0, sizeof(*lp));
531 spin_lock_init(&lp->lock);
532#ifndef MODULE
533#if ALLOW_DMA
534 if (g_cs89x0_dma) {
535 lp->use_dma = 1;
536 lp->dma = g_cs89x0_dma;
537 lp->dmasize = 16; /* Could make this an option... */
538 }
539#endif
540 lp->force = g_cs89x0_media__force;
541#endif
542 }
543
Lennert Buytenhek277cb102006-01-08 01:01:14 -0800544#ifdef CONFIG_ARCH_PNX010X
dmitry pervushin0dd3c782005-06-20 15:32:54 -0700545 initialize_ebi();
546
547 /* Map GPIO registers for the pins connected to the CS8900a. */
548 if (map_cirrus_gpio() < 0)
549 return -ENODEV;
550
551 reset_cirrus();
552
553 /* Map event-router registers. */
554 if (map_event_router() < 0)
555 return -ENODEV;
556
557 enable_cirrus_irq();
558
559 unmap_cirrus_gpio();
560 unmap_event_router();
561
562 dev->base_addr = ioaddr;
563
564 for (i = 0 ; i < 3 ; i++)
565 readreg(dev, 0);
566#endif
567
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 /* Grab the region so we can find another board if autoIRQ fails. */
569 /* WTF is going on here? */
570 if (!request_region(ioaddr & ~3, NETCARD_IO_EXTENT, DRV_NAME)) {
571 printk(KERN_ERR "%s: request_region(0x%x, 0x%x) failed\n",
572 DRV_NAME, ioaddr, NETCARD_IO_EXTENT);
573 retval = -EBUSY;
574 goto out1;
575 }
576
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 /* if they give us an odd I/O address, then do ONE write to
578 the address port, to get it back to address zero, where we
579 expect to find the EISA signature word. An IO with a base of 0x3
580 will skip the test for the ADD_PORT. */
581 if (ioaddr & 1) {
582 if (net_debug > 1)
583 printk(KERN_INFO "%s: odd ioaddr 0x%x\n", dev->name, ioaddr);
584 if ((ioaddr & 2) != 2)
Lennert Buytenhekfc8c7d72006-01-08 01:01:08 -0800585 if ((readword(ioaddr & ~3, ADD_PORT) & ADD_MASK) != ADD_SIG) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 printk(KERN_ERR "%s: bad signature 0x%x\n",
Lennert Buytenhekfc8c7d72006-01-08 01:01:08 -0800587 dev->name, readword(ioaddr & ~3, ADD_PORT));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 retval = -ENODEV;
589 goto out2;
590 }
591 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592
593 ioaddr &= ~3;
George G. Davis9e1402a2006-11-16 14:50:14 -0500594 printk(KERN_DEBUG "PP_addr at %x[%x]: 0x%x\n",
595 ioaddr, ADD_PORT, readword(ioaddr, ADD_PORT));
Lennert Buytenhekfc8c7d72006-01-08 01:01:08 -0800596 writeword(ioaddr, ADD_PORT, PP_ChipID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
Lennert Buytenhekfc8c7d72006-01-08 01:01:08 -0800598 tmp = readword(ioaddr, DATA_PORT);
Denis Vlasenko01bdc032005-07-31 22:34:50 -0700599 if (tmp != CHIP_EISA_ID_SIG) {
Lennert Buytenhekfc8c7d72006-01-08 01:01:08 -0800600 printk(KERN_DEBUG "%s: incorrect signature at %x[%x]: 0x%x!="
Denis Vlasenko01bdc032005-07-31 22:34:50 -0700601 CHIP_EISA_ID_SIG_STR "\n",
Lennert Buytenhekfc8c7d72006-01-08 01:01:08 -0800602 dev->name, ioaddr, DATA_PORT, tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 retval = -ENODEV;
604 goto out2;
605 }
606
607 /* Fill in the 'dev' fields. */
608 dev->base_addr = ioaddr;
609
610 /* get the chip type */
611 rev_type = readreg(dev, PRODUCT_ID_ADD);
612 lp->chip_type = rev_type &~ REVISON_BITS;
613 lp->chip_revision = ((rev_type & REVISON_BITS) >> 8) + 'A';
614
615 /* Check the chip type and revision in order to set the correct send command
616 CS8920 revision C and CS8900 revision F can use the faster send. */
617 lp->send_cmd = TX_AFTER_381;
618 if (lp->chip_type == CS8900 && lp->chip_revision >= 'F')
619 lp->send_cmd = TX_NOW;
620 if (lp->chip_type != CS8900 && lp->chip_revision >= 'C')
621 lp->send_cmd = TX_NOW;
622
623 if (net_debug && version_printed++ == 0)
624 printk(version);
625
626 printk(KERN_INFO "%s: cs89%c0%s rev %c found at %#3lx ",
627 dev->name,
628 lp->chip_type==CS8900?'0':'2',
629 lp->chip_type==CS8920M?"M":"",
630 lp->chip_revision,
631 dev->base_addr);
632
633 reset_chip(dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400634
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 /* Here we read the current configuration of the chip. If there
636 is no Extended EEPROM then the idea is to not disturb the chip
637 configuration, it should have been correctly setup by automatic
638 EEPROM read on reset. So, if the chip says it read the EEPROM
639 the driver will always do *something* instead of complain that
640 adapter_cnf is 0. */
641
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400643 if ((readreg(dev, PP_SelfST) & (EEPROM_OK | EEPROM_PRESENT)) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 (EEPROM_OK|EEPROM_PRESENT)) {
645 /* Load the MAC. */
646 for (i=0; i < ETH_ALEN/2; i++) {
647 unsigned int Addr;
648 Addr = readreg(dev, PP_IA+i*2);
649 dev->dev_addr[i*2] = Addr & 0xFF;
650 dev->dev_addr[i*2+1] = Addr >> 8;
651 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400652
653 /* Load the Adapter Configuration.
654 Note: Barring any more specific information from some
655 other source (ie EEPROM+Schematics), we would not know
656 how to operate a 10Base2 interface on the AUI port.
657 However, since we do read the status of HCB1 and use
658 settings that always result in calls to control_dc_dc(dev,0)
659 a BNC interface should work if the enable pin
660 (dc/dc converter) is on HCB1. It will be called AUI
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 however. */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400662
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 lp->adapter_cnf = 0;
664 i = readreg(dev, PP_LineCTL);
665 /* Preserve the setting of the HCB1 pin. */
666 if ((i & (HCB1 | HCB1_ENBL)) == (HCB1 | HCB1_ENBL))
667 lp->adapter_cnf |= A_CNF_DC_DC_POLARITY;
668 /* Save the sqelch bit */
669 if ((i & LOW_RX_SQUELCH) == LOW_RX_SQUELCH)
670 lp->adapter_cnf |= A_CNF_EXTND_10B_2 | A_CNF_LOW_RX_SQUELCH;
671 /* Check if the card is in 10Base-t only mode */
672 if ((i & (AUI_ONLY | AUTO_AUI_10BASET)) == 0)
673 lp->adapter_cnf |= A_CNF_10B_T | A_CNF_MEDIA_10B_T;
674 /* Check if the card is in AUI only mode */
675 if ((i & (AUI_ONLY | AUTO_AUI_10BASET)) == AUI_ONLY)
676 lp->adapter_cnf |= A_CNF_AUI | A_CNF_MEDIA_AUI;
677 /* Check if the card is in Auto mode. */
678 if ((i & (AUI_ONLY | AUTO_AUI_10BASET)) == AUTO_AUI_10BASET)
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400679 lp->adapter_cnf |= A_CNF_AUI | A_CNF_10B_T |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 A_CNF_MEDIA_AUI | A_CNF_MEDIA_10B_T | A_CNF_MEDIA_AUTO;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400681
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 if (net_debug > 1)
683 printk(KERN_INFO "%s: PP_LineCTL=0x%x, adapter_cnf=0x%x\n",
684 dev->name, i, lp->adapter_cnf);
685
686 /* IRQ. Other chips already probe, see below. */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400687 if (lp->chip_type == CS8900)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 lp->isa_config = readreg(dev, PP_CS8900_ISAINT) & INT_NO_MASK;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400689
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 printk( "[Cirrus EEPROM] ");
691 }
692
693 printk("\n");
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400694
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 /* First check to see if an EEPROM is attached. */
Christoph Eggeref3cf9f2010-07-14 13:40:36 -0700696
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 if ((readreg(dev, PP_SelfST) & EEPROM_PRESENT) == 0)
698 printk(KERN_WARNING "cs89x0: No EEPROM, relying on command line....\n");
699 else if (get_eeprom_data(dev, START_EEPROM_DATA,CHKSUM_LEN,eeprom_buff) < 0) {
700 printk(KERN_WARNING "\ncs89x0: EEPROM read failed, relying on command line.\n");
701 } else if (get_eeprom_cksum(START_EEPROM_DATA,CHKSUM_LEN,eeprom_buff) < 0) {
702 /* Check if the chip was able to read its own configuration starting
703 at 0 in the EEPROM*/
704 if ((readreg(dev, PP_SelfST) & (EEPROM_OK | EEPROM_PRESENT)) !=
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400705 (EEPROM_OK|EEPROM_PRESENT))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 printk(KERN_WARNING "cs89x0: Extended EEPROM checksum bad and no Cirrus EEPROM, relying on command line\n");
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400707
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 } else {
709 /* This reads an extended EEPROM that is not documented
710 in the CS8900 datasheet. */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400711
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 /* get transmission control word but keep the autonegotiation bits */
713 if (!lp->auto_neg_cnf) lp->auto_neg_cnf = eeprom_buff[AUTO_NEG_CNF_OFFSET/2];
714 /* Store adapter configuration */
715 if (!lp->adapter_cnf) lp->adapter_cnf = eeprom_buff[ADAPTER_CNF_OFFSET/2];
716 /* Store ISA configuration */
717 lp->isa_config = eeprom_buff[ISA_CNF_OFFSET/2];
718 dev->mem_start = eeprom_buff[PACKET_PAGE_OFFSET/2] << 8;
719
720 /* eeprom_buff has 32-bit ints, so we can't just memcpy it */
721 /* store the initial memory base address */
722 for (i = 0; i < ETH_ALEN/2; i++) {
723 dev->dev_addr[i*2] = eeprom_buff[i];
724 dev->dev_addr[i*2+1] = eeprom_buff[i] >> 8;
725 }
726 if (net_debug > 1)
727 printk(KERN_DEBUG "%s: new adapter_cnf: 0x%x\n",
728 dev->name, lp->adapter_cnf);
729 }
730
731 /* allow them to force multiple transceivers. If they force multiple, autosense */
732 {
733 int count = 0;
734 if (lp->force & FORCE_RJ45) {lp->adapter_cnf |= A_CNF_10B_T; count++; }
735 if (lp->force & FORCE_AUI) {lp->adapter_cnf |= A_CNF_AUI; count++; }
736 if (lp->force & FORCE_BNC) {lp->adapter_cnf |= A_CNF_10B_2; count++; }
737 if (count > 1) {lp->adapter_cnf |= A_CNF_MEDIA_AUTO; }
738 else if (lp->force & FORCE_RJ45){lp->adapter_cnf |= A_CNF_MEDIA_10B_T; }
739 else if (lp->force & FORCE_AUI) {lp->adapter_cnf |= A_CNF_MEDIA_AUI; }
740 else if (lp->force & FORCE_BNC) {lp->adapter_cnf |= A_CNF_MEDIA_10B_2; }
741 }
742
743 if (net_debug > 1)
744 printk(KERN_DEBUG "%s: after force 0x%x, adapter_cnf=0x%x\n",
745 dev->name, lp->force, lp->adapter_cnf);
746
747 /* FIXME: We don't let you set dc-dc polarity or low RX squelch from the command line: add it here */
748
749 /* FIXME: We don't let you set the IMM bit from the command line: add it to lp->auto_neg_cnf here */
750
751 /* FIXME: we don't set the Ethernet address on the command line. Use
752 ifconfig IFACE hw ether AABBCCDDEEFF */
753
754 printk(KERN_INFO "cs89x0 media %s%s%s",
755 (lp->adapter_cnf & A_CNF_10B_T)?"RJ-45,":"",
756 (lp->adapter_cnf & A_CNF_AUI)?"AUI,":"",
757 (lp->adapter_cnf & A_CNF_10B_2)?"BNC,":"");
758
759 lp->irq_map = 0xffff;
760
761 /* If this is a CS8900 then no pnp soft */
762 if (lp->chip_type != CS8900 &&
763 /* Check if the ISA IRQ has been set */
764 (i = readreg(dev, PP_CS8920_ISAINT) & 0xff,
765 (i != 0 && i < CS8920_NO_INTS))) {
766 if (!dev->irq)
767 dev->irq = i;
768 } else {
769 i = lp->isa_config & INT_NO_MASK;
770 if (lp->chip_type == CS8900) {
Gilles Chanteperdrix0ac4ed92008-09-26 15:44:43 +0100771#ifdef CONFIG_CS89x0_NONISA_IRQ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 i = cs8900_irq_map[0];
773#else
774 /* Translate the IRQ using the IRQ mapping table. */
Denis Chengff8ac602007-09-02 18:30:18 +0800775 if (i >= ARRAY_SIZE(cs8900_irq_map))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 printk("\ncs89x0: invalid ISA interrupt number %d\n", i);
777 else
778 i = cs8900_irq_map[i];
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400779
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 lp->irq_map = CS8900_IRQ_MAP; /* fixed IRQ map for CS8900 */
781 } else {
782 int irq_map_buff[IRQ_MAP_LEN/2];
783
784 if (get_eeprom_data(dev, IRQ_MAP_EEPROM_DATA,
785 IRQ_MAP_LEN/2,
786 irq_map_buff) >= 0) {
787 if ((irq_map_buff[0] & 0xff) == PNP_IRQ_FRMT)
788 lp->irq_map = (irq_map_buff[0]>>8) | (irq_map_buff[1] << 8);
789 }
790#endif
791 }
792 if (!dev->irq)
793 dev->irq = i;
794 }
795
796 printk(" IRQ %d", dev->irq);
797
798#if ALLOW_DMA
799 if (lp->use_dma) {
800 get_dma_channel(dev);
801 printk(", DMA %d", dev->dma);
802 }
803 else
804#endif
805 {
806 printk(", programmed I/O");
807 }
808
809 /* print the ethernet address. */
Johannes Berge1749612008-10-27 15:59:26 -0700810 printk(", MAC %pM", dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
Stephen Hemminger15d23e72009-03-26 15:11:43 +0000812 dev->netdev_ops = &net_ops;
813 dev->watchdog_timeo = HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
815 printk("\n");
816 if (net_debug)
817 printk("cs89x0_probe1() successful\n");
b1fc5502005-05-12 20:11:55 -0400818
819 retval = register_netdev(dev);
820 if (retval)
821 goto out3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 return 0;
b1fc5502005-05-12 20:11:55 -0400823out3:
Lennert Buytenhekfc8c7d72006-01-08 01:01:08 -0800824 writeword(dev->base_addr, ADD_PORT, PP_ChipID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825out2:
826 release_region(ioaddr & ~3, NETCARD_IO_EXTENT);
827out1:
828 return retval;
829}
830
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400831
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832/*********************************
833 * This page contains DMA routines
834**********************************/
835
836#if ALLOW_DMA
837
838#define dma_page_eq(ptr1, ptr2) ((long)(ptr1)>>17 == (long)(ptr2)>>17)
839
840static void
841get_dma_channel(struct net_device *dev)
842{
843 struct net_local *lp = netdev_priv(dev);
844
845 if (lp->dma) {
846 dev->dma = lp->dma;
847 lp->isa_config |= ISA_RxDMA;
848 } else {
849 if ((lp->isa_config & ANY_ISA_DMA) == 0)
850 return;
851 dev->dma = lp->isa_config & DMA_NO_MASK;
852 if (lp->chip_type == CS8900)
853 dev->dma += 5;
854 if (dev->dma < 5 || dev->dma > 7) {
855 lp->isa_config &= ~ANY_ISA_DMA;
856 return;
857 }
858 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859}
860
861static void
862write_dma(struct net_device *dev, int chip_type, int dma)
863{
864 struct net_local *lp = netdev_priv(dev);
865 if ((lp->isa_config & ANY_ISA_DMA) == 0)
866 return;
867 if (chip_type == CS8900) {
868 writereg(dev, PP_CS8900_ISADMA, dma-5);
869 } else {
870 writereg(dev, PP_CS8920_ISADMA, dma);
871 }
872}
873
874static void
875set_dma_cfg(struct net_device *dev)
876{
877 struct net_local *lp = netdev_priv(dev);
878
879 if (lp->use_dma) {
880 if ((lp->isa_config & ANY_ISA_DMA) == 0) {
881 if (net_debug > 3)
882 printk("set_dma_cfg(): no DMA\n");
883 return;
884 }
885 if (lp->isa_config & ISA_RxDMA) {
886 lp->curr_rx_cfg |= RX_DMA_ONLY;
887 if (net_debug > 3)
888 printk("set_dma_cfg(): RX_DMA_ONLY\n");
889 } else {
890 lp->curr_rx_cfg |= AUTO_RX_DMA; /* not that we support it... */
891 if (net_debug > 3)
892 printk("set_dma_cfg(): AUTO_RX_DMA\n");
893 }
894 }
895}
896
897static int
898dma_bufcfg(struct net_device *dev)
899{
900 struct net_local *lp = netdev_priv(dev);
901 if (lp->use_dma)
902 return (lp->isa_config & ANY_ISA_DMA)? RX_DMA_ENBL : 0;
903 else
904 return 0;
905}
906
907static int
908dma_busctl(struct net_device *dev)
909{
910 int retval = 0;
911 struct net_local *lp = netdev_priv(dev);
912 if (lp->use_dma) {
913 if (lp->isa_config & ANY_ISA_DMA)
914 retval |= RESET_RX_DMA; /* Reset the DMA pointer */
915 if (lp->isa_config & DMA_BURST)
916 retval |= DMA_BURST_MODE; /* Does ISA config specify DMA burst ? */
917 if (lp->dmasize == 64)
918 retval |= RX_DMA_SIZE_64K; /* did they ask for 64K? */
919 retval |= MEMORY_ON; /* we need memory enabled to use DMA. */
920 }
921 return retval;
922}
923
924static void
925dma_rx(struct net_device *dev)
926{
927 struct net_local *lp = netdev_priv(dev);
928 struct sk_buff *skb;
929 int status, length;
930 unsigned char *bp = lp->rx_dma_ptr;
931
932 status = bp[0] + (bp[1]<<8);
933 length = bp[2] + (bp[3]<<8);
934 bp += 4;
935 if (net_debug > 5) {
936 printk( "%s: receiving DMA packet at %lx, status %x, length %x\n",
937 dev->name, (unsigned long)bp, status, length);
938 }
939 if ((status & RX_OK) == 0) {
Kulikov Vasiliy661a16c2010-07-05 02:13:15 +0000940 count_rx_errors(status, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 goto skip_this_frame;
942 }
943
944 /* Malloc up new buffer. */
945 skb = dev_alloc_skb(length + 2);
946 if (skb == NULL) {
947 if (net_debug) /* I don't think we want to do this to a stressed system */
948 printk("%s: Memory squeeze, dropping packet.\n", dev->name);
Kulikov Vasiliy661a16c2010-07-05 02:13:15 +0000949 dev->stats.rx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950
951 /* AKPM: advance bp to the next frame */
952skip_this_frame:
953 bp += (length + 3) & ~3;
954 if (bp >= lp->end_dma_buff) bp -= lp->dmasize*1024;
955 lp->rx_dma_ptr = bp;
956 return;
957 }
958 skb_reserve(skb, 2); /* longword align L3 header */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959
960 if (bp + length > lp->end_dma_buff) {
961 int semi_cnt = lp->end_dma_buff - bp;
962 memcpy(skb_put(skb,semi_cnt), bp, semi_cnt);
963 memcpy(skb_put(skb,length - semi_cnt), lp->dma_buff,
964 length - semi_cnt);
965 } else {
966 memcpy(skb_put(skb,length), bp, length);
967 }
968 bp += (length + 3) & ~3;
969 if (bp >= lp->end_dma_buff) bp -= lp->dmasize*1024;
970 lp->rx_dma_ptr = bp;
971
972 if (net_debug > 3) {
973 printk( "%s: received %d byte DMA packet of type %x\n",
974 dev->name, length,
975 (skb->data[ETH_ALEN+ETH_ALEN] << 8) | skb->data[ETH_ALEN+ETH_ALEN+1]);
976 }
977 skb->protocol=eth_type_trans(skb,dev);
978 netif_rx(skb);
Kulikov Vasiliy661a16c2010-07-05 02:13:15 +0000979 dev->stats.rx_packets++;
980 dev->stats.rx_bytes += length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981}
982
983#endif /* ALLOW_DMA */
984
Hannes Ederdac499f2008-12-25 23:56:45 -0800985static void __init reset_chip(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986{
Gilles Chanteperdrix0ac4ed92008-09-26 15:44:43 +0100987#if !defined(CONFIG_MACH_MX31ADS)
Deepak Saxena9c878962006-01-14 13:21:18 -0800988#if !defined(CONFIG_MACH_IXDP2351) && !defined(CONFIG_ARCH_IXDP2X01)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 struct net_local *lp = netdev_priv(dev);
990 int ioaddr = dev->base_addr;
991#endif
992 int reset_start_time;
993
994 writereg(dev, PP_SelfCTL, readreg(dev, PP_SelfCTL) | POWER_ON_RESET);
995
996 /* wait 30 ms */
997 msleep(30);
998
Deepak Saxena9c878962006-01-14 13:21:18 -0800999#if !defined(CONFIG_MACH_IXDP2351) && !defined(CONFIG_ARCH_IXDP2X01)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 if (lp->chip_type != CS8900) {
1001 /* Hardware problem requires PNP registers to be reconfigured after a reset */
Lennert Buytenhekfc8c7d72006-01-08 01:01:08 -08001002 writeword(ioaddr, ADD_PORT, PP_CS8920_ISAINT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 outb(dev->irq, ioaddr + DATA_PORT);
1004 outb(0, ioaddr + DATA_PORT + 1);
1005
Lennert Buytenhekfc8c7d72006-01-08 01:01:08 -08001006 writeword(ioaddr, ADD_PORT, PP_CS8920_ISAMemB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 outb((dev->mem_start >> 16) & 0xff, ioaddr + DATA_PORT);
1008 outb((dev->mem_start >> 8) & 0xff, ioaddr + DATA_PORT + 1);
1009 }
1010#endif /* IXDP2x01 */
1011
1012 /* Wait until the chip is reset */
1013 reset_start_time = jiffies;
1014 while( (readreg(dev, PP_SelfST) & INIT_DONE) == 0 && jiffies - reset_start_time < 2)
1015 ;
Gilles Chanteperdrix0ac4ed92008-09-26 15:44:43 +01001016#endif /* !CONFIG_MACH_MX31ADS */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017}
1018
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001019
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020static void
1021control_dc_dc(struct net_device *dev, int on_not_off)
1022{
1023 struct net_local *lp = netdev_priv(dev);
1024 unsigned int selfcontrol;
1025 int timenow = jiffies;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001026 /* control the DC to DC convertor in the SelfControl register.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 Note: This is hooked up to a general purpose pin, might not
1028 always be a DC to DC convertor. */
1029
1030 selfcontrol = HCB1_ENBL; /* Enable the HCB1 bit as an output */
1031 if (((lp->adapter_cnf & A_CNF_DC_DC_POLARITY) != 0) ^ on_not_off)
1032 selfcontrol |= HCB1;
1033 else
1034 selfcontrol &= ~HCB1;
1035 writereg(dev, PP_SelfCTL, selfcontrol);
1036
1037 /* Wait for the DC/DC converter to power up - 500ms */
1038 while (jiffies - timenow < HZ)
1039 ;
1040}
1041
1042#define DETECTED_NONE 0
1043#define DETECTED_RJ45H 1
1044#define DETECTED_RJ45F 2
1045#define DETECTED_AUI 3
1046#define DETECTED_BNC 4
1047
1048static int
1049detect_tp(struct net_device *dev)
1050{
1051 struct net_local *lp = netdev_priv(dev);
1052 int timenow = jiffies;
1053 int fdx;
1054
1055 if (net_debug > 1) printk("%s: Attempting TP\n", dev->name);
1056
1057 /* If connected to another full duplex capable 10-Base-T card the link pulses
1058 seem to be lost when the auto detect bit in the LineCTL is set.
1059 To overcome this the auto detect bit will be cleared whilst testing the
1060 10-Base-T interface. This would not be necessary for the sparrow chip but
1061 is simpler to do it anyway. */
1062 writereg(dev, PP_LineCTL, lp->linectl &~ AUI_ONLY);
1063 control_dc_dc(dev, 0);
1064
1065 /* Delay for the hardware to work out if the TP cable is present - 150ms */
1066 for (timenow = jiffies; jiffies - timenow < 15; )
1067 ;
1068 if ((readreg(dev, PP_LineST) & LINK_OK) == 0)
1069 return DETECTED_NONE;
1070
1071 if (lp->chip_type == CS8900) {
1072 switch (lp->force & 0xf0) {
1073#if 0
1074 case FORCE_AUTO:
1075 printk("%s: cs8900 doesn't autonegotiate\n",dev->name);
1076 return DETECTED_NONE;
1077#endif
1078 /* CS8900 doesn't support AUTO, change to HALF*/
1079 case FORCE_AUTO:
1080 lp->force &= ~FORCE_AUTO;
1081 lp->force |= FORCE_HALF;
1082 break;
1083 case FORCE_HALF:
1084 break;
1085 case FORCE_FULL:
1086 writereg(dev, PP_TestCTL, readreg(dev, PP_TestCTL) | FDX_8900);
1087 break;
1088 }
1089 fdx = readreg(dev, PP_TestCTL) & FDX_8900;
1090 } else {
1091 switch (lp->force & 0xf0) {
1092 case FORCE_AUTO:
1093 lp->auto_neg_cnf = AUTO_NEG_ENABLE;
1094 break;
1095 case FORCE_HALF:
1096 lp->auto_neg_cnf = 0;
1097 break;
1098 case FORCE_FULL:
1099 lp->auto_neg_cnf = RE_NEG_NOW | ALLOW_FDX;
1100 break;
1101 }
1102
1103 writereg(dev, PP_AutoNegCTL, lp->auto_neg_cnf & AUTO_NEG_MASK);
1104
1105 if ((lp->auto_neg_cnf & AUTO_NEG_BITS) == AUTO_NEG_ENABLE) {
1106 printk(KERN_INFO "%s: negotiating duplex...\n",dev->name);
1107 while (readreg(dev, PP_AutoNegST) & AUTO_NEG_BUSY) {
1108 if (jiffies - timenow > 4000) {
1109 printk(KERN_ERR "**** Full / half duplex auto-negotiation timed out ****\n");
1110 break;
1111 }
1112 }
1113 }
1114 fdx = readreg(dev, PP_AutoNegST) & FDX_ACTIVE;
1115 }
1116 if (fdx)
1117 return DETECTED_RJ45F;
1118 else
1119 return DETECTED_RJ45H;
1120}
1121
1122/* send a test packet - return true if carrier bits are ok */
1123static int
1124send_test_pkt(struct net_device *dev)
1125{
1126 char test_packet[] = { 0,0,0,0,0,0, 0,0,0,0,0,0,
1127 0, 46, /* A 46 in network order */
1128 0, 0, /* DSAP=0 & SSAP=0 fields */
1129 0xf3, 0 /* Control (Test Req + P bit set) */ };
1130 long timenow = jiffies;
1131
1132 writereg(dev, PP_LineCTL, readreg(dev, PP_LineCTL) | SERIAL_TX_ON);
1133
1134 memcpy(test_packet, dev->dev_addr, ETH_ALEN);
1135 memcpy(test_packet+ETH_ALEN, dev->dev_addr, ETH_ALEN);
1136
Lennert Buytenhek974dffc2006-01-08 01:01:06 -08001137 writeword(dev->base_addr, TX_CMD_PORT, TX_AFTER_ALL);
1138 writeword(dev->base_addr, TX_LEN_PORT, ETH_ZLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139
1140 /* Test to see if the chip has allocated memory for the packet */
1141 while (jiffies - timenow < 5)
1142 if (readreg(dev, PP_BusST) & READY_FOR_TX_NOW)
1143 break;
1144 if (jiffies - timenow >= 5)
1145 return 0; /* this shouldn't happen */
1146
1147 /* Write the contents of the packet */
Lennert Buytenhek084f7462006-01-08 01:01:12 -08001148 writewords(dev->base_addr, TX_FRAME_PORT,test_packet,(ETH_ZLEN+1) >>1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149
1150 if (net_debug > 1) printk("Sending test packet ");
1151 /* wait a couple of jiffies for packet to be received */
1152 for (timenow = jiffies; jiffies - timenow < 3; )
1153 ;
1154 if ((readreg(dev, PP_TxEvent) & TX_SEND_OK_BITS) == TX_OK) {
1155 if (net_debug > 1) printk("succeeded\n");
1156 return 1;
1157 }
1158 if (net_debug > 1) printk("failed\n");
1159 return 0;
1160}
1161
1162
1163static int
1164detect_aui(struct net_device *dev)
1165{
1166 struct net_local *lp = netdev_priv(dev);
1167
1168 if (net_debug > 1) printk("%s: Attempting AUI\n", dev->name);
1169 control_dc_dc(dev, 0);
1170
1171 writereg(dev, PP_LineCTL, (lp->linectl &~ AUTO_AUI_10BASET) | AUI_ONLY);
1172
1173 if (send_test_pkt(dev))
1174 return DETECTED_AUI;
1175 else
1176 return DETECTED_NONE;
1177}
1178
1179static int
1180detect_bnc(struct net_device *dev)
1181{
1182 struct net_local *lp = netdev_priv(dev);
1183
1184 if (net_debug > 1) printk("%s: Attempting BNC\n", dev->name);
1185 control_dc_dc(dev, 1);
1186
1187 writereg(dev, PP_LineCTL, (lp->linectl &~ AUTO_AUI_10BASET) | AUI_ONLY);
1188
1189 if (send_test_pkt(dev))
1190 return DETECTED_BNC;
1191 else
1192 return DETECTED_NONE;
1193}
1194
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001195
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196static void
1197write_irq(struct net_device *dev, int chip_type, int irq)
1198{
1199 int i;
1200
1201 if (chip_type == CS8900) {
1202 /* Search the mapping table for the corresponding IRQ pin. */
Denis Chengff8ac602007-09-02 18:30:18 +08001203 for (i = 0; i != ARRAY_SIZE(cs8900_irq_map); i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 if (cs8900_irq_map[i] == irq)
1205 break;
1206 /* Not found */
Denis Chengff8ac602007-09-02 18:30:18 +08001207 if (i == ARRAY_SIZE(cs8900_irq_map))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 i = 3;
1209 writereg(dev, PP_CS8900_ISAINT, i);
1210 } else {
1211 writereg(dev, PP_CS8920_ISAINT, irq);
1212 }
1213}
1214
1215/* Open/initialize the board. This is called (in the current kernel)
1216 sometime after booting when the 'ifconfig' program is run.
1217
1218 This routine should set everything up anew at each open, even
1219 registers that "should" only need to be set once at boot, so that
1220 there is non-reboot way to recover if something goes wrong.
1221 */
1222
1223/* AKPM: do we need to do any locking here? */
1224
1225static int
1226net_open(struct net_device *dev)
1227{
1228 struct net_local *lp = netdev_priv(dev);
1229 int result = 0;
1230 int i;
1231 int ret;
1232
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 if (dev->irq < 2) {
1234 /* Allow interrupts to be generated by the chip */
1235/* Cirrus' release had this: */
1236#if 0
1237 writereg(dev, PP_BusCTL, readreg(dev, PP_BusCTL)|ENABLE_IRQ );
1238#endif
1239/* And 2.3.47 had this: */
1240 writereg(dev, PP_BusCTL, ENABLE_IRQ | MEMORY_ON);
1241
1242 for (i = 2; i < CS8920_NO_INTS; i++) {
1243 if ((1 << i) & lp->irq_map) {
1244 if (request_irq(i, net_interrupt, 0, dev->name, dev) == 0) {
1245 dev->irq = i;
1246 write_irq(dev, lp->chip_type, i);
1247 /* writereg(dev, PP_BufCFG, GENERATE_SW_INTERRUPT); */
1248 break;
1249 }
1250 }
1251 }
1252
1253 if (i >= CS8920_NO_INTS) {
1254 writereg(dev, PP_BusCTL, 0); /* disable interrupts. */
1255 printk(KERN_ERR "cs89x0: can't get an interrupt\n");
1256 ret = -EAGAIN;
1257 goto bad_out;
1258 }
1259 }
1260 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 {
Gilles Chanteperdrix0ac4ed92008-09-26 15:44:43 +01001262#ifndef CONFIG_CS89x0_NONISA_IRQ
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 if (((1 << dev->irq) & lp->irq_map) == 0) {
1264 printk(KERN_ERR "%s: IRQ %d is not in our map of allowable IRQs, which is %x\n",
1265 dev->name, dev->irq, lp->irq_map);
1266 ret = -EAGAIN;
1267 goto bad_out;
1268 }
1269#endif
1270/* FIXME: Cirrus' release had this: */
1271 writereg(dev, PP_BusCTL, readreg(dev, PP_BusCTL)|ENABLE_IRQ );
1272/* And 2.3.47 had this: */
1273#if 0
1274 writereg(dev, PP_BusCTL, ENABLE_IRQ | MEMORY_ON);
1275#endif
1276 write_irq(dev, lp->chip_type, dev->irq);
Joe Perchesa0607fd2009-11-18 23:29:17 -08001277 ret = request_irq(dev->irq, net_interrupt, 0, dev->name, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 if (ret) {
Mark Brown569b7892010-01-07 00:53:05 -08001279 printk(KERN_ERR "cs89x0: request_irq(%d) failed\n", dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 goto bad_out;
1281 }
1282 }
1283
1284#if ALLOW_DMA
1285 if (lp->use_dma) {
1286 if (lp->isa_config & ANY_ISA_DMA) {
1287 unsigned long flags;
1288 lp->dma_buff = (unsigned char *)__get_dma_pages(GFP_KERNEL,
1289 get_order(lp->dmasize * 1024));
1290
1291 if (!lp->dma_buff) {
1292 printk(KERN_ERR "%s: cannot get %dK memory for DMA\n", dev->name, lp->dmasize);
1293 goto release_irq;
1294 }
1295 if (net_debug > 1) {
1296 printk( "%s: dma %lx %lx\n",
1297 dev->name,
1298 (unsigned long)lp->dma_buff,
1299 (unsigned long)isa_virt_to_bus(lp->dma_buff));
1300 }
1301 if ((unsigned long) lp->dma_buff >= MAX_DMA_ADDRESS ||
1302 !dma_page_eq(lp->dma_buff, lp->dma_buff+lp->dmasize*1024-1)) {
1303 printk(KERN_ERR "%s: not usable as DMA buffer\n", dev->name);
1304 goto release_irq;
1305 }
1306 memset(lp->dma_buff, 0, lp->dmasize * 1024); /* Why? */
1307 if (request_dma(dev->dma, dev->name)) {
1308 printk(KERN_ERR "%s: cannot get dma channel %d\n", dev->name, dev->dma);
1309 goto release_irq;
1310 }
1311 write_dma(dev, lp->chip_type, dev->dma);
1312 lp->rx_dma_ptr = lp->dma_buff;
1313 lp->end_dma_buff = lp->dma_buff + lp->dmasize*1024;
1314 spin_lock_irqsave(&lp->lock, flags);
1315 disable_dma(dev->dma);
1316 clear_dma_ff(dev->dma);
Julia Lawallef0657c2009-07-06 19:09:50 -07001317 set_dma_mode(dev->dma, DMA_RX_MODE); /* auto_init as well */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 set_dma_addr(dev->dma, isa_virt_to_bus(lp->dma_buff));
1319 set_dma_count(dev->dma, lp->dmasize*1024);
1320 enable_dma(dev->dma);
1321 spin_unlock_irqrestore(&lp->lock, flags);
1322 }
1323 }
1324#endif /* ALLOW_DMA */
1325
1326 /* set the Ethernet address */
1327 for (i=0; i < ETH_ALEN/2; i++)
1328 writereg(dev, PP_IA+i*2, dev->dev_addr[i*2] | (dev->dev_addr[i*2+1] << 8));
1329
1330 /* while we're testing the interface, leave interrupts disabled */
1331 writereg(dev, PP_BusCTL, MEMORY_ON);
1332
1333 /* Set the LineCTL quintuplet based on adapter configuration read from EEPROM */
1334 if ((lp->adapter_cnf & A_CNF_EXTND_10B_2) && (lp->adapter_cnf & A_CNF_LOW_RX_SQUELCH))
1335 lp->linectl = LOW_RX_SQUELCH;
1336 else
1337 lp->linectl = 0;
1338
1339 /* check to make sure that they have the "right" hardware available */
1340 switch(lp->adapter_cnf & A_CNF_MEDIA_TYPE) {
1341 case A_CNF_MEDIA_10B_T: result = lp->adapter_cnf & A_CNF_10B_T; break;
1342 case A_CNF_MEDIA_AUI: result = lp->adapter_cnf & A_CNF_AUI; break;
1343 case A_CNF_MEDIA_10B_2: result = lp->adapter_cnf & A_CNF_10B_2; break;
1344 default: result = lp->adapter_cnf & (A_CNF_10B_T | A_CNF_AUI | A_CNF_10B_2);
1345 }
Lennert Buytenhek277cb102006-01-08 01:01:14 -08001346#ifdef CONFIG_ARCH_PNX010X
dmitry pervushin0dd3c782005-06-20 15:32:54 -07001347 result = A_CNF_10B_T;
1348#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 if (!result) {
1350 printk(KERN_ERR "%s: EEPROM is configured for unavailable media\n", dev->name);
Wang Chen17a94402008-05-30 11:18:55 +08001351release_dma:
1352#if ALLOW_DMA
1353 free_dma(dev->dma);
Wang Chen17a94402008-05-30 11:18:55 +08001354release_irq:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 release_dma_buff(lp);
1356#endif
1357 writereg(dev, PP_LineCTL, readreg(dev, PP_LineCTL) & ~(SERIAL_TX_ON | SERIAL_RX_ON));
1358 free_irq(dev->irq, dev);
1359 ret = -EAGAIN;
1360 goto bad_out;
1361 }
1362
1363 /* set the hardware to the configured choice */
1364 switch(lp->adapter_cnf & A_CNF_MEDIA_TYPE) {
1365 case A_CNF_MEDIA_10B_T:
1366 result = detect_tp(dev);
1367 if (result==DETECTED_NONE) {
1368 printk(KERN_WARNING "%s: 10Base-T (RJ-45) has no cable\n", dev->name);
1369 if (lp->auto_neg_cnf & IMM_BIT) /* check "ignore missing media" bit */
1370 result = DETECTED_RJ45H; /* Yes! I don't care if I see a link pulse */
1371 }
1372 break;
1373 case A_CNF_MEDIA_AUI:
1374 result = detect_aui(dev);
1375 if (result==DETECTED_NONE) {
1376 printk(KERN_WARNING "%s: 10Base-5 (AUI) has no cable\n", dev->name);
1377 if (lp->auto_neg_cnf & IMM_BIT) /* check "ignore missing media" bit */
1378 result = DETECTED_AUI; /* Yes! I don't care if I see a carrrier */
1379 }
1380 break;
1381 case A_CNF_MEDIA_10B_2:
1382 result = detect_bnc(dev);
1383 if (result==DETECTED_NONE) {
1384 printk(KERN_WARNING "%s: 10Base-2 (BNC) has no cable\n", dev->name);
1385 if (lp->auto_neg_cnf & IMM_BIT) /* check "ignore missing media" bit */
1386 result = DETECTED_BNC; /* Yes! I don't care if I can xmit a packet */
1387 }
1388 break;
1389 case A_CNF_MEDIA_AUTO:
1390 writereg(dev, PP_LineCTL, lp->linectl | AUTO_AUI_10BASET);
1391 if (lp->adapter_cnf & A_CNF_10B_T)
1392 if ((result = detect_tp(dev)) != DETECTED_NONE)
1393 break;
1394 if (lp->adapter_cnf & A_CNF_AUI)
1395 if ((result = detect_aui(dev)) != DETECTED_NONE)
1396 break;
1397 if (lp->adapter_cnf & A_CNF_10B_2)
1398 if ((result = detect_bnc(dev)) != DETECTED_NONE)
1399 break;
1400 printk(KERN_ERR "%s: no media detected\n", dev->name);
Wang Chen17a94402008-05-30 11:18:55 +08001401 goto release_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 }
1403 switch(result) {
1404 case DETECTED_NONE:
1405 printk(KERN_ERR "%s: no network cable attached to configured media\n", dev->name);
Wang Chen17a94402008-05-30 11:18:55 +08001406 goto release_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 case DETECTED_RJ45H:
1408 printk(KERN_INFO "%s: using half-duplex 10Base-T (RJ-45)\n", dev->name);
1409 break;
1410 case DETECTED_RJ45F:
1411 printk(KERN_INFO "%s: using full-duplex 10Base-T (RJ-45)\n", dev->name);
1412 break;
1413 case DETECTED_AUI:
1414 printk(KERN_INFO "%s: using 10Base-5 (AUI)\n", dev->name);
1415 break;
1416 case DETECTED_BNC:
1417 printk(KERN_INFO "%s: using 10Base-2 (BNC)\n", dev->name);
1418 break;
1419 }
1420
1421 /* Turn on both receive and transmit operations */
1422 writereg(dev, PP_LineCTL, readreg(dev, PP_LineCTL) | SERIAL_RX_ON | SERIAL_TX_ON);
1423
1424 /* Receive only error free packets addressed to this card */
1425 lp->rx_mode = 0;
1426 writereg(dev, PP_RxCTL, DEF_RX_ACCEPT);
1427
1428 lp->curr_rx_cfg = RX_OK_ENBL | RX_CRC_ERROR_ENBL;
1429
1430 if (lp->isa_config & STREAM_TRANSFER)
1431 lp->curr_rx_cfg |= RX_STREAM_ENBL;
1432#if ALLOW_DMA
1433 set_dma_cfg(dev);
1434#endif
1435 writereg(dev, PP_RxCFG, lp->curr_rx_cfg);
1436
1437 writereg(dev, PP_TxCFG, TX_LOST_CRS_ENBL | TX_SQE_ERROR_ENBL | TX_OK_ENBL |
1438 TX_LATE_COL_ENBL | TX_JBR_ENBL | TX_ANY_COL_ENBL | TX_16_COL_ENBL);
1439
1440 writereg(dev, PP_BufCFG, READY_FOR_TX_ENBL | RX_MISS_COUNT_OVRFLOW_ENBL |
1441#if ALLOW_DMA
1442 dma_bufcfg(dev) |
1443#endif
1444 TX_COL_COUNT_OVRFLOW_ENBL | TX_UNDERRUN_ENBL);
1445
1446 /* now that we've got our act together, enable everything */
1447 writereg(dev, PP_BusCTL, ENABLE_IRQ
1448 | (dev->mem_start?MEMORY_ON : 0) /* turn memory on */
1449#if ALLOW_DMA
1450 | dma_busctl(dev)
1451#endif
1452 );
1453 netif_start_queue(dev);
1454 if (net_debug > 1)
1455 printk("cs89x0: net_open() succeeded\n");
1456 return 0;
1457bad_out:
1458 return ret;
1459}
1460
1461static void net_timeout(struct net_device *dev)
1462{
1463 /* If we get here, some higher level has decided we are broken.
1464 There should really be a "kick me" function call instead. */
1465 if (net_debug > 0) printk("%s: transmit timed out, %s?\n", dev->name,
1466 tx_done(dev) ? "IRQ conflict ?" : "network cable problem");
1467 /* Try to restart the adaptor. */
1468 netif_wake_queue(dev);
1469}
1470
Stephen Hemminger613573252009-08-31 19:50:58 +00001471static netdev_tx_t net_send_packet(struct sk_buff *skb,struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472{
1473 struct net_local *lp = netdev_priv(dev);
Dongdong Deng79fbe132009-07-12 20:27:06 +00001474 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475
1476 if (net_debug > 3) {
1477 printk("%s: sent %d byte packet of type %x\n",
1478 dev->name, skb->len,
1479 (skb->data[ETH_ALEN+ETH_ALEN] << 8) | skb->data[ETH_ALEN+ETH_ALEN+1]);
1480 }
1481
1482 /* keep the upload from being interrupted, since we
1483 ask the chip to start transmitting before the
1484 whole packet has been completely uploaded. */
1485
Dongdong Deng79fbe132009-07-12 20:27:06 +00001486 spin_lock_irqsave(&lp->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 netif_stop_queue(dev);
1488
1489 /* initiate a transmit sequence */
Lennert Buytenhek974dffc2006-01-08 01:01:06 -08001490 writeword(dev->base_addr, TX_CMD_PORT, lp->send_cmd);
1491 writeword(dev->base_addr, TX_LEN_PORT, skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492
1493 /* Test to see if the chip has allocated memory for the packet */
1494 if ((readreg(dev, PP_BusST) & READY_FOR_TX_NOW) == 0) {
1495 /*
1496 * Gasp! It hasn't. But that shouldn't happen since
1497 * we're waiting for TxOk, so return 1 and requeue this packet.
1498 */
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001499
Dongdong Deng79fbe132009-07-12 20:27:06 +00001500 spin_unlock_irqrestore(&lp->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 if (net_debug) printk("cs89x0: Tx buffer not free!\n");
Patrick McHardy5b548142009-06-12 06:22:29 +00001502 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 }
1504 /* Write the contents of the packet */
Lennert Buytenhek084f7462006-01-08 01:01:12 -08001505 writewords(dev->base_addr, TX_FRAME_PORT,skb->data,(skb->len+1) >>1);
Dongdong Deng79fbe132009-07-12 20:27:06 +00001506 spin_unlock_irqrestore(&lp->lock, flags);
Kulikov Vasiliy661a16c2010-07-05 02:13:15 +00001507 dev->stats.tx_bytes += skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 dev_kfree_skb (skb);
1509
1510 /*
1511 * We DO NOT call netif_wake_queue() here.
1512 * We also DO NOT call netif_start_queue().
1513 *
1514 * Either of these would cause another bottom half run through
1515 * net_send_packet() before this packet has fully gone out. That causes
1516 * us to hit the "Gasp!" above and the send is rescheduled. it runs like
1517 * a dog. We just return and wait for the Tx completion interrupt handler
1518 * to restart the netdevice layer
1519 */
1520
Patrick McHardy6ed10652009-06-23 06:03:08 +00001521 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522}
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001523
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524/* The typical workload of the driver:
1525 Handle the network interface interrupts. */
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001526
David Howells7d12e782006-10-05 14:55:46 +01001527static irqreturn_t net_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528{
1529 struct net_device *dev = dev_id;
1530 struct net_local *lp;
1531 int ioaddr, status;
1532 int handled = 0;
1533
1534 ioaddr = dev->base_addr;
1535 lp = netdev_priv(dev);
1536
1537 /* we MUST read all the events out of the ISQ, otherwise we'll never
1538 get interrupted again. As a consequence, we can't have any limit
1539 on the number of times we loop in the interrupt handler. The
1540 hardware guarantees that eventually we'll run out of events. Of
1541 course, if you're on a slow machine, and packets are arriving
1542 faster than you can read them off, you're screwed. Hasta la
1543 vista, baby! */
Lennert Buytenhek974dffc2006-01-08 01:01:06 -08001544 while ((status = readword(dev->base_addr, ISQ_PORT))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 if (net_debug > 4)printk("%s: event=%04x\n", dev->name, status);
1546 handled = 1;
1547 switch(status & ISQ_EVENT_MASK) {
1548 case ISQ_RECEIVER_EVENT:
1549 /* Got a packet(s). */
1550 net_rx(dev);
1551 break;
1552 case ISQ_TRANSMITTER_EVENT:
Kulikov Vasiliy661a16c2010-07-05 02:13:15 +00001553 dev->stats.tx_packets++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 netif_wake_queue(dev); /* Inform upper layers. */
1555 if ((status & ( TX_OK |
1556 TX_LOST_CRS |
1557 TX_SQE_ERROR |
1558 TX_LATE_COL |
1559 TX_16_COL)) != TX_OK) {
Kulikov Vasiliy661a16c2010-07-05 02:13:15 +00001560 if ((status & TX_OK) == 0)
1561 dev->stats.tx_errors++;
1562 if (status & TX_LOST_CRS)
1563 dev->stats.tx_carrier_errors++;
1564 if (status & TX_SQE_ERROR)
1565 dev->stats.tx_heartbeat_errors++;
1566 if (status & TX_LATE_COL)
1567 dev->stats.tx_window_errors++;
1568 if (status & TX_16_COL)
1569 dev->stats.tx_aborted_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 }
1571 break;
1572 case ISQ_BUFFER_EVENT:
1573 if (status & READY_FOR_TX) {
1574 /* we tried to transmit a packet earlier,
1575 but inexplicably ran out of buffers.
1576 That shouldn't happen since we only ever
1577 load one packet. Shrug. Do the right
1578 thing anyway. */
1579 netif_wake_queue(dev); /* Inform upper layers. */
1580 }
1581 if (status & TX_UNDERRUN) {
1582 if (net_debug > 0) printk("%s: transmit underrun\n", dev->name);
1583 lp->send_underrun++;
1584 if (lp->send_underrun == 3) lp->send_cmd = TX_AFTER_381;
1585 else if (lp->send_underrun == 6) lp->send_cmd = TX_AFTER_ALL;
1586 /* transmit cycle is done, although
1587 frame wasn't transmitted - this
1588 avoids having to wait for the upper
1589 layers to timeout on us, in the
1590 event of a tx underrun */
1591 netif_wake_queue(dev); /* Inform upper layers. */
1592 }
1593#if ALLOW_DMA
1594 if (lp->use_dma && (status & RX_DMA)) {
1595 int count = readreg(dev, PP_DmaFrameCnt);
1596 while(count) {
1597 if (net_debug > 5)
1598 printk("%s: receiving %d DMA frames\n", dev->name, count);
1599 if (net_debug > 2 && count >1)
1600 printk("%s: receiving %d DMA frames\n", dev->name, count);
1601 dma_rx(dev);
1602 if (--count == 0)
1603 count = readreg(dev, PP_DmaFrameCnt);
1604 if (net_debug > 2 && count > 0)
1605 printk("%s: continuing with %d DMA frames\n", dev->name, count);
1606 }
1607 }
1608#endif
1609 break;
1610 case ISQ_RX_MISS_EVENT:
Kulikov Vasiliy661a16c2010-07-05 02:13:15 +00001611 dev->stats.rx_missed_errors += (status >> 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 break;
1613 case ISQ_TX_COL_EVENT:
Kulikov Vasiliy661a16c2010-07-05 02:13:15 +00001614 dev->stats.collisions += (status >> 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 break;
1616 }
1617 }
1618 return IRQ_RETVAL(handled);
1619}
1620
1621static void
Kulikov Vasiliy661a16c2010-07-05 02:13:15 +00001622count_rx_errors(int status, struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623{
Kulikov Vasiliy661a16c2010-07-05 02:13:15 +00001624 dev->stats.rx_errors++;
1625 if (status & RX_RUNT)
1626 dev->stats.rx_length_errors++;
1627 if (status & RX_EXTRA_DATA)
1628 dev->stats.rx_length_errors++;
1629 if ((status & RX_CRC_ERROR) && !(status & (RX_EXTRA_DATA|RX_RUNT)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 /* per str 172 */
Kulikov Vasiliy661a16c2010-07-05 02:13:15 +00001631 dev->stats.rx_crc_errors++;
1632 if (status & RX_DRIBBLE)
1633 dev->stats.rx_frame_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634}
1635
1636/* We have a good packet(s), get it/them out of the buffers. */
1637static void
1638net_rx(struct net_device *dev)
1639{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 struct sk_buff *skb;
1641 int status, length;
1642
1643 int ioaddr = dev->base_addr;
Lennert Buytenhekfc8c7d72006-01-08 01:01:08 -08001644 status = readword(ioaddr, RX_FRAME_PORT);
1645 length = readword(ioaddr, RX_FRAME_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646
1647 if ((status & RX_OK) == 0) {
Kulikov Vasiliy661a16c2010-07-05 02:13:15 +00001648 count_rx_errors(status, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649 return;
1650 }
1651
1652 /* Malloc up new buffer. */
1653 skb = dev_alloc_skb(length + 2);
1654 if (skb == NULL) {
1655#if 0 /* Again, this seems a cruel thing to do */
1656 printk(KERN_WARNING "%s: Memory squeeze, dropping packet.\n", dev->name);
1657#endif
Kulikov Vasiliy661a16c2010-07-05 02:13:15 +00001658 dev->stats.rx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 return;
1660 }
1661 skb_reserve(skb, 2); /* longword align L3 header */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662
Lennert Buytenhek084f7462006-01-08 01:01:12 -08001663 readwords(ioaddr, RX_FRAME_PORT, skb_put(skb, length), length >> 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 if (length & 1)
Lennert Buytenhekfc8c7d72006-01-08 01:01:08 -08001665 skb->data[length-1] = readword(ioaddr, RX_FRAME_PORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666
1667 if (net_debug > 3) {
1668 printk( "%s: received %d byte packet of type %x\n",
1669 dev->name, length,
1670 (skb->data[ETH_ALEN+ETH_ALEN] << 8) | skb->data[ETH_ALEN+ETH_ALEN+1]);
1671 }
1672
1673 skb->protocol=eth_type_trans(skb,dev);
1674 netif_rx(skb);
Kulikov Vasiliy661a16c2010-07-05 02:13:15 +00001675 dev->stats.rx_packets++;
1676 dev->stats.rx_bytes += length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677}
1678
1679#if ALLOW_DMA
1680static void release_dma_buff(struct net_local *lp)
1681{
1682 if (lp->dma_buff) {
1683 free_pages((unsigned long)(lp->dma_buff), get_order(lp->dmasize * 1024));
1684 lp->dma_buff = NULL;
1685 }
1686}
1687#endif
1688
1689/* The inverse routine to net_open(). */
1690static int
1691net_close(struct net_device *dev)
1692{
1693#if ALLOW_DMA
1694 struct net_local *lp = netdev_priv(dev);
1695#endif
1696
1697 netif_stop_queue(dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001698
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 writereg(dev, PP_RxCFG, 0);
1700 writereg(dev, PP_TxCFG, 0);
1701 writereg(dev, PP_BufCFG, 0);
1702 writereg(dev, PP_BusCTL, 0);
1703
1704 free_irq(dev->irq, dev);
1705
1706#if ALLOW_DMA
1707 if (lp->use_dma && lp->dma) {
1708 free_dma(dev->dma);
1709 release_dma_buff(lp);
1710 }
1711#endif
1712
1713 /* Update the statistics here. */
1714 return 0;
1715}
1716
1717/* Get the current statistics. This may be called with the card open or
1718 closed. */
1719static struct net_device_stats *
1720net_get_stats(struct net_device *dev)
1721{
1722 struct net_local *lp = netdev_priv(dev);
1723 unsigned long flags;
1724
1725 spin_lock_irqsave(&lp->lock, flags);
1726 /* Update the statistics from the device registers. */
Kulikov Vasiliy661a16c2010-07-05 02:13:15 +00001727 dev->stats.rx_missed_errors += (readreg(dev, PP_RxMiss) >> 6);
1728 dev->stats.collisions += (readreg(dev, PP_TxCol) >> 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 spin_unlock_irqrestore(&lp->lock, flags);
1730
Kulikov Vasiliy661a16c2010-07-05 02:13:15 +00001731 return &dev->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732}
1733
1734static void set_multicast_list(struct net_device *dev)
1735{
1736 struct net_local *lp = netdev_priv(dev);
1737 unsigned long flags;
1738
1739 spin_lock_irqsave(&lp->lock, flags);
1740 if(dev->flags&IFF_PROMISC)
1741 {
1742 lp->rx_mode = RX_ALL_ACCEPT;
1743 }
Jiri Pirkoe1d44472010-02-17 11:09:31 +00001744 else if ((dev->flags & IFF_ALLMULTI) || !netdev_mc_empty(dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 {
1746 /* The multicast-accept list is initialized to accept-all, and we
1747 rely on higher-level filtering for now. */
1748 lp->rx_mode = RX_MULTCAST_ACCEPT;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001749 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 else
1751 lp->rx_mode = 0;
1752
1753 writereg(dev, PP_RxCTL, DEF_RX_ACCEPT | lp->rx_mode);
1754
1755 /* in promiscuous mode, we accept errored packets, so we have to enable interrupts on them also */
1756 writereg(dev, PP_RxCFG, lp->curr_rx_cfg |
1757 (lp->rx_mode == RX_ALL_ACCEPT? (RX_CRC_ERROR_ENBL|RX_RUNT_ENBL|RX_EXTRA_DATA_ENBL) : 0));
1758 spin_unlock_irqrestore(&lp->lock, flags);
1759}
1760
1761
1762static int set_mac_address(struct net_device *dev, void *p)
1763{
1764 int i;
1765 struct sockaddr *addr = p;
1766
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 if (netif_running(dev))
1768 return -EBUSY;
1769
1770 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1771
Johannes Berge1749612008-10-27 15:59:26 -07001772 if (net_debug)
1773 printk("%s: Setting MAC address to %pM.\n",
1774 dev->name, dev->dev_addr);
1775
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 /* set the Ethernet address */
1777 for (i=0; i < ETH_ALEN/2; i++)
1778 writereg(dev, PP_IA+i*2, dev->dev_addr[i*2] | (dev->dev_addr[i*2+1] << 8));
1779
1780 return 0;
1781}
1782
1783#ifdef MODULE
1784
1785static struct net_device *dev_cs89x0;
1786
1787/*
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001788 * Support the 'debug' module parm even if we're compiled for non-debug to
1789 * avoid breaking someone's startup scripts
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 */
1791
1792static int io;
1793static int irq;
1794static int debug;
1795static char media[8];
1796static int duplex=-1;
1797
1798static int use_dma; /* These generate unused var warnings if ALLOW_DMA = 0 */
1799static int dma;
1800static int dmasize=16; /* or 64 */
1801
1802module_param(io, int, 0);
1803module_param(irq, int, 0);
1804module_param(debug, int, 0);
1805module_param_string(media, media, sizeof(media), 0);
1806module_param(duplex, int, 0);
1807module_param(dma , int, 0);
1808module_param(dmasize , int, 0);
1809module_param(use_dma , int, 0);
1810MODULE_PARM_DESC(io, "cs89x0 I/O base address");
1811MODULE_PARM_DESC(irq, "cs89x0 IRQ number");
1812#if DEBUGGING
1813MODULE_PARM_DESC(debug, "cs89x0 debug level (0-6)");
1814#else
1815MODULE_PARM_DESC(debug, "(ignored)");
1816#endif
1817MODULE_PARM_DESC(media, "Set cs89x0 adapter(s) media type(s) (rj45,bnc,aui)");
1818/* No other value than -1 for duplex seems to be currently interpreted */
1819MODULE_PARM_DESC(duplex, "(ignored)");
1820#if ALLOW_DMA
1821MODULE_PARM_DESC(dma , "cs89x0 ISA DMA channel; ignored if use_dma=0");
1822MODULE_PARM_DESC(dmasize , "cs89x0 DMA size in kB (16,64); ignored if use_dma=0");
1823MODULE_PARM_DESC(use_dma , "cs89x0 using DMA (0-1)");
1824#else
1825MODULE_PARM_DESC(dma , "(ignored)");
1826MODULE_PARM_DESC(dmasize , "(ignored)");
1827MODULE_PARM_DESC(use_dma , "(ignored)");
1828#endif
1829
Francois Camie1f8e872008-10-15 22:01:59 -07001830MODULE_AUTHOR("Mike Cruse, Russwll Nelson <nelson@crynwr.com>, Andrew Morton");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831MODULE_LICENSE("GPL");
1832
1833
1834/*
1835* media=t - specify media type
1836 or media=2
1837 or media=aui
1838 or medai=auto
1839* duplex=0 - specify forced half/full/autonegotiate duplex
1840* debug=# - debug level
1841
1842
1843* Default Chip Configuration:
1844 * DMA Burst = enabled
1845 * IOCHRDY Enabled = enabled
1846 * UseSA = enabled
1847 * CS8900 defaults to half-duplex if not specified on command-line
1848 * CS8920 defaults to autoneg if not specified on command-line
1849 * Use reset defaults for other config parameters
1850
1851* Assumptions:
1852 * media type specified is supported (circuitry is present)
1853 * if memory address is > 1MB, then required mem decode hw is present
1854 * if 10B-2, then agent other than driver will enable DC/DC converter
1855 (hw or software util)
1856
1857
1858*/
1859
Andrew Mortone26c1292006-08-14 22:59:59 -07001860int __init init_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861{
1862 struct net_device *dev = alloc_etherdev(sizeof(struct net_local));
1863 struct net_local *lp;
1864 int ret = 0;
1865
1866#if DEBUGGING
1867 net_debug = debug;
1868#else
1869 debug = 0;
1870#endif
1871 if (!dev)
1872 return -ENOMEM;
1873
1874 dev->irq = irq;
1875 dev->base_addr = io;
1876 lp = netdev_priv(dev);
1877
1878#if ALLOW_DMA
1879 if (use_dma) {
1880 lp->use_dma = use_dma;
1881 lp->dma = dma;
1882 lp->dmasize = dmasize;
1883 }
1884#endif
1885
1886 spin_lock_init(&lp->lock);
1887
1888 /* boy, they'd better get these right */
1889 if (!strcmp(media, "rj45"))
1890 lp->adapter_cnf = A_CNF_MEDIA_10B_T | A_CNF_10B_T;
1891 else if (!strcmp(media, "aui"))
1892 lp->adapter_cnf = A_CNF_MEDIA_AUI | A_CNF_AUI;
1893 else if (!strcmp(media, "bnc"))
1894 lp->adapter_cnf = A_CNF_MEDIA_10B_2 | A_CNF_10B_2;
1895 else
1896 lp->adapter_cnf = A_CNF_MEDIA_10B_T | A_CNF_10B_T;
1897
1898 if (duplex==-1)
1899 lp->auto_neg_cnf = AUTO_NEG_ENABLE;
1900
1901 if (io == 0) {
1902 printk(KERN_ERR "cs89x0.c: Module autoprobing not allowed.\n");
1903 printk(KERN_ERR "cs89x0.c: Append io=0xNNN\n");
1904 ret = -EPERM;
1905 goto out;
1906 } else if (io <= 0x1ff) {
1907 ret = -ENXIO;
1908 goto out;
1909 }
1910
1911#if ALLOW_DMA
1912 if (use_dma && dmasize != 16 && dmasize != 64) {
1913 printk(KERN_ERR "cs89x0.c: dma size must be either 16K or 64K, not %dK\n", dmasize);
1914 ret = -EPERM;
1915 goto out;
1916 }
1917#endif
1918 ret = cs89x0_probe1(dev, io, 1);
1919 if (ret)
1920 goto out;
1921
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922 dev_cs89x0 = dev;
1923 return 0;
1924out:
1925 free_netdev(dev);
1926 return ret;
1927}
1928
Al Viroafc8eb42006-06-14 18:50:53 -04001929void __exit
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930cleanup_module(void)
1931{
1932 unregister_netdev(dev_cs89x0);
Lennert Buytenhekfc8c7d72006-01-08 01:01:08 -08001933 writeword(dev_cs89x0->base_addr, ADD_PORT, PP_ChipID);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934 release_region(dev_cs89x0->base_addr, NETCARD_IO_EXTENT);
1935 free_netdev(dev_cs89x0);
1936}
1937#endif /* MODULE */
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001938
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939/*
1940 * Local variables:
1941 * version-control: t
1942 * kept-new-versions: 5
1943 * c-indent-level: 8
1944 * tab-width: 8
1945 * End:
1946 *
1947 */