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"; 31 #include <linux/module.h> 32 #include <linux/version.h> 35 #include <linux/config.h> 39 This driver wouldn't have been written with the availability of the 40 Crynwr driver source code. It provided a known-working implementation 41 that filled in the gaping holes of the Intel documentation. Three cheers 44 Intel Microcommunications Databook, Vol. 1, 1990. It provides just enough 45 info that the casual reader might think that it documents the i82586 :-<. 48 #include <linux/kernel.h> 49 #include <linux/sched.h> 50 #include <linux/types.h> 51 #include <linux/fcntl.h> 52 #include <linux/interrupt.h> 53 #include <linux/ptrace.h> 54 #include <linux/ioport.h> 56 #include <linux/string.h> 57 #include <asm/system.h> 58 #include <asm/bitops.h> 61 #include <linux/errno.h> 63 #include <linux/netdevice.h> 64 #include <linux/etherdevice.h> 65 #include <linux/skbuff.h> 66 #include <linux/malloc.h> 69 /* use 0 for production, 1 for verification, 2..7 for debug */ 73 static unsigned int net_debug
= NET_DEBUG
; 75 /* A zero-terminated list of common I/O addresses to be probed. */ 76 static unsigned int netcard_portlist
[] = 77 {0x300,0x320,0x340,0x280,0}; 80 Details of the i82586. 82 You'll really need the databook to understand the details of this part, 83 but the outline is that the i82586 has two separate processing units. 84 Both are started from a list of three configuration tables, of which only 85 the last, the System Control Block (SCB), is used after reset-time. The SCB 86 has the following fields: 89 Tx/Command block addr. 91 The command word accepts the following controls for the Tx and Rx units: 94 #define CUC_START 0x0100 95 #define CUC_RESUME 0x0200 96 #define CUC_SUSPEND 0x0300 97 #define RX_START 0x0010 98 #define RX_RESUME 0x0020 99 #define RX_SUSPEND 0x0030 101 /* The Rx unit uses a list of frame descriptors and a list of data buffer 102 descriptors. We use full-sized (1518 byte) data buffers, so there is 103 a one-to-one pairing of frame descriptors to buffer descriptors. 105 The Tx ("command") unit executes a list of commands that look like: 106 Status word Written by the 82586 when the command is done. 107 Command word Command in lower 3 bits, post-command action in upper 3 108 Link word The address of the next command. 109 Parameters (as needed). 111 Some definitions related to the Command Word are: 113 #define CMD_EOL 0x8000/* The last command of the list, stop. */ 114 #define CMD_SUSP 0x4000/* Suspend after doing cmd. */ 115 #define CMD_INTR 0x2000/* Interrupt after doing cmd. */ 118 CmdNOp
=0, CmdSASetup
=1, CmdConfigure
=2, CmdMulticastList
=3, 119 CmdTx
=4, CmdTDR
=5, CmdDump
=6, CmdDiagnose
=7}; 121 /* Information that need to be kept for each board. */ 123 struct enet_statistics stats
; 133 Details of the EtherLink16 Implementation 134 The 3c507 is a generic shared-memory i82586 implementation. 135 The host can map 16K, 32K, 48K, or 64K of the 64K memory into 136 0x0[CD][08]0000, or all 64K into 0xF[02468]0000. 139 /* Offsets from the base I/O address. */ 140 #define SA_DATA 0/* Station address data, or 3Com signature. */ 141 #define MISC_CTRL 6/* Switch the SA_DATA banks, and bus config bits. */ 142 #define RESET_IRQ 10/* Reset the latched IRQ line. */ 143 #define SIGNAL_CA 11/* Frob the 82586 Channel Attention line. */ 144 #define ROM_CONFIG 13 145 #define MEM_CONFIG 14 146 #define IRQ_CONFIG 15 147 #define EL16_IO_EXTENT 16 149 /* The ID port is used at boot-time to locate the ethercard. */ 150 #define ID_PORT 0x100 152 /* Offsets to registers in the mailbox (SCB). */ 153 #define iSCB_STATUS 0x8 155 #define iSCB_CBL 0xC/* Command BLock offset. */ 156 #define iSCB_RFA 0xE/* Rx Frame Area offset. */ 158 /* Since the 3c507 maps the shared memory window so that the last byte is 159 at 82586 address FFFF, the first byte is at 82586 address 0, 16K, 32K, or 160 48K corresponding to window sizes of 64K, 48K, 32K and 16K respectively. 161 We can account for this be setting the 'SBC Base' entry in the ISCP table 162 below for all the 16 bit offset addresses, and also adding the 'SCB Base' 163 value to all 24 bit physical addresses (in the SCP table and the TX and RX 167 #define SCB_BASE ((unsigned)64*1024 - (dev->mem_end - dev->mem_start)) 170 What follows in 'init_words[]' is the "program" that is downloaded to the 171 82586 memory. It's mostly tables and command blocks, and starts at the 172 reset address 0xfffff6. This is designed to be similar to the EtherExpress, 173 thus the unusual location of the SCB at 0x0008. 175 Even with the additional "don't care" values, doing it this way takes less 176 program space than initializing the individual tables, and I feel it's much 179 The databook is particularly useless for the first two structures, I had 180 to use the Crynwr driver as an example. 182 The memory setup is as follows: 185 #define CONFIG_CMD 0x0018 186 #define SET_SA_CMD 0x0024 187 #define SA_OFFSET 0x002A 188 #define IDLELOOP 0x30 190 #define TDR_TIME 0x3C 191 #define DUMP_CMD 0x40 192 #define DIAG_CMD 0x48 193 #define SET_MC_CMD 0x4E 194 #define DUMP_DATA 0x56/* A 170 byte buffer for dump and Set-MC into. */ 196 #define TX_BUF_START 0x0100 197 #define NUM_TX_BUFS 4 198 #define TX_BUF_SIZE (1518+14+20+16)/* packet+header+TBD */ 200 #define RX_BUF_START 0x2000 201 #define RX_BUF_SIZE (1518+14+18)/* packet+header+RBD */ 202 #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 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 device
*dev
);/* Called from Space.c */ 285 static intel16_probe1(struct device
*dev
,int ioaddr
); 286 static intel16_open(struct device
*dev
); 287 static intel16_send_packet(struct sk_buff
*skb
,struct device
*dev
); 288 static voidel16_interrupt(int irq
,struct pt_regs
*regs
); 289 static voidel16_rx(struct device
*dev
); 290 static intel16_close(struct device
*dev
); 291 static struct enet_statistics
*el16_get_stats(struct device
*dev
); 293 static voidhardware_send_packet(struct device
*dev
,void*buf
,short length
); 294 voidinit_82586_mem(struct device
*dev
); 298 struct netdev_entry netcard_drv
= 299 {"3c507", el16_probe1
, EL16_IO_EXTENT
, netcard_portlist
}; 302 /* Check for a network adaptor of this type, and return '0' iff one exists. 303 If dev->base_addr == 0, probe all likely locations. 304 If dev->base_addr == 1, always return failure. 305 If dev->base_addr == 2, (detachable devices only) allocate space for the 306 device and return success. 309 el16_probe(struct device
*dev
) 311 int base_addr
= dev
? dev
->base_addr
:0; 314 if(base_addr
>0x1ff)/* Check a single specified location. */ 315 returnel16_probe1(dev
, base_addr
); 316 else if(base_addr
!=0) 317 return ENXIO
;/* Don't probe at all. */ 319 for(i
=0; netcard_portlist
[i
]; i
++) { 320 int ioaddr
= netcard_portlist
[i
]; 321 if(check_region(ioaddr
, EL16_IO_EXTENT
)) 323 if(el16_probe1(dev
, ioaddr
) ==0) 330 intel16_probe1(struct device
*dev
,int ioaddr
) 332 static unsigned char init_ID_done
=0, version_printed
=0; 335 if(init_ID_done
==0) { 336 ushort lrs_state
=0xff; 337 /* Send the ID sequence to the ID_PORT to enable the board(s). */ 339 for(i
=0; i
<255; i
++) { 340 outb(lrs_state
, ID_PORT
); 349 if(inb(ioaddr
) =='*'&&inb(ioaddr
+1) =='3' 350 &&inb(ioaddr
+2) =='C'&&inb(ioaddr
+3) =='O') 355 /* Allocate a new 'dev' if needed. */ 357 dev
=init_etherdev(0,sizeof(struct net_local
),0); 359 if(net_debug
&& version_printed
++ ==0) 362 printk("%s: 3c507 at %#x,", dev
->name
, ioaddr
); 364 /* We should make a few more checks here, like the first three octets of 365 the S.A. for the manufacturer's code. */ 367 irq
=inb(ioaddr
+ IRQ_CONFIG
) &0x0f; 369 irqval
=request_irq(irq
, &el16_interrupt
,0,"3c507"); 371 printk("unable to get IRQ %d (irqval=%d).\n", irq
, irqval
); 375 /* We've committed to using the board, and can start filling in *dev. */ 376 request_region(ioaddr
, EL16_IO_EXTENT
,"3c507"); 377 dev
->base_addr
= ioaddr
; 379 outb(0x01, ioaddr
+ MISC_CTRL
); 380 for(i
=0; i
<6; i
++) { 381 dev
->dev_addr
[i
] =inb(ioaddr
+ i
); 382 printk(" %02x", dev
->dev_addr
[i
]); 385 if((dev
->mem_start
&0xf) >0) 386 net_debug
= dev
->mem_start
&7; 389 dev
->mem_start
= MEM_BASE
; 390 dev
->mem_end
= dev
->mem_start
+0x10000; 395 char mem_config
=inb(ioaddr
+ MEM_CONFIG
); 396 if(mem_config
&0x20) { 398 base
=0xf00000+ (mem_config
&0x08?0x080000 399 : ((mem_config
&3) <<17)); 401 size
= ((mem_config
&3) +1) <<14; 402 base
=0x0c0000+ ( (mem_config
&0x18) <<12); 404 dev
->mem_start
= base
; 405 dev
->mem_end
= base
+ size
; 409 dev
->if_port
= (inb(ioaddr
+ ROM_CONFIG
) &0x80) ?1:0; 410 dev
->irq
=inb(ioaddr
+ IRQ_CONFIG
) &0x0f; 412 printk(", IRQ %d, %sternal xcvr, memory %#lx-%#lx.\n", dev
->irq
, 413 dev
->if_port
?"ex":"in", dev
->mem_start
, dev
->mem_end
-1); 418 /* Initialize the device structure. */ 419 dev
->priv
=kmalloc(sizeof(struct net_local
), GFP_KERNEL
); 420 if(dev
->priv
== NULL
) 422 memset(dev
->priv
,0,sizeof(struct net_local
)); 424 dev
->open
= el16_open
; 425 dev
->stop
= el16_close
; 426 dev
->hard_start_xmit
= el16_send_packet
; 427 dev
->get_stats
= el16_get_stats
; 429 ether_setup(dev
);/* Generic ethernet behaviour */ 437 el16_open(struct device
*dev
) 439 irq2dev_map
[dev
->irq
] = dev
; 441 /* Initialize the 82586 memory and start it. */ 456 el16_send_packet(struct sk_buff
*skb
,struct device
*dev
) 458 struct net_local
*lp
= (struct net_local
*)dev
->priv
; 459 int ioaddr
= dev
->base_addr
; 460 short*shmem
= (short*)dev
->mem_start
; 463 /* If we get here, some higher level has decided we are broken. 464 There should really be a "kick me" function call instead. */ 465 int tickssofar
= jiffies
- dev
->trans_start
; 469 printk("%s: transmit timed out, %s? ", dev
->name
, 470 shmem
[iSCB_STATUS
>>1] &0x8000?"IRQ conflict": 471 "network cable problem"); 472 /* Try to restart the adaptor. */ 473 if(lp
->last_restart
== lp
->stats
.tx_packets
) { 474 if(net_debug
>1)printk("Resetting board.\n"); 475 /* Completely reset the adaptor. */ 478 /* Issue the channel attention signal and hope it "gets better". */ 479 if(net_debug
>1)printk("Kicking board.\n"); 480 shmem
[iSCB_CMD
>>1] =0xf000|CUC_START
|RX_START
; 481 outb(0, ioaddr
+ SIGNAL_CA
);/* Issue channel-attn. */ 482 lp
->last_restart
= lp
->stats
.tx_packets
; 485 dev
->trans_start
= jiffies
; 488 /* If some higher layer thinks we've missed an tx-done interrupt 489 we are passed NULL. Caution: dev_tint() handles the cli()/sti() 496 /* Block a timer-based transmit from overlapping. */ 497 if(set_bit(0, (void*)&dev
->tbusy
) !=0) 498 printk("%s: Transmitter access conflict.\n", dev
->name
); 500 short length
= ETH_ZLEN
< skb
->len
? skb
->len
: ETH_ZLEN
; 501 unsigned char*buf
= skb
->data
; 503 /* Disable the 82586's input to the interrupt line. */ 504 outb(0x80, ioaddr
+ MISC_CTRL
); 505 hardware_send_packet(dev
, buf
, length
); 506 dev
->trans_start
= jiffies
; 507 /* Enable the 82586 interrupt input. */ 508 outb(0x84, ioaddr
+ MISC_CTRL
); 511 dev_kfree_skb(skb
, FREE_WRITE
); 513 /* You might need to clean up and record Tx statistics here. */ 518 /* The typical workload of the driver: 519 Handle the network interface interrupts. */ 521 el16_interrupt(int irq
,struct pt_regs
*regs
) 523 struct device
*dev
= (struct device
*)(irq2dev_map
[irq
]); 524 struct net_local
*lp
; 525 int ioaddr
, status
, boguscount
=0; 530 printk("net_interrupt(): irq %d for unknown device.\n", irq
); 535 ioaddr
= dev
->base_addr
; 536 lp
= (struct net_local
*)dev
->priv
; 537 shmem
= ((ushort
*)dev
->mem_start
); 539 status
= shmem
[iSCB_STATUS
>>1]; 542 printk("%s: 3c507 interrupt, status %4.4x.\n", dev
->name
, status
); 545 /* Disable the 82586's input to the interrupt line. */ 546 outb(0x80, ioaddr
+ MISC_CTRL
); 548 /* Reap the Tx packet buffers. */ 549 while(lp
->tx_reap
!= lp
->tx_head
) { 550 unsigned short tx_status
= shmem
[lp
->tx_reap
>>1]; 553 if(net_debug
>5)printk("Couldn't reap %#x.\n", lp
->tx_reap
); 556 if(tx_status
&0x2000) { 557 lp
->stats
.tx_packets
++; 558 lp
->stats
.collisions
+= tx_status
&0xf; 560 mark_bh(NET_BH
);/* Inform upper layers. */ 562 lp
->stats
.tx_errors
++; 563 if(tx_status
&0x0600) lp
->stats
.tx_carrier_errors
++; 564 if(tx_status
&0x0100) lp
->stats
.tx_fifo_errors
++; 565 if(!(tx_status
&0x0040)) lp
->stats
.tx_heartbeat_errors
++; 566 if(tx_status
&0x0020) lp
->stats
.tx_aborted_errors
++; 569 printk("Reaped %x, Tx status %04x.\n", lp
->tx_reap
, tx_status
); 570 lp
->tx_reap
+= TX_BUF_SIZE
; 571 if(lp
->tx_reap
> RX_BUF_START
- TX_BUF_SIZE
) 572 lp
->tx_reap
= TX_BUF_START
; 577 if(status
&0x4000) {/* Packet received. */ 579 printk("Received packet, rx_head %04x.\n", lp
->rx_head
); 583 /* Acknowledge the interrupt sources. */ 584 ack_cmd
= status
&0xf000; 586 if((status
&0x0700) !=0x0200&& dev
->start
) { 588 printk("%s: Command unit stopped, status %04x, restarting.\n", 590 /* If this ever occurs we should really re-write the idle loop, reset 591 the Tx list, and do a complete restart of the command unit. 592 For now we rely on the Tx timeout if the resume doesn't work. */ 593 ack_cmd
|= CUC_RESUME
; 596 if((status
&0x0070) !=0x0040&& dev
->start
) { 597 static voidinit_rx_bufs(struct device
*); 598 /* The Rx unit is not ready, it must be hung. Restart the receiver by 599 initializing the rx buffers, and issuing an Rx start command. */ 601 printk("%s: Rx unit stopped, status %04x, restarting.\n", 604 shmem
[iSCB_RFA
>>1] = RX_BUF_START
; 608 shmem
[iSCB_CMD
>>1] = ack_cmd
; 609 outb(0, ioaddr
+ SIGNAL_CA
);/* Issue channel-attn. */ 611 /* Clear the latched interrupt. */ 612 outb(0, ioaddr
+ RESET_IRQ
); 614 /* Enable the 82586's interrupt input. */ 615 outb(0x84, ioaddr
+ MISC_CTRL
); 621 el16_close(struct device
*dev
) 623 int ioaddr
= dev
->base_addr
; 624 ushort
*shmem
= (short*)dev
->mem_start
; 629 /* Flush the Tx and disable Rx. */ 630 shmem
[iSCB_CMD
>>1] = RX_SUSPEND
| CUC_SUSPEND
; 631 outb(0, ioaddr
+ SIGNAL_CA
); 633 /* Disable the 82586's input to the interrupt line. */ 634 outb(0x80, ioaddr
+ MISC_CTRL
); 636 /* We always physically use the IRQ line, so we don't do free_irq(). 637 We do remove ourselves from the map. */ 639 irq2dev_map
[dev
->irq
] =0; 641 /* Update the statistics here. */ 650 /* Get the current statistics. This may be called with the card open or 652 static struct enet_statistics
* 653 el16_get_stats(struct device
*dev
) 655 struct net_local
*lp
= (struct net_local
*)dev
->priv
; 657 /* ToDo: decide if there are any useful statistics from the SCB. */ 662 /* Initialize the Rx-block list. */ 664 init_rx_bufs(struct device
*dev
) 666 struct net_local
*lp
= (struct net_local
*)dev
->priv
; 667 unsigned short*write_ptr
; 668 unsigned short SCB_base
= SCB_BASE
; 670 int cur_rxbuf
= lp
->rx_head
= RX_BUF_START
; 672 /* Initialize each Rx frame + data buffer. */ 673 do{/* While there is room for one more. */ 675 write_ptr
= (unsigned short*)(dev
->mem_start
+ cur_rxbuf
); 677 *write_ptr
++ =0x0000;/* Status */ 678 *write_ptr
++ =0x0000;/* Command */ 679 *write_ptr
++ = cur_rxbuf
+ RX_BUF_SIZE
;/* Link */ 680 *write_ptr
++ = cur_rxbuf
+22;/* Buffer offset */ 681 *write_ptr
++ =0x0000;/* Pad for dest addr. */ 682 *write_ptr
++ =0x0000; 683 *write_ptr
++ =0x0000; 684 *write_ptr
++ =0x0000;/* Pad for source addr. */ 685 *write_ptr
++ =0x0000; 686 *write_ptr
++ =0x0000; 687 *write_ptr
++ =0x0000;/* Pad for protocol. */ 689 *write_ptr
++ =0x0000;/* Buffer: Actual count */ 690 *write_ptr
++ = -1;/* Buffer: Next (none). */ 691 *write_ptr
++ = cur_rxbuf
+0x20+ SCB_base
;/* Buffer: Address low */ 692 *write_ptr
++ =0x0000; 693 /* Finally, the number of bytes in the buffer. */ 694 *write_ptr
++ =0x8000+ RX_BUF_SIZE
-0x20; 696 lp
->rx_tail
= cur_rxbuf
; 697 cur_rxbuf
+= RX_BUF_SIZE
; 698 }while(cur_rxbuf
<= RX_BUF_END
- RX_BUF_SIZE
); 700 /* Terminate the list by setting the EOL bit, and wrap the pointer to make 702 write_ptr
= (unsigned short*) 703 (dev
->mem_start
+ lp
->rx_tail
+2); 704 *write_ptr
++ =0xC000;/* Command, mark as last. */ 705 *write_ptr
++ = lp
->rx_head
;/* Link */ 710 init_82586_mem(struct device
*dev
) 712 struct net_local
*lp
= (struct net_local
*)dev
->priv
; 713 short ioaddr
= dev
->base_addr
; 714 ushort
*shmem
= (short*)dev
->mem_start
; 716 /* Enable loopback to protect the wire while starting up, 717 and hold the 586 in reset during the memory initialization. */ 718 outb(0x20, ioaddr
+ MISC_CTRL
); 720 /* Fix the ISCP address and base. */ 721 init_words
[3] = SCB_BASE
; 722 init_words
[7] = SCB_BASE
; 724 /* Write the words at 0xfff6 (address-aliased to 0xfffff6). */ 725 memcpy((void*)dev
->mem_end
-10, init_words
,10); 727 /* Write the words at 0x0000. */ 728 memcpy((char*)dev
->mem_start
, init_words
+5,sizeof(init_words
) -10); 730 /* Fill in the station address. */ 731 memcpy((char*)dev
->mem_start
+SA_OFFSET
, dev
->dev_addr
, 732 sizeof(dev
->dev_addr
)); 734 /* The Tx-block list is written as needed. We just set up the values. */ 735 lp
->tx_cmd_link
= IDLELOOP
+4; 736 lp
->tx_head
= lp
->tx_reap
= TX_BUF_START
; 740 /* Start the 586 by releasing the reset line, but leave loopback. */ 741 outb(0xA0, ioaddr
+ MISC_CTRL
); 743 /* This was time consuming to track down: you need to give two channel 744 attention signals to reliably start up the i82586. */ 745 outb(0, ioaddr
+ SIGNAL_CA
); 749 while(shmem
[iSCB_STATUS
>>1] ==0) 751 printk("%s: i82586 initialization timed out with status %04x," 752 "cmd %04x.\n", dev
->name
, 753 shmem
[iSCB_STATUS
>>1], shmem
[iSCB_CMD
>>1]); 756 /* Issue channel-attn -- the 82586 won't start. */ 757 outb(0, ioaddr
+ SIGNAL_CA
); 760 /* Disable loopback and enable interrupts. */ 761 outb(0x84, ioaddr
+ MISC_CTRL
); 763 printk("%s: Initialized 82586, status %04x.\n", dev
->name
, 764 shmem
[iSCB_STATUS
>>1]); 769 hardware_send_packet(struct device
*dev
,void*buf
,short length
) 771 struct net_local
*lp
= (struct net_local
*)dev
->priv
; 772 short ioaddr
= dev
->base_addr
; 773 ushort tx_block
= lp
->tx_head
; 774 ushort
*write_ptr
= (ushort
*)(dev
->mem_start
+ tx_block
); 776 /* Set the write pointer to the Tx block, and put out the header. */ 777 *write_ptr
++ =0x0000;/* Tx status */ 778 *write_ptr
++ = CMD_INTR
|CmdTx
;/* Tx command */ 779 *write_ptr
++ = tx_block
+16;/* Next command is a NoOp. */ 780 *write_ptr
++ = tx_block
+8;/* Data Buffer offset. */ 782 /* Output the data buffer descriptor. */ 783 *write_ptr
++ = length
|0x8000;/* Byte count parameter. */ 784 *write_ptr
++ = -1;/* No next data buffer. */ 785 *write_ptr
++ = tx_block
+22+SCB_BASE
;/* Buffer follows the NoOp command. */ 786 *write_ptr
++ =0x0000;/* Buffer address high bits (always zero). */ 788 /* Output the Loop-back NoOp command. */ 789 *write_ptr
++ =0x0000;/* Tx status */ 790 *write_ptr
++ = CmdNOp
;/* Tx command */ 791 *write_ptr
++ = tx_block
+16;/* Next is myself. */ 793 /* Output the packet at the write pointer. */ 794 memcpy(write_ptr
, buf
, length
); 796 /* Set the old command link pointing to this send packet. */ 797 *(ushort
*)(dev
->mem_start
+ lp
->tx_cmd_link
) = tx_block
; 798 lp
->tx_cmd_link
= tx_block
+20; 800 /* Set the next free tx region. */ 801 lp
->tx_head
= tx_block
+ TX_BUF_SIZE
; 802 if(lp
->tx_head
> RX_BUF_START
- TX_BUF_SIZE
) 803 lp
->tx_head
= TX_BUF_START
; 806 printk("%s: 3c507 @%x send length = %d, tx_block %3x, next %3x.\n", 807 dev
->name
, ioaddr
, length
, tx_block
, lp
->tx_head
); 810 if(lp
->tx_head
!= lp
->tx_reap
) 815 el16_rx(struct device
*dev
) 817 struct net_local
*lp
= (struct net_local
*)dev
->priv
; 818 short*shmem
= (short*)dev
->mem_start
; 819 ushort rx_head
= lp
->rx_head
; 820 ushort rx_tail
= lp
->rx_tail
; 821 ushort boguscount
=10; 824 while((frame_status
= shmem
[rx_head
>>1]) <0) {/* Command complete */ 825 ushort
*read_frame
= (short*)(dev
->mem_start
+ rx_head
); 826 ushort rfd_cmd
= read_frame
[1]; 827 ushort next_rx_frame
= read_frame
[2]; 828 ushort data_buffer_addr
= read_frame
[3]; 829 ushort
*data_frame
= (short*)(dev
->mem_start
+ data_buffer_addr
); 830 ushort pkt_len
= data_frame
[0]; 832 if(rfd_cmd
!=0|| data_buffer_addr
!= rx_head
+22 833 || (pkt_len
&0xC000) !=0xC000) { 834 printk("%s: Rx frame at %#x corrupted, status %04x cmd %04x" 835 "next %04x data-buf @%04x %04x.\n", dev
->name
, rx_head
, 836 frame_status
, rfd_cmd
, next_rx_frame
, data_buffer_addr
, 838 }else if((frame_status
&0x2000) ==0) { 839 /* Frame Rxed, but with error. */ 840 lp
->stats
.rx_errors
++; 841 if(frame_status
&0x0800) lp
->stats
.rx_crc_errors
++; 842 if(frame_status
&0x0400) lp
->stats
.rx_frame_errors
++; 843 if(frame_status
&0x0200) lp
->stats
.rx_fifo_errors
++; 844 if(frame_status
&0x0100) lp
->stats
.rx_over_errors
++; 845 if(frame_status
&0x0080) lp
->stats
.rx_length_errors
++; 847 /* Malloc up new buffer. */ 851 skb
=dev_alloc_skb(pkt_len
+2); 853 printk("%s: Memory squeeze, dropping packet.\n", dev
->name
); 854 lp
->stats
.rx_dropped
++; 861 /* 'skb->data' points to the start of sk_buff data area. */ 862 memcpy(skb_put(skb
,pkt_len
), data_frame
+5, pkt_len
); 864 skb
->protocol
=eth_type_trans(skb
,dev
); 866 lp
->stats
.rx_packets
++; 869 /* Clear the status word and set End-of-List on the rx frame. */ 871 read_frame
[1] =0xC000; 872 /* Clear the end-of-list on the prev. RFD. */ 873 *(short*)(dev
->mem_start
+ rx_tail
+2) =0x0000; 876 rx_head
= next_rx_frame
; 881 lp
->rx_head
= rx_head
; 882 lp
->rx_tail
= rx_tail
; 885 char kernel_version
[] = UTS_RELEASE
; 886 static char devicename
[9] = {0, }; 887 static struct device dev_3c507
= { 888 devicename
,/* device name is inserted by linux/drivers/net/net_init.c */ 891 0,0,0, NULL
, el16_probe
900 printk("3c507: You should not use auto-probing with insmod!\n"); 901 dev_3c507
.base_addr
= io
; 903 if(register_netdev(&dev_3c507
) !=0) { 904 printk("3c507: register_netdev() returned non-zero.\n"); 914 printk("3c507: device busy, remove delayed\n"); 917 unregister_netdev(&dev_3c507
); 918 kfree(dev_3c507
.priv
); 919 dev_3c507
.priv
= NULL
; 921 /* If we don't do this, we can't re-insmod it later. */ 922 free_irq(dev_3c507
.irq
); 923 release_region(dev_3c507
.base_addr
, EL16_IO_EXTENT
); 930 * 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" 932 * kept-new-versions: 5