OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [net/] [eexpress.c] - Blame information for rev 1275

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/* Intel EtherExpress 16 device driver for Linux
2
 *
3
 * Written by John Sullivan, 1995
4
 *  based on original code by Donald Becker, with changes by
5
 *  Alan Cox and Pauline Middelink.
6
 *
7
 * Support for 8-bit mode by Zoltan Szilagyi <zoltans@cs.arizona.edu>
8
 *
9
 * Many modifications, and currently maintained, by
10
 *  Philip Blundell <Philip.Blundell@pobox.com>
11
 * Added the Compaq LTE  Alan Cox <alan@redhat.com>
12
 * Added MCA support Adam Fritzler <mid@auk.cx>
13
 *
14
 * Note - this driver is experimental still - it has problems on faster
15
 * machines. Someone needs to sit down and go through it line by line with
16
 * a databook...
17
 */
18
 
19
/* The EtherExpress 16 is a fairly simple card, based on a shared-memory
20
 * design using the i82586 Ethernet coprocessor.  It bears no relationship,
21
 * as far as I know, to the similarly-named "EtherExpress Pro" range.
22
 *
23
 * Historically, Linux support for these cards has been very bad.  However,
24
 * things seem to be getting better slowly.
25
 */
26
 
27
/* If your card is confused about what sort of interface it has (eg it
28
 * persistently reports "10baseT" when none is fitted), running 'SOFTSET /BART'
29
 * or 'SOFTSET /LISA' from DOS seems to help.
30
 */
31
 
32
/* Here's the scoop on memory mapping.
33
 *
34
 * There are three ways to access EtherExpress card memory: either using the
35
 * shared-memory mapping, or using PIO through the dataport, or using PIO
36
 * through the "shadow memory" ports.
37
 *
38
 * The shadow memory system works by having the card map some of its memory
39
 * as follows:
40
 *
41
 * (the low five bits of the SMPTR are ignored)
42
 *
43
 *  base+0x4000..400f      memory at SMPTR+0..15
44
 *  base+0x8000..800f      memory at SMPTR+16..31
45
 *  base+0xc000..c007      dubious stuff (memory at SMPTR+16..23 apparently)
46
 *  base+0xc008..c00f      memory at 0x0008..0x000f
47
 *
48
 * This last set (the one at c008) is particularly handy because the SCB
49
 * lives at 0x0008.  So that set of ports gives us easy random access to data
50
 * in the SCB without having to mess around setting up pointers and the like.
51
 * We always use this method to access the SCB (via the scb_xx() functions).
52
 *
53
 * Dataport access works by aiming the appropriate (read or write) pointer
54
 * at the first address you're interested in, and then reading or writing from
55
 * the dataport.  The pointers auto-increment after each transfer.  We use
56
 * this for data transfer.
57
 *
58
 * We don't use the shared-memory system because it allegedly doesn't work on
59
 * all cards, and because it's a bit more prone to go wrong (it's one more
60
 * thing to configure...).
61
 */
62
 
63
/* Known bugs:
64
 *
65
 * - The card seems to want to give us two interrupts every time something
66
 *   happens, where just one would be better.
67
 */
68
 
69
/*
70
 *
71
 * Note by Zoltan Szilagyi 10-12-96:
72
 *
73
 * I've succeeded in eliminating the "CU wedged" messages, and hence the
74
 * lockups, which were only occurring with cards running in 8-bit mode ("force
75
 * 8-bit operation" in Intel's SoftSet utility). This version of the driver
76
 * sets the 82586 and the ASIC to 8-bit mode at startup; it also stops the
77
 * CU before submitting a packet for transmission, and then restarts it as soon
78
 * as the process of handing the packet is complete. This is definitely an
79
 * unnecessary slowdown if the card is running in 16-bit mode; therefore one
80
 * should detect 16-bit vs 8-bit mode from the EEPROM settings and act
81
 * accordingly. In 8-bit mode with this bugfix I'm getting about 150 K/s for
82
 * ftp's, which is significantly better than I get in DOS, so the overhead of
83
 * stopping and restarting the CU with each transmit is not prohibitive in
84
 * practice.
85
 *
86
 * Update by David Woodhouse 11/5/99:
87
 *
88
 * I've seen "CU wedged" messages in 16-bit mode, on the Alpha architecture.
89
 * I assume that this is because 16-bit accesses are actually handled as two
90
 * 8-bit accesses.
91
 */
92
 
93
#ifdef __alpha__
94
#define LOCKUP16 1
95
#endif
96
#ifndef LOCKUP16
97
#define LOCKUP16 0
98
#endif
99
 
100
#include <linux/config.h>
101
#include <linux/module.h>
102
 
103
#include <linux/kernel.h>
104
#include <linux/sched.h>
105
#include <linux/types.h>
106
#include <linux/fcntl.h>
107
#include <linux/interrupt.h>
108
#include <linux/ptrace.h>
109
#include <linux/ioport.h>
110
#include <linux/string.h>
111
#include <linux/in.h>
112
#include <asm/system.h>
113
#include <asm/bitops.h>
114
#include <asm/io.h>
115
#include <asm/irq.h>
116
#include <linux/delay.h>
117
#include <linux/errno.h>
118
#include <linux/init.h>
119
 
120
#include <linux/netdevice.h>
121
#include <linux/etherdevice.h>
122
#include <linux/skbuff.h>
123
#include <linux/slab.h>
124
#include <linux/mca.h>
125
 
126
#include <linux/spinlock.h>
127
 
128
#ifndef NET_DEBUG
129
#define NET_DEBUG 4
130
#endif
131
 
132
#include "eexpress.h"
133
 
134
#define EEXP_IO_EXTENT  16
135
 
136
/*
137
 * Private data declarations
138
 */
139
 
140
struct net_local
141
{
142
        struct net_device_stats stats;
143
        unsigned long last_tx;       /* jiffies when last transmit started */
144
        unsigned long init_time;     /* jiffies when eexp_hw_init586 called */
145
        unsigned short rx_first;     /* first rx buf, same as RX_BUF_START */
146
        unsigned short rx_last;      /* last rx buf */
147
        unsigned short rx_ptr;       /* first rx buf to look at */
148
        unsigned short tx_head;      /* next free tx buf */
149
        unsigned short tx_reap;      /* first in-use tx buf */
150
        unsigned short tx_tail;      /* previous tx buf to tx_head */
151
        unsigned short tx_link;      /* last known-executing tx buf */
152
        unsigned short last_tx_restart;   /* set to tx_link when we
153
                                             restart the CU */
154
        unsigned char started;
155
        unsigned short rx_buf_start;
156
        unsigned short rx_buf_end;
157
        unsigned short num_tx_bufs;
158
        unsigned short num_rx_bufs;
159
        unsigned char width;         /* 0 for 16bit, 1 for 8bit */
160
        unsigned char was_promisc;
161
        unsigned char old_mc_count;
162
        spinlock_t lock;
163
};
164
 
165
/* This is the code and data that is downloaded to the EtherExpress card's
166
 * memory at boot time.
167
 */
168
 
169
static unsigned short start_code[] = {
170
/* 0x0000 */
171
        0x0001,                 /* ISCP: busy - cleared after reset */
172
        0x0008,0x0000,0x0000,   /* offset,address (lo,hi) of SCB */
173
 
174
        0x0000,0x0000,          /* SCB: status, commands */
175
        0x0000,0x0000,          /* links to first command block,
176
                                   first receive descriptor */
177
        0x0000,0x0000,          /* CRC error, alignment error counts */
178
        0x0000,0x0000,          /* out of resources, overrun error counts */
179
 
180
        0x0000,0x0000,          /* pad */
181
        0x0000,0x0000,
182
 
183
/* 0x20 -- start of 82586 CU program */
184
#define CONF_LINK 0x20
185
        0x0000,Cmd_Config,
186
        0x0032,                 /* link to next command */
187
        0x080c,                 /* 12 bytes follow : fifo threshold=8 */
188
        0x2e40,                 /* don't rx bad frames
189
                                 * SRDY/ARDY => ext. sync. : preamble len=8
190
                                 * take addresses from data buffers
191
                                 * 6 bytes/address
192
                                 */
193
        0x6000,                 /* default backoff method & priority
194
                                 * interframe spacing = 0x60 */
195
        0xf200,                 /* slot time=0x200
196
                                 * max collision retry = 0xf */
197
#define CONF_PROMISC  0x2e
198
        0x0000,                 /* no HDLC : normal CRC : enable broadcast
199
                                 * disable promiscuous/multicast modes */
200
        0x003c,                 /* minimum frame length = 60 octets) */
201
 
202
        0x0000,Cmd_SetAddr,
203
        0x003e,                 /* link to next command */
204
#define CONF_HWADDR  0x38
205
        0x0000,0x0000,0x0000,   /* hardware address placed here */
206
 
207
        0x0000,Cmd_MCast,
208
        0x0076,                 /* link to next command */
209
#define CONF_NR_MULTICAST 0x44
210
        0x0000,                 /* number of multicast addresses */
211
#define CONF_MULTICAST 0x46
212
        0x0000, 0x0000, 0x0000, /* some addresses */
213
        0x0000, 0x0000, 0x0000,
214
        0x0000, 0x0000, 0x0000,
215
        0x0000, 0x0000, 0x0000,
216
        0x0000, 0x0000, 0x0000,
217
        0x0000, 0x0000, 0x0000,
218
        0x0000, 0x0000, 0x0000,
219
        0x0000, 0x0000, 0x0000,
220
 
221
#define CONF_DIAG_RESULT  0x76
222
        0x0000, Cmd_Diag,
223
        0x007c,                 /* link to next command */
224
 
225
        0x0000,Cmd_TDR|Cmd_INT,
226
        0x0084,
227
#define CONF_TDR_RESULT  0x82
228
        0x0000,
229
 
230
        0x0000,Cmd_END|Cmd_Nop, /* end of configure sequence */
231
        0x0084                  /* dummy link */
232
};
233
 
234
/* maps irq number to EtherExpress magic value */
235
static char irqrmap[] = { 0,0,1,2,3,4,0,0,0,1,5,6,0,0,0,0 };
236
 
237
#ifdef CONFIG_MCA
238
/* mapping of the first four bits of the second POS register */
239
static unsigned short mca_iomap[] = {
240
        0x270, 0x260, 0x250, 0x240, 0x230, 0x220, 0x210, 0x200,
241
        0x370, 0x360, 0x350, 0x340, 0x330, 0x320, 0x310, 0x300
242
};
243
/* bits 5-7 of the second POS register */
244
static char mca_irqmap[] = { 12, 9, 3, 4, 5, 10, 11, 15 };
245
#endif 
246
 
247
/*
248
 * Prototypes for Linux interface
249
 */
250
 
251
extern int express_probe(struct net_device *dev);
252
static int eexp_open(struct net_device *dev);
253
static int eexp_close(struct net_device *dev);
254
static void eexp_timeout(struct net_device *dev);
255
static struct net_device_stats *eexp_stats(struct net_device *dev);
256
static int eexp_xmit(struct sk_buff *buf, struct net_device *dev);
257
 
258
static void eexp_irq(int irq, void *dev_addr, struct pt_regs *regs);
259
static void eexp_set_multicast(struct net_device *dev);
260
 
261
/*
262
 * Prototypes for hardware access functions
263
 */
264
 
265
static void eexp_hw_rx_pio(struct net_device *dev);
266
static void eexp_hw_tx_pio(struct net_device *dev, unsigned short *buf,
267
                       unsigned short len);
268
static int eexp_hw_probe(struct net_device *dev,unsigned short ioaddr);
269
static unsigned short eexp_hw_readeeprom(unsigned short ioaddr,
270
                                         unsigned char location);
271
 
272
static unsigned short eexp_hw_lasttxstat(struct net_device *dev);
273
static void eexp_hw_txrestart(struct net_device *dev);
274
 
275
static void eexp_hw_txinit    (struct net_device *dev);
276
static void eexp_hw_rxinit    (struct net_device *dev);
277
 
278
static void eexp_hw_init586   (struct net_device *dev);
279
static void eexp_setup_filter (struct net_device *dev);
280
 
281
static char *eexp_ifmap[]={"AUI", "BNC", "RJ45"};
282
enum eexp_iftype {AUI=0, BNC=1, TPE=2};
283
 
284
#define STARTED_RU      2
285
#define STARTED_CU      1
286
 
287
/*
288
 * Primitive hardware access functions.
289
 */
290
 
291
static inline unsigned short scb_status(struct net_device *dev)
292
{
293
        return inw(dev->base_addr + 0xc008);
294
}
295
 
296
static inline unsigned short scb_rdcmd(struct net_device *dev)
297
{
298
        return inw(dev->base_addr + 0xc00a);
299
}
300
 
301
static inline void scb_command(struct net_device *dev, unsigned short cmd)
302
{
303
        outw(cmd, dev->base_addr + 0xc00a);
304
}
305
 
306
static inline void scb_wrcbl(struct net_device *dev, unsigned short val)
307
{
308
        outw(val, dev->base_addr + 0xc00c);
309
}
310
 
311
static inline void scb_wrrfa(struct net_device *dev, unsigned short val)
312
{
313
        outw(val, dev->base_addr + 0xc00e);
314
}
315
 
316
static inline void set_loopback(struct net_device *dev)
317
{
318
        outb(inb(dev->base_addr + Config) | 2, dev->base_addr + Config);
319
}
320
 
321
static inline void clear_loopback(struct net_device *dev)
322
{
323
        outb(inb(dev->base_addr + Config) & ~2, dev->base_addr + Config);
324
}
325
 
326
static inline unsigned short int SHADOW(short int addr)
327
{
328
        addr &= 0x1f;
329
        if (addr > 0xf) addr += 0x3ff0;
330
        return addr + 0x4000;
331
}
332
 
333
/*
334
 * Linux interface
335
 */
336
 
337
/*
338
 * checks for presence of EtherExpress card
339
 */
340
 
341
int __init express_probe(struct net_device *dev)
342
{
343
        unsigned short *port;
344
        static unsigned short ports[] = { 0x240,0x300,0x310,0x270,0x320,0x340,0 };
345
        unsigned short ioaddr = dev->base_addr;
346
 
347
        SET_MODULE_OWNER(dev);
348
 
349
        dev->if_port = 0xff; /* not set */
350
 
351
#ifdef CONFIG_MCA
352
        if (MCA_bus) {
353
                int slot = 0;
354
 
355
                /*
356
                 * Only find one card at a time.  Subsequent calls
357
                 * will find others, however, proper multicard MCA
358
                 * probing and setup can't be done with the
359
                 * old-style Space.c init routines.  -- ASF
360
                 */
361
                while (slot != MCA_NOTFOUND) {
362
                        int pos0, pos1;
363
 
364
                        slot = mca_find_unused_adapter(0x628B, slot);
365
                        if (slot == MCA_NOTFOUND)
366
                                break;
367
 
368
                        pos0 = mca_read_stored_pos(slot, 2);
369
                        pos1 = mca_read_stored_pos(slot, 3);
370
                        ioaddr = mca_iomap[pos1&0xf];
371
 
372
                        dev->irq = mca_irqmap[(pos1>>4)&0x7];
373
 
374
                        /*
375
                         * XXX: Transciever selection is done
376
                         * differently on the MCA version.
377
                         * How to get it to select something
378
                         * other than external/AUI is currently
379
                         * unknown.  This code is just for looks. -- ASF
380
                         */
381
                        if ((pos0 & 0x7) == 0x1)
382
                                dev->if_port = AUI;
383
                        else if ((pos0 & 0x7) == 0x5) {
384
                                if (pos1 & 0x80)
385
                                        dev->if_port = BNC;
386
                                else
387
                                        dev->if_port = TPE;
388
                        }
389
 
390
                        mca_set_adapter_name(slot, "Intel EtherExpress 16 MCA");
391
                        mca_set_adapter_procfn(slot, NULL, dev);
392
                        mca_mark_as_used(slot);
393
 
394
                        break;
395
                }
396
        }
397
#endif
398
        if (ioaddr&0xfe00)
399
                return eexp_hw_probe(dev,ioaddr);
400
        else if (ioaddr)
401
                return -ENXIO;
402
 
403
        for (port=&ports[0] ; *port ; port++ )
404
        {
405
                unsigned short sum = 0;
406
                int i;
407
                for ( i=0 ; i<4 ; i++ )
408
                {
409
                        unsigned short t;
410
                        t = inb(*port + ID_PORT);
411
                        sum |= (t>>4) << ((t & 0x03)<<2);
412
                }
413
                if (sum==0xbaba && !eexp_hw_probe(dev,*port))
414
                        return 0;
415
        }
416
        return -ENODEV;
417
}
418
 
419
/*
420
 * open and initialize the adapter, ready for use
421
 */
422
 
423
static int eexp_open(struct net_device *dev)
424
{
425
        int ret;
426
        unsigned short ioaddr = dev->base_addr;
427
        struct net_local *lp = (struct net_local *)dev->priv;
428
 
429
#if NET_DEBUG > 6
430
        printk(KERN_DEBUG "%s: eexp_open()\n", dev->name);
431
#endif
432
 
433
        if (!dev->irq || !irqrmap[dev->irq])
434
                return -ENXIO;
435
 
436
        ret = request_irq(dev->irq,&eexp_irq,0,dev->name,dev);
437
        if (ret) return ret;
438
 
439
        if (!request_region(ioaddr, EEXP_IO_EXTENT, "EtherExpress")) {
440
                printk(KERN_WARNING "EtherExpress io port %x, is busy.\n"
441
                        , ioaddr);
442
                goto err_out1;
443
        }
444
        if (!request_region(ioaddr+0x4000, EEXP_IO_EXTENT, "EtherExpress shadow")) {
445
                printk(KERN_WARNING "EtherExpress io port %x, is busy.\n"
446
                        , ioaddr+0x4000);
447
                goto err_out2;
448
        }
449
        if (!request_region(ioaddr+0x8000, EEXP_IO_EXTENT, "EtherExpress shadow")) {
450
                printk(KERN_WARNING "EtherExpress io port %x, is busy.\n"
451
                        , ioaddr+0x8000);
452
                goto err_out3;
453
        }
454
        if (!request_region(ioaddr+0xc000, EEXP_IO_EXTENT, "EtherExpress shadow")) {
455
                printk(KERN_WARNING "EtherExpress io port %x, is busy.\n"
456
                        , ioaddr+0xc000);
457
                goto err_out4;
458
        }
459
 
460
        if (lp->width) {
461
                printk("%s: forcing ASIC to 8-bit mode\n", dev->name);
462
                outb(inb(dev->base_addr+Config)&~4, dev->base_addr+Config);
463
        }
464
 
465
        eexp_hw_init586(dev);
466
        netif_start_queue(dev);
467
#if NET_DEBUG > 6
468
        printk(KERN_DEBUG "%s: leaving eexp_open()\n", dev->name);
469
#endif
470
        return 0;
471
 
472
        err_out4:
473
                release_region(ioaddr+0x8000, EEXP_IO_EXTENT);
474
        err_out3:
475
                release_region(ioaddr+0x4000, EEXP_IO_EXTENT);
476
        err_out2:
477
                release_region(ioaddr, EEXP_IO_EXTENT);
478
        err_out1:
479
                free_irq(dev->irq, dev);
480
                return -EBUSY;
481
}
482
 
483
/*
484
 * close and disable the interface, leaving the 586 in reset.
485
 */
486
 
487
static int eexp_close(struct net_device *dev)
488
{
489
        unsigned short ioaddr = dev->base_addr;
490
        struct net_local *lp = dev->priv;
491
 
492
        int irq = dev->irq;
493
 
494
        netif_stop_queue(dev);
495
 
496
        outb(SIRQ_dis|irqrmap[irq],ioaddr+SET_IRQ);
497
        lp->started = 0;
498
        scb_command(dev, SCB_CUsuspend|SCB_RUsuspend);
499
        outb(0,ioaddr+SIGNAL_CA);
500
        free_irq(irq,dev);
501
        outb(i586_RST,ioaddr+EEPROM_Ctrl);
502
        release_region(ioaddr, EEXP_IO_EXTENT);
503
        release_region(ioaddr+0x4000, 16);
504
        release_region(ioaddr+0x8000, 16);
505
        release_region(ioaddr+0xc000, 16);
506
 
507
        return 0;
508
}
509
 
510
/*
511
 * Return interface stats
512
 */
513
 
514
static struct net_device_stats *eexp_stats(struct net_device *dev)
515
{
516
        struct net_local *lp = (struct net_local *)dev->priv;
517
 
518
        return &lp->stats;
519
}
520
 
521
/*
522
 * This gets called when a higher level thinks we are broken.  Check that
523
 * nothing has become jammed in the CU.
524
 */
525
 
526
static void unstick_cu(struct net_device *dev)
527
{
528
        struct net_local *lp = (struct net_local *)dev->priv;
529
        unsigned short ioaddr = dev->base_addr;
530
 
531
        if (lp->started)
532
        {
533
                if ((jiffies - dev->trans_start)>50)
534
                {
535
                        if (lp->tx_link==lp->last_tx_restart)
536
                        {
537
                                unsigned short boguscount=200,rsst;
538
                                printk(KERN_WARNING "%s: Retransmit timed out, status %04x, resetting...\n",
539
                                       dev->name, scb_status(dev));
540
                                eexp_hw_txinit(dev);
541
                                lp->last_tx_restart = 0;
542
                                scb_wrcbl(dev, lp->tx_link);
543
                                scb_command(dev, SCB_CUstart);
544
                                outb(0,ioaddr+SIGNAL_CA);
545
                                while (!SCB_complete(rsst=scb_status(dev)))
546
                                {
547
                                        if (!--boguscount)
548
                                        {
549
                                                boguscount=200;
550
                                                printk(KERN_WARNING "%s: Reset timed out status %04x, retrying...\n",
551
                                                       dev->name,rsst);
552
                                                scb_wrcbl(dev, lp->tx_link);
553
                                                scb_command(dev, SCB_CUstart);
554
                                                outb(0,ioaddr+SIGNAL_CA);
555
                                        }
556
                                }
557
                                netif_wake_queue(dev);
558
                        }
559
                        else
560
                        {
561
                                unsigned short status = scb_status(dev);
562
                                if (SCB_CUdead(status))
563
                                {
564
                                        unsigned short txstatus = eexp_hw_lasttxstat(dev);
565
                                        printk(KERN_WARNING "%s: Transmit timed out, CU not active status %04x %04x, restarting...\n",
566
                                               dev->name, status, txstatus);
567
                                        eexp_hw_txrestart(dev);
568
                                }
569
                                else
570
                                {
571
                                        unsigned short txstatus = eexp_hw_lasttxstat(dev);
572
                                        if (netif_queue_stopped(dev) && !txstatus)
573
                                        {
574
                                                printk(KERN_WARNING "%s: CU wedged, status %04x %04x, resetting...\n",
575
                                                       dev->name,status,txstatus);
576
                                                eexp_hw_init586(dev);
577
                                                netif_wake_queue(dev);
578
                                        }
579
                                        else
580
                                        {
581
                                                printk(KERN_WARNING "%s: transmit timed out\n", dev->name);
582
                                        }
583
                                }
584
                        }
585
                }
586
        }
587
        else
588
        {
589
                if ((jiffies-lp->init_time)>10)
590
                {
591
                        unsigned short status = scb_status(dev);
592
                        printk(KERN_WARNING "%s: i82586 startup timed out, status %04x, resetting...\n",
593
                               dev->name, status);
594
                        eexp_hw_init586(dev);
595
                        netif_wake_queue(dev);
596
                }
597
        }
598
}
599
 
600
static void eexp_timeout(struct net_device *dev)
601
{
602
        struct net_local *lp = (struct net_local *)dev->priv;
603
#ifdef CONFIG_SMP
604
        unsigned long flags;
605
#endif
606
        int status;
607
 
608
        disable_irq(dev->irq);
609
 
610
        /*
611
         *      Best would be to use synchronize_irq(); spin_lock() here
612
         *      lets make it work first..
613
         */
614
 
615
#ifdef CONFIG_SMP
616
        spin_lock_irqsave(&lp->lock, flags);
617
#endif
618
 
619
        status = scb_status(dev);
620
        unstick_cu(dev);
621
        printk(KERN_INFO "%s: transmit timed out, %s?\n", dev->name,
622
               (SCB_complete(status)?"lost interrupt":
623
                "board on fire"));
624
        lp->stats.tx_errors++;
625
        lp->last_tx = jiffies;
626
        if (!SCB_complete(status)) {
627
                scb_command(dev, SCB_CUabort);
628
                outb(0,dev->base_addr+SIGNAL_CA);
629
        }
630
        netif_wake_queue(dev);
631
#ifdef CONFIG_SMP
632
        spin_unlock_irqrestore(&lp->lock, flags);
633
#endif
634
}
635
 
636
/*
637
 * Called to transmit a packet, or to allow us to right ourselves
638
 * if the kernel thinks we've died.
639
 */
640
static int eexp_xmit(struct sk_buff *buf, struct net_device *dev)
641
{
642
        struct net_local *lp = (struct net_local *)dev->priv;
643
        short length = buf->len;
644
#ifdef CONFIG_SMP
645
        unsigned long flags;
646
#endif
647
 
648
#if NET_DEBUG > 6
649
        printk(KERN_DEBUG "%s: eexp_xmit()\n", dev->name);
650
#endif
651
 
652
        if(buf->len < ETH_ZLEN)
653
        {
654
                buf = skb_padto(buf, ETH_ZLEN);
655
                if(buf == NULL)
656
                        return 0;
657
                length = ETH_ZLEN;
658
        }
659
 
660
        disable_irq(dev->irq);
661
 
662
        /*
663
         *      Best would be to use synchronize_irq(); spin_lock() here
664
         *      lets make it work first..
665
         */
666
 
667
#ifdef CONFIG_SMP
668
        spin_lock_irqsave(&lp->lock, flags);
669
#endif
670
 
671
        {
672
                unsigned short *data = (unsigned short *)buf->data;
673
 
674
                lp->stats.tx_bytes += length;
675
 
676
                eexp_hw_tx_pio(dev,data,length);
677
        }
678
        dev_kfree_skb(buf);
679
#ifdef CONFIG_SMP
680
        spin_unlock_irqrestore(&lp->lock, flags);
681
#endif
682
        enable_irq(dev->irq);
683
        return 0;
684
}
685
 
686
/*
687
 * Handle an EtherExpress interrupt
688
 * If we've finished initializing, start the RU and CU up.
689
 * If we've already started, reap tx buffers, handle any received packets,
690
 * check to make sure we've not become wedged.
691
 */
692
 
693
/*
694
 * Handle an EtherExpress interrupt
695
 * If we've finished initializing, start the RU and CU up.
696
 * If we've already started, reap tx buffers, handle any received packets,
697
 * check to make sure we've not become wedged.
698
 */
699
 
700
static unsigned short eexp_start_irq(struct net_device *dev,
701
                                     unsigned short status)
702
{
703
        unsigned short ack_cmd = SCB_ack(status);
704
        struct net_local *lp = (struct net_local *)dev->priv;
705
        unsigned short ioaddr = dev->base_addr;
706
        if ((dev->flags & IFF_UP) && !(lp->started & STARTED_CU)) {
707
                short diag_status, tdr_status;
708
                while (SCB_CUstat(status)==2)
709
                        status = scb_status(dev);
710
#if NET_DEBUG > 4
711
                printk("%s: CU went non-active (status %04x)\n",
712
                       dev->name, status);
713
#endif
714
 
715
                outw(CONF_DIAG_RESULT & ~31, ioaddr + SM_PTR);
716
                diag_status = inw(ioaddr + SHADOW(CONF_DIAG_RESULT));
717
                if (diag_status & 1<<11) {
718
                        printk(KERN_WARNING "%s: 82586 failed self-test\n",
719
                               dev->name);
720
                } else if (!(diag_status & 1<<13)) {
721
                        printk(KERN_WARNING "%s: 82586 self-test failed to complete\n", dev->name);
722
                }
723
 
724
                outw(CONF_TDR_RESULT & ~31, ioaddr + SM_PTR);
725
                tdr_status = inw(ioaddr + SHADOW(CONF_TDR_RESULT));
726
                if (tdr_status & (TDR_SHORT|TDR_OPEN)) {
727
                        printk(KERN_WARNING "%s: TDR reports cable %s at %d tick%s\n", dev->name, (tdr_status & TDR_SHORT)?"short":"broken", tdr_status & TDR_TIME, ((tdr_status & TDR_TIME) != 1) ? "s" : "");
728
                }
729
                else if (tdr_status & TDR_XCVRPROBLEM) {
730
                        printk(KERN_WARNING "%s: TDR reports transceiver problem\n", dev->name);
731
                }
732
                else if (tdr_status & TDR_LINKOK) {
733
#if NET_DEBUG > 4
734
                        printk(KERN_DEBUG "%s: TDR reports link OK\n", dev->name);
735
#endif
736
                } else {
737
                        printk("%s: TDR is ga-ga (status %04x)\n", dev->name,
738
                               tdr_status);
739
                }
740
 
741
                lp->started |= STARTED_CU;
742
                scb_wrcbl(dev, lp->tx_link);
743
                /* if the RU isn't running, start it now */
744
                if (!(lp->started & STARTED_RU)) {
745
                        ack_cmd |= SCB_RUstart;
746
                        scb_wrrfa(dev, lp->rx_buf_start);
747
                        lp->rx_ptr = lp->rx_buf_start;
748
                        lp->started |= STARTED_RU;
749
                }
750
                ack_cmd |= SCB_CUstart | 0x2000;
751
        }
752
 
753
        if ((dev->flags & IFF_UP) && !(lp->started & STARTED_RU) && SCB_RUstat(status)==4)
754
                lp->started|=STARTED_RU;
755
 
756
        return ack_cmd;
757
}
758
 
759
static void eexp_cmd_clear(struct net_device *dev)
760
{
761
        unsigned long int oldtime = jiffies;
762
        while (scb_rdcmd(dev) && ((jiffies-oldtime)<10));
763
        if (scb_rdcmd(dev)) {
764
                printk("%s: command didn't clear\n", dev->name);
765
        }
766
}
767
 
768
static void eexp_irq(int irq, void *dev_info, struct pt_regs *regs)
769
{
770
        struct net_device *dev = dev_info;
771
        struct net_local *lp;
772
        unsigned short ioaddr,status,ack_cmd;
773
        unsigned short old_read_ptr, old_write_ptr;
774
 
775
        if (dev==NULL)
776
        {
777
                printk(KERN_WARNING "eexpress: irq %d for unknown device\n",
778
                       irq);
779
                return;
780
        }
781
 
782
        lp = (struct net_local *)dev->priv;
783
        ioaddr = dev->base_addr;
784
 
785
        spin_lock(&lp->lock);
786
 
787
        old_read_ptr = inw(ioaddr+READ_PTR);
788
        old_write_ptr = inw(ioaddr+WRITE_PTR);
789
 
790
        outb(SIRQ_dis|irqrmap[irq],ioaddr+SET_IRQ);
791
 
792
 
793
        status = scb_status(dev);
794
 
795
#if NET_DEBUG > 4
796
        printk(KERN_DEBUG "%s: interrupt (status %x)\n", dev->name, status);
797
#endif
798
 
799
        if (lp->started == (STARTED_CU | STARTED_RU)) {
800
 
801
                do {
802
                        eexp_cmd_clear(dev);
803
 
804
                        ack_cmd = SCB_ack(status);
805
                        scb_command(dev, ack_cmd);
806
                        outb(0,ioaddr+SIGNAL_CA);
807
 
808
                        eexp_cmd_clear(dev);
809
 
810
                        if (SCB_complete(status)) {
811
                                if (!eexp_hw_lasttxstat(dev)) {
812
                                        printk("%s: tx interrupt but no status\n", dev->name);
813
                                }
814
                        }
815
 
816
                        if (SCB_rxdframe(status))
817
                                eexp_hw_rx_pio(dev);
818
 
819
                        status = scb_status(dev);
820
                } while (status & 0xc000);
821
 
822
                if (SCB_RUdead(status))
823
                {
824
                        printk(KERN_WARNING "%s: RU stopped: status %04x\n",
825
                               dev->name,status);
826
#if 0
827
                        printk(KERN_WARNING "%s: cur_rfd=%04x, cur_rbd=%04x\n", dev->name, lp->cur_rfd, lp->cur_rbd);
828
                        outw(lp->cur_rfd, ioaddr+READ_PTR);
829
                        printk(KERN_WARNING "%s: [%04x]\n", dev->name, inw(ioaddr+DATAPORT));
830
                        outw(lp->cur_rfd+6, ioaddr+READ_PTR);
831
                        printk(KERN_WARNING "%s: rbd is %04x\n", dev->name, rbd= inw(ioaddr+DATAPORT));
832
                        outw(rbd, ioaddr+READ_PTR);
833
                        printk(KERN_WARNING "%s: [%04x %04x] ", dev->name, inw(ioaddr+DATAPORT), inw(ioaddr+DATAPORT));
834
                        outw(rbd+8, ioaddr+READ_PTR);
835
                        printk("[%04x]\n", inw(ioaddr+DATAPORT));
836
#endif
837
                        lp->stats.rx_errors++;
838
#if 1
839
                        eexp_hw_rxinit(dev);
840
#else
841
                        lp->cur_rfd = lp->first_rfd;
842
#endif
843
                        scb_wrrfa(dev, lp->rx_buf_start);
844
                        scb_command(dev, SCB_RUstart);
845
                        outb(0,ioaddr+SIGNAL_CA);
846
                }
847
        } else {
848
                if (status & 0x8000)
849
                        ack_cmd = eexp_start_irq(dev, status);
850
                else
851
                        ack_cmd = SCB_ack(status);
852
                scb_command(dev, ack_cmd);
853
                outb(0,ioaddr+SIGNAL_CA);
854
        }
855
 
856
        eexp_cmd_clear(dev);
857
 
858
        outb(SIRQ_en|irqrmap[irq],ioaddr+SET_IRQ);
859
 
860
#if NET_DEBUG > 6 
861
        printk("%s: leaving eexp_irq()\n", dev->name);
862
#endif
863
        outw(old_read_ptr, ioaddr+READ_PTR);
864
        outw(old_write_ptr, ioaddr+WRITE_PTR);
865
 
866
        spin_unlock(&lp->lock);
867
        return;
868
}
869
 
870
/*
871
 * Hardware access functions
872
 */
873
 
874
/*
875
 * Set the cable type to use.
876
 */
877
 
878
static void eexp_hw_set_interface(struct net_device *dev)
879
{
880
        unsigned char oldval = inb(dev->base_addr + 0x300e);
881
        oldval &= ~0x82;
882
        switch (dev->if_port) {
883
        case TPE:
884
                oldval |= 0x2;
885
        case BNC:
886
                oldval |= 0x80;
887
                break;
888
        }
889
        outb(oldval, dev->base_addr+0x300e);
890
        mdelay(20);
891
}
892
 
893
/*
894
 * Check all the receive buffers, and hand any received packets
895
 * to the upper levels. Basic sanity check on each frame
896
 * descriptor, though we don't bother trying to fix broken ones.
897
 */
898
 
899
static void eexp_hw_rx_pio(struct net_device *dev)
900
{
901
        struct net_local *lp = (struct net_local *)dev->priv;
902
        unsigned short rx_block = lp->rx_ptr;
903
        unsigned short boguscount = lp->num_rx_bufs;
904
        unsigned short ioaddr = dev->base_addr;
905
        unsigned short status;
906
 
907
#if NET_DEBUG > 6
908
        printk(KERN_DEBUG "%s: eexp_hw_rx()\n", dev->name);
909
#endif
910
 
911
        do {
912
                unsigned short rfd_cmd, rx_next, pbuf, pkt_len;
913
 
914
                outw(rx_block, ioaddr + READ_PTR);
915
                status = inw(ioaddr + DATAPORT);
916
 
917
                if (FD_Done(status))
918
                {
919
                        rfd_cmd = inw(ioaddr + DATAPORT);
920
                        rx_next = inw(ioaddr + DATAPORT);
921
                        pbuf = inw(ioaddr + DATAPORT);
922
 
923
                        outw(pbuf, ioaddr + READ_PTR);
924
                        pkt_len = inw(ioaddr + DATAPORT);
925
 
926
                        if (rfd_cmd!=0x0000)
927
                        {
928
                                printk(KERN_WARNING "%s: rfd_cmd not zero:0x%04x\n",
929
                                       dev->name, rfd_cmd);
930
                                continue;
931
                        }
932
                        else if (pbuf!=rx_block+0x16)
933
                        {
934
                                printk(KERN_WARNING "%s: rfd and rbd out of sync 0x%04x 0x%04x\n",
935
                                       dev->name, rx_block+0x16, pbuf);
936
                                continue;
937
                        }
938
                        else if ((pkt_len & 0xc000)!=0xc000)
939
                        {
940
                                printk(KERN_WARNING "%s: EOF or F not set on received buffer (%04x)\n",
941
                                       dev->name, pkt_len & 0xc000);
942
                                continue;
943
                        }
944
                        else if (!FD_OK(status))
945
                        {
946
                                lp->stats.rx_errors++;
947
                                if (FD_CRC(status))
948
                                        lp->stats.rx_crc_errors++;
949
                                if (FD_Align(status))
950
                                        lp->stats.rx_frame_errors++;
951
                                if (FD_Resrc(status))
952
                                        lp->stats.rx_fifo_errors++;
953
                                if (FD_DMA(status))
954
                                        lp->stats.rx_over_errors++;
955
                                if (FD_Short(status))
956
                                        lp->stats.rx_length_errors++;
957
                        }
958
                        else
959
                        {
960
                                struct sk_buff *skb;
961
                                pkt_len &= 0x3fff;
962
                                skb = dev_alloc_skb(pkt_len+16);
963
                                if (skb == NULL)
964
                                {
965
                                        printk(KERN_WARNING "%s: Memory squeeze, dropping packet\n",dev->name);
966
                                        lp->stats.rx_dropped++;
967
                                        break;
968
                                }
969
                                skb->dev = dev;
970
                                skb_reserve(skb, 2);
971
                                outw(pbuf+10, ioaddr+READ_PTR);
972
                                insw(ioaddr+DATAPORT, skb_put(skb,pkt_len),(pkt_len+1)>>1);
973
                                skb->protocol = eth_type_trans(skb,dev);
974
                                netif_rx(skb);
975
                                dev->last_rx = jiffies;
976
                                lp->stats.rx_packets++;
977
                                lp->stats.rx_bytes += pkt_len;
978
                        }
979
                        outw(rx_block, ioaddr+WRITE_PTR);
980
                        outw(0, ioaddr+DATAPORT);
981
                        outw(0, ioaddr+DATAPORT);
982
                        rx_block = rx_next;
983
                }
984
        } while (FD_Done(status) && boguscount--);
985
        lp->rx_ptr = rx_block;
986
}
987
 
988
/*
989
 * Hand a packet to the card for transmission
990
 * If we get here, we MUST have already checked
991
 * to make sure there is room in the transmit
992
 * buffer region.
993
 */
994
 
995
static void eexp_hw_tx_pio(struct net_device *dev, unsigned short *buf,
996
                       unsigned short len)
997
{
998
        struct net_local *lp = (struct net_local *)dev->priv;
999
        unsigned short ioaddr = dev->base_addr;
1000
 
1001
        if (LOCKUP16 || lp->width) {
1002
                /* Stop the CU so that there is no chance that it
1003
                   jumps off to a bogus address while we are writing the
1004
                   pointer to the next transmit packet in 8-bit mode --
1005
                   this eliminates the "CU wedged" errors in 8-bit mode.
1006
                   (Zoltan Szilagyi 10-12-96) */
1007
                scb_command(dev, SCB_CUsuspend);
1008
                outw(0xFFFF, ioaddr+SIGNAL_CA);
1009
        }
1010
 
1011
        outw(lp->tx_head, ioaddr + WRITE_PTR);
1012
 
1013
        outw(0x0000, ioaddr + DATAPORT);
1014
        outw(Cmd_INT|Cmd_Xmit, ioaddr + DATAPORT);
1015
        outw(lp->tx_head+0x08, ioaddr + DATAPORT);
1016
        outw(lp->tx_head+0x0e, ioaddr + DATAPORT);
1017
 
1018
        outw(0x0000, ioaddr + DATAPORT);
1019
        outw(0x0000, ioaddr + DATAPORT);
1020
        outw(lp->tx_head+0x08, ioaddr + DATAPORT);
1021
 
1022
        outw(0x8000|len, ioaddr + DATAPORT);
1023
        outw(-1, ioaddr + DATAPORT);
1024
        outw(lp->tx_head+0x16, ioaddr + DATAPORT);
1025
        outw(0, ioaddr + DATAPORT);
1026
 
1027
        outsw(ioaddr + DATAPORT, buf, (len+1)>>1);
1028
 
1029
        outw(lp->tx_tail+0xc, ioaddr + WRITE_PTR);
1030
        outw(lp->tx_head, ioaddr + DATAPORT);
1031
 
1032
        dev->trans_start = jiffies;
1033
        lp->tx_tail = lp->tx_head;
1034
        if (lp->tx_head==TX_BUF_START+((lp->num_tx_bufs-1)*TX_BUF_SIZE))
1035
                lp->tx_head = TX_BUF_START;
1036
        else
1037
                lp->tx_head += TX_BUF_SIZE;
1038
        if (lp->tx_head != lp->tx_reap)
1039
                netif_wake_queue(dev);
1040
 
1041
        if (LOCKUP16 || lp->width) {
1042
                /* Restart the CU so that the packet can actually
1043
                   be transmitted. (Zoltan Szilagyi 10-12-96) */
1044
                scb_command(dev, SCB_CUresume);
1045
                outw(0xFFFF, ioaddr+SIGNAL_CA);
1046
        }
1047
 
1048
        lp->stats.tx_packets++;
1049
        lp->last_tx = jiffies;
1050
}
1051
 
1052
/*
1053
 * Sanity check the suspected EtherExpress card
1054
 * Read hardware address, reset card, size memory and initialize buffer
1055
 * memory pointers. These are held in dev->priv, in case someone has more
1056
 * than one card in a machine.
1057
 */
1058
 
1059
static int __init eexp_hw_probe(struct net_device *dev, unsigned short ioaddr)
1060
{
1061
        unsigned short hw_addr[3];
1062
        unsigned char buswidth;
1063
        unsigned int memory_size;
1064
        int i;
1065
        unsigned short xsum = 0;
1066
        struct net_local *lp;
1067
 
1068
        printk("%s: EtherExpress 16 at %#x ",dev->name,ioaddr);
1069
 
1070
        outb(ASIC_RST, ioaddr+EEPROM_Ctrl);
1071
        outb(0, ioaddr+EEPROM_Ctrl);
1072
        udelay(500);
1073
        outb(i586_RST, ioaddr+EEPROM_Ctrl);
1074
 
1075
        hw_addr[0] = eexp_hw_readeeprom(ioaddr,2);
1076
        hw_addr[1] = eexp_hw_readeeprom(ioaddr,3);
1077
        hw_addr[2] = eexp_hw_readeeprom(ioaddr,4);
1078
 
1079
        /* Standard Address or Compaq LTE Address */
1080
        if (!((hw_addr[2]==0x00aa && ((hw_addr[1] & 0xff00)==0x0000)) ||
1081
              (hw_addr[2]==0x0080 && ((hw_addr[1] & 0xff00)==0x5F00))))
1082
        {
1083
                printk(" rejected: invalid address %04x%04x%04x\n",
1084
                        hw_addr[2],hw_addr[1],hw_addr[0]);
1085
                return -ENODEV;
1086
        }
1087
 
1088
        /* Calculate the EEPROM checksum.  Carry on anyway if it's bad,
1089
         * though.
1090
         */
1091
        for (i = 0; i < 64; i++)
1092
                xsum += eexp_hw_readeeprom(ioaddr, i);
1093
        if (xsum != 0xbaba)
1094
                printk(" (bad EEPROM xsum 0x%02x)", xsum);
1095
 
1096
        dev->base_addr = ioaddr;
1097
        for ( i=0 ; i<6 ; i++ )
1098
                dev->dev_addr[i] = ((unsigned char *)hw_addr)[5-i];
1099
 
1100
        {
1101
                static char irqmap[]={0, 9, 3, 4, 5, 10, 11, 0};
1102
                unsigned short setupval = eexp_hw_readeeprom(ioaddr,0);
1103
 
1104
                /* Use the IRQ from EEPROM if none was given */
1105
                if (!dev->irq)
1106
                        dev->irq = irqmap[setupval>>13];
1107
 
1108
                if (dev->if_port == 0xff) {
1109
                        dev->if_port = !(setupval & 0x1000) ? AUI :
1110
                                eexp_hw_readeeprom(ioaddr,5) & 0x1 ? TPE : BNC;
1111
                }
1112
 
1113
                buswidth = !((setupval & 0x400) >> 10);
1114
        }
1115
 
1116
        dev->priv = lp = kmalloc(sizeof(struct net_local), GFP_KERNEL);
1117
        if (!dev->priv)
1118
                return -ENOMEM;
1119
 
1120
        memset(dev->priv, 0, sizeof(struct net_local));
1121
        spin_lock_init(&lp->lock);
1122
 
1123
        printk("(IRQ %d, %s connector, %d-bit bus", dev->irq,
1124
               eexp_ifmap[dev->if_port], buswidth?8:16);
1125
 
1126
        eexp_hw_set_interface(dev);
1127
 
1128
        /* Find out how much RAM we have on the card */
1129
        outw(0, dev->base_addr + WRITE_PTR);
1130
        for (i = 0; i < 32768; i++)
1131
                outw(0, dev->base_addr + DATAPORT);
1132
 
1133
        for (memory_size = 0; memory_size < 64; memory_size++)
1134
        {
1135
                outw(memory_size<<10, dev->base_addr + READ_PTR);
1136
                if (inw(dev->base_addr+DATAPORT))
1137
                        break;
1138
                outw(memory_size<<10, dev->base_addr + WRITE_PTR);
1139
                outw(memory_size | 0x5000, dev->base_addr+DATAPORT);
1140
                outw(memory_size<<10, dev->base_addr + READ_PTR);
1141
                if (inw(dev->base_addr+DATAPORT) != (memory_size | 0x5000))
1142
                        break;
1143
        }
1144
 
1145
        /* Sort out the number of buffers.  We may have 16, 32, 48 or 64k
1146
         * of RAM to play with.
1147
         */
1148
        lp->num_tx_bufs = 4;
1149
        lp->rx_buf_end = 0x3ff6;
1150
        switch (memory_size)
1151
        {
1152
        case 64:
1153
                lp->rx_buf_end += 0x4000;
1154
        case 48:
1155
                lp->num_tx_bufs += 4;
1156
                lp->rx_buf_end += 0x4000;
1157
        case 32:
1158
                lp->rx_buf_end += 0x4000;
1159
        case 16:
1160
                printk(", %dk RAM)\n", memory_size);
1161
                break;
1162
        default:
1163
                printk(") bad memory size (%dk).\n", memory_size);
1164
                kfree(dev->priv);
1165
                return -ENODEV;
1166
                break;
1167
        }
1168
 
1169
        lp->rx_buf_start = TX_BUF_START + (lp->num_tx_bufs*TX_BUF_SIZE);
1170
        lp->width = buswidth;
1171
 
1172
        dev->open = eexp_open;
1173
        dev->stop = eexp_close;
1174
        dev->hard_start_xmit = eexp_xmit;
1175
        dev->get_stats = eexp_stats;
1176
        dev->set_multicast_list = &eexp_set_multicast;
1177
        dev->tx_timeout = eexp_timeout;
1178
        dev->watchdog_timeo = 2*HZ;
1179
        ether_setup(dev);
1180
        return 0;
1181
}
1182
 
1183
/*
1184
 * Read a word from the EtherExpress on-board serial EEPROM.
1185
 * The EEPROM contains 64 words of 16 bits.
1186
 */
1187
static unsigned short __init eexp_hw_readeeprom(unsigned short ioaddr,
1188
                                                    unsigned char location)
1189
{
1190
        unsigned short cmd = 0x180|(location&0x7f);
1191
        unsigned short rval = 0,wval = EC_CS|i586_RST;
1192
        int i;
1193
 
1194
        outb(EC_CS|i586_RST,ioaddr+EEPROM_Ctrl);
1195
        for (i=0x100 ; i ; i>>=1 )
1196
        {
1197
                if (cmd&i)
1198
                        wval |= EC_Wr;
1199
                else
1200
                        wval &= ~EC_Wr;
1201
 
1202
                outb(wval,ioaddr+EEPROM_Ctrl);
1203
                outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl);
1204
                eeprom_delay();
1205
                outb(wval,ioaddr+EEPROM_Ctrl);
1206
                eeprom_delay();
1207
        }
1208
        wval &= ~EC_Wr;
1209
        outb(wval,ioaddr+EEPROM_Ctrl);
1210
        for (i=0x8000 ; i ; i>>=1 )
1211
        {
1212
                outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl);
1213
                eeprom_delay();
1214
                if (inb(ioaddr+EEPROM_Ctrl)&EC_Rd)
1215
                        rval |= i;
1216
                outb(wval,ioaddr+EEPROM_Ctrl);
1217
                eeprom_delay();
1218
        }
1219
        wval &= ~EC_CS;
1220
        outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl);
1221
        eeprom_delay();
1222
        outb(wval,ioaddr+EEPROM_Ctrl);
1223
        eeprom_delay();
1224
        return rval;
1225
}
1226
 
1227
/*
1228
 * Reap tx buffers and return last transmit status.
1229
 * if ==0 then either:
1230
 *    a) we're not transmitting anything, so why are we here?
1231
 *    b) we've died.
1232
 * otherwise, Stat_Busy(return) means we've still got some packets
1233
 * to transmit, Stat_Done(return) means our buffers should be empty
1234
 * again
1235
 */
1236
 
1237
static unsigned short eexp_hw_lasttxstat(struct net_device *dev)
1238
{
1239
        struct net_local *lp = (struct net_local *)dev->priv;
1240
        unsigned short tx_block = lp->tx_reap;
1241
        unsigned short status;
1242
 
1243
        if (!netif_queue_stopped(dev) && lp->tx_head==lp->tx_reap)
1244
                return 0x0000;
1245
 
1246
        do
1247
        {
1248
                outw(tx_block & ~31, dev->base_addr + SM_PTR);
1249
                status = inw(dev->base_addr + SHADOW(tx_block));
1250
                if (!Stat_Done(status))
1251
                {
1252
                        lp->tx_link = tx_block;
1253
                        return status;
1254
                }
1255
                else
1256
                {
1257
                        lp->last_tx_restart = 0;
1258
                        lp->stats.collisions += Stat_NoColl(status);
1259
                        if (!Stat_OK(status))
1260
                        {
1261
                                char *whatsup = NULL;
1262
                                lp->stats.tx_errors++;
1263
                                if (Stat_Abort(status))
1264
                                        lp->stats.tx_aborted_errors++;
1265
                                if (Stat_TNoCar(status)) {
1266
                                        whatsup = "aborted, no carrier";
1267
                                        lp->stats.tx_carrier_errors++;
1268
                                }
1269
                                if (Stat_TNoCTS(status)) {
1270
                                        whatsup = "aborted, lost CTS";
1271
                                        lp->stats.tx_carrier_errors++;
1272
                                }
1273
                                if (Stat_TNoDMA(status)) {
1274
                                        whatsup = "FIFO underran";
1275
                                        lp->stats.tx_fifo_errors++;
1276
                                }
1277
                                if (Stat_TXColl(status)) {
1278
                                        whatsup = "aborted, too many collisions";
1279
                                        lp->stats.tx_aborted_errors++;
1280
                                }
1281
                                if (whatsup)
1282
                                        printk(KERN_INFO "%s: transmit %s\n",
1283
                                               dev->name, whatsup);
1284
                        }
1285
                        else
1286
                                lp->stats.tx_packets++;
1287
                }
1288
                if (tx_block == TX_BUF_START+((lp->num_tx_bufs-1)*TX_BUF_SIZE))
1289
                        lp->tx_reap = tx_block = TX_BUF_START;
1290
                else
1291
                        lp->tx_reap = tx_block += TX_BUF_SIZE;
1292
                netif_wake_queue(dev);
1293
        }
1294
        while (lp->tx_reap != lp->tx_head);
1295
 
1296
        lp->tx_link = lp->tx_tail + 0x08;
1297
 
1298
        return status;
1299
}
1300
 
1301
/*
1302
 * This should never happen. It is called when some higher routine detects
1303
 * that the CU has stopped, to try to restart it from the last packet we knew
1304
 * we were working on, or the idle loop if we had finished for the time.
1305
 */
1306
 
1307
static void eexp_hw_txrestart(struct net_device *dev)
1308
{
1309
        struct net_local *lp = (struct net_local *)dev->priv;
1310
        unsigned short ioaddr = dev->base_addr;
1311
 
1312
        lp->last_tx_restart = lp->tx_link;
1313
        scb_wrcbl(dev, lp->tx_link);
1314
        scb_command(dev, SCB_CUstart);
1315
        outb(0,ioaddr+SIGNAL_CA);
1316
 
1317
        {
1318
                unsigned short boguscount=50,failcount=5;
1319
                while (!scb_status(dev))
1320
                {
1321
                        if (!--boguscount)
1322
                        {
1323
                                if (--failcount)
1324
                                {
1325
                                        printk(KERN_WARNING "%s: CU start timed out, status %04x, cmd %04x\n", dev->name, scb_status(dev), scb_rdcmd(dev));
1326
                                        scb_wrcbl(dev, lp->tx_link);
1327
                                        scb_command(dev, SCB_CUstart);
1328
                                        outb(0,ioaddr+SIGNAL_CA);
1329
                                        boguscount = 100;
1330
                                }
1331
                                else
1332
                                {
1333
                                        printk(KERN_WARNING "%s: Failed to restart CU, resetting board...\n",dev->name);
1334
                                        eexp_hw_init586(dev);
1335
                                        netif_wake_queue(dev);
1336
                                        return;
1337
                                }
1338
                        }
1339
                }
1340
        }
1341
}
1342
 
1343
/*
1344
 * Writes down the list of transmit buffers into card memory.  Each
1345
 * entry consists of an 82586 transmit command, followed by a jump
1346
 * pointing to itself.  When we want to transmit a packet, we write
1347
 * the data into the appropriate transmit buffer and then modify the
1348
 * preceding jump to point at the new transmit command.  This means that
1349
 * the 586 command unit is continuously active.
1350
 */
1351
 
1352
static void eexp_hw_txinit(struct net_device *dev)
1353
{
1354
        struct net_local *lp = (struct net_local *)dev->priv;
1355
        unsigned short tx_block = TX_BUF_START;
1356
        unsigned short curtbuf;
1357
        unsigned short ioaddr = dev->base_addr;
1358
 
1359
        for ( curtbuf=0 ; curtbuf<lp->num_tx_bufs ; curtbuf++ )
1360
        {
1361
                outw(tx_block, ioaddr + WRITE_PTR);
1362
 
1363
                outw(0x0000, ioaddr + DATAPORT);
1364
                outw(Cmd_INT|Cmd_Xmit, ioaddr + DATAPORT);
1365
                outw(tx_block+0x08, ioaddr + DATAPORT);
1366
                outw(tx_block+0x0e, ioaddr + DATAPORT);
1367
 
1368
                outw(0x0000, ioaddr + DATAPORT);
1369
                outw(0x0000, ioaddr + DATAPORT);
1370
                outw(tx_block+0x08, ioaddr + DATAPORT);
1371
 
1372
                outw(0x8000, ioaddr + DATAPORT);
1373
                outw(-1, ioaddr + DATAPORT);
1374
                outw(tx_block+0x16, ioaddr + DATAPORT);
1375
                outw(0x0000, ioaddr + DATAPORT);
1376
 
1377
                tx_block += TX_BUF_SIZE;
1378
        }
1379
        lp->tx_head = TX_BUF_START;
1380
        lp->tx_reap = TX_BUF_START;
1381
        lp->tx_tail = tx_block - TX_BUF_SIZE;
1382
        lp->tx_link = lp->tx_tail + 0x08;
1383
        lp->rx_buf_start = tx_block;
1384
 
1385
}
1386
 
1387
/*
1388
 * Write the circular list of receive buffer descriptors to card memory.
1389
 * The end of the list isn't marked, which means that the 82586 receive
1390
 * unit will loop until buffers become available (this avoids it giving us
1391
 * "out of resources" messages).
1392
 */
1393
 
1394
static void eexp_hw_rxinit(struct net_device *dev)
1395
{
1396
        struct net_local *lp = (struct net_local *)dev->priv;
1397
        unsigned short rx_block = lp->rx_buf_start;
1398
        unsigned short ioaddr = dev->base_addr;
1399
 
1400
        lp->num_rx_bufs = 0;
1401
        lp->rx_first = lp->rx_ptr = rx_block;
1402
        do
1403
        {
1404
                lp->num_rx_bufs++;
1405
 
1406
                outw(rx_block, ioaddr + WRITE_PTR);
1407
 
1408
                outw(0, ioaddr + DATAPORT);  outw(0, ioaddr+DATAPORT);
1409
                outw(rx_block + RX_BUF_SIZE, ioaddr+DATAPORT);
1410
                outw(0xffff, ioaddr+DATAPORT);
1411
 
1412
                outw(0x0000, ioaddr+DATAPORT);
1413
                outw(0xdead, ioaddr+DATAPORT);
1414
                outw(0xdead, ioaddr+DATAPORT);
1415
                outw(0xdead, ioaddr+DATAPORT);
1416
                outw(0xdead, ioaddr+DATAPORT);
1417
                outw(0xdead, ioaddr+DATAPORT);
1418
                outw(0xdead, ioaddr+DATAPORT);
1419
 
1420
                outw(0x0000, ioaddr+DATAPORT);
1421
                outw(rx_block + RX_BUF_SIZE + 0x16, ioaddr+DATAPORT);
1422
                outw(rx_block + 0x20, ioaddr+DATAPORT);
1423
                outw(0, ioaddr+DATAPORT);
1424
                outw(RX_BUF_SIZE-0x20, ioaddr+DATAPORT);
1425
 
1426
                lp->rx_last = rx_block;
1427
                rx_block += RX_BUF_SIZE;
1428
        } while (rx_block <= lp->rx_buf_end-RX_BUF_SIZE);
1429
 
1430
 
1431
        /* Make first Rx frame descriptor point to first Rx buffer
1432
           descriptor */
1433
        outw(lp->rx_first + 6, ioaddr+WRITE_PTR);
1434
        outw(lp->rx_first + 0x16, ioaddr+DATAPORT);
1435
 
1436
        /* Close Rx frame descriptor ring */
1437
        outw(lp->rx_last + 4, ioaddr+WRITE_PTR);
1438
        outw(lp->rx_first, ioaddr+DATAPORT);
1439
 
1440
        /* Close Rx buffer descriptor ring */
1441
        outw(lp->rx_last + 0x16 + 2, ioaddr+WRITE_PTR);
1442
        outw(lp->rx_first + 0x16, ioaddr+DATAPORT);
1443
 
1444
}
1445
 
1446
/*
1447
 * Un-reset the 586, and start the configuration sequence. We don't wait for
1448
 * this to finish, but allow the interrupt handler to start the CU and RU for
1449
 * us.  We can't start the receive/transmission system up before we know that
1450
 * the hardware is configured correctly.
1451
 */
1452
 
1453
static void eexp_hw_init586(struct net_device *dev)
1454
{
1455
        struct net_local *lp = (struct net_local *)dev->priv;
1456
        unsigned short ioaddr = dev->base_addr;
1457
        int i;
1458
 
1459
#if NET_DEBUG > 6
1460
        printk("%s: eexp_hw_init586()\n", dev->name);
1461
#endif
1462
 
1463
        lp->started = 0;
1464
 
1465
        set_loopback(dev);
1466
 
1467
        outb(SIRQ_dis|irqrmap[dev->irq],ioaddr+SET_IRQ);
1468
 
1469
        /* Download the startup code */
1470
        outw(lp->rx_buf_end & ~31, ioaddr + SM_PTR);
1471
        outw(lp->width?0x0001:0x0000, ioaddr + 0x8006);
1472
        outw(0x0000, ioaddr + 0x8008);
1473
        outw(0x0000, ioaddr + 0x800a);
1474
        outw(0x0000, ioaddr + 0x800c);
1475
        outw(0x0000, ioaddr + 0x800e);
1476
 
1477
        for (i = 0; i < (sizeof(start_code)); i+=32) {
1478
                int j;
1479
                outw(i, ioaddr + SM_PTR);
1480
                for (j = 0; j < 16; j+=2)
1481
                        outw(start_code[(i+j)/2],
1482
                             ioaddr+0x4000+j);
1483
                for (j = 0; j < 16; j+=2)
1484
                        outw(start_code[(i+j+16)/2],
1485
                             ioaddr+0x8000+j);
1486
        }
1487
 
1488
        /* Do we want promiscuous mode or multicast? */
1489
        outw(CONF_PROMISC & ~31, ioaddr+SM_PTR);
1490
        i = inw(ioaddr+SHADOW(CONF_PROMISC));
1491
        outw((dev->flags & IFF_PROMISC)?(i|1):(i & ~1),
1492
             ioaddr+SHADOW(CONF_PROMISC));
1493
        lp->was_promisc = dev->flags & IFF_PROMISC;
1494
#if 0
1495
        eexp_setup_filter(dev);
1496
#endif
1497
 
1498
        /* Write our hardware address */
1499
        outw(CONF_HWADDR & ~31, ioaddr+SM_PTR);
1500
        outw(((unsigned short *)dev->dev_addr)[0], ioaddr+SHADOW(CONF_HWADDR));
1501
        outw(((unsigned short *)dev->dev_addr)[1],
1502
             ioaddr+SHADOW(CONF_HWADDR+2));
1503
        outw(((unsigned short *)dev->dev_addr)[2],
1504
             ioaddr+SHADOW(CONF_HWADDR+4));
1505
 
1506
        eexp_hw_txinit(dev);
1507
        eexp_hw_rxinit(dev);
1508
 
1509
        outb(0,ioaddr+EEPROM_Ctrl);
1510
        mdelay(5);
1511
 
1512
        scb_command(dev, 0xf000);
1513
        outb(0,ioaddr+SIGNAL_CA);
1514
 
1515
        outw(0, ioaddr+SM_PTR);
1516
 
1517
        {
1518
                unsigned short rboguscount=50,rfailcount=5;
1519
                while (inw(ioaddr+0x4000))
1520
                {
1521
                        if (!--rboguscount)
1522
                        {
1523
                                printk(KERN_WARNING "%s: i82586 reset timed out, kicking...\n",
1524
                                        dev->name);
1525
                                scb_command(dev, 0);
1526
                                outb(0,ioaddr+SIGNAL_CA);
1527
                                rboguscount = 100;
1528
                                if (!--rfailcount)
1529
                                {
1530
                                        printk(KERN_WARNING "%s: i82586 not responding, giving up.\n",
1531
                                                dev->name);
1532
                                        return;
1533
                                }
1534
                        }
1535
                }
1536
        }
1537
 
1538
        scb_wrcbl(dev, CONF_LINK);
1539
        scb_command(dev, 0xf000|SCB_CUstart);
1540
        outb(0,ioaddr+SIGNAL_CA);
1541
 
1542
        {
1543
                unsigned short iboguscount=50,ifailcount=5;
1544
                while (!scb_status(dev))
1545
                {
1546
                        if (!--iboguscount)
1547
                        {
1548
                                if (--ifailcount)
1549
                                {
1550
                                        printk(KERN_WARNING "%s: i82586 initialization timed out, status %04x, cmd %04x\n",
1551
                                                dev->name, scb_status(dev), scb_rdcmd(dev));
1552
                                        scb_wrcbl(dev, CONF_LINK);
1553
                                        scb_command(dev, 0xf000|SCB_CUstart);
1554
                                        outb(0,ioaddr+SIGNAL_CA);
1555
                                        iboguscount = 100;
1556
                                }
1557
                                else
1558
                                {
1559
                                        printk(KERN_WARNING "%s: Failed to initialize i82586, giving up.\n",dev->name);
1560
                                        return;
1561
                                }
1562
                        }
1563
                }
1564
        }
1565
 
1566
        clear_loopback(dev);
1567
        outb(SIRQ_en|irqrmap[dev->irq],ioaddr+SET_IRQ);
1568
 
1569
        lp->init_time = jiffies;
1570
#if NET_DEBUG > 6
1571
        printk("%s: leaving eexp_hw_init586()\n", dev->name);
1572
#endif
1573
        return;
1574
}
1575
 
1576
static void eexp_setup_filter(struct net_device *dev)
1577
{
1578
        struct dev_mc_list *dmi = dev->mc_list;
1579
        unsigned short ioaddr = dev->base_addr;
1580
        int count = dev->mc_count;
1581
        int i;
1582
        if (count > 8) {
1583
                printk(KERN_INFO "%s: too many multicast addresses (%d)\n",
1584
                       dev->name, count);
1585
                count = 8;
1586
        }
1587
 
1588
        outw(CONF_NR_MULTICAST & ~31, ioaddr+SM_PTR);
1589
        outw(count, ioaddr+SHADOW(CONF_NR_MULTICAST));
1590
        for (i = 0; i < count; i++) {
1591
                unsigned short *data = (unsigned short *)dmi->dmi_addr;
1592
                if (!dmi) {
1593
                        printk(KERN_INFO "%s: too few multicast addresses\n", dev->name);
1594
                        break;
1595
                }
1596
                if (dmi->dmi_addrlen != ETH_ALEN) {
1597
                        printk(KERN_INFO "%s: invalid multicast address length given.\n", dev->name);
1598
                        continue;
1599
                }
1600
                outw((CONF_MULTICAST+(6*i)) & ~31, ioaddr+SM_PTR);
1601
                outw(data[0], ioaddr+SHADOW(CONF_MULTICAST+(6*i)));
1602
                outw((CONF_MULTICAST+(6*i)+2) & ~31, ioaddr+SM_PTR);
1603
                outw(data[1], ioaddr+SHADOW(CONF_MULTICAST+(6*i)+2));
1604
                outw((CONF_MULTICAST+(6*i)+4) & ~31, ioaddr+SM_PTR);
1605
                outw(data[2], ioaddr+SHADOW(CONF_MULTICAST+(6*i)+4));
1606
        }
1607
}
1608
 
1609
/*
1610
 * Set or clear the multicast filter for this adaptor.
1611
 */
1612
static void
1613
eexp_set_multicast(struct net_device *dev)
1614
{
1615
        unsigned short ioaddr = dev->base_addr;
1616
        struct net_local *lp = (struct net_local *)dev->priv;
1617
        int kick = 0, i;
1618
        if ((dev->flags & IFF_PROMISC) != lp->was_promisc) {
1619
                outw(CONF_PROMISC & ~31, ioaddr+SM_PTR);
1620
                i = inw(ioaddr+SHADOW(CONF_PROMISC));
1621
                outw((dev->flags & IFF_PROMISC)?(i|1):(i & ~1),
1622
                     ioaddr+SHADOW(CONF_PROMISC));
1623
                lp->was_promisc = dev->flags & IFF_PROMISC;
1624
                kick = 1;
1625
        }
1626
        if (!(dev->flags & IFF_PROMISC)) {
1627
                eexp_setup_filter(dev);
1628
                if (lp->old_mc_count != dev->mc_count) {
1629
                        kick = 1;
1630
                        lp->old_mc_count = dev->mc_count;
1631
                }
1632
        }
1633
        if (kick) {
1634
                unsigned long oj;
1635
                scb_command(dev, SCB_CUsuspend);
1636
                outb(0, ioaddr+SIGNAL_CA);
1637
                outb(0, ioaddr+SIGNAL_CA);
1638
#if 0
1639
                printk("%s: waiting for CU to go suspended\n", dev->name);
1640
#endif
1641
                oj = jiffies;
1642
                while ((SCB_CUstat(scb_status(dev)) == 2) &&
1643
                       ((jiffies-oj) < 2000));
1644
                if (SCB_CUstat(scb_status(dev)) == 2)
1645
                        printk("%s: warning, CU didn't stop\n", dev->name);
1646
                lp->started &= ~(STARTED_CU);
1647
                scb_wrcbl(dev, CONF_LINK);
1648
                scb_command(dev, SCB_CUstart);
1649
                outb(0, ioaddr+SIGNAL_CA);
1650
        }
1651
}
1652
 
1653
 
1654
/*
1655
 * MODULE stuff
1656
 */
1657
 
1658
#ifdef MODULE
1659
 
1660
#define EEXP_MAX_CARDS     4    /* max number of cards to support */
1661
 
1662
static struct net_device dev_eexp[EEXP_MAX_CARDS];
1663
static int irq[EEXP_MAX_CARDS];
1664
static int io[EEXP_MAX_CARDS];
1665
 
1666
MODULE_PARM(io, "1-" __MODULE_STRING(EEXP_MAX_CARDS) "i");
1667
MODULE_PARM(irq, "1-" __MODULE_STRING(EEXP_MAX_CARDS) "i");
1668
MODULE_PARM_DESC(io, "EtherExpress 16 I/O base address(es)");
1669
MODULE_PARM_DESC(irq, "EtherExpress 16 IRQ number(s)");
1670
MODULE_LICENSE("GPL");
1671
 
1672
 
1673
/* Ideally the user would give us io=, irq= for every card.  If any parameters
1674
 * are specified, we verify and then use them.  If no parameters are given, we
1675
 * autoprobe for one card only.
1676
 */
1677
int init_module(void)
1678
{
1679
        int this_dev, found = 0;
1680
 
1681
        for (this_dev = 0; this_dev < EEXP_MAX_CARDS; this_dev++) {
1682
                struct net_device *dev = &dev_eexp[this_dev];
1683
                dev->irq = irq[this_dev];
1684
                dev->base_addr = io[this_dev];
1685
                dev->init = express_probe;
1686
                if (io[this_dev] == 0) {
1687
                        if (this_dev) break;
1688
                        printk(KERN_NOTICE "eexpress.c: Module autoprobe not recommended, give io=xx.\n");
1689
                }
1690
                if (register_netdev(dev) != 0) {
1691
                        printk(KERN_WARNING "eexpress.c: Failed to register card at 0x%x.\n", io[this_dev]);
1692
                        if (found != 0) return 0;
1693
                        return -ENXIO;
1694
                }
1695
                found++;
1696
        }
1697
        return 0;
1698
}
1699
 
1700
void cleanup_module(void)
1701
{
1702
        int this_dev;
1703
 
1704
        for (this_dev = 0; this_dev < EEXP_MAX_CARDS; this_dev++) {
1705
                struct net_device *dev = &dev_eexp[this_dev];
1706
                if (dev->priv != NULL) {
1707
                        unregister_netdev(dev);
1708
                        kfree(dev->priv);
1709
                        dev->priv = NULL;
1710
                }
1711
        }
1712
}
1713
#endif
1714
 
1715
/*
1716
 * Local Variables:
1717
 *  c-file-style: "linux"
1718
 *  tab-width: 8
1719
 * End:
1720
 */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.