2 * Linux Ethernet device driver for the 3Com Etherlink Plus (3C505) 3 * By Craig Southeren, Juha Laiho and Philip Blundell 5 * 3c505.c This module implements an interface to the 3Com 6 * Etherlink Plus (3c505) Ethernet card. Linux device 7 * driver interface reverse engineered from the Linux 3C509 8 * device drivers. Some 3C505 information gleaned from 9 * the Crynwr packet driver. Still this driver would not 10 * be here without 3C505 technical reference provided by 13 * $Id: 3c505.c,v 1.10 1996/04/16 13:06:27 phil Exp $ 15 * Authors: Linux 3c505 device driver by 16 * Craig Southeren, <craigs@ineluki.apana.org.au> 18 * Andrew Tridgell, <tridge@nimbus.anu.edu.au> 19 * Auto irq/address, tuning, cleanup and v1.1.4+ kernel mods by 20 * Juha Laiho, <jlaiho@ichaos.nullnet.fi> 21 * Linux 3C509 driver by 22 * Donald Becker, <becker@super.org> 23 * Crynwr packet driver by 24 * Krishnan Gopalan and Gregg Stefancik, 25 * Clemson University Engineering Computer Operations. 26 * Portions of the code have been adapted from the 3c505 27 * driver for NCSA Telnet by Bruce Orchard and later 28 * modified by Warren Van Houten and krus@diku.dk. 29 * 3C505 technical information provided by 30 * Terry Murphy, of 3Com Network Adapter Division 31 * Linux 1.3.0 changes by 32 * Alan Cox <Alan.Cox@linux.org> 33 * More debugging, DMA support, currently maintained by 34 * Philip Blundell <Philip.Blundell@pobox.com> 35 * Multicard/soft configurable dma channel/rev 2 hardware support 36 * by Christopher Collins <ccollins@pcug.org.au> 39 /* Theory of operation: 41 * The 3c505 is quite an intelligent board. All communication with it is done 42 * by means of Primary Command Blocks (PCBs); these are transferred using PIO 43 * through the command register. The card has 256k of on-board RAM, which is 44 * used to buffer received packets. It might seem at first that more buffers 45 * are better, but in fact this isn't true. From my tests, it seems that 46 * more than about 10 buffers are unnecessary, and there is a noticeable 47 * performance hit in having more active on the card. So the majority of the 48 * card's memory isn't, in fact, used. Sadly, the card only has one transmit 49 * buffer and, short of loading our own firmware into it (which is what some 50 * drivers resort to) there's nothing we can do about this. 52 * We keep up to 4 "receive packet" commands active on the board at a time. 53 * When a packet comes in, so long as there is a receive command active, the 54 * board will send us a "packet received" PCB and then add the data for that 55 * packet to the DMA queue. If a DMA transfer is not already in progress, we 56 * set one up to start uploading the data. We have to maintain a list of 57 * backlogged receive packets, because the card may decide to tell us about 58 * a newly-arrived packet at any time, and we may not be able to start a DMA 59 * transfer immediately (ie one may already be going on). We can't NAK the 60 * PCB, because then it would throw the packet away. 62 * Trying to send a PCB to the card at the wrong moment seems to have bad 63 * effects. If we send it a transmit PCB while a receive DMA is happening, 64 * it will just NAK the PCB and so we will have wasted our time. Worse, it 65 * sometimes seems to interrupt the transfer. The majority of the low-level 66 * code is protected by one huge semaphore -- "busy" -- which is set whenever 67 * it probably isn't safe to do anything to the card. The receive routine 68 * must gain a lock on "busy" before it can start a DMA transfer, and the 69 * transmit routine must gain a lock before it sends the first PCB to the card. 70 * The send_pcb() routine also has an internal semaphore to protect it against 71 * being re-entered (which would be disastrous) -- this is needed because 72 * several things can happen asynchronously (re-priming the receiver and 73 * asking the card for statistics, for example). send_pcb() will also refuse 74 * to talk to the card at all if a DMA upload is happening. The higher-level 75 * networking code will reschedule a later retry if some part of the driver 76 * is blocked. In practice, this doesn't seem to happen very often. 79 /* This driver may now work with revision 2.x hardware, since all the read 80 * operations on the HCR have been removed (we now keep our own softcopy). 81 * But I don't have an old card to test it on. 83 * This has had the bad effect that the autoprobe routine is now a bit 84 * less friendly to other devices. However, it was never very good. 85 * before, so I doubt it will hurt anybody. 88 /* The driver is a mess. I took Craig's and Juha's code, and hacked it firstly 89 * to make it more reliable, and secondly to add DMA mode. Many things could 90 * probably be done better; the concurrency protection is particularly awful. 93 #include <linux/module.h> 95 #include <linux/kernel.h> 96 #include <linux/sched.h> 97 #include <linux/string.h> 98 #include <linux/interrupt.h> 99 #include <linux/ptrace.h> 100 #include <linux/errno.h> 101 #include <linux/in.h> 102 #include <linux/malloc.h> 103 #include <linux/ioport.h> 104 #include <linux/spinlock.h> 105 #include <asm/bitops.h> 109 #include <linux/netdevice.h> 110 #include <linux/etherdevice.h> 111 #include <linux/skbuff.h> 112 #include <linux/init.h> 116 /********************************************************* 118 * define debug messages here as common strings to reduce space 120 *********************************************************/ 122 static const char*filename
= __FILE__
; 124 static const char*timeout_msg
="*** timeout at %s:%s (line %d) ***\n"; 125 #define TIMEOUT_MSG(lineno) \ 126 printk(timeout_msg, filename,__FUNCTION__,(lineno)) 128 static const char*invalid_pcb_msg
= 129 "*** invalid pcb length %d at %s:%s (line %d) ***\n"; 130 #define INVALID_PCB_MSG(len) \ 131 printk(invalid_pcb_msg, (len),filename,__FUNCTION__,__LINE__) 133 static char search_msg
[] __initdata
="%s: Looking for 3c505 adapter at address %#x..."; 135 static char stilllooking_msg
[] __initdata
="still looking..."; 137 static char found_msg
[] __initdata
="found.\n"; 139 static char notfound_msg
[] __initdata
="not found (reason = %d)\n"; 141 static char couldnot_msg
[] __initdata
="%s: 3c505 not found\n"; 143 /********************************************************* 145 * various other debug stuff 147 *********************************************************/ 150 static const int elp_debug
= ELP_DEBUG
; 152 static const int elp_debug
=0; 156 * 0 = no messages (well, some) 157 * 1 = messages when high level commands performed 158 * 2 = messages when low level commands performed 159 * 3 = messages when interrupts received 162 /***************************************************************** 166 *****************************************************************/ 177 /***************************************************************** 179 * List of I/O-addresses we try to auto-sense 180 * Last element MUST BE 0! 181 *****************************************************************/ 183 static int addr_list
[] __initdata
= {0x300,0x280,0x310,0}; 185 /* Dma Memory related stuff */ 187 static unsigned longdma_mem_alloc(int size
) 189 int order
=get_order(size
); 191 return__get_dma_pages(GFP_KERNEL
, order
); 195 /***************************************************************** 197 * Functions for I/O (note the inline !) 199 *****************************************************************/ 201 staticinlineunsigned charinb_status(unsigned int base_addr
) 203 returninb(base_addr
+ PORT_STATUS
); 206 staticinlineintinb_command(unsigned int base_addr
) 208 returninb(base_addr
+ PORT_COMMAND
); 211 staticinlinevoidoutb_control(unsigned char val
,struct net_device
*dev
) 213 outb(val
, dev
->base_addr
+ PORT_CONTROL
); 214 ((elp_device
*)(dev
->priv
))->hcr_val
= val
; 217 #define HCR_VAL(x) (((elp_device *)((x)->priv))->hcr_val) 219 staticinlinevoidoutb_command(unsigned char val
,unsigned int base_addr
) 221 outb(val
, base_addr
+ PORT_COMMAND
); 224 staticinlineunsigned intinw_data(unsigned int base_addr
) 226 returninw(base_addr
+ PORT_DATA
); 229 staticinlinevoidoutw_data(unsigned int val
,unsigned int base_addr
) 231 outw(val
, base_addr
+ PORT_DATA
); 234 staticinlineunsigned intbacklog_next(unsigned int n
) 236 return(n
+1) % BACKLOG_SIZE
; 239 /***************************************************************** 241 * useful functions for accessing the adapter 243 *****************************************************************/ 246 * use this routine when accessing the ASF bits as they are 247 * changed asynchronously by the adapter 250 /* get adapter PCB status */ 251 #define GET_ASF(addr) \ 252 (get_status(addr)&ASF_PCB_MASK) 254 staticinlineintget_status(unsigned int base_addr
) 256 int timeout
= jiffies
+10*HZ
/100; 259 stat1
=inb_status(base_addr
); 260 }while(stat1
!=inb_status(base_addr
) &&time_before(jiffies
, timeout
)); 261 if(time_after_eq(jiffies
, timeout
)) 262 TIMEOUT_MSG(__LINE__
); 266 staticinlinevoidset_hsf(struct net_device
*dev
,int hsf
) 269 outb_control((HCR_VAL(dev
) & ~HSF_PCB_MASK
) | hsf
, dev
); 273 static intstart_receive(struct net_device
*, pcb_struct
*); 275 inlinestatic voidadapter_reset(struct net_device
*dev
) 278 elp_device
*adapter
= dev
->priv
; 279 unsigned char orig_hcr
= adapter
->hcr_val
; 281 outb_control(0, dev
); 283 if(inb_status(dev
->base_addr
) & ACRF
) { 285 inb_command(dev
->base_addr
); 286 timeout
= jiffies
+2*HZ
/100; 287 while(time_before_eq(jiffies
, timeout
) && !(inb_status(dev
->base_addr
) & ACRF
)); 288 }while(inb_status(dev
->base_addr
) & ACRF
); 289 set_hsf(dev
, HSF_PCB_NAK
); 291 outb_control(adapter
->hcr_val
| ATTN
|DIR, dev
); 292 timeout
= jiffies
+1*HZ
/100; 293 while(time_before_eq(jiffies
, timeout
)); 294 outb_control(adapter
->hcr_val
& ~ATTN
, dev
); 295 timeout
= jiffies
+1*HZ
/100; 296 while(time_before_eq(jiffies
, timeout
)); 297 outb_control(adapter
->hcr_val
| FLSH
, dev
); 298 timeout
= jiffies
+1*HZ
/100; 299 while(time_before_eq(jiffies
, timeout
)); 300 outb_control(adapter
->hcr_val
& ~FLSH
, dev
); 301 timeout
= jiffies
+1*HZ
/100; 302 while(time_before_eq(jiffies
, timeout
)); 304 outb_control(orig_hcr
, dev
); 305 if(!start_receive(dev
, &adapter
->tx_pcb
)) 306 printk("%s: start receive command failed\n", dev
->name
); 309 /* Check to make sure that a DMA transfer hasn't timed out. This should 310 * never happen in theory, but seems to occur occasionally if the card gets 311 * prodded at the wrong time. 313 staticinlinevoidcheck_3c505_dma(struct net_device
*dev
) 315 elp_device
*adapter
= dev
->priv
; 316 if(adapter
->dmaing
&&time_after(jiffies
, adapter
->current_dma
.start_time
+10)) { 317 unsigned long flags
, f
; 318 printk("%s: DMA %s timed out, %d bytes left\n", dev
->name
, adapter
->current_dma
.direction
?"download":"upload",get_dma_residue(dev
->dma
)); 325 disable_dma(dev
->dma
); 328 if(adapter
->rx_active
) 329 adapter
->rx_active
--; 330 outb_control(adapter
->hcr_val
& ~(DMAE
| TCEN
|DIR), dev
); 331 restore_flags(flags
); 335 /* Primitive functions used by send_pcb() */ 336 staticinlineunsigned intsend_pcb_slow(unsigned int base_addr
,unsigned char byte
) 338 unsigned int timeout
; 339 outb_command(byte
, base_addr
); 340 for(timeout
= jiffies
+5*HZ
/100;time_before(jiffies
, timeout
);) { 341 if(inb_status(base_addr
) & HCRE
) 344 printk("3c505: send_pcb_slow timed out\n"); 348 staticinlineunsigned intsend_pcb_fast(unsigned int base_addr
,unsigned char byte
) 350 unsigned int timeout
; 351 outb_command(byte
, base_addr
); 352 for(timeout
=0; timeout
<40000; timeout
++) { 353 if(inb_status(base_addr
) & HCRE
) 356 printk("3c505: send_pcb_fast timed out\n"); 360 /* Check to see if the receiver needs restarting, and kick it if so */ 361 staticinlinevoidprime_rx(struct net_device
*dev
) 363 elp_device
*adapter
= dev
->priv
; 364 while(adapter
->rx_active
< ELP_RX_PCBS
&&netif_running(dev
)) { 365 if(!start_receive(dev
, &adapter
->itx_pcb
)) 370 /***************************************************************** 373 * Send a PCB to the adapter. 375 * output byte to command reg --<--+ 376 * wait until HCRE is non zero | 377 * loop until all bytes sent -->--+ 378 * set HSF1 and HSF2 to 1 380 * wait until ASF give ACK or NAK 381 * set HSF1 and HSF2 to 0 383 *****************************************************************/ 385 /* This can be quite slow -- the adapter is allowed to take up to 40ms 386 * to respond to the initial interrupt. 388 * We run initially with interrupts turned on, but with a semaphore set 389 * so that nobody tries to re-enter this code. Once the first byte has 390 * gone through, we turn interrupts off and then send the others (the 391 * timeout is reduced to 500us). 394 static intsend_pcb(struct net_device
*dev
, pcb_struct
* pcb
) 398 elp_device
*adapter
= dev
->priv
; 400 check_3c505_dma(dev
); 402 if(adapter
->dmaing
&& adapter
->current_dma
.direction
==0) 405 /* Avoid contention */ 406 if(test_and_set_bit(1, &adapter
->send_pcb_semaphore
)) { 408 printk("%s: send_pcb entered while threaded\n", dev
->name
); 413 * load each byte into the command register and 414 * wait for the HCRE bit to indicate the adapter 419 if(send_pcb_slow(dev
->base_addr
, pcb
->command
)) 424 if(send_pcb_fast(dev
->base_addr
, pcb
->length
)) 427 for(i
=0; i
< pcb
->length
; i
++) { 428 if(send_pcb_fast(dev
->base_addr
, pcb
->data
.raw
[i
])) 432 outb_control(adapter
->hcr_val
|3, dev
);/* signal end of PCB */ 433 outb_command(2+ pcb
->length
, dev
->base_addr
); 435 /* now wait for the acknowledgement */ 438 for(timeout
= jiffies
+5*HZ
/100;time_before(jiffies
, timeout
);) { 439 switch(GET_ASF(dev
->base_addr
)) { 441 adapter
->send_pcb_semaphore
=0; 446 printk(KERN_DEBUG
"%s: send_pcb got NAK\n", dev
->name
); 454 printk("%s: timeout waiting for PCB acknowledge (status %02x)\n", dev
->name
,inb_status(dev
->base_addr
)); 459 adapter
->send_pcb_semaphore
=0; 464 /***************************************************************** 467 * Read a PCB from the adapter 469 * wait for ACRF to be non-zero ---<---+ 471 * if ASF1 and ASF2 were not both one | 472 * before byte was read, loop --->---+ 473 * set HSF1 and HSF2 for ack 475 *****************************************************************/ 477 static intreceive_pcb(struct net_device
*dev
, pcb_struct
* pcb
) 484 elp_device
*adapter
= dev
->priv
; 488 /* get the command code */ 489 timeout
= jiffies
+2*HZ
/100; 490 while(((stat
=get_status(dev
->base_addr
)) & ACRF
) ==0&&time_before(jiffies
, timeout
)); 491 if(time_after_eq(jiffies
, timeout
)) { 492 TIMEOUT_MSG(__LINE__
); 495 pcb
->command
=inb_command(dev
->base_addr
); 497 /* read the data length */ 498 timeout
= jiffies
+3*HZ
/100; 499 while(((stat
=get_status(dev
->base_addr
)) & ACRF
) ==0&&time_before(jiffies
, timeout
)); 500 if(time_after_eq(jiffies
, timeout
)) { 501 TIMEOUT_MSG(__LINE__
); 502 printk("%s: status %02x\n", dev
->name
, stat
); 505 pcb
->length
=inb_command(dev
->base_addr
); 507 if(pcb
->length
> MAX_PCB_DATA
) { 508 INVALID_PCB_MSG(pcb
->length
); 517 while(((stat
=get_status(dev
->base_addr
)) & ACRF
) ==0&& j
++ <20000); 518 pcb
->data
.raw
[i
++] =inb_command(dev
->base_addr
); 521 }while((stat
& ASF_PCB_MASK
) != ASF_PCB_END
&& j
<20000); 524 TIMEOUT_MSG(__LINE__
); 527 /* woops, the last "data" byte was really the length! */ 528 total_length
= pcb
->data
.raw
[--i
]; 530 /* safety check total length vs data length */ 531 if(total_length
!= (pcb
->length
+2)) { 533 printk("%s: mangled PCB received\n", dev
->name
); 534 set_hsf(dev
, HSF_PCB_NAK
); 538 if(pcb
->command
== CMD_RECEIVE_PACKET_COMPLETE
) { 539 if(test_and_set_bit(0, (void*) &adapter
->busy
)) { 540 if(backlog_next(adapter
->rx_backlog
.in
) == adapter
->rx_backlog
.out
) { 541 set_hsf(dev
, HSF_PCB_NAK
); 542 printk("%s: PCB rejected, transfer in progress and backlog full\n", dev
->name
); 550 set_hsf(dev
, HSF_PCB_ACK
); 554 /****************************************************** 556 * queue a receive command on the adapter so we will get an 557 * interrupt when a packet is received. 559 ******************************************************/ 561 static intstart_receive(struct net_device
*dev
, pcb_struct
* tx_pcb
) 564 elp_device
*adapter
= dev
->priv
; 567 printk("%s: restarting receiver\n", dev
->name
); 568 tx_pcb
->command
= CMD_RECEIVE_PACKET
; 569 tx_pcb
->length
=sizeof(struct Rcv_pkt
); 570 tx_pcb
->data
.rcv_pkt
.buf_seg
571 = tx_pcb
->data
.rcv_pkt
.buf_ofs
=0;/* Unused */ 572 tx_pcb
->data
.rcv_pkt
.buf_len
=1600; 573 tx_pcb
->data
.rcv_pkt
.timeout
=0;/* set timeout to zero */ 574 status
=send_pcb(dev
, tx_pcb
); 576 adapter
->rx_active
++; 580 /****************************************************** 582 * extract a packet from the adapter 583 * this routine is only called from within the interrupt 584 * service routine, so no cli/sti calls are needed 585 * note that the length is always assumed to be even 587 ******************************************************/ 589 static voidreceive_packet(struct net_device
*dev
,int len
) 592 elp_device
*adapter
= dev
->priv
; 597 rlen
= (len
+1) & ~1; 598 skb
=dev_alloc_skb(rlen
+2); 601 printk("%s: memory squeeze, dropping packet\n", dev
->name
); 602 target
= adapter
->dma_buffer
; 603 adapter
->current_dma
.target
= NULL
; 606 target
=skb_put(skb
, rlen
); 607 if(virt_to_bus(target
+ rlen
) >= MAX_DMA_ADDRESS
) { 608 adapter
->current_dma
.target
= target
; 609 target
= adapter
->dma_buffer
; 611 adapter
->current_dma
.target
= NULL
; 615 /* if this happens, we die */ 616 if(test_and_set_bit(0, (void*) &adapter
->dmaing
)) 617 printk("%s: rx blocked, DMA in progress, dir %d\n", dev
->name
, adapter
->current_dma
.direction
); 620 adapter
->current_dma
.direction
=0; 621 adapter
->current_dma
.length
= rlen
; 622 adapter
->current_dma
.skb
= skb
; 623 adapter
->current_dma
.start_time
= jiffies
; 625 outb_control(adapter
->hcr_val
|DIR| TCEN
| DMAE
, dev
); 627 flags
=claim_dma_lock(); 628 disable_dma(dev
->dma
); 629 clear_dma_ff(dev
->dma
); 630 set_dma_mode(dev
->dma
,0x04);/* dma read */ 631 set_dma_addr(dev
->dma
,virt_to_bus(target
)); 632 set_dma_count(dev
->dma
, rlen
); 633 enable_dma(dev
->dma
); 634 release_dma_lock(flags
); 637 printk("%s: rx DMA transfer started\n", dev
->name
); 640 if(adapter
->rx_active
) 641 adapter
->rx_active
--; 644 printk("%s: receive_packet called, busy not set.\n", dev
->name
); 647 /****************************************************** 651 ******************************************************/ 653 static voidelp_interrupt(int irq
,void*dev_id
,struct pt_regs
*reg_ptr
) 658 struct net_device
*dev
; 663 adapter
= (elp_device
*) dev
->priv
; 665 spin_lock(&adapter
->lock
); 669 * has a DMA transfer finished? 671 if(inb_status(dev
->base_addr
) & DONE
) { 672 if(!adapter
->dmaing
) { 673 printk("%s: phantom DMA completed\n", dev
->name
); 676 printk("%s: %s DMA complete, status %02x\n", dev
->name
, adapter
->current_dma
.direction
?"tx":"rx",inb_status(dev
->base_addr
)); 679 outb_control(adapter
->hcr_val
& ~(DMAE
| TCEN
|DIR), dev
); 680 if(adapter
->current_dma
.direction
) { 681 dev_kfree_skb_irq(adapter
->current_dma
.skb
); 683 struct sk_buff
*skb
= adapter
->current_dma
.skb
; 685 if(adapter
->current_dma
.target
) { 686 /* have already done the skb_put() */ 687 memcpy(adapter
->current_dma
.target
, adapter
->dma_buffer
, adapter
->current_dma
.length
); 689 skb
->protocol
=eth_type_trans(skb
,dev
); 690 adapter
->stats
.rx_bytes
+= skb
->len
; 695 if(adapter
->rx_backlog
.in
!= adapter
->rx_backlog
.out
) { 696 int t
= adapter
->rx_backlog
.length
[adapter
->rx_backlog
.out
]; 697 adapter
->rx_backlog
.out
=backlog_next(adapter
->rx_backlog
.out
); 699 printk("%s: receiving backlogged packet (%d)\n", dev
->name
, t
); 700 receive_packet(dev
, t
); 705 /* has one timed out? */ 706 check_3c505_dma(dev
); 710 * receive a PCB from the adapter 712 timeout
= jiffies
+3*HZ
/100; 713 while((inb_status(dev
->base_addr
) & ACRF
) !=0&&time_before(jiffies
, timeout
)) { 714 if(receive_pcb(dev
, &adapter
->irx_pcb
)) { 715 switch(adapter
->irx_pcb
.command
) 720 * received a packet - this must be handled fast 723 case CMD_RECEIVE_PACKET_COMPLETE
: 724 /* if the device isn't open, don't pass packets up the stack */ 725 if(!netif_running(dev
)) 727 len
= adapter
->irx_pcb
.data
.rcv_resp
.pkt_len
; 728 dlen
= adapter
->irx_pcb
.data
.rcv_resp
.buf_len
; 729 if(adapter
->irx_pcb
.data
.rcv_resp
.timeout
!=0) { 730 printk(KERN_ERR
"%s: interrupt - packet not received correctly\n", dev
->name
); 733 printk("%s: interrupt - packet received of length %i (%i)\n", dev
->name
, len
, dlen
); 735 if(adapter
->irx_pcb
.command
==0xff) { 737 printk("%s: adding packet to backlog (len = %d)\n", dev
->name
, dlen
); 738 adapter
->rx_backlog
.length
[adapter
->rx_backlog
.in
] = dlen
; 739 adapter
->rx_backlog
.in
=backlog_next(adapter
->rx_backlog
.in
); 741 receive_packet(dev
, dlen
); 744 printk("%s: packet received\n", dev
->name
); 749 * 82586 configured correctly 751 case CMD_CONFIGURE_82586_RESPONSE
: 752 adapter
->got
[CMD_CONFIGURE_82586
] =1; 754 printk("%s: interrupt - configure response received\n", dev
->name
); 758 * Adapter memory configuration 760 case CMD_CONFIGURE_ADAPTER_RESPONSE
: 761 adapter
->got
[CMD_CONFIGURE_ADAPTER_MEMORY
] =1; 763 printk("%s: Adapter memory configuration %s.\n", dev
->name
, 764 adapter
->irx_pcb
.data
.failed
?"failed":"succeeded"); 768 * Multicast list loading 770 case CMD_LOAD_MULTICAST_RESPONSE
: 771 adapter
->got
[CMD_LOAD_MULTICAST_LIST
] =1; 773 printk("%s: Multicast address list loading %s.\n", dev
->name
, 774 adapter
->irx_pcb
.data
.failed
?"failed":"succeeded"); 778 * Station address setting 780 case CMD_SET_ADDRESS_RESPONSE
: 781 adapter
->got
[CMD_SET_STATION_ADDRESS
] =1; 783 printk("%s: Ethernet address setting %s.\n", dev
->name
, 784 adapter
->irx_pcb
.data
.failed
?"failed":"succeeded"); 789 * received board statistics 791 case CMD_NETWORK_STATISTICS_RESPONSE
: 792 adapter
->stats
.rx_packets
+= adapter
->irx_pcb
.data
.netstat
.tot_recv
; 793 adapter
->stats
.tx_packets
+= adapter
->irx_pcb
.data
.netstat
.tot_xmit
; 794 adapter
->stats
.rx_crc_errors
+= adapter
->irx_pcb
.data
.netstat
.err_CRC
; 795 adapter
->stats
.rx_frame_errors
+= adapter
->irx_pcb
.data
.netstat
.err_align
; 796 adapter
->stats
.rx_fifo_errors
+= adapter
->irx_pcb
.data
.netstat
.err_ovrrun
; 797 adapter
->stats
.rx_over_errors
+= adapter
->irx_pcb
.data
.netstat
.err_res
; 798 adapter
->got
[CMD_NETWORK_STATISTICS
] =1; 800 printk("%s: interrupt - statistics response received\n", dev
->name
); 806 case CMD_TRANSMIT_PACKET_COMPLETE
: 808 printk("%s: interrupt - packet sent\n", dev
->name
); 809 if(!netif_running(dev
)) 811 switch(adapter
->irx_pcb
.data
.xmit_resp
.c_stat
) { 813 adapter
->stats
.tx_aborted_errors
++; 814 printk(KERN_INFO
"%s: transmit timed out, network cable problem?\n", dev
->name
); 817 adapter
->stats
.tx_fifo_errors
++; 818 printk(KERN_INFO
"%s: transmit timed out, FIFO underrun\n", dev
->name
); 821 netif_wake_queue(dev
); 828 printk(KERN_DEBUG
"%s: unknown PCB received - %2.2x\n", dev
->name
, adapter
->irx_pcb
.command
); 832 printk("%s: failed to read PCB on interrupt\n", dev
->name
); 837 }while(icount
++ <5&& (inb_status(dev
->base_addr
) & (ACRF
| DONE
))); 842 * indicate no longer in interrupt routine 844 spin_unlock(&adapter
->lock
); 848 /****************************************************** 852 ******************************************************/ 854 static intelp_open(struct net_device
*dev
) 862 printk("%s: request to open device\n", dev
->name
); 865 * make sure we actually found the device 867 if(adapter
== NULL
) { 868 printk("%s: Opening a non-existent physical device\n", dev
->name
); 872 * disable interrupts on the board 874 outb_control(0, dev
); 877 * clear any pending interrupts 879 inb_command(dev
->base_addr
); 883 * no receive PCBs active 885 adapter
->rx_active
=0; 888 adapter
->send_pcb_semaphore
=0; 889 adapter
->rx_backlog
.in
=0; 890 adapter
->rx_backlog
.out
=0; 892 spin_lock_init(&adapter
->lock
); 895 * install our interrupt service routine 897 if((retval
=request_irq(dev
->irq
, &elp_interrupt
,0, dev
->name
, dev
))) { 898 printk(KERN_ERR
"%s: could not allocate IRQ%d\n", dev
->name
, dev
->irq
); 901 if((retval
=request_dma(dev
->dma
, dev
->name
))) { 902 free_irq(dev
->irq
, dev
); 903 printk(KERN_ERR
"%s: could not allocate DMA%d channel\n", dev
->name
, dev
->dma
); 906 adapter
->dma_buffer
= (void*)dma_mem_alloc(DMA_BUFFER_SIZE
); 907 if(!adapter
->dma_buffer
) { 908 printk(KERN_ERR
"%s: could not allocate DMA buffer\n", dev
->name
); 910 free_irq(dev
->irq
, dev
); 916 * enable interrupts on the board 918 outb_control(CMDE
, dev
); 921 * configure adapter memory: we need 10 multicast addresses, default==0 924 printk(KERN_DEBUG
"%s: sending 3c505 memory configuration command\n", dev
->name
); 925 adapter
->tx_pcb
.command
= CMD_CONFIGURE_ADAPTER_MEMORY
; 926 adapter
->tx_pcb
.data
.memconf
.cmd_q
=10; 927 adapter
->tx_pcb
.data
.memconf
.rcv_q
=20; 928 adapter
->tx_pcb
.data
.memconf
.mcast
=10; 929 adapter
->tx_pcb
.data
.memconf
.frame
=20; 930 adapter
->tx_pcb
.data
.memconf
.rcv_b
=20; 931 adapter
->tx_pcb
.data
.memconf
.progs
=0; 932 adapter
->tx_pcb
.length
=sizeof(struct Memconf
); 933 adapter
->got
[CMD_CONFIGURE_ADAPTER_MEMORY
] =0; 934 if(!send_pcb(dev
, &adapter
->tx_pcb
)) 935 printk("%s: couldn't send memory configuration command\n", dev
->name
); 937 int timeout
= jiffies
+ TIMEOUT
; 938 while(adapter
->got
[CMD_CONFIGURE_ADAPTER_MEMORY
] ==0&&time_before(jiffies
, timeout
)); 939 if(time_after_eq(jiffies
, timeout
)) 940 TIMEOUT_MSG(__LINE__
); 945 * configure adapter to receive broadcast messages and wait for response 948 printk("%s: sending 82586 configure command\n", dev
->name
); 949 adapter
->tx_pcb
.command
= CMD_CONFIGURE_82586
; 950 adapter
->tx_pcb
.data
.configure
= NO_LOOPBACK
| RECV_BROAD
; 951 adapter
->tx_pcb
.length
=2; 952 adapter
->got
[CMD_CONFIGURE_82586
] =0; 953 if(!send_pcb(dev
, &adapter
->tx_pcb
)) 954 printk("%s: couldn't send 82586 configure command\n", dev
->name
); 956 int timeout
= jiffies
+ TIMEOUT
; 957 while(adapter
->got
[CMD_CONFIGURE_82586
] ==0&&time_before(jiffies
, timeout
)); 958 if(time_after_eq(jiffies
, timeout
)) 959 TIMEOUT_MSG(__LINE__
); 962 /* enable burst-mode DMA */ 963 /* outb(0x1, dev->base_addr + PORT_AUXDMA); */ 966 * queue receive commands to provide buffering 970 printk("%s: %d receive PCBs active\n", dev
->name
, adapter
->rx_active
); 973 * device is now officially open! 976 netif_start_queue(dev
); 981 /****************************************************** 983 * send a packet to the adapter 985 ******************************************************/ 987 static intsend_packet(struct net_device
*dev
,struct sk_buff
*skb
) 989 elp_device
*adapter
= dev
->priv
; 990 unsigned long target
; 994 * make sure the length is even and no shorter than 60 bytes 996 unsigned int nlen
= (((skb
->len
<60) ?60: skb
->len
) +1) & (~1); 998 if(test_and_set_bit(0, (void*) &adapter
->busy
)) { 1000 printk("%s: transmit blocked\n", dev
->name
); 1004 adapter
->stats
.tx_bytes
+= nlen
; 1007 * send the adapter a transmit packet command. Ignore segment and offset 1008 * and make sure the length is even 1010 adapter
->tx_pcb
.command
= CMD_TRANSMIT_PACKET
; 1011 adapter
->tx_pcb
.length
=sizeof(struct Xmit_pkt
); 1012 adapter
->tx_pcb
.data
.xmit_pkt
.buf_ofs
1013 = adapter
->tx_pcb
.data
.xmit_pkt
.buf_seg
=0;/* Unused */ 1014 adapter
->tx_pcb
.data
.xmit_pkt
.pkt_len
= nlen
; 1016 if(!send_pcb(dev
, &adapter
->tx_pcb
)) { 1020 /* if this happens, we die */ 1021 if(test_and_set_bit(0, (void*) &adapter
->dmaing
)) 1022 printk("%s: tx: DMA %d in progress\n", dev
->name
, adapter
->current_dma
.direction
); 1024 adapter
->current_dma
.direction
=1; 1025 adapter
->current_dma
.start_time
= jiffies
; 1027 target
=virt_to_bus(skb
->data
); 1028 if((target
+ nlen
) >= MAX_DMA_ADDRESS
) { 1029 memcpy(adapter
->dma_buffer
, skb
->data
, nlen
); 1030 target
=virt_to_bus(adapter
->dma_buffer
); 1032 adapter
->current_dma
.skb
= skb
; 1034 flags
=claim_dma_lock(); 1035 disable_dma(dev
->dma
); 1036 clear_dma_ff(dev
->dma
); 1037 set_dma_mode(dev
->dma
,0x48);/* dma memory -> io */ 1038 set_dma_addr(dev
->dma
, target
); 1039 set_dma_count(dev
->dma
, nlen
); 1040 outb_control(adapter
->hcr_val
| DMAE
| TCEN
, dev
); 1041 enable_dma(dev
->dma
); 1042 release_dma_lock(flags
); 1045 printk("%s: DMA transfer started\n", dev
->name
); 1051 * The upper layer thinks we timed out 1054 static voidelp_timeout(struct net_device
*dev
) 1056 elp_device
*adapter
= dev
->priv
; 1059 stat
=inb_status(dev
->base_addr
); 1060 printk(KERN_WARNING
"%s: transmit timed out, lost %s?\n", dev
->name
, (stat
& ACRF
) ?"interrupt":"command"); 1062 printk("%s: status %#02x\n", dev
->name
, stat
); 1063 dev
->trans_start
= jiffies
; 1064 adapter
->stats
.tx_dropped
++; 1065 netif_wake_queue(dev
); 1068 /****************************************************** 1070 * start the transmitter 1071 * return 0 if sent OK, else return 1 1073 ******************************************************/ 1075 static intelp_start_xmit(struct sk_buff
*skb
,struct net_device
*dev
) 1077 unsigned long flags
; 1078 elp_device
*adapter
= dev
->priv
; 1080 spin_lock_irqsave(&adapter
->lock
, flags
); 1081 check_3c505_dma(dev
); 1084 printk("%s: request to send packet of length %d\n", dev
->name
, (int) skb
->len
); 1086 netif_stop_queue(dev
); 1089 * send the packet at skb->data for skb->len 1091 if(!send_packet(dev
, skb
)) { 1093 printk("%s: failed to transmit packet\n", dev
->name
); 1095 spin_unlock_irqrestore(&adapter
->lock
, flags
); 1099 printk("%s: packet of length %d sent\n", dev
->name
, (int) skb
->len
); 1102 * start the transmit timeout 1104 dev
->trans_start
= jiffies
; 1107 spin_unlock_irqrestore(&adapter
->lock
, flags
); 1108 netif_start_queue(dev
); 1112 /****************************************************** 1114 * return statistics on the board 1116 ******************************************************/ 1118 static struct net_device_stats
*elp_get_stats(struct net_device
*dev
) 1120 elp_device
*adapter
= (elp_device
*) dev
->priv
; 1123 printk("%s: request for stats\n", dev
->name
); 1125 /* If the device is closed, just return the latest stats we have, 1126 - we cannot ask from the adapter without interrupts */ 1127 if(!netif_running(dev
)) 1128 return&adapter
->stats
; 1130 /* send a get statistics command to the board */ 1131 adapter
->tx_pcb
.command
= CMD_NETWORK_STATISTICS
; 1132 adapter
->tx_pcb
.length
=0; 1133 adapter
->got
[CMD_NETWORK_STATISTICS
] =0; 1134 if(!send_pcb(dev
, &adapter
->tx_pcb
)) 1135 printk("%s: couldn't send get statistics command\n", dev
->name
); 1137 int timeout
= jiffies
+ TIMEOUT
; 1138 while(adapter
->got
[CMD_NETWORK_STATISTICS
] ==0&&time_before(jiffies
, timeout
)); 1139 if(time_after_eq(jiffies
, timeout
)) { 1140 TIMEOUT_MSG(__LINE__
); 1141 return&adapter
->stats
; 1145 /* statistics are now up to date */ 1146 return&adapter
->stats
; 1149 /****************************************************** 1153 ******************************************************/ 1155 static intelp_close(struct net_device
*dev
) 1157 elp_device
*adapter
; 1159 adapter
= dev
->priv
; 1162 printk("%s: request to close device\n", dev
->name
); 1164 netif_stop_queue(dev
); 1166 /* Someone may request the device statistic information even when 1167 * the interface is closed. The following will update the statistics 1168 * structure in the driver, so we'll be able to give current statistics. 1170 (void)elp_get_stats(dev
); 1173 * disable interrupts on the board 1175 outb_control(0, dev
); 1180 free_irq(dev
->irq
, dev
); 1183 free_pages((unsigned long) adapter
->dma_buffer
,get_order(DMA_BUFFER_SIZE
)); 1189 /************************************************************ 1191 * Set multicast list 1192 * num_addrs==0: clear mc_list 1193 * num_addrs==-1: set promiscuous mode 1194 * num_addrs>0: set mc_list 1196 ************************************************************/ 1198 static voidelp_set_mc_list(struct net_device
*dev
) 1200 elp_device
*adapter
= (elp_device
*) dev
->priv
; 1201 struct dev_mc_list
*dmi
= dev
->mc_list
; 1203 unsigned long flags
; 1206 printk("%s: request to set multicast list\n", dev
->name
); 1208 spin_lock_irqsave(&adapter
->lock
, flags
); 1210 if(!(dev
->flags
& (IFF_PROMISC
| IFF_ALLMULTI
))) { 1211 /* send a "load multicast list" command to the board, max 10 addrs/cmd */ 1212 /* if num_addrs==0 the list will be cleared */ 1213 adapter
->tx_pcb
.command
= CMD_LOAD_MULTICAST_LIST
; 1214 adapter
->tx_pcb
.length
=6* dev
->mc_count
; 1215 for(i
=0; i
< dev
->mc_count
; i
++) { 1216 memcpy(adapter
->tx_pcb
.data
.multicast
[i
], dmi
->dmi_addr
,6); 1219 adapter
->got
[CMD_LOAD_MULTICAST_LIST
] =0; 1220 if(!send_pcb(dev
, &adapter
->tx_pcb
)) 1221 printk("%s: couldn't send set_multicast command\n", dev
->name
); 1223 int timeout
= jiffies
+ TIMEOUT
; 1224 while(adapter
->got
[CMD_LOAD_MULTICAST_LIST
] ==0&&time_before(jiffies
, timeout
)); 1225 if(time_after_eq(jiffies
, timeout
)) { 1226 TIMEOUT_MSG(__LINE__
); 1230 adapter
->tx_pcb
.data
.configure
= NO_LOOPBACK
| RECV_BROAD
| RECV_MULTI
; 1231 else/* num_addrs == 0 */ 1232 adapter
->tx_pcb
.data
.configure
= NO_LOOPBACK
| RECV_BROAD
; 1234 adapter
->tx_pcb
.data
.configure
= NO_LOOPBACK
| RECV_PROMISC
; 1236 * configure adapter to receive messages (as specified above) 1237 * and wait for response 1240 printk("%s: sending 82586 configure command\n", dev
->name
); 1241 adapter
->tx_pcb
.command
= CMD_CONFIGURE_82586
; 1242 adapter
->tx_pcb
.length
=2; 1243 adapter
->got
[CMD_CONFIGURE_82586
] =0; 1244 if(!send_pcb(dev
, &adapter
->tx_pcb
)) 1246 spin_unlock_irqrestore(&adapter
->lock
, flags
); 1247 printk("%s: couldn't send 82586 configure command\n", dev
->name
); 1250 int timeout
= jiffies
+ TIMEOUT
; 1251 spin_unlock_irqrestore(&adapter
->lock
, flags
); 1252 while(adapter
->got
[CMD_CONFIGURE_82586
] ==0&&time_before(jiffies
, timeout
)); 1253 if(time_after_eq(jiffies
, timeout
)) 1254 TIMEOUT_MSG(__LINE__
); 1258 /****************************************************** 1260 * initialise Etherlink Plus board 1262 ******************************************************/ 1264 staticinlinevoidelp_init(struct net_device
*dev
) 1266 elp_device
*adapter
= dev
->priv
; 1269 * set ptrs to various functions 1271 dev
->open
= elp_open
;/* local */ 1272 dev
->stop
= elp_close
;/* local */ 1273 dev
->get_stats
= elp_get_stats
;/* local */ 1274 dev
->hard_start_xmit
= elp_start_xmit
;/* local */ 1275 dev
->tx_timeout
= elp_timeout
;/* local */ 1276 dev
->watchdog_timeo
=10*HZ
; 1277 dev
->set_multicast_list
= elp_set_mc_list
;/* local */ 1279 /* Setup the generic properties */ 1283 * setup ptr to adapter specific information 1285 memset(&(adapter
->stats
),0,sizeof(struct net_device_stats
)); 1288 * memory information 1290 dev
->mem_start
= dev
->mem_end
= dev
->rmem_end
= dev
->rmem_start
=0; 1293 /************************************************************ 1295 * A couple of tests to see if there's 3C505 or not 1296 * Called only by elp_autodetect 1297 ************************************************************/ 1299 static int __init
elp_sense(struct net_device
*dev
) 1302 int addr
= dev
->base_addr
; 1303 const char*name
= dev
->name
; 1307 if(!request_region(addr
, ELP_IO_EXTENT
,"3c505")) 1310 orig_HSR
=inb_status(addr
); 1313 printk(search_msg
, name
, addr
); 1315 if(orig_HSR
==0xff) { 1317 printk(notfound_msg
,1); 1320 /* Enable interrupts - we need timers! */ 1324 /* Wait for a while; the adapter may still be booting up */ 1326 printk(stilllooking_msg
); 1329 /* If HCR.DIR is up, we pull it down. HSR.DIR should follow. */ 1330 outb(0, dev
->base_addr
+ PORT_CONTROL
); 1331 timeout
= jiffies
+30*HZ
/100; 1332 while(time_before(jiffies
, timeout
)); 1333 restore_flags(flags
); 1334 if(inb_status(addr
) &DIR) { 1336 printk(notfound_msg
,2); 1340 /* If HCR.DIR is down, we pull it up. HSR.DIR should follow. */ 1341 outb(DIR, dev
->base_addr
+ PORT_CONTROL
); 1342 timeout
= jiffies
+30*HZ
/100; 1343 while(time_before(jiffies
, timeout
)); 1344 restore_flags(flags
); 1345 if(!(inb_status(addr
) &DIR)) { 1347 printk(notfound_msg
,3); 1352 * It certainly looks like a 3c505. 1359 release_region(addr
, ELP_IO_EXTENT
); 1363 /************************************************************* 1365 * Search through addr_list[] and try to find a 3C505 1366 * Called only by eplus_probe 1367 *************************************************************/ 1369 static int __init
elp_autodetect(struct net_device
*dev
) 1373 /* if base address set, then only check that address 1374 otherwise, run through the table */ 1375 if(dev
->base_addr
!=0) {/* dev->base_addr == 0 ==> plain autodetect */ 1376 if(elp_sense(dev
) ==0) 1377 return dev
->base_addr
; 1379 while((dev
->base_addr
= addr_list
[idx
++])) { 1380 if(elp_sense(dev
) ==0) 1381 return dev
->base_addr
; 1384 /* could not find an adapter */ 1386 printk(couldnot_msg
, dev
->name
); 1388 return0;/* Because of this, the layer above will return -ENODEV */ 1392 /****************************************************** 1394 * probe for an Etherlink Plus board at the specified address 1396 ******************************************************/ 1398 /* There are three situations we need to be able to detect here: 1400 * a) the card is idle 1401 * b) the card is still booting up 1402 * c) the card is stuck in a strange state (some DOS drivers do this) 1404 * In case (a), all is well. In case (b), we wait 10 seconds to see if the 1405 * card finishes booting, and carry on if so. In case (c), we do a hard reset, 1406 * loop round, and hope for the best. 1408 * This is all very unpleasant, but hopefully avoids the problems with the old 1409 * probe code (which had a 15-second delay if the card was idle, and didn't 1410 * work at all if it was in a weird state). 1413 int __init
elplus_probe(struct net_device
*dev
) 1415 elp_device
*adapter
; 1416 int i
, tries
, tries1
, timeout
, okay
; 1417 unsigned long cookie
=0; 1419 SET_MODULE_OWNER(dev
); 1422 * setup adapter structure 1425 dev
->base_addr
=elp_autodetect(dev
); 1426 if(!(dev
->base_addr
)) 1430 * setup ptr to adapter specific information 1432 adapter
= (elp_device
*) (dev
->priv
=kmalloc(sizeof(elp_device
), GFP_KERNEL
)); 1433 if(adapter
== NULL
) { 1434 printk("%s: out of memory\n", dev
->name
); 1438 adapter
->send_pcb_semaphore
=0; 1440 for(tries1
=0; tries1
<3; tries1
++) { 1441 outb_control((adapter
->hcr_val
| CMDE
) & ~DIR, dev
); 1442 /* First try to write just one byte, to see if the card is 1443 * responding at all normally. 1445 timeout
= jiffies
+5*HZ
/100; 1447 while(time_before(jiffies
, timeout
) && !(inb_status(dev
->base_addr
) & HCRE
)); 1448 if((inb_status(dev
->base_addr
) & HCRE
)) { 1449 outb_command(0, dev
->base_addr
);/* send a spurious byte */ 1450 timeout
= jiffies
+5*HZ
/100; 1451 while(time_before(jiffies
, timeout
) && !(inb_status(dev
->base_addr
) & HCRE
)); 1452 if(inb_status(dev
->base_addr
) & HCRE
) 1456 /* Nope, it's ignoring the command register. This means that 1457 * either it's still booting up, or it's died. 1459 printk("%s: command register wouldn't drain, ", dev
->name
); 1460 if((inb_status(dev
->base_addr
) &7) ==3) { 1461 /* If the adapter status is 3, it *could* still be booting. 1462 * Give it the benefit of the doubt for 10 seconds. 1464 printk("assuming 3c505 still starting\n"); 1465 timeout
= jiffies
+10*HZ
; 1466 while(time_before(jiffies
, timeout
) && (inb_status(dev
->base_addr
) &7)); 1467 if(inb_status(dev
->base_addr
) &7) { 1468 printk("%s: 3c505 failed to start\n", dev
->name
); 1470 okay
=1;/* It started */ 1473 /* Otherwise, it must just be in a strange 1474 * state. We probably need to kick it. 1476 printk("3c505 is sulking\n"); 1479 for(tries
=0; tries
<5&& okay
; tries
++) { 1482 * Try to set the Ethernet address, to make sure that the board 1485 adapter
->tx_pcb
.command
= CMD_STATION_ADDRESS
; 1486 adapter
->tx_pcb
.length
=0; 1487 cookie
=probe_irq_on(); 1488 if(!send_pcb(dev
, &adapter
->tx_pcb
)) { 1489 printk("%s: could not send first PCB\n", dev
->name
); 1490 probe_irq_off(cookie
); 1493 if(!receive_pcb(dev
, &adapter
->rx_pcb
)) { 1494 printk("%s: could not read first PCB\n", dev
->name
); 1495 probe_irq_off(cookie
); 1498 if((adapter
->rx_pcb
.command
!= CMD_ADDRESS_RESPONSE
) || 1499 (adapter
->rx_pcb
.length
!=6)) { 1500 printk("%s: first PCB wrong (%d, %d)\n", dev
->name
, adapter
->rx_pcb
.command
, adapter
->rx_pcb
.length
); 1501 probe_irq_off(cookie
); 1506 /* It's broken. Do a hard reset to re-initialise the board, 1509 printk(KERN_INFO
"%s: resetting adapter\n", dev
->name
); 1510 outb_control(adapter
->hcr_val
| FLSH
| ATTN
, dev
); 1511 outb_control(adapter
->hcr_val
& ~(FLSH
| ATTN
), dev
); 1513 printk("%s: failed to initialise 3c505\n", dev
->name
); 1514 release_region(dev
->base_addr
, ELP_IO_EXTENT
); 1518 if(dev
->irq
) {/* Is there a preset IRQ? */ 1519 int rpt
=probe_irq_off(cookie
); 1520 if(dev
->irq
!= rpt
) { 1521 printk("%s: warning, irq %d configured but %d detected\n", dev
->name
, dev
->irq
, rpt
); 1523 /* if dev->irq == probe_irq_off(cookie), all is well */ 1524 }else/* No preset IRQ; just use what we can detect */ 1525 dev
->irq
=probe_irq_off(cookie
); 1526 switch(dev
->irq
) {/* Legal, sane? */ 1528 printk("%s: IRQ probe failed: check 3c505 jumpers.\n", 1535 printk("%s: Impossible IRQ %d reported by probe_irq_off().\n", 1536 dev
->name
, dev
->irq
); 1540 * Now we have the IRQ number so we can disable the interrupts from 1541 * the board until the board is opened. 1543 outb_control(adapter
->hcr_val
& ~CMDE
, dev
); 1546 * copy Ethernet address into structure 1548 for(i
=0; i
<6; i
++) 1549 dev
->dev_addr
[i
] = adapter
->rx_pcb
.data
.eth_addr
[i
]; 1551 /* find a DMA channel */ 1553 if(dev
->mem_start
) { 1554 dev
->dma
= dev
->mem_start
&7; 1557 printk(KERN_WARNING
"%s: warning, DMA channel not specified, using default\n", dev
->name
); 1563 * print remainder of startup message 1565 printk("%s: 3c505 at %#lx, irq %d, dma %d, ", 1566 dev
->name
, dev
->base_addr
, dev
->irq
, dev
->dma
); 1567 printk("addr %02x:%02x:%02x:%02x:%02x:%02x, ", 1568 dev
->dev_addr
[0], dev
->dev_addr
[1], dev
->dev_addr
[2], 1569 dev
->dev_addr
[3], dev
->dev_addr
[4], dev
->dev_addr
[5]); 1572 * read more information from the adapter 1575 adapter
->tx_pcb
.command
= CMD_ADAPTER_INFO
; 1576 adapter
->tx_pcb
.length
=0; 1577 if(!send_pcb(dev
, &adapter
->tx_pcb
) || 1578 !receive_pcb(dev
, &adapter
->rx_pcb
) || 1579 (adapter
->rx_pcb
.command
!= CMD_ADAPTER_INFO_RESPONSE
) || 1580 (adapter
->rx_pcb
.length
!=10)) { 1581 printk("not responding to second PCB\n"); 1583 printk("rev %d.%d, %dk\n", adapter
->rx_pcb
.data
.info
.major_vers
, adapter
->rx_pcb
.data
.info
.minor_vers
, adapter
->rx_pcb
.data
.info
.RAM_sz
); 1586 * reconfigure the adapter memory to better suit our purposes 1588 adapter
->tx_pcb
.command
= CMD_CONFIGURE_ADAPTER_MEMORY
; 1589 adapter
->tx_pcb
.length
=12; 1590 adapter
->tx_pcb
.data
.memconf
.cmd_q
=8; 1591 adapter
->tx_pcb
.data
.memconf
.rcv_q
=8; 1592 adapter
->tx_pcb
.data
.memconf
.mcast
=10; 1593 adapter
->tx_pcb
.data
.memconf
.frame
=10; 1594 adapter
->tx_pcb
.data
.memconf
.rcv_b
=10; 1595 adapter
->tx_pcb
.data
.memconf
.progs
=0; 1596 if(!send_pcb(dev
, &adapter
->tx_pcb
) || 1597 !receive_pcb(dev
, &adapter
->rx_pcb
) || 1598 (adapter
->rx_pcb
.command
!= CMD_CONFIGURE_ADAPTER_RESPONSE
) || 1599 (adapter
->rx_pcb
.length
!=2)) { 1600 printk("%s: could not configure adapter memory\n", dev
->name
); 1602 if(adapter
->rx_pcb
.data
.configure
) { 1603 printk("%s: adapter configuration failed\n", dev
->name
); 1607 * initialise the device 1615 static struct net_device dev_3c505
[ELP_MAX_CARDS
]; 1616 static int io
[ELP_MAX_CARDS
]; 1617 static int irq
[ELP_MAX_CARDS
]; 1618 static int dma
[ELP_MAX_CARDS
]; 1619 MODULE_PARM(io
,"1-"__MODULE_STRING(ELP_MAX_CARDS
)"i"); 1620 MODULE_PARM(irq
,"1-"__MODULE_STRING(ELP_MAX_CARDS
)"i"); 1621 MODULE_PARM(dma
,"1-"__MODULE_STRING(ELP_MAX_CARDS
)"i"); 1623 intinit_module(void) 1625 int this_dev
, found
=0; 1627 for(this_dev
=0; this_dev
< ELP_MAX_CARDS
; this_dev
++) { 1628 struct net_device
*dev
= &dev_3c505
[this_dev
]; 1629 dev
->irq
= irq
[this_dev
]; 1630 dev
->base_addr
= io
[this_dev
]; 1631 dev
->init
= elplus_probe
; 1633 dev
->dma
= dma
[this_dev
]; 1636 printk(KERN_WARNING
"3c505.c: warning, using default DMA channel,\n"); 1638 if(io
[this_dev
] ==0) { 1640 printk(KERN_NOTICE
"3c505.c: module autoprobe not recommended, give io=xx.\n"); 1642 if(register_netdev(dev
) !=0) { 1643 printk(KERN_WARNING
"3c505.c: Failed to register card at 0x%x.\n", io
[this_dev
]); 1644 if(found
!=0)return0; 1652 voidcleanup_module(void) 1656 for(this_dev
=0; this_dev
< ELP_MAX_CARDS
; this_dev
++) { 1657 struct net_device
*dev
= &dev_3c505
[this_dev
]; 1658 if(dev
->priv
!= NULL
) { 1659 unregister_netdev(dev
); 1662 release_region(dev
->base_addr
, ELP_IO_EXTENT
);