1 /* 3c507.c: An EtherLink16 device driver for Linux. */
3 Written 1993,1994 by Donald Becker.
5 Copyright 1993 United States Government as represented by the
6 Director, National Security Agency.
8 This software may be used and distributed according to the terms
9 of the GNU Public License, incorporated herein by reference.
11 The author may be reached as becker@CESDIS.gsfc.nasa.gov, or C/O
12 Center of Excellence in Space Data and Information Sciences
13 Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771
15 Thanks go to jennings@Montrouge.SMR.slb.com ( Patrick Jennings)
16 and jrs@world.std.com (Rick Sladkey) for testing and bugfixes.
17 Mark Salazar <leslie@access.digex.net> made the changes for cards with
18 only 16K packet buffers.
20 Things remaining to do:
21 Verify that the tx and rx buffers don't have fencepost errors.
22 Move the theory of operation and memory map documentation.
23 The statistics need to be updated correctly.
26 static const char *version
=
27 "3c507.c:v1.10 9/23/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
30 #include <linux/module.h>
34 This driver wouldn't have been written with the availability of the
35 Crynwr driver source code. It provided a known-working implementation
36 that filled in the gaping holes of the Intel documentation. Three cheers
39 Intel Microcommunications Databook, Vol. 1, 1990. It provides just enough
40 info that the casual reader might think that it documents the i82586 :-<.
43 #include <linux/config.h>
44 #include <linux/kernel.h>
45 #include <linux/sched.h>
46 #include <linux/types.h>
47 #include <linux/fcntl.h>
48 #include <linux/interrupt.h>
49 #include <linux/ptrace.h>
50 #include <linux/ioport.h>
52 #include <linux/string.h>
53 #include <linux/spinlock.h>
54 #include <asm/system.h>
55 #include <asm/bitops.h>
58 #include <linux/errno.h>
60 #include <linux/netdevice.h>
61 #include <linux/etherdevice.h>
62 #include <linux/skbuff.h>
63 #include <linux/malloc.h>
64 #include <linux/init.h>
67 /* use 0 for production, 1 for verification, 2..7 for debug */
71 static unsigned int net_debug
= NET_DEBUG
;
73 /* A zero-terminated list of common I/O addresses to be probed. */
74 static unsigned int netcard_portlist
[] __initdata
=
75 { 0x300, 0x320, 0x340, 0x280, 0};
78 Details of the i82586.
80 You'll really need the databook to understand the details of this part,
81 but the outline is that the i82586 has two separate processing units.
82 Both are started from a list of three configuration tables, of which only
83 the last, the System Control Block (SCB), is used after reset-time. The SCB
84 has the following fields:
87 Tx/Command block addr.
89 The command word accepts the following controls for the Tx and Rx units:
92 #define CUC_START 0x0100
93 #define CUC_RESUME 0x0200
94 #define CUC_SUSPEND 0x0300
95 #define RX_START 0x0010
96 #define RX_RESUME 0x0020
97 #define RX_SUSPEND 0x0030
99 /* The Rx unit uses a list of frame descriptors and a list of data buffer
100 descriptors. We use full-sized (1518 byte) data buffers, so there is
101 a one-to-one pairing of frame descriptors to buffer descriptors.
103 The Tx ("command") unit executes a list of commands that look like:
104 Status word Written by the 82586 when the command is done.
105 Command word Command in lower 3 bits, post-command action in upper 3
106 Link word The address of the next command.
107 Parameters (as needed).
109 Some definitions related to the Command Word are:
111 #define CMD_EOL 0x8000 /* The last command of the list, stop. */
112 #define CMD_SUSP 0x4000 /* Suspend after doing cmd. */
113 #define CMD_INTR 0x2000 /* Interrupt after doing cmd. */
116 CmdNOp
= 0, CmdSASetup
= 1, CmdConfigure
= 2, CmdMulticastList
= 3,
117 CmdTx
= 4, CmdTDR
= 5, CmdDump
= 6, CmdDiagnose
= 7};
119 /* Information that need to be kept for each board. */
121 struct net_device_stats stats
;
132 Details of the EtherLink16 Implementation
133 The 3c507 is a generic shared-memory i82586 implementation.
134 The host can map 16K, 32K, 48K, or 64K of the 64K memory into
135 0x0[CD][08]0000, or all 64K into 0xF[02468]0000.
138 /* Offsets from the base I/O address. */
139 #define SA_DATA 0 /* Station address data, or 3Com signature. */
140 #define MISC_CTRL 6 /* Switch the SA_DATA banks, and bus config bits. */
141 #define RESET_IRQ 10 /* Reset the latched IRQ line. */
142 #define SIGNAL_CA 11 /* Frob the 82586 Channel Attention line. */
143 #define ROM_CONFIG 13
144 #define MEM_CONFIG 14
145 #define IRQ_CONFIG 15
146 #define EL16_IO_EXTENT 16
148 /* The ID port is used at boot-time to locate the ethercard. */
149 #define ID_PORT 0x100
151 /* Offsets to registers in the mailbox (SCB). */
152 #define iSCB_STATUS 0x8
154 #define iSCB_CBL 0xC /* Command BLock offset. */
155 #define iSCB_RFA 0xE /* Rx Frame Area offset. */
157 /* Since the 3c507 maps the shared memory window so that the last byte is
158 at 82586 address FFFF, the first byte is at 82586 address 0, 16K, 32K, or
159 48K corresponding to window sizes of 64K, 48K, 32K and 16K respectively.
160 We can account for this be setting the 'SBC Base' entry in the ISCP table
161 below for all the 16 bit offset addresses, and also adding the 'SCB Base'
162 value to all 24 bit physical addresses (in the SCP table and the TX and RX
166 #define SCB_BASE ((unsigned)64*1024 - (dev->mem_end - dev->mem_start))
169 What follows in 'init_words[]' is the "program" that is downloaded to the
170 82586 memory. It's mostly tables and command blocks, and starts at the
171 reset address 0xfffff6. This is designed to be similar to the EtherExpress,
172 thus the unusual location of the SCB at 0x0008.
174 Even with the additional "don't care" values, doing it this way takes less
175 program space than initializing the individual tables, and I feel it's much
178 The databook is particularly useless for the first two structures, I had
179 to use the Crynwr driver as an example.
181 The memory setup is as follows:
184 #define CONFIG_CMD 0x0018
185 #define SET_SA_CMD 0x0024
186 #define SA_OFFSET 0x002A
187 #define IDLELOOP 0x30
189 #define TDR_TIME 0x3C
190 #define DUMP_CMD 0x40
191 #define DIAG_CMD 0x48
192 #define SET_MC_CMD 0x4E
193 #define DUMP_DATA 0x56 /* A 170 byte buffer for dump and Set-MC into. */
195 #define TX_BUF_START 0x0100
196 #define NUM_TX_BUFS 4
197 #define TX_BUF_SIZE (1518+14+20+16) /* packet+header+TBD */
199 #define RX_BUF_START 0x2000
200 #define RX_BUF_SIZE (1518+14+18) /* packet+header+RBD */
201 #define RX_BUF_END (dev->mem_end - dev->mem_start)
204 That's it: only 86 bytes to set up the beast, including every extra
205 command available. The 170 byte buffer at DUMP_DATA is shared between the
206 Dump command (called only by the diagnostic program) and the SetMulticastList
209 To complete the memory setup you only have to write the station address at
210 SA_OFFSET and create the Tx & Rx buffer lists.
212 The Tx command chain and buffer list is setup as follows:
213 A Tx command table, with the data buffer pointing to...
214 A Tx data buffer descriptor. The packet is in a single buffer, rather than
215 chaining together several smaller buffers.
216 A NoOp command, which initially points to itself,
219 A transmit is done by filling in the Tx command table and data buffer,
220 re-writing the NoOp command, and finally changing the offset of the last
221 command to point to the current Tx command. When the Tx command is finished,
222 it jumps to the NoOp, when it loops until the next Tx command changes the
223 "link offset" in the NoOp. This way the 82586 never has to go through the
224 slow restart sequence.
226 The Rx buffer list is set up in the obvious ring structure. We have enough
227 memory (and low enough interrupt latency) that we can avoid the complicated
228 Rx buffer linked lists by alway associating a full-size Rx data buffer with
231 I current use four transmit buffers starting at TX_BUF_START (0x0100), and
232 use the rest of memory, from RX_BUF_START to RX_BUF_END, for Rx buffers.
236 static unsigned short init_words
[] = {
237 /* System Configuration Pointer (SCP). */
238 0x0000, /* Set bus size to 16 bits. */
239 0,0, /* pad words. */
240 0x0000,0x0000, /* ISCP phys addr, set in init_82586_mem(). */
242 /* Intermediate System Configuration Pointer (ISCP). */
243 0x0001, /* Status word that's cleared when init is done. */
244 0x0008,0,0, /* SCB offset, (skip, skip) */
246 /* System Control Block (SCB). */
247 0,0xf000|RX_START
|CUC_START
, /* SCB status and cmd. */
248 CONFIG_CMD
, /* Command list pointer, points to Configure. */
249 RX_BUF_START
, /* Rx block list. */
250 0,0,0,0, /* Error count: CRC, align, buffer, overrun. */
252 /* 0x0018: Configure command. Change to put MAC data with packet. */
253 0, CmdConfigure
, /* Status, command. */
254 SET_SA_CMD
, /* Next command is Set Station Addr. */
255 0x0804, /* "4" bytes of config data, 8 byte FIFO. */
256 0x2e40, /* Magic values, including MAC data location. */
257 0, /* Unused pad word. */
259 /* 0x0024: Setup station address command. */
261 SET_MC_CMD
, /* Next command. */
262 0xaa00,0xb000,0x0bad, /* Station address (to be filled in) */
264 /* 0x0030: NOP, looping back to itself. Point to first Tx buffer to Tx. */
265 0, CmdNOp
, IDLELOOP
, 0 /* pad */,
267 /* 0x0038: A unused Time-Domain Reflectometer command. */
268 0, CmdTDR
, IDLELOOP
, 0,
270 /* 0x0040: An unused Dump State command. */
271 0, CmdDump
, IDLELOOP
, DUMP_DATA
,
273 /* 0x0048: An unused Diagnose command. */
274 0, CmdDiagnose
, IDLELOOP
,
276 /* 0x004E: An empty set-multicast-list command. */
277 0, CmdMulticastList
, IDLELOOP
, 0,
280 /* Index to functions, as function prototypes. */
282 extern int el16_probe(struct net_device
*dev
); /* Called from Space.c */
284 static int el16_probe1(struct net_device
*dev
, int ioaddr
);
285 static int el16_open(struct net_device
*dev
);
286 static int el16_send_packet(struct sk_buff
*skb
, struct net_device
*dev
);
287 static void el16_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
);
288 static void el16_rx(struct net_device
*dev
);
289 static int el16_close(struct net_device
*dev
);
290 static struct net_device_stats
*el16_get_stats(struct net_device
*dev
);
292 static void hardware_send_packet(struct net_device
*dev
, void *buf
, short length
);
293 static void init_82586_mem(struct net_device
*dev
);
297 struct netdev_entry netcard_drv
=
298 {"3c507", el16_probe1
, EL16_IO_EXTENT
, netcard_portlist
};
301 /* Check for a network adaptor of this type, and return '0' iff one exists.
302 If dev->base_addr == 0, probe all likely locations.
303 If dev->base_addr == 1, always return failure.
304 If dev->base_addr == 2, (detachable devices only) allocate space for the
305 device and return success.
308 int __init
el16_probe(struct net_device
*dev
)
310 int base_addr
= dev
? dev
->base_addr
: 0;
313 if (base_addr
> 0x1ff) /* Check a single specified location. */
314 return el16_probe1(dev
, base_addr
);
315 else if (base_addr
!= 0)
316 return ENXIO
; /* Don't probe at all. */
318 for (i
= 0; netcard_portlist
[i
]; i
++) {
319 int ioaddr
= netcard_portlist
[i
];
320 if (check_region(ioaddr
, EL16_IO_EXTENT
))
322 if (el16_probe1(dev
, ioaddr
) == 0)
329 int __init
el16_probe1(struct net_device
*dev
, int ioaddr
)
331 static unsigned char init_ID_done
= 0, version_printed
= 0;
334 if (init_ID_done
== 0) {
335 ushort lrs_state
= 0xff;
336 /* Send the ID sequence to the ID_PORT to enable the board(s). */
338 for(i
= 0; i
< 255; i
++) {
339 outb(lrs_state
, ID_PORT
);
341 if (lrs_state
& 0x100)
348 if (inb(ioaddr
) == '*' && inb(ioaddr
+1) == '3'
349 && inb(ioaddr
+2) == 'C' && inb(ioaddr
+3) == 'O')
354 /* Allocate a new 'dev' if needed. */
356 dev
= init_etherdev(0, sizeof(struct net_local
));
358 if (net_debug
&& version_printed
++ == 0)
361 printk("%s: 3c507 at %#x,", dev
->name
, ioaddr
);
363 /* We should make a few more checks here, like the first three octets of
364 the S.A. for the manufacturer's code. */
366 irq
= inb(ioaddr
+ IRQ_CONFIG
) & 0x0f;
368 irqval
= request_irq(irq
, &el16_interrupt
, 0, "3c507", dev
);
370 printk ("unable to get IRQ %d (irqval=%d).\n", irq
, irqval
);
374 /* We've committed to using the board, and can start filling in *dev. */
375 request_region(ioaddr
, EL16_IO_EXTENT
, "3c507");
376 dev
->base_addr
= ioaddr
;
378 outb(0x01, ioaddr
+ MISC_CTRL
);
379 for (i
= 0; i
< 6; i
++) {
380 dev
->dev_addr
[i
] = inb(ioaddr
+ i
);
381 printk(" %02x", dev
->dev_addr
[i
]);
384 if ((dev
->mem_start
& 0xf) > 0)
385 net_debug
= dev
->mem_start
& 7;
388 dev
->mem_start
= MEM_BASE
;
389 dev
->mem_end
= dev
->mem_start
+ 0x10000;
394 char mem_config
= inb(ioaddr
+ MEM_CONFIG
);
395 if (mem_config
& 0x20) {
397 base
= 0xf00000 + (mem_config
& 0x08 ? 0x080000
398 : ((mem_config
& 3) << 17));
400 size
= ((mem_config
& 3) + 1) << 14;
401 base
= 0x0c0000 + ( (mem_config
& 0x18) << 12);
403 dev
->mem_start
= base
;
404 dev
->mem_end
= base
+ size
;
408 dev
->if_port
= (inb(ioaddr
+ ROM_CONFIG
) & 0x80) ? 1 : 0;
409 dev
->irq
= inb(ioaddr
+ IRQ_CONFIG
) & 0x0f;
411 printk(", IRQ %d, %sternal xcvr, memory %#lx-%#lx.\n", dev
->irq
,
412 dev
->if_port
? "ex" : "in", dev
->mem_start
, dev
->mem_end
-1);
417 /* Initialize the device structure. */
418 dev
->priv
= kmalloc(sizeof(struct net_local
), GFP_KERNEL
);
419 if (dev
->priv
== NULL
)
421 memset(dev
->priv
, 0, sizeof(struct net_local
));
423 dev
->open
= el16_open
;
424 dev
->stop
= el16_close
;
425 dev
->hard_start_xmit
= el16_send_packet
;
426 dev
->get_stats
= el16_get_stats
;
428 ether_setup(dev
); /* Generic ethernet behaviour */
430 dev
->flags
&=~IFF_MULTICAST
; /* Multicast doesn't work */
435 static int el16_open(struct net_device
*dev
)
437 /* Initialize the 82586 memory and start it. */
449 static int el16_send_packet(struct sk_buff
*skb
, struct net_device
*dev
)
451 struct net_local
*lp
= (struct net_local
*)dev
->priv
;
452 int ioaddr
= dev
->base_addr
;
453 unsigned long shmem
= dev
->mem_start
;
458 /* If we get here, some higher level has decided we are broken.
459 There should really be a "kick me" function call instead. */
460 int tickssofar
= jiffies
- dev
->trans_start
;
464 printk("%s: transmit timed out, %s? ", dev
->name
,
465 readw(shmem
+iSCB_STATUS
) & 0x8000 ? "IRQ conflict" :
466 "network cable problem");
467 /* Try to restart the adaptor. */
468 if (lp
->last_restart
== lp
->stats
.tx_packets
) {
469 if (net_debug
> 1) printk("Resetting board.\n");
470 /* Completely reset the adaptor. */
473 /* Issue the channel attention signal and hope it "gets better". */
474 if (net_debug
> 1) printk("Kicking board.\n");
475 writew(0xf000|CUC_START
|RX_START
,shmem
+iSCB_CMD
);
476 outb(0, ioaddr
+ SIGNAL_CA
); /* Issue channel-attn. */
477 lp
->last_restart
= lp
->stats
.tx_packets
;
480 dev
->trans_start
= jiffies
;
483 /* Block a timer-based transmit from overlapping. */
484 if (test_and_set_bit(0, (void*)&dev
->tbusy
) != 0)
485 printk("%s: Transmitter access conflict.\n", dev
->name
);
488 short length
= ETH_ZLEN
< skb
->len
? skb
->len
: ETH_ZLEN
;
489 unsigned char *buf
= skb
->data
;
491 lp
->stats
.tx_bytes
+=length
;
492 /* Disable the 82586's input to the interrupt line. */
493 outb(0x80, ioaddr
+ MISC_CTRL
);
495 spin_lock_irqsave(&lp
->lock
, flags
);
496 hardware_send_packet(dev
, buf
, length
);
497 spin_unlock_irqrestore(&lp
->lock
, flags
);
499 hardware_send_packet(dev
, buf
, length
);
501 dev
->trans_start
= jiffies
;
502 /* Enable the 82586 interrupt input. */
503 outb(0x84, ioaddr
+ MISC_CTRL
);
508 /* You might need to clean up and record Tx statistics here. */
513 /* The typical workload of the driver:
514 Handle the network interface interrupts. */
515 static void el16_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
517 struct net_device
*dev
= dev_id
;
518 struct net_local
*lp
;
519 int ioaddr
, status
, boguscount
= 0;
524 printk ("net_interrupt(): irq %d for unknown device.\n", irq
);
530 ioaddr
= dev
->base_addr
;
531 lp
= (struct net_local
*)dev
->priv
;
532 shmem
= dev
->mem_start
;
534 spin_lock(&lp
->lock
);
536 status
= readw(shmem
+iSCB_STATUS
);
539 printk("%s: 3c507 interrupt, status %4.4x.\n", dev
->name
, status
);
542 /* Disable the 82586's input to the interrupt line. */
543 outb(0x80, ioaddr
+ MISC_CTRL
);
545 /* Reap the Tx packet buffers. */
546 while (lp
->tx_reap
!= lp
->tx_head
) {
547 unsigned short tx_status
= readw(shmem
+lp
->tx_reap
);
549 if (tx_status
== 0) {
550 if (net_debug
> 5) printk("Couldn't reap %#x.\n", lp
->tx_reap
);
553 if (tx_status
& 0x2000) {
554 lp
->stats
.tx_packets
++;
555 lp
->stats
.collisions
+= tx_status
& 0xf;
557 mark_bh(NET_BH
); /* Inform upper layers. */
559 lp
->stats
.tx_errors
++;
560 if (tx_status
& 0x0600) lp
->stats
.tx_carrier_errors
++;
561 if (tx_status
& 0x0100) lp
->stats
.tx_fifo_errors
++;
562 if (!(tx_status
& 0x0040)) lp
->stats
.tx_heartbeat_errors
++;
563 if (tx_status
& 0x0020) lp
->stats
.tx_aborted_errors
++;
566 printk("Reaped %x, Tx status %04x.\n" , lp
->tx_reap
, tx_status
);
567 lp
->tx_reap
+= TX_BUF_SIZE
;
568 if (lp
->tx_reap
> RX_BUF_START
- TX_BUF_SIZE
)
569 lp
->tx_reap
= TX_BUF_START
;
570 if (++boguscount
> 4)
574 if (status
& 0x4000) { /* Packet received. */
576 printk("Received packet, rx_head %04x.\n", lp
->rx_head
);
580 /* Acknowledge the interrupt sources. */
581 ack_cmd
= status
& 0xf000;
583 if ((status
& 0x0700) != 0x0200 && dev
->start
) {
585 printk("%s: Command unit stopped, status %04x, restarting.\n",
587 /* If this ever occurs we should really re-write the idle loop, reset
588 the Tx list, and do a complete restart of the command unit.
589 For now we rely on the Tx timeout if the resume doesn't work. */
590 ack_cmd
|= CUC_RESUME
;
593 if ((status
& 0x0070) != 0x0040 && dev
->start
)
595 static void init_rx_bufs(struct net_device
*);
596 /* The Rx unit is not ready, it must be hung. Restart the receiver by
597 initializing the rx buffers, and issuing an Rx start command. */
599 printk("%s: Rx unit stopped, status %04x, restarting.\n",
602 writew(RX_BUF_START
,shmem
+iSCB_RFA
);
606 writew(ack_cmd
,shmem
+iSCB_CMD
);
607 outb(0, ioaddr
+ SIGNAL_CA
); /* Issue channel-attn. */
609 /* Clear the latched interrupt. */
610 outb(0, ioaddr
+ RESET_IRQ
);
612 /* Enable the 82586's interrupt input. */
613 outb(0x84, ioaddr
+ MISC_CTRL
);
614 spin_unlock(&lp
->lock
);
619 static int el16_close(struct net_device
*dev
)
621 int ioaddr
= dev
->base_addr
;
622 unsigned long shmem
= dev
->mem_start
;
627 /* Flush the Tx and disable Rx. */
628 writew(RX_SUSPEND
| CUC_SUSPEND
,shmem
+iSCB_CMD
);
629 outb(0, ioaddr
+ SIGNAL_CA
);
631 /* Disable the 82586's input to the interrupt line. */
632 outb(0x80, ioaddr
+ MISC_CTRL
);
634 /* We always physically use the IRQ line, so we don't do free_irq(). */
636 /* Update the statistics here. */
643 /* Get the current statistics. This may be called with the card open or
645 static struct net_device_stats
*el16_get_stats(struct net_device
*dev
)
647 struct net_local
*lp
= (struct net_local
*)dev
->priv
;
649 /* ToDo: decide if there are any useful statistics from the SCB. */
654 /* Initialize the Rx-block list. */
655 static void init_rx_bufs(struct net_device
*dev
)
657 struct net_local
*lp
= (struct net_local
*)dev
->priv
;
658 unsigned long write_ptr
;
659 unsigned short SCB_base
= SCB_BASE
;
661 int cur_rxbuf
= lp
->rx_head
= RX_BUF_START
;
663 /* Initialize each Rx frame + data buffer. */
664 do { /* While there is room for one more. */
666 write_ptr
= dev
->mem_start
+ cur_rxbuf
;
668 writew(0x0000,write_ptr
); /* Status */
669 writew(0x0000,write_ptr
+=2); /* Command */
670 writew(cur_rxbuf
+ RX_BUF_SIZE
,write_ptr
+=2); /* Link */
671 writew(cur_rxbuf
+ 22,write_ptr
+=2); /* Buffer offset */
672 writew(0x0000,write_ptr
+=2); /* Pad for dest addr. */
673 writew(0x0000,write_ptr
+=2);
674 writew(0x0000,write_ptr
+=2);
675 writew(0x0000,write_ptr
+=2); /* Pad for source addr. */
676 writew(0x0000,write_ptr
+=2);
677 writew(0x0000,write_ptr
+=2);
678 writew(0x0000,write_ptr
+=2); /* Pad for protocol. */
680 writew(0x0000,write_ptr
+=2); /* Buffer: Actual count */
681 writew(-1,write_ptr
+=2); /* Buffer: Next (none). */
682 writew(cur_rxbuf
+ 0x20 + SCB_base
,write_ptr
+=2);/* Buffer: Address low */
683 writew(0x0000,write_ptr
+=2);
684 /* Finally, the number of bytes in the buffer. */
685 writew(0x8000 + RX_BUF_SIZE
-0x20,write_ptr
+=2);
687 lp
->rx_tail
= cur_rxbuf
;
688 cur_rxbuf
+= RX_BUF_SIZE
;
689 } while (cur_rxbuf
<= RX_BUF_END
- RX_BUF_SIZE
);
691 /* Terminate the list by setting the EOL bit, and wrap the pointer to make
693 write_ptr
= dev
->mem_start
+ lp
->rx_tail
+ 2;
694 writew(0xC000,write_ptr
); /* Command, mark as last. */
695 writew(lp
->rx_head
,write_ptr
+2); /* Link */
698 static void init_82586_mem(struct net_device
*dev
)
700 struct net_local
*lp
= (struct net_local
*)dev
->priv
;
701 short ioaddr
= dev
->base_addr
;
702 unsigned long shmem
= dev
->mem_start
;
704 /* Enable loopback to protect the wire while starting up,
705 and hold the 586 in reset during the memory initialization. */
706 outb(0x20, ioaddr
+ MISC_CTRL
);
708 /* Fix the ISCP address and base. */
709 init_words
[3] = SCB_BASE
;
710 init_words
[7] = SCB_BASE
;
712 /* Write the words at 0xfff6 (address-aliased to 0xfffff6). */
713 memcpy_toio(dev
->mem_end
-10, init_words
, 10);
715 /* Write the words at 0x0000. */
716 memcpy_toio(dev
->mem_start
, init_words
+ 5, sizeof(init_words
) - 10);
718 /* Fill in the station address. */
719 memcpy_toio(dev
->mem_start
+SA_OFFSET
, dev
->dev_addr
,
720 sizeof(dev
->dev_addr
));
722 /* The Tx-block list is written as needed. We just set up the values. */
723 lp
->tx_cmd_link
= IDLELOOP
+ 4;
724 lp
->tx_head
= lp
->tx_reap
= TX_BUF_START
;
728 /* Start the 586 by releasing the reset line, but leave loopback. */
729 outb(0xA0, ioaddr
+ MISC_CTRL
);
731 /* This was time consuming to track down: you need to give two channel
732 attention signals to reliably start up the i82586. */
733 outb(0, ioaddr
+ SIGNAL_CA
);
737 while (readw(shmem
+iSCB_STATUS
) == 0)
738 if (--boguscnt
== 0) {
739 printk("%s: i82586 initialization timed out with status %04x,"
740 "cmd %04x.\n", dev
->name
,
741 readw(shmem
+iSCB_STATUS
), readw(shmem
+iSCB_CMD
));
744 /* Issue channel-attn -- the 82586 won't start. */
745 outb(0, ioaddr
+ SIGNAL_CA
);
748 /* Disable loopback and enable interrupts. */
749 outb(0x84, ioaddr
+ MISC_CTRL
);
751 printk("%s: Initialized 82586, status %04x.\n", dev
->name
,
752 readw(shmem
+iSCB_STATUS
));
756 static void hardware_send_packet(struct net_device
*dev
, void *buf
, short length
)
758 struct net_local
*lp
= (struct net_local
*)dev
->priv
;
759 short ioaddr
= dev
->base_addr
;
760 ushort tx_block
= lp
->tx_head
;
761 unsigned long write_ptr
= dev
->mem_start
+ tx_block
;
763 /* Set the write pointer to the Tx block, and put out the header. */
764 writew(0x0000,write_ptr
); /* Tx status */
765 writew(CMD_INTR
|CmdTx
,write_ptr
+=2); /* Tx command */
766 writew(tx_block
+16,write_ptr
+=2); /* Next command is a NoOp. */
767 writew(tx_block
+8,write_ptr
+=2); /* Data Buffer offset. */
769 /* Output the data buffer descriptor. */
770 writew(length
| 0x8000,write_ptr
+=2); /* Byte count parameter. */
771 writew(-1,write_ptr
+=2); /* No next data buffer. */
772 writew(tx_block
+22+SCB_BASE
,write_ptr
+=2); /* Buffer follows the NoOp command. */
773 writew(0x0000,write_ptr
+=2); /* Buffer address high bits (always zero). */
775 /* Output the Loop-back NoOp command. */
776 writew(0x0000,write_ptr
+=2); /* Tx status */
777 writew(CmdNOp
,write_ptr
+=2); /* Tx command */
778 writew(tx_block
+16,write_ptr
+=2); /* Next is myself. */
780 /* Output the packet at the write pointer. */
781 memcpy_toio(write_ptr
+2, buf
, length
);
783 /* Set the old command link pointing to this send packet. */
784 writew(tx_block
,dev
->mem_start
+ lp
->tx_cmd_link
);
785 lp
->tx_cmd_link
= tx_block
+ 20;
787 /* Set the next free tx region. */
788 lp
->tx_head
= tx_block
+ TX_BUF_SIZE
;
789 if (lp
->tx_head
> RX_BUF_START
- TX_BUF_SIZE
)
790 lp
->tx_head
= TX_BUF_START
;
793 printk("%s: 3c507 @%x send length = %d, tx_block %3x, next %3x.\n",
794 dev
->name
, ioaddr
, length
, tx_block
, lp
->tx_head
);
797 if (lp
->tx_head
!= lp
->tx_reap
)
801 static void el16_rx(struct net_device
*dev
)
803 struct net_local
*lp
= (struct net_local
*)dev
->priv
;
804 unsigned long shmem
= dev
->mem_start
;
805 ushort rx_head
= lp
->rx_head
;
806 ushort rx_tail
= lp
->rx_tail
;
807 ushort boguscount
= 10;
810 while ((frame_status
= readw(shmem
+rx_head
)) < 0) { /* Command complete */
811 unsigned long read_frame
= dev
->mem_start
+ rx_head
;
812 ushort rfd_cmd
= readw(read_frame
+2);
813 ushort next_rx_frame
= readw(read_frame
+4);
814 ushort data_buffer_addr
= readw(read_frame
+6);
815 unsigned long data_frame
= dev
->mem_start
+ data_buffer_addr
;
816 ushort pkt_len
= readw(data_frame
);
818 if (rfd_cmd
!= 0 || data_buffer_addr
!= rx_head
+ 22
819 || (pkt_len
& 0xC000) != 0xC000) {
820 printk("%s: Rx frame at %#x corrupted, status %04x cmd %04x"
821 "next %04x data-buf @%04x %04x.\n", dev
->name
, rx_head
,
822 frame_status
, rfd_cmd
, next_rx_frame
, data_buffer_addr
,
824 } else if ((frame_status
& 0x2000) == 0) {
825 /* Frame Rxed, but with error. */
826 lp
->stats
.rx_errors
++;
827 if (frame_status
& 0x0800) lp
->stats
.rx_crc_errors
++;
828 if (frame_status
& 0x0400) lp
->stats
.rx_frame_errors
++;
829 if (frame_status
& 0x0200) lp
->stats
.rx_fifo_errors
++;
830 if (frame_status
& 0x0100) lp
->stats
.rx_over_errors
++;
831 if (frame_status
& 0x0080) lp
->stats
.rx_length_errors
++;
833 /* Malloc up new buffer. */
837 skb
= dev_alloc_skb(pkt_len
+2);
839 printk("%s: Memory squeeze, dropping packet.\n", dev
->name
);
840 lp
->stats
.rx_dropped
++;
847 /* 'skb->data' points to the start of sk_buff data area. */
848 memcpy_fromio(skb_put(skb
,pkt_len
), data_frame
+ 10, pkt_len
);
850 skb
->protocol
=eth_type_trans(skb
,dev
);
852 lp
->stats
.rx_packets
++;
855 /* Clear the status word and set End-of-List on the rx frame. */
856 writew(0,read_frame
);
857 writew(0xC000,read_frame
+2);
858 /* Clear the end-of-list on the prev. RFD. */
859 writew(0x0000,dev
->mem_start
+ rx_tail
+ 2);
862 rx_head
= next_rx_frame
;
863 if (--boguscount
== 0)
867 lp
->rx_head
= rx_head
;
868 lp
->rx_tail
= rx_tail
;
871 static char devicename
[9] = { 0, };
872 static struct net_device dev_3c507
= {
873 devicename
, /* device name is inserted by linux/drivers/net/net_init.c */
876 0, 0, 0, NULL
, el16_probe
879 static int io
= 0x300;
881 MODULE_PARM(io
, "i");
882 MODULE_PARM(irq
, "i");
884 int init_module(void)
887 printk("3c507: You should not use auto-probing with insmod!\n");
888 dev_3c507
.base_addr
= io
;
890 if (register_netdev(&dev_3c507
) != 0) {
891 printk("3c507: register_netdev() returned non-zero.\n");
900 unregister_netdev(&dev_3c507
);
901 kfree(dev_3c507
.priv
);
902 dev_3c507
.priv
= NULL
;
904 /* If we don't do this, we can't re-insmod it later. */
905 free_irq(dev_3c507
.irq
, &dev_3c507
);
906 release_region(dev_3c507
.base_addr
, EL16_IO_EXTENT
);
912 * compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -I/usr/src/linux/drivers/net -Wall -Wstrict-prototypes -O6 -m486 -c 3c507.c"
914 * kept-new-versions: 5