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/kernel.h> 44 #include <linux/sched.h> 45 #include <linux/types.h> 46 #include <linux/fcntl.h> 47 #include <linux/interrupt.h> 48 #include <linux/ptrace.h> 49 #include <linux/ioport.h> 51 #include <linux/string.h> 52 #include <linux/spinlock.h> 53 #include <asm/system.h> 54 #include <asm/bitops.h> 57 #include <linux/errno.h> 59 #include <linux/netdevice.h> 60 #include <linux/etherdevice.h> 61 #include <linux/skbuff.h> 62 #include <linux/malloc.h> 63 #include <linux/init.h> 66 /* use 0 for production, 1 for verification, 2..7 for debug */ 70 static unsigned int net_debug
= NET_DEBUG
; 72 /* A zero-terminated list of common I/O addresses to be probed. */ 73 static unsigned int netcard_portlist
[] __initdata
= 74 {0x300,0x320,0x340,0x280,0}; 77 Details of the i82586. 79 You'll really need the databook to understand the details of this part, 80 but the outline is that the i82586 has two separate processing units. 81 Both are started from a list of three configuration tables, of which only 82 the last, the System Control Block (SCB), is used after reset-time. The SCB 83 has the following fields: 86 Tx/Command block addr. 88 The command word accepts the following controls for the Tx and Rx units: 91 #define CUC_START 0x0100 92 #define CUC_RESUME 0x0200 93 #define CUC_SUSPEND 0x0300 94 #define RX_START 0x0010 95 #define RX_RESUME 0x0020 96 #define RX_SUSPEND 0x0030 98 /* The Rx unit uses a list of frame descriptors and a list of data buffer 99 descriptors. We use full-sized (1518 byte) data buffers, so there is 100 a one-to-one pairing of frame descriptors to buffer descriptors. 102 The Tx ("command") unit executes a list of commands that look like: 103 Status word Written by the 82586 when the command is done. 104 Command word Command in lower 3 bits, post-command action in upper 3 105 Link word The address of the next command. 106 Parameters (as needed). 108 Some definitions related to the Command Word are: 110 #define CMD_EOL 0x8000/* The last command of the list, stop. */ 111 #define CMD_SUSP 0x4000/* Suspend after doing cmd. */ 112 #define CMD_INTR 0x2000/* Interrupt after doing cmd. */ 115 CmdNOp
=0, CmdSASetup
=1, CmdConfigure
=2, CmdMulticastList
=3, 116 CmdTx
=4, CmdTDR
=5, CmdDump
=6, CmdDiagnose
=7}; 118 /* Information that need to be kept for each board. */ 120 struct net_device_stats stats
; 131 Details of the EtherLink16 Implementation 132 The 3c507 is a generic shared-memory i82586 implementation. 133 The host can map 16K, 32K, 48K, or 64K of the 64K memory into 134 0x0[CD][08]0000, or all 64K into 0xF[02468]0000. 137 /* Offsets from the base I/O address. */ 138 #define SA_DATA 0/* Station address data, or 3Com signature. */ 139 #define MISC_CTRL 6/* Switch the SA_DATA banks, and bus config bits. */ 140 #define RESET_IRQ 10/* Reset the latched IRQ line. */ 141 #define SIGNAL_CA 11/* Frob the 82586 Channel Attention line. */ 142 #define ROM_CONFIG 13 143 #define MEM_CONFIG 14 144 #define IRQ_CONFIG 15 145 #define EL16_IO_EXTENT 16 147 /* The ID port is used at boot-time to locate the ethercard. */ 148 #define ID_PORT 0x100 150 /* Offsets to registers in the mailbox (SCB). */ 151 #define iSCB_STATUS 0x8 153 #define iSCB_CBL 0xC/* Command BLock offset. */ 154 #define iSCB_RFA 0xE/* Rx Frame Area offset. */ 156 /* Since the 3c507 maps the shared memory window so that the last byte is 157 at 82586 address FFFF, the first byte is at 82586 address 0, 16K, 32K, or 158 48K corresponding to window sizes of 64K, 48K, 32K and 16K respectively. 159 We can account for this be setting the 'SBC Base' entry in the ISCP table 160 below for all the 16 bit offset addresses, and also adding the 'SCB Base' 161 value to all 24 bit physical addresses (in the SCP table and the TX and RX 165 #define SCB_BASE ((unsigned)64*1024 - (dev->mem_end - dev->mem_start)) 168 What follows in 'init_words[]' is the "program" that is downloaded to the 169 82586 memory. It's mostly tables and command blocks, and starts at the 170 reset address 0xfffff6. This is designed to be similar to the EtherExpress, 171 thus the unusual location of the SCB at 0x0008. 173 Even with the additional "don't care" values, doing it this way takes less 174 program space than initializing the individual tables, and I feel it's much 177 The databook is particularly useless for the first two structures, I had 178 to use the Crynwr driver as an example. 180 The memory setup is as follows: 183 #define CONFIG_CMD 0x0018 184 #define SET_SA_CMD 0x0024 185 #define SA_OFFSET 0x002A 186 #define IDLELOOP 0x30 188 #define TDR_TIME 0x3C 189 #define DUMP_CMD 0x40 190 #define DIAG_CMD 0x48 191 #define SET_MC_CMD 0x4E 192 #define DUMP_DATA 0x56/* A 170 byte buffer for dump and Set-MC into. */ 194 #define TX_BUF_START 0x0100 195 #define NUM_TX_BUFS 4 196 #define TX_BUF_SIZE (1518+14+20+16)/* packet+header+TBD */ 198 #define RX_BUF_START 0x2000 199 #define RX_BUF_SIZE (1518+14+18)/* packet+header+RBD */ 200 #define RX_BUF_END (dev->mem_end - dev->mem_start) 205 That's it: only 86 bytes to set up the beast, including every extra 206 command available. The 170 byte buffer at DUMP_DATA is shared between the 207 Dump command (called only by the diagnostic program) and the SetMulticastList 210 To complete the memory setup you only have to write the station address at 211 SA_OFFSET and create the Tx & Rx buffer lists. 213 The Tx command chain and buffer list is setup as follows: 214 A Tx command table, with the data buffer pointing to... 215 A Tx data buffer descriptor. The packet is in a single buffer, rather than 216 chaining together several smaller buffers. 217 A NoOp command, which initially points to itself, 220 A transmit is done by filling in the Tx command table and data buffer, 221 re-writing the NoOp command, and finally changing the offset of the last 222 command to point to the current Tx command. When the Tx command is finished, 223 it jumps to the NoOp, when it loops until the next Tx command changes the 224 "link offset" in the NoOp. This way the 82586 never has to go through the 225 slow restart sequence. 227 The Rx buffer list is set up in the obvious ring structure. We have enough 228 memory (and low enough interrupt latency) that we can avoid the complicated 229 Rx buffer linked lists by alway associating a full-size Rx data buffer with 232 I current use four transmit buffers starting at TX_BUF_START (0x0100), and 233 use the rest of memory, from RX_BUF_START to RX_BUF_END, for Rx buffers. 237 static unsigned short init_words
[] = { 238 /* System Configuration Pointer (SCP). */ 239 0x0000,/* Set bus size to 16 bits. */ 241 0x0000,0x0000,/* ISCP phys addr, set in init_82586_mem(). */ 243 /* Intermediate System Configuration Pointer (ISCP). */ 244 0x0001,/* Status word that's cleared when init is done. */ 245 0x0008,0,0,/* SCB offset, (skip, skip) */ 247 /* System Control Block (SCB). */ 248 0,0xf000|RX_START
|CUC_START
,/* SCB status and cmd. */ 249 CONFIG_CMD
,/* Command list pointer, points to Configure. */ 250 RX_BUF_START
,/* Rx block list. */ 251 0,0,0,0,/* Error count: CRC, align, buffer, overrun. */ 253 /* 0x0018: Configure command. Change to put MAC data with packet. */ 254 0, CmdConfigure
,/* Status, command. */ 255 SET_SA_CMD
,/* Next command is Set Station Addr. */ 256 0x0804,/* "4" bytes of config data, 8 byte FIFO. */ 257 0x2e40,/* Magic values, including MAC data location. */ 258 0,/* Unused pad word. */ 260 /* 0x0024: Setup station address command. */ 262 SET_MC_CMD
,/* Next command. */ 263 0xaa00,0xb000,0x0bad,/* Station address (to be filled in) */ 265 /* 0x0030: NOP, looping back to itself. Point to first Tx buffer to Tx. */ 266 0, CmdNOp
, IDLELOOP
,0/* pad */, 268 /* 0x0038: A unused Time-Domain Reflectometer command. */ 269 0, CmdTDR
, IDLELOOP
,0, 271 /* 0x0040: An unused Dump State command. */ 272 0, CmdDump
, IDLELOOP
, DUMP_DATA
, 274 /* 0x0048: An unused Diagnose command. */ 275 0, CmdDiagnose
, IDLELOOP
, 277 /* 0x004E: An empty set-multicast-list command. */ 278 0, CmdMulticastList
, IDLELOOP
,0, 281 /* Index to functions, as function prototypes. */ 283 externintel16_probe(struct net_device
*dev
);/* Called from Space.c */ 285 static intel16_probe1(struct net_device
*dev
,int ioaddr
); 286 static intel16_open(struct net_device
*dev
); 287 static intel16_send_packet(struct sk_buff
*skb
,struct net_device
*dev
); 288 static voidel16_interrupt(int irq
,void*dev_id
,struct pt_regs
*regs
); 289 static voidel16_rx(struct net_device
*dev
); 290 static intel16_close(struct net_device
*dev
); 291 static struct net_device_stats
*el16_get_stats(struct net_device
*dev
); 292 static voidel16_tx_timeout(struct net_device
*dev
); 294 static voidhardware_send_packet(struct net_device
*dev
,void*buf
,short length
); 295 static voidinit_82586_mem(struct net_device
*dev
); 298 /* Check for a network adaptor of this type, and return '0' iff one exists. 299 If dev->base_addr == 0, probe all likely locations. 300 If dev->base_addr == 1, always return failure. 301 If dev->base_addr == 2, (detachable devices only) allocate space for the 302 device and return success. 305 int __init
el16_probe(struct net_device
*dev
) 307 int base_addr
= dev
->base_addr
; 310 SET_MODULE_OWNER(dev
); 312 if(base_addr
>0x1ff)/* Check a single specified location. */ 313 returnel16_probe1(dev
, base_addr
); 314 else if(base_addr
!=0) 315 return-ENXIO
;/* Don't probe at all. */ 317 for(i
=0; netcard_portlist
[i
]; i
++) 318 if(el16_probe1(dev
, netcard_portlist
[i
]) ==0) 324 static int __init
el16_probe1(struct net_device
*dev
,int ioaddr
) 326 static unsigned char init_ID_done
=0, version_printed
=0; 327 int i
, irq
, irqval
, retval
; 328 struct net_local
*lp
; 330 if(init_ID_done
==0) { 331 ushort lrs_state
=0xff; 332 /* Send the ID sequence to the ID_PORT to enable the board(s). */ 334 for(i
=0; i
<255; i
++) { 335 outb(lrs_state
, ID_PORT
); 344 if(!request_region(ioaddr
, EL16_IO_EXTENT
, dev
->name
)) 347 if((inb(ioaddr
) !='*') || (inb(ioaddr
+1) !='3') || 348 (inb(ioaddr
+2) !='C') || (inb(ioaddr
+3) !='O')) { 353 if(net_debug
&& version_printed
++ ==0) 356 printk("%s: 3c507 at %#x,", dev
->name
, ioaddr
); 358 /* We should make a few more checks here, like the first three octets of 359 the S.A. for the manufacturer's code. */ 361 irq
=inb(ioaddr
+ IRQ_CONFIG
) &0x0f; 363 irqval
=request_irq(irq
, &el16_interrupt
,0, dev
->name
, dev
); 365 printk("unable to get IRQ %d (irqval=%d).\n", irq
, irqval
); 370 /* We've committed to using the board, and can start filling in *dev. */ 371 dev
->base_addr
= ioaddr
; 373 outb(0x01, ioaddr
+ MISC_CTRL
); 374 for(i
=0; i
<6; i
++) { 375 dev
->dev_addr
[i
] =inb(ioaddr
+ i
); 376 printk(" %02x", dev
->dev_addr
[i
]); 379 if((dev
->mem_start
&0xf) >0) 380 net_debug
= dev
->mem_start
&7; 383 dev
->mem_start
= MEM_BASE
; 384 dev
->mem_end
= dev
->mem_start
+0x10000; 389 char mem_config
=inb(ioaddr
+ MEM_CONFIG
); 390 if(mem_config
&0x20) { 392 base
=0xf00000+ (mem_config
&0x08?0x080000 393 : ((mem_config
&3) <<17)); 395 size
= ((mem_config
&3) +1) <<14; 396 base
=0x0c0000+ ( (mem_config
&0x18) <<12); 398 dev
->mem_start
= base
; 399 dev
->mem_end
= base
+ size
; 403 dev
->if_port
= (inb(ioaddr
+ ROM_CONFIG
) &0x80) ?1:0; 404 dev
->irq
=inb(ioaddr
+ IRQ_CONFIG
) &0x0f; 406 printk(", IRQ %d, %sternal xcvr, memory %#lx-%#lx.\n", dev
->irq
, 407 dev
->if_port
?"ex":"in", dev
->mem_start
, dev
->mem_end
-1); 412 /* Initialize the device structure. */ 413 lp
= dev
->priv
=kmalloc(sizeof(struct net_local
), GFP_KERNEL
); 414 if(dev
->priv
== NULL
) { 418 memset(dev
->priv
,0,sizeof(struct net_local
)); 419 spin_lock_init(&lp
->lock
); 421 dev
->open
= el16_open
; 422 dev
->stop
= el16_close
; 423 dev
->hard_start_xmit
= el16_send_packet
; 424 dev
->get_stats
= el16_get_stats
; 425 dev
->tx_timeout
= el16_tx_timeout
; 426 dev
->watchdog_timeo
= TX_TIMEOUT
; 428 ether_setup(dev
);/* Generic ethernet behaviour */ 430 dev
->flags
&=~IFF_MULTICAST
;/* Multicast doesn't work */ 434 release_region(ioaddr
, EL16_IO_EXTENT
); 438 static intel16_open(struct net_device
*dev
) 440 /* Initialize the 82586 memory and start it. */ 443 netif_start_queue(dev
); 448 static voidel16_tx_timeout(struct net_device
*dev
) 450 struct net_local
*lp
= (struct net_local
*) dev
->priv
; 451 int ioaddr
= dev
->base_addr
; 452 unsigned long shmem
= dev
->mem_start
; 455 printk("%s: transmit timed out, %s? ", dev
->name
, 456 isa_readw(shmem
+ iSCB_STATUS
) &0x8000?"IRQ conflict": 457 "network cable problem"); 458 /* Try to restart the adaptor. */ 459 if(lp
->last_restart
== lp
->stats
.tx_packets
) { 461 printk("Resetting board.\n"); 462 /* Completely reset the adaptor. */ 465 /* Issue the channel attention signal and hope it "gets better". */ 467 printk("Kicking board.\n"); 468 isa_writew(0xf000| CUC_START
| RX_START
, shmem
+ iSCB_CMD
); 469 outb(0, ioaddr
+ SIGNAL_CA
);/* Issue channel-attn. */ 470 lp
->last_restart
= lp
->stats
.tx_packets
; 472 dev
->trans_start
= jiffies
; 473 netif_wake_queue(dev
); 477 static intel16_send_packet(struct sk_buff
*skb
,struct net_device
*dev
) 479 struct net_local
*lp
= (struct net_local
*) dev
->priv
; 480 int ioaddr
= dev
->base_addr
; 482 short length
= ETH_ZLEN
< skb
->len
? skb
->len
: ETH_ZLEN
; 483 unsigned char*buf
= skb
->data
; 485 netif_stop_queue(dev
); 487 spin_lock_irqsave(&lp
->lock
, flags
); 489 lp
->stats
.tx_bytes
+= length
; 490 /* Disable the 82586's input to the interrupt line. */ 491 outb(0x80, ioaddr
+ MISC_CTRL
); 493 hardware_send_packet(dev
, buf
, length
); 495 dev
->trans_start
= jiffies
; 496 /* Enable the 82586 interrupt input. */ 497 outb(0x84, ioaddr
+ MISC_CTRL
); 499 spin_unlock_irqrestore(&lp
->lock
, flags
); 503 /* You might need to clean up and record Tx statistics here. */ 508 /* The typical workload of the driver: 509 Handle the network interface interrupts. */ 510 static voidel16_interrupt(int irq
,void*dev_id
,struct pt_regs
*regs
) 512 struct net_device
*dev
= dev_id
; 513 struct net_local
*lp
; 514 int ioaddr
, status
, boguscount
=0; 519 printk("net_interrupt(): irq %d for unknown device.\n", irq
); 523 ioaddr
= dev
->base_addr
; 524 lp
= (struct net_local
*)dev
->priv
; 525 shmem
= dev
->mem_start
; 527 spin_lock(&lp
->lock
); 529 status
=isa_readw(shmem
+iSCB_STATUS
); 532 printk("%s: 3c507 interrupt, status %4.4x.\n", dev
->name
, status
); 535 /* Disable the 82586's input to the interrupt line. */ 536 outb(0x80, ioaddr
+ MISC_CTRL
); 538 /* Reap the Tx packet buffers. */ 539 while(lp
->tx_reap
!= lp
->tx_head
) { 540 unsigned short tx_status
=isa_readw(shmem
+lp
->tx_reap
); 543 if(net_debug
>5)printk("Couldn't reap %#x.\n", lp
->tx_reap
); 546 if(tx_status
&0x2000) { 547 lp
->stats
.tx_packets
++; 548 lp
->stats
.collisions
+= tx_status
&0xf; 549 netif_wake_queue(dev
); 551 lp
->stats
.tx_errors
++; 552 if(tx_status
&0x0600) lp
->stats
.tx_carrier_errors
++; 553 if(tx_status
&0x0100) lp
->stats
.tx_fifo_errors
++; 554 if(!(tx_status
&0x0040)) lp
->stats
.tx_heartbeat_errors
++; 555 if(tx_status
&0x0020) lp
->stats
.tx_aborted_errors
++; 558 printk("Reaped %x, Tx status %04x.\n", lp
->tx_reap
, tx_status
); 559 lp
->tx_reap
+= TX_BUF_SIZE
; 560 if(lp
->tx_reap
> RX_BUF_START
- TX_BUF_SIZE
) 561 lp
->tx_reap
= TX_BUF_START
; 566 if(status
&0x4000) {/* Packet received. */ 568 printk("Received packet, rx_head %04x.\n", lp
->rx_head
); 572 /* Acknowledge the interrupt sources. */ 573 ack_cmd
= status
&0xf000; 575 if((status
&0x0700) !=0x0200&&netif_running(dev
)) { 577 printk("%s: Command unit stopped, status %04x, restarting.\n", 579 /* If this ever occurs we should really re-write the idle loop, reset 580 the Tx list, and do a complete restart of the command unit. 581 For now we rely on the Tx timeout if the resume doesn't work. */ 582 ack_cmd
|= CUC_RESUME
; 585 if((status
&0x0070) !=0x0040&&netif_running(dev
)) { 586 static voidinit_rx_bufs(struct net_device
*); 587 /* The Rx unit is not ready, it must be hung. Restart the receiver by 588 initializing the rx buffers, and issuing an Rx start command. */ 590 printk("%s: Rx unit stopped, status %04x, restarting.\n", 593 isa_writew(RX_BUF_START
,shmem
+iSCB_RFA
); 597 isa_writew(ack_cmd
,shmem
+iSCB_CMD
); 598 outb(0, ioaddr
+ SIGNAL_CA
);/* Issue channel-attn. */ 600 /* Clear the latched interrupt. */ 601 outb(0, ioaddr
+ RESET_IRQ
); 603 /* Enable the 82586's interrupt input. */ 604 outb(0x84, ioaddr
+ MISC_CTRL
); 605 spin_unlock(&lp
->lock
); 608 static intel16_close(struct net_device
*dev
) 610 int ioaddr
= dev
->base_addr
; 611 unsigned long shmem
= dev
->mem_start
; 613 netif_stop_queue(dev
); 615 /* Flush the Tx and disable Rx. */ 616 isa_writew(RX_SUSPEND
| CUC_SUSPEND
,shmem
+iSCB_CMD
); 617 outb(0, ioaddr
+ SIGNAL_CA
); 619 /* Disable the 82586's input to the interrupt line. */ 620 outb(0x80, ioaddr
+ MISC_CTRL
); 622 /* We always physically use the IRQ line, so we don't do free_irq(). */ 624 /* Update the statistics here. */ 629 /* Get the current statistics. This may be called with the card open or 631 static struct net_device_stats
*el16_get_stats(struct net_device
*dev
) 633 struct net_local
*lp
= (struct net_local
*)dev
->priv
; 635 /* ToDo: decide if there are any useful statistics from the SCB. */ 640 /* Initialize the Rx-block list. */ 641 static voidinit_rx_bufs(struct net_device
*dev
) 643 struct net_local
*lp
= (struct net_local
*)dev
->priv
; 644 unsigned long write_ptr
; 645 unsigned short SCB_base
= SCB_BASE
; 647 int cur_rxbuf
= lp
->rx_head
= RX_BUF_START
; 649 /* Initialize each Rx frame + data buffer. */ 650 do{/* While there is room for one more. */ 652 write_ptr
= dev
->mem_start
+ cur_rxbuf
; 654 isa_writew(0x0000,write_ptr
);/* Status */ 655 isa_writew(0x0000,write_ptr
+=2);/* Command */ 656 isa_writew(cur_rxbuf
+ RX_BUF_SIZE
,write_ptr
+=2);/* Link */ 657 isa_writew(cur_rxbuf
+22,write_ptr
+=2);/* Buffer offset */ 658 isa_writew(0x0000,write_ptr
+=2);/* Pad for dest addr. */ 659 isa_writew(0x0000,write_ptr
+=2); 660 isa_writew(0x0000,write_ptr
+=2); 661 isa_writew(0x0000,write_ptr
+=2);/* Pad for source addr. */ 662 isa_writew(0x0000,write_ptr
+=2); 663 isa_writew(0x0000,write_ptr
+=2); 664 isa_writew(0x0000,write_ptr
+=2);/* Pad for protocol. */ 666 isa_writew(0x0000,write_ptr
+=2);/* Buffer: Actual count */ 667 isa_writew(-1,write_ptr
+=2);/* Buffer: Next (none). */ 668 isa_writew(cur_rxbuf
+0x20+ SCB_base
,write_ptr
+=2);/* Buffer: Address low */ 669 isa_writew(0x0000,write_ptr
+=2); 670 /* Finally, the number of bytes in the buffer. */ 671 isa_writew(0x8000+ RX_BUF_SIZE
-0x20,write_ptr
+=2); 673 lp
->rx_tail
= cur_rxbuf
; 674 cur_rxbuf
+= RX_BUF_SIZE
; 675 }while(cur_rxbuf
<= RX_BUF_END
- RX_BUF_SIZE
); 677 /* Terminate the list by setting the EOL bit, and wrap the pointer to make 679 write_ptr
= dev
->mem_start
+ lp
->rx_tail
+2; 680 isa_writew(0xC000,write_ptr
);/* Command, mark as last. */ 681 isa_writew(lp
->rx_head
,write_ptr
+2);/* Link */ 684 static voidinit_82586_mem(struct net_device
*dev
) 686 struct net_local
*lp
= (struct net_local
*)dev
->priv
; 687 short ioaddr
= dev
->base_addr
; 688 unsigned long shmem
= dev
->mem_start
; 690 /* Enable loopback to protect the wire while starting up, 691 and hold the 586 in reset during the memory initialization. */ 692 outb(0x20, ioaddr
+ MISC_CTRL
); 694 /* Fix the ISCP address and base. */ 695 init_words
[3] = SCB_BASE
; 696 init_words
[7] = SCB_BASE
; 698 /* Write the words at 0xfff6 (address-aliased to 0xfffff6). */ 699 isa_memcpy_toio(dev
->mem_end
-10, init_words
,10); 701 /* Write the words at 0x0000. */ 702 isa_memcpy_toio(dev
->mem_start
, init_words
+5,sizeof(init_words
) -10); 704 /* Fill in the station address. */ 705 isa_memcpy_toio(dev
->mem_start
+SA_OFFSET
, dev
->dev_addr
, 706 sizeof(dev
->dev_addr
)); 708 /* The Tx-block list is written as needed. We just set up the values. */ 709 lp
->tx_cmd_link
= IDLELOOP
+4; 710 lp
->tx_head
= lp
->tx_reap
= TX_BUF_START
; 714 /* Start the 586 by releasing the reset line, but leave loopback. */ 715 outb(0xA0, ioaddr
+ MISC_CTRL
); 717 /* This was time consuming to track down: you need to give two channel 718 attention signals to reliably start up the i82586. */ 719 outb(0, ioaddr
+ SIGNAL_CA
); 723 while(isa_readw(shmem
+iSCB_STATUS
) ==0) 725 printk("%s: i82586 initialization timed out with status %04x," 726 "cmd %04x.\n", dev
->name
, 727 isa_readw(shmem
+iSCB_STATUS
),isa_readw(shmem
+iSCB_CMD
)); 730 /* Issue channel-attn -- the 82586 won't start. */ 731 outb(0, ioaddr
+ SIGNAL_CA
); 734 /* Disable loopback and enable interrupts. */ 735 outb(0x84, ioaddr
+ MISC_CTRL
); 737 printk("%s: Initialized 82586, status %04x.\n", dev
->name
, 738 isa_readw(shmem
+iSCB_STATUS
)); 742 static voidhardware_send_packet(struct net_device
*dev
,void*buf
,short length
) 744 struct net_local
*lp
= (struct net_local
*)dev
->priv
; 745 short ioaddr
= dev
->base_addr
; 746 ushort tx_block
= lp
->tx_head
; 747 unsigned long write_ptr
= dev
->mem_start
+ tx_block
; 749 /* Set the write pointer to the Tx block, and put out the header. */ 750 isa_writew(0x0000,write_ptr
);/* Tx status */ 751 isa_writew(CMD_INTR
|CmdTx
,write_ptr
+=2);/* Tx command */ 752 isa_writew(tx_block
+16,write_ptr
+=2);/* Next command is a NoOp. */ 753 isa_writew(tx_block
+8,write_ptr
+=2);/* Data Buffer offset. */ 755 /* Output the data buffer descriptor. */ 756 isa_writew(length
|0x8000,write_ptr
+=2);/* Byte count parameter. */ 757 isa_writew(-1,write_ptr
+=2);/* No next data buffer. */ 758 isa_writew(tx_block
+22+SCB_BASE
,write_ptr
+=2);/* Buffer follows the NoOp command. */ 759 isa_writew(0x0000,write_ptr
+=2);/* Buffer address high bits (always zero). */ 761 /* Output the Loop-back NoOp command. */ 762 isa_writew(0x0000,write_ptr
+=2);/* Tx status */ 763 isa_writew(CmdNOp
,write_ptr
+=2);/* Tx command */ 764 isa_writew(tx_block
+16,write_ptr
+=2);/* Next is myself. */ 766 /* Output the packet at the write pointer. */ 767 isa_memcpy_toio(write_ptr
+2, buf
, length
); 769 /* Set the old command link pointing to this send packet. */ 770 isa_writew(tx_block
,dev
->mem_start
+ lp
->tx_cmd_link
); 771 lp
->tx_cmd_link
= tx_block
+20; 773 /* Set the next free tx region. */ 774 lp
->tx_head
= tx_block
+ TX_BUF_SIZE
; 775 if(lp
->tx_head
> RX_BUF_START
- TX_BUF_SIZE
) 776 lp
->tx_head
= TX_BUF_START
; 779 printk("%s: 3c507 @%x send length = %d, tx_block %3x, next %3x.\n", 780 dev
->name
, ioaddr
, length
, tx_block
, lp
->tx_head
); 783 if(lp
->tx_head
!= lp
->tx_reap
) 784 netif_wake_queue(dev
); 787 static voidel16_rx(struct net_device
*dev
) 789 struct net_local
*lp
= (struct net_local
*)dev
->priv
; 790 unsigned long shmem
= dev
->mem_start
; 791 ushort rx_head
= lp
->rx_head
; 792 ushort rx_tail
= lp
->rx_tail
; 793 ushort boguscount
=10; 796 while((frame_status
=isa_readw(shmem
+rx_head
)) <0) {/* Command complete */ 797 unsigned long read_frame
= dev
->mem_start
+ rx_head
; 798 ushort rfd_cmd
=isa_readw(read_frame
+2); 799 ushort next_rx_frame
=isa_readw(read_frame
+4); 800 ushort data_buffer_addr
=isa_readw(read_frame
+6); 801 unsigned long data_frame
= dev
->mem_start
+ data_buffer_addr
; 802 ushort pkt_len
=isa_readw(data_frame
); 804 if(rfd_cmd
!=0|| data_buffer_addr
!= rx_head
+22 805 || (pkt_len
&0xC000) !=0xC000) { 806 printk("%s: Rx frame at %#x corrupted, status %04x cmd %04x" 807 "next %04x data-buf @%04x %04x.\n", dev
->name
, rx_head
, 808 frame_status
, rfd_cmd
, next_rx_frame
, data_buffer_addr
, 810 }else if((frame_status
&0x2000) ==0) { 811 /* Frame Rxed, but with error. */ 812 lp
->stats
.rx_errors
++; 813 if(frame_status
&0x0800) lp
->stats
.rx_crc_errors
++; 814 if(frame_status
&0x0400) lp
->stats
.rx_frame_errors
++; 815 if(frame_status
&0x0200) lp
->stats
.rx_fifo_errors
++; 816 if(frame_status
&0x0100) lp
->stats
.rx_over_errors
++; 817 if(frame_status
&0x0080) lp
->stats
.rx_length_errors
++; 819 /* Malloc up new buffer. */ 823 skb
=dev_alloc_skb(pkt_len
+2); 825 printk("%s: Memory squeeze, dropping packet.\n", dev
->name
); 826 lp
->stats
.rx_dropped
++; 833 /* 'skb->data' points to the start of sk_buff data area. */ 834 isa_memcpy_fromio(skb_put(skb
,pkt_len
), data_frame
+10, pkt_len
); 836 skb
->protocol
=eth_type_trans(skb
,dev
); 838 lp
->stats
.rx_packets
++; 841 /* Clear the status word and set End-of-List on the rx frame. */ 842 isa_writew(0,read_frame
); 843 isa_writew(0xC000,read_frame
+2); 844 /* Clear the end-of-list on the prev. RFD. */ 845 isa_writew(0x0000,dev
->mem_start
+ rx_tail
+2); 848 rx_head
= next_rx_frame
; 853 lp
->rx_head
= rx_head
; 854 lp
->rx_tail
= rx_tail
; 857 static struct net_device dev_3c507
; 858 static int io
=0x300; 861 MODULE_PARM(irq
,"i"); 866 printk("3c507: You should not use auto-probing with insmod!\n"); 867 dev_3c507
.base_addr
= io
; 869 dev_3c507
.init
= el16_probe
; 870 if(register_netdev(&dev_3c507
) !=0) { 871 printk("3c507: register_netdev() returned non-zero.\n"); 880 unregister_netdev(&dev_3c507
); 881 kfree(dev_3c507
.priv
); 882 dev_3c507
.priv
= NULL
; 884 /* If we don't do this, we can't re-insmod it later. */ 885 free_irq(dev_3c507
.irq
, &dev_3c507
); 886 release_region(dev_3c507
.base_addr
, EL16_IO_EXTENT
); 892 * 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" 894 * kept-new-versions: 5