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 <asm/system.h> 53 #include <asm/bitops.h> 56 #include <asm/spinlock.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) 203 That's it: only 86 bytes to set up the beast, including every extra 204 command available. The 170 byte buffer at DUMP_DATA is shared between the 205 Dump command (called only by the diagnostic program) and the SetMulticastList 208 To complete the memory setup you only have to write the station address at 209 SA_OFFSET and create the Tx & Rx buffer lists. 211 The Tx command chain and buffer list is setup as follows: 212 A Tx command table, with the data buffer pointing to... 213 A Tx data buffer descriptor. The packet is in a single buffer, rather than 214 chaining together several smaller buffers. 215 A NoOp command, which initially points to itself, 218 A transmit is done by filling in the Tx command table and data buffer, 219 re-writing the NoOp command, and finally changing the offset of the last 220 command to point to the current Tx command. When the Tx command is finished, 221 it jumps to the NoOp, when it loops until the next Tx command changes the 222 "link offset" in the NoOp. This way the 82586 never has to go through the 223 slow restart sequence. 225 The Rx buffer list is set up in the obvious ring structure. We have enough 226 memory (and low enough interrupt latency) that we can avoid the complicated 227 Rx buffer linked lists by alway associating a full-size Rx data buffer with 230 I current use four transmit buffers starting at TX_BUF_START (0x0100), and 231 use the rest of memory, from RX_BUF_START to RX_BUF_END, for Rx buffers. 235 static unsigned short init_words
[] = { 236 /* System Configuration Pointer (SCP). */ 237 0x0000,/* Set bus size to 16 bits. */ 239 0x0000,0x0000,/* ISCP phys addr, set in init_82586_mem(). */ 241 /* Intermediate System Configuration Pointer (ISCP). */ 242 0x0001,/* Status word that's cleared when init is done. */ 243 0x0008,0,0,/* SCB offset, (skip, skip) */ 245 /* System Control Block (SCB). */ 246 0,0xf000|RX_START
|CUC_START
,/* SCB status and cmd. */ 247 CONFIG_CMD
,/* Command list pointer, points to Configure. */ 248 RX_BUF_START
,/* Rx block list. */ 249 0,0,0,0,/* Error count: CRC, align, buffer, overrun. */ 251 /* 0x0018: Configure command. Change to put MAC data with packet. */ 252 0, CmdConfigure
,/* Status, command. */ 253 SET_SA_CMD
,/* Next command is Set Station Addr. */ 254 0x0804,/* "4" bytes of config data, 8 byte FIFO. */ 255 0x2e40,/* Magic values, including MAC data location. */ 256 0,/* Unused pad word. */ 258 /* 0x0024: Setup station address command. */ 260 SET_MC_CMD
,/* Next command. */ 261 0xaa00,0xb000,0x0bad,/* Station address (to be filled in) */ 263 /* 0x0030: NOP, looping back to itself. Point to first Tx buffer to Tx. */ 264 0, CmdNOp
, IDLELOOP
,0/* pad */, 266 /* 0x0038: A unused Time-Domain Reflectometer command. */ 267 0, CmdTDR
, IDLELOOP
,0, 269 /* 0x0040: An unused Dump State command. */ 270 0, CmdDump
, IDLELOOP
, DUMP_DATA
, 272 /* 0x0048: An unused Diagnose command. */ 273 0, CmdDiagnose
, IDLELOOP
, 275 /* 0x004E: An empty set-multicast-list command. */ 276 0, CmdMulticastList
, IDLELOOP
,0, 279 /* Index to functions, as function prototypes. */ 281 externintel16_probe(struct device
*dev
);/* Called from Space.c */ 283 static intel16_probe1(struct device
*dev
,int ioaddr
); 284 static intel16_open(struct device
*dev
); 285 static intel16_send_packet(struct sk_buff
*skb
,struct device
*dev
); 286 static voidel16_interrupt(int irq
,void*dev_id
,struct pt_regs
*regs
); 287 static voidel16_rx(struct device
*dev
); 288 static intel16_close(struct device
*dev
); 289 static struct net_device_stats
*el16_get_stats(struct device
*dev
); 291 static voidhardware_send_packet(struct device
*dev
,void*buf
,short length
); 292 static voidinit_82586_mem(struct device
*dev
); 296 struct netdev_entry netcard_drv
= 297 {"3c507", el16_probe1
, EL16_IO_EXTENT
, netcard_portlist
}; 300 /* Check for a network adaptor of this type, and return '0' iff one exists. 301 If dev->base_addr == 0, probe all likely locations. 302 If dev->base_addr == 1, always return failure. 303 If dev->base_addr == 2, (detachable devices only) allocate space for the 304 device and return success. 307 __initfunc(intel16_probe(struct device
*dev
)) 309 int base_addr
= dev
? dev
->base_addr
:0; 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 int ioaddr
= netcard_portlist
[i
]; 319 if(check_region(ioaddr
, EL16_IO_EXTENT
)) 321 if(el16_probe1(dev
, ioaddr
) ==0) 328 __initfunc(intel16_probe1(struct device
*dev
,int ioaddr
)) 330 static unsigned char init_ID_done
=0, version_printed
=0; 333 if(init_ID_done
==0) { 334 ushort lrs_state
=0xff; 335 /* Send the ID sequence to the ID_PORT to enable the board(s). */ 337 for(i
=0; i
<255; i
++) { 338 outb(lrs_state
, ID_PORT
); 347 if(inb(ioaddr
) =='*'&&inb(ioaddr
+1) =='3' 348 &&inb(ioaddr
+2) =='C'&&inb(ioaddr
+3) =='O') 353 /* Allocate a new 'dev' if needed. */ 355 dev
=init_etherdev(0,sizeof(struct net_local
)); 357 if(net_debug
&& version_printed
++ ==0) 360 printk("%s: 3c507 at %#x,", dev
->name
, ioaddr
); 362 /* We should make a few more checks here, like the first three octets of 363 the S.A. for the manufacturer's code. */ 365 irq
=inb(ioaddr
+ IRQ_CONFIG
) &0x0f; 367 irqval
=request_irq(irq
, &el16_interrupt
,0,"3c507", dev
); 369 printk("unable to get IRQ %d (irqval=%d).\n", irq
, irqval
); 373 /* We've committed to using the board, and can start filling in *dev. */ 374 request_region(ioaddr
, EL16_IO_EXTENT
,"3c507"); 375 dev
->base_addr
= ioaddr
; 377 outb(0x01, ioaddr
+ MISC_CTRL
); 378 for(i
=0; i
<6; i
++) { 379 dev
->dev_addr
[i
] =inb(ioaddr
+ i
); 380 printk(" %02x", dev
->dev_addr
[i
]); 383 if((dev
->mem_start
&0xf) >0) 384 net_debug
= dev
->mem_start
&7; 387 dev
->mem_start
= MEM_BASE
; 388 dev
->mem_end
= dev
->mem_start
+0x10000; 393 char mem_config
=inb(ioaddr
+ MEM_CONFIG
); 394 if(mem_config
&0x20) { 396 base
=0xf00000+ (mem_config
&0x08?0x080000 397 : ((mem_config
&3) <<17)); 399 size
= ((mem_config
&3) +1) <<14; 400 base
=0x0c0000+ ( (mem_config
&0x18) <<12); 402 dev
->mem_start
= base
; 403 dev
->mem_end
= base
+ size
; 407 dev
->if_port
= (inb(ioaddr
+ ROM_CONFIG
) &0x80) ?1:0; 408 dev
->irq
=inb(ioaddr
+ IRQ_CONFIG
) &0x0f; 410 printk(", IRQ %d, %sternal xcvr, memory %#lx-%#lx.\n", dev
->irq
, 411 dev
->if_port
?"ex":"in", dev
->mem_start
, dev
->mem_end
-1); 416 /* Initialize the device structure. */ 417 dev
->priv
=kmalloc(sizeof(struct net_local
), GFP_KERNEL
); 418 if(dev
->priv
== NULL
) 420 memset(dev
->priv
,0,sizeof(struct net_local
)); 422 dev
->open
= el16_open
; 423 dev
->stop
= el16_close
; 424 dev
->hard_start_xmit
= el16_send_packet
; 425 dev
->get_stats
= el16_get_stats
; 427 ether_setup(dev
);/* Generic ethernet behaviour */ 429 dev
->flags
&=~IFF_MULTICAST
;/* Multicast doesn't work */ 434 static intel16_open(struct device
*dev
) 436 /* Initialize the 82586 memory and start it. */ 448 static intel16_send_packet(struct sk_buff
*skb
,struct 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
; 457 /* If we get here, some higher level has decided we are broken. 458 There should really be a "kick me" function call instead. */ 459 int tickssofar
= jiffies
- dev
->trans_start
; 463 printk("%s: transmit timed out, %s? ", dev
->name
, 464 readw(shmem
+iSCB_STATUS
) &0x8000?"IRQ conflict": 465 "network cable problem"); 466 /* Try to restart the adaptor. */ 467 if(lp
->last_restart
== lp
->stats
.tx_packets
) { 468 if(net_debug
>1)printk("Resetting board.\n"); 469 /* Completely reset the adaptor. */ 472 /* Issue the channel attention signal and hope it "gets better". */ 473 if(net_debug
>1)printk("Kicking board.\n"); 474 writew(0xf000|CUC_START
|RX_START
,shmem
+iSCB_CMD
); 475 outb(0, ioaddr
+ SIGNAL_CA
);/* Issue channel-attn. */ 476 lp
->last_restart
= lp
->stats
.tx_packets
; 479 dev
->trans_start
= jiffies
; 482 /* Block a timer-based transmit from overlapping. */ 483 if(test_and_set_bit(0, (void*)&dev
->tbusy
) !=0) 484 printk("%s: Transmitter access conflict.\n", dev
->name
); 487 short length
= ETH_ZLEN
< skb
->len
? skb
->len
: ETH_ZLEN
; 488 unsigned char*buf
= skb
->data
; 490 lp
->stats
.tx_bytes
+=length
; 491 /* Disable the 82586's input to the interrupt line. */ 492 outb(0x80, ioaddr
+ MISC_CTRL
); 494 spin_lock_irqsave(&lp
->lock
, flags
); 495 hardware_send_packet(dev
, buf
, length
); 496 spin_unlock_irqrestore(&lp
->lock
, flags
); 498 hardware_send_packet(dev
, buf
, length
); 500 dev
->trans_start
= jiffies
; 501 /* Enable the 82586 interrupt input. */ 502 outb(0x84, ioaddr
+ MISC_CTRL
); 507 /* You might need to clean up and record Tx statistics here. */ 512 /* The typical workload of the driver: 513 Handle the network interface interrupts. */ 514 static voidel16_interrupt(int irq
,void*dev_id
,struct pt_regs
*regs
) 516 struct device
*dev
= dev_id
; 517 struct net_local
*lp
; 518 int ioaddr
, status
, boguscount
=0; 523 printk("net_interrupt(): irq %d for unknown device.\n", irq
); 529 ioaddr
= dev
->base_addr
; 530 lp
= (struct net_local
*)dev
->priv
; 531 shmem
= dev
->mem_start
; 533 spin_lock(&lp
->lock
); 535 status
=readw(shmem
+iSCB_STATUS
); 538 printk("%s: 3c507 interrupt, status %4.4x.\n", dev
->name
, status
); 541 /* Disable the 82586's input to the interrupt line. */ 542 outb(0x80, ioaddr
+ MISC_CTRL
); 544 /* Reap the Tx packet buffers. */ 545 while(lp
->tx_reap
!= lp
->tx_head
) { 546 unsigned short tx_status
=readw(shmem
+lp
->tx_reap
); 549 if(net_debug
>5)printk("Couldn't reap %#x.\n", lp
->tx_reap
); 552 if(tx_status
&0x2000) { 553 lp
->stats
.tx_packets
++; 554 lp
->stats
.collisions
+= tx_status
&0xf; 556 mark_bh(NET_BH
);/* Inform upper layers. */ 558 lp
->stats
.tx_errors
++; 559 if(tx_status
&0x0600) lp
->stats
.tx_carrier_errors
++; 560 if(tx_status
&0x0100) lp
->stats
.tx_fifo_errors
++; 561 if(!(tx_status
&0x0040)) lp
->stats
.tx_heartbeat_errors
++; 562 if(tx_status
&0x0020) lp
->stats
.tx_aborted_errors
++; 565 printk("Reaped %x, Tx status %04x.\n", lp
->tx_reap
, tx_status
); 566 lp
->tx_reap
+= TX_BUF_SIZE
; 567 if(lp
->tx_reap
> RX_BUF_START
- TX_BUF_SIZE
) 568 lp
->tx_reap
= TX_BUF_START
; 573 if(status
&0x4000) {/* Packet received. */ 575 printk("Received packet, rx_head %04x.\n", lp
->rx_head
); 579 /* Acknowledge the interrupt sources. */ 580 ack_cmd
= status
&0xf000; 582 if((status
&0x0700) !=0x0200&& dev
->start
) { 584 printk("%s: Command unit stopped, status %04x, restarting.\n", 586 /* If this ever occurs we should really re-write the idle loop, reset 587 the Tx list, and do a complete restart of the command unit. 588 For now we rely on the Tx timeout if the resume doesn't work. */ 589 ack_cmd
|= CUC_RESUME
; 592 if((status
&0x0070) !=0x0040&& dev
->start
) 594 static voidinit_rx_bufs(struct device
*); 595 /* The Rx unit is not ready, it must be hung. Restart the receiver by 596 initializing the rx buffers, and issuing an Rx start command. */ 598 printk("%s: Rx unit stopped, status %04x, restarting.\n", 601 writew(RX_BUF_START
,shmem
+iSCB_RFA
); 605 writew(ack_cmd
,shmem
+iSCB_CMD
); 606 outb(0, ioaddr
+ SIGNAL_CA
);/* Issue channel-attn. */ 608 /* Clear the latched interrupt. */ 609 outb(0, ioaddr
+ RESET_IRQ
); 611 /* Enable the 82586's interrupt input. */ 612 outb(0x84, ioaddr
+ MISC_CTRL
); 613 spin_unlock(&lp
->lock
); 618 static intel16_close(struct device
*dev
) 620 int ioaddr
= dev
->base_addr
; 621 unsigned long shmem
= dev
->mem_start
; 626 /* Flush the Tx and disable Rx. */ 627 writew(RX_SUSPEND
| CUC_SUSPEND
,shmem
+iSCB_CMD
); 628 outb(0, ioaddr
+ SIGNAL_CA
); 630 /* Disable the 82586's input to the interrupt line. */ 631 outb(0x80, ioaddr
+ MISC_CTRL
); 633 /* We always physically use the IRQ line, so we don't do free_irq(). */ 635 /* Update the statistics here. */ 642 /* Get the current statistics. This may be called with the card open or 644 static struct net_device_stats
*el16_get_stats(struct device
*dev
) 646 struct net_local
*lp
= (struct net_local
*)dev
->priv
; 648 /* ToDo: decide if there are any useful statistics from the SCB. */ 653 /* Initialize the Rx-block list. */ 654 static voidinit_rx_bufs(struct device
*dev
) 656 struct net_local
*lp
= (struct net_local
*)dev
->priv
; 657 unsigned long write_ptr
; 658 unsigned short SCB_base
= SCB_BASE
; 660 int cur_rxbuf
= lp
->rx_head
= RX_BUF_START
; 662 /* Initialize each Rx frame + data buffer. */ 663 do{/* While there is room for one more. */ 665 write_ptr
= dev
->mem_start
+ cur_rxbuf
; 667 writew(0x0000,write_ptr
);/* Status */ 668 writew(0x0000,write_ptr
+=2);/* Command */ 669 writew(cur_rxbuf
+ RX_BUF_SIZE
,write_ptr
+=2);/* Link */ 670 writew(cur_rxbuf
+22,write_ptr
+=2);/* Buffer offset */ 671 writew(0x0000,write_ptr
+=2);/* Pad for dest addr. */ 672 writew(0x0000,write_ptr
+=2); 673 writew(0x0000,write_ptr
+=2); 674 writew(0x0000,write_ptr
+=2);/* Pad for source addr. */ 675 writew(0x0000,write_ptr
+=2); 676 writew(0x0000,write_ptr
+=2); 677 writew(0x0000,write_ptr
+=2);/* Pad for protocol. */ 679 writew(0x0000,write_ptr
+=2);/* Buffer: Actual count */ 680 writew(-1,write_ptr
+=2);/* Buffer: Next (none). */ 681 writew(cur_rxbuf
+0x20+ SCB_base
,write_ptr
+=2);/* Buffer: Address low */ 682 writew(0x0000,write_ptr
+=2); 683 /* Finally, the number of bytes in the buffer. */ 684 writew(0x8000+ RX_BUF_SIZE
-0x20,write_ptr
+=2); 686 lp
->rx_tail
= cur_rxbuf
; 687 cur_rxbuf
+= RX_BUF_SIZE
; 688 }while(cur_rxbuf
<= RX_BUF_END
- RX_BUF_SIZE
); 690 /* Terminate the list by setting the EOL bit, and wrap the pointer to make 692 write_ptr
= dev
->mem_start
+ lp
->rx_tail
+2; 693 writew(0xC000,write_ptr
);/* Command, mark as last. */ 694 writew(lp
->rx_head
,write_ptr
+2);/* Link */ 697 static voidinit_82586_mem(struct device
*dev
) 699 struct net_local
*lp
= (struct net_local
*)dev
->priv
; 700 short ioaddr
= dev
->base_addr
; 701 unsigned long shmem
= dev
->mem_start
; 703 /* Enable loopback to protect the wire while starting up, 704 and hold the 586 in reset during the memory initialization. */ 705 outb(0x20, ioaddr
+ MISC_CTRL
); 707 /* Fix the ISCP address and base. */ 708 init_words
[3] = SCB_BASE
; 709 init_words
[7] = SCB_BASE
; 711 /* Write the words at 0xfff6 (address-aliased to 0xfffff6). */ 712 memcpy_toio(dev
->mem_end
-10, init_words
,10); 714 /* Write the words at 0x0000. */ 715 memcpy_toio(dev
->mem_start
, init_words
+5,sizeof(init_words
) -10); 717 /* Fill in the station address. */ 718 memcpy_toio(dev
->mem_start
+SA_OFFSET
, dev
->dev_addr
, 719 sizeof(dev
->dev_addr
)); 721 /* The Tx-block list is written as needed. We just set up the values. */ 722 lp
->tx_cmd_link
= IDLELOOP
+4; 723 lp
->tx_head
= lp
->tx_reap
= TX_BUF_START
; 727 /* Start the 586 by releasing the reset line, but leave loopback. */ 728 outb(0xA0, ioaddr
+ MISC_CTRL
); 730 /* This was time consuming to track down: you need to give two channel 731 attention signals to reliably start up the i82586. */ 732 outb(0, ioaddr
+ SIGNAL_CA
); 736 while(readw(shmem
+iSCB_STATUS
) ==0) 738 printk("%s: i82586 initialization timed out with status %04x," 739 "cmd %04x.\n", dev
->name
, 740 readw(shmem
+iSCB_STATUS
),readw(shmem
+iSCB_CMD
)); 743 /* Issue channel-attn -- the 82586 won't start. */ 744 outb(0, ioaddr
+ SIGNAL_CA
); 747 /* Disable loopback and enable interrupts. */ 748 outb(0x84, ioaddr
+ MISC_CTRL
); 750 printk("%s: Initialized 82586, status %04x.\n", dev
->name
, 751 readw(shmem
+iSCB_STATUS
)); 755 static voidhardware_send_packet(struct device
*dev
,void*buf
,short length
) 757 struct net_local
*lp
= (struct net_local
*)dev
->priv
; 758 short ioaddr
= dev
->base_addr
; 759 ushort tx_block
= lp
->tx_head
; 760 unsigned long write_ptr
= dev
->mem_start
+ tx_block
; 762 /* Set the write pointer to the Tx block, and put out the header. */ 763 writew(0x0000,write_ptr
);/* Tx status */ 764 writew(CMD_INTR
|CmdTx
,write_ptr
+=2);/* Tx command */ 765 writew(tx_block
+16,write_ptr
+=2);/* Next command is a NoOp. */ 766 writew(tx_block
+8,write_ptr
+=2);/* Data Buffer offset. */ 768 /* Output the data buffer descriptor. */ 769 writew(length
|0x8000,write_ptr
+=2);/* Byte count parameter. */ 770 writew(-1,write_ptr
+=2);/* No next data buffer. */ 771 writew(tx_block
+22+SCB_BASE
,write_ptr
+=2);/* Buffer follows the NoOp command. */ 772 writew(0x0000,write_ptr
+=2);/* Buffer address high bits (always zero). */ 774 /* Output the Loop-back NoOp command. */ 775 writew(0x0000,write_ptr
+=2);/* Tx status */ 776 writew(CmdNOp
,write_ptr
+=2);/* Tx command */ 777 writew(tx_block
+16,write_ptr
+=2);/* Next is myself. */ 779 /* Output the packet at the write pointer. */ 780 memcpy_toio(write_ptr
+2, buf
, length
); 782 /* Set the old command link pointing to this send packet. */ 783 writew(tx_block
,dev
->mem_start
+ lp
->tx_cmd_link
); 784 lp
->tx_cmd_link
= tx_block
+20; 786 /* Set the next free tx region. */ 787 lp
->tx_head
= tx_block
+ TX_BUF_SIZE
; 788 if(lp
->tx_head
> RX_BUF_START
- TX_BUF_SIZE
) 789 lp
->tx_head
= TX_BUF_START
; 792 printk("%s: 3c507 @%x send length = %d, tx_block %3x, next %3x.\n", 793 dev
->name
, ioaddr
, length
, tx_block
, lp
->tx_head
); 796 if(lp
->tx_head
!= lp
->tx_reap
) 800 static voidel16_rx(struct device
*dev
) 802 struct net_local
*lp
= (struct net_local
*)dev
->priv
; 803 unsigned long shmem
= dev
->mem_start
; 804 ushort rx_head
= lp
->rx_head
; 805 ushort rx_tail
= lp
->rx_tail
; 806 ushort boguscount
=10; 809 while((frame_status
=readw(shmem
+rx_head
)) <0) {/* Command complete */ 810 unsigned long read_frame
= dev
->mem_start
+ rx_head
; 811 ushort rfd_cmd
=readw(read_frame
+2); 812 ushort next_rx_frame
=readw(read_frame
+4); 813 ushort data_buffer_addr
=readw(read_frame
+6); 814 unsigned long data_frame
= dev
->mem_start
+ data_buffer_addr
; 815 ushort pkt_len
=readw(data_frame
); 817 if(rfd_cmd
!=0|| data_buffer_addr
!= rx_head
+22 818 || (pkt_len
&0xC000) !=0xC000) { 819 printk("%s: Rx frame at %#x corrupted, status %04x cmd %04x" 820 "next %04x data-buf @%04x %04x.\n", dev
->name
, rx_head
, 821 frame_status
, rfd_cmd
, next_rx_frame
, data_buffer_addr
, 823 }else if((frame_status
&0x2000) ==0) { 824 /* Frame Rxed, but with error. */ 825 lp
->stats
.rx_errors
++; 826 if(frame_status
&0x0800) lp
->stats
.rx_crc_errors
++; 827 if(frame_status
&0x0400) lp
->stats
.rx_frame_errors
++; 828 if(frame_status
&0x0200) lp
->stats
.rx_fifo_errors
++; 829 if(frame_status
&0x0100) lp
->stats
.rx_over_errors
++; 830 if(frame_status
&0x0080) lp
->stats
.rx_length_errors
++; 832 /* Malloc up new buffer. */ 836 skb
=dev_alloc_skb(pkt_len
+2); 838 printk("%s: Memory squeeze, dropping packet.\n", dev
->name
); 839 lp
->stats
.rx_dropped
++; 846 /* 'skb->data' points to the start of sk_buff data area. */ 847 memcpy_fromio(skb_put(skb
,pkt_len
), data_frame
+10, pkt_len
); 849 skb
->protocol
=eth_type_trans(skb
,dev
); 851 lp
->stats
.rx_packets
++; 854 /* Clear the status word and set End-of-List on the rx frame. */ 855 writew(0,read_frame
); 856 writew(0xC000,read_frame
+2); 857 /* Clear the end-of-list on the prev. RFD. */ 858 writew(0x0000,dev
->mem_start
+ rx_tail
+2); 861 rx_head
= next_rx_frame
; 866 lp
->rx_head
= rx_head
; 867 lp
->rx_tail
= rx_tail
; 870 static char devicename
[9] = {0, }; 871 static struct device dev_3c507
= { 872 devicename
,/* device name is inserted by linux/drivers/net/net_init.c */ 875 0,0,0, NULL
, el16_probe
878 static int io
=0x300; 881 MODULE_PARM(irq
,"i"); 886 printk("3c507: You should not use auto-probing with insmod!\n"); 887 dev_3c507
.base_addr
= io
; 889 if(register_netdev(&dev_3c507
) !=0) { 890 printk("3c507: register_netdev() returned non-zero.\n"); 899 unregister_netdev(&dev_3c507
); 900 kfree(dev_3c507
.priv
); 901 dev_3c507
.priv
= NULL
; 903 /* If we don't do this, we can't re-insmod it later. */ 904 free_irq(dev_3c507
.irq
, &dev_3c507
); 905 release_region(dev_3c507
.base_addr
, EL16_IO_EXTENT
); 911 * 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" 913 * kept-new-versions: 5