2 * An Ethernet driver for the dual-function NCR 53C885 SCSI/Ethernet
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
13 static const char *version
=
14 "ncr885e.c:v0.8 11/30/98 dan@synergymicro.com\n";
16 #include <linux/config.h>
20 #include <linux/modversions.h>
22 #include <linux/module.h>
23 #include <linux/version.h>
25 #define MOD_INC_USE_COUNT
26 #define MOD_DEC_USE_COUNT
29 #include <linux/kernel.h>
30 #include <linux/sched.h>
31 #include <linux/timer.h>
32 #include <linux/ptrace.h>
33 #include <linux/malloc.h>
34 #include <linux/netdevice.h>
35 #include <linux/pci.h>
36 #include <linux/malloc.h>
37 #include <linux/delay.h>
38 #include <linux/ioport.h>
39 #include <linux/errno.h>
40 #include <linux/init.h>
42 #include <asm/dbdma.h>
43 #include <asm/uaccess.h>
45 #include <linux/etherdevice.h>
46 #include <linux/skbuff.h>
49 #include "ncr885_debug.h"
51 static const char *chipname
= "ncr885e";
55 #define DEBUG_FUNC 0x0001
56 #define DEBUG_PACKET 0x0002
57 #define DEBUG_CMD 0x0004
58 #define DEBUG_CHANNEL 0x0008
59 #define DEBUG_INT 0x0010
60 #define DEBUG_RX 0x0020
61 #define DEBUG_TX 0x0040
62 #define DEBUG_DMA 0x0080
63 #define DEBUG_MAC 0x0100
64 #define DEBUG_DRIVER 0x0200
65 #define DEBUG_ALL 0x1fff
69 #define NCR885E_DEBUG 0
71 #define NCR885E_DEBUG 0
74 /* The 885's Ethernet PCI device id. */
75 #ifndef PCI_DEVICE_ID_NCR_53C885_ETHERNET
76 #define PCI_DEVICE_ID_NCR_53C885_ETHERNET 0x0701
81 #define MAX_TX_ACTIVE (NR_TX_RING-1)
82 #define NCMDS_TX NR_TX_RING
84 #define RX_BUFLEN (ETH_FRAME_LEN + 8)
85 #define TX_TIMEOUT 5*HZ
87 #define NCR885E_TOTAL_SIZE 0xe0
89 #define TXSR (1<<6) /* tx: xfer status written */
90 #define TXABORT (1<<7) /* tx: abort */
91 #define EOP (1<<7) /* rx: end of packet written to buffer */
93 int ncr885e_debug
= NCR885E_DEBUG
;
94 static int print_version
= 0;
96 struct ncr885e_private
{
98 /* preserve a 1-1 marking with buffs */
99 struct dbdma_cmd
*head
;
100 struct dbdma_cmd
*tx_cmds
;
101 struct dbdma_cmd
*rx_cmds
;
102 struct dbdma_cmd
*stop_cmd
;
104 struct sk_buff
*tx_skbufs
[NR_TX_RING
];
105 struct sk_buff
*rx_skbufs
[NR_RX_RING
];
113 unsigned short tx_status
[NR_TX_RING
];
115 unsigned char tx_fullup
;
116 unsigned char tx_active
;
118 struct net_device_stats stats
;
120 struct net_device
*dev
;
122 struct timer_list tx_timeout
;
129 static struct net_device
*root_dev
= NULL
;
133 static int ncr885e_open( struct net_device
*dev
);
134 static int ncr885e_close( struct net_device
*dev
);
135 static void ncr885e_rx( struct net_device
*dev
);
136 static void ncr885e_tx( struct net_device
*dev
);
137 static int ncr885e_probe1( struct net_device
*dev
, unsigned long ioaddr
,
139 static int ncr885e_xmit_start( struct sk_buff
*skb
, struct net_device
*dev
);
140 static struct net_device_stats
*ncr885e_stats( struct net_device
*dev
);
141 static void ncr885e_set_multicast( struct net_device
*dev
);
142 static void ncr885e_config( struct net_device
*dev
);
143 static int ncr885e_set_address( struct net_device
*dev
, void *addr
);
144 static void ncr885e_interrupt( int irq
, void *dev_id
, struct pt_regs
*regs
);
145 static void show_dbdma_cmd( volatile struct dbdma_cmd
*cmd
);
147 static int read_eeprom( unsigned int ioadddr
, int location
);
150 #ifdef NCR885E_DEBUG_MII
151 static void show_mii( unsigned long ioaddr
);
152 static int read_mii( unsigned long ioaddr
, int reg
);
153 static void write_mii( unsigned long ioaddr
, int reg
, int data
);
154 #endif /* NCR885E_DEBUG_MII */
156 #define TX_RESET_FLAGS (TX_CHANNEL_RUN|TX_CHANNEL_PAUSE|TX_CHANNEL_WAKE)
157 #define RX_RESET_FLAGS (RX_CHANNEL_RUN|RX_CHANNEL_PAUSE|RX_CHANNEL_WAKE)
162 debug_ioctl( struct net_device
*dev
, struct ifreq
*req
, int cmd
)
164 unsigned long ioaddr
= dev
->base_addr
;
165 struct ncr885e_private
*sp
= (struct ncr885e_private
*) dev
->priv
;
166 struct ncr885e_private
*data
;
167 struct ncr885e_regs
*regs
;
171 struct ncr885e_regs dump
;
172 struct ncr885e_private priv
;
177 /* dump the rx ring status */
178 case NCR885E_GET_PRIV
:
180 data
= (struct ncr885e_private
*) &req
->ifr_data
;
182 if ( verify_area(VERIFY_WRITE
, &req
->ifr_data
,
183 sizeof( struct ncr885e_private
)))
186 memcpy((char *) &temp
.priv
, sp
, sizeof( struct ncr885e_private
));
187 copy_to_user( data
, (char *) &temp
.priv
, sizeof( struct ncr885e_private
));
190 case NCR885E_GET_REGS
:
192 regs
= (struct ncr885e_regs
*) &req
->ifr_data
;
194 if ( verify_area( VERIFY_WRITE
, &req
->ifr_data
,
195 sizeof( struct ncr885e_regs
)))
198 spin_lock_irqsave( &sp
->lock
, flags
);
200 temp
.dump
.tx_status
= inl( ioaddr
+ TX_CHANNEL_STATUS
);
201 temp
.dump
.rx_status
= inl( ioaddr
+ RX_CHANNEL_STATUS
);
202 temp
.dump
.mac_config
= inl( ioaddr
+ MAC_CONFIG
);
203 temp
.dump
.tx_control
= inl( ioaddr
+ TX_CHANNEL_CONTROL
);
204 temp
.dump
.rx_control
= inl( ioaddr
+ RX_CHANNEL_CONTROL
);
205 temp
.dump
.tx_cmd_ptr
= inl( ioaddr
+ TX_CMD_PTR_LO
);
206 temp
.dump
.rx_cmd_ptr
= inl( ioaddr
+ RX_CMD_PTR_LO
);
207 temp
.dump
.int_status
= inl( ioaddr
+ INTERRUPT_STATUS_REG
);
209 spin_unlock_irqrestore( &sp
->lock
, flags
);
210 copy_to_user( regs
, (char *) &temp
.dump
, sizeof( struct ncr885e_regs
));
221 /* Enable interrupts on the 53C885 */
223 ncr885e_enable( struct net_device
*dev
)
226 unsigned long ioaddr
= dev
->base_addr
;
229 reg
= inw(ioaddr
+ INTERRUPT_ENABLE
);
230 outw(reg
| INTERRUPT_INTE
, ioaddr
+ INTERRUPT_ENABLE
);
233 /* Disable interrupts on the 53c885 */
235 ncr885e_disable( struct net_device
*dev
)
238 unsigned long ioaddr
= dev
->base_addr
;
241 reg
= inw( ioaddr
+ INTERRUPT_ENABLE
);
242 outw( reg
& ~INTERRUPT_INTE
, ioaddr
+ INTERRUPT_ENABLE
);
247 ncr885e_reset( struct net_device
*dev
)
253 unsigned long ioaddr
= dev
->base_addr
;
255 if (ncr885e_debug
> 1)
256 printk( KERN_INFO
"%s: Resetting 53C885...\n", dev
->name
);
258 /* disable interrupts on the 53C885 */
259 ncr885e_disable( dev
);
261 /* disable rx in the MAC */
262 reg
= inw( ioaddr
+ MAC_CONFIG
);
263 outw( reg
& ~MAC_CONFIG_RXEN
, ioaddr
+ MAC_CONFIG
);
265 for( i
=0; i
< 100; i
++ ) {
267 if ( !(inw( ioaddr
+ MAC_CONFIG
) & MAC_CONFIG_RXEN
))
272 reg
= inw( ioaddr
+ MAC_CONFIG
);
273 outw( reg
| MAC_CONFIG_SRST
, ioaddr
+ MAC_CONFIG
);
274 outw( reg
, ioaddr
+ MAC_CONFIG
);
276 /* disable both rx and tx DBDMA channels */
277 outl( TX_DBDMA_ENABLE
<< 16, ioaddr
+ TX_CHANNEL_CONTROL
);
278 outl( RX_DBDMA_ENABLE
<< 16, ioaddr
+ RX_CHANNEL_CONTROL
);
280 for( i
=0; i
< 100; i
++ ) {
282 if ( !(inw( ioaddr
+ TX_CHANNEL_STATUS
) & TX_DBDMA_ENABLE
) &&
283 !(inw( ioaddr
+ RX_CHANNEL_STATUS
) & RX_DBDMA_ENABLE
))
288 /* perform a "software reset" */
289 cntl
= inl( ioaddr
+ DBDMA_CONTROL
);
290 outl( cntl
| DBDMA_SRST
, ioaddr
+ DBDMA_CONTROL
);
292 for( i
=0; i
< 100; i
++ ) {
294 if ( !(inl( ioaddr
+ DBDMA_CONTROL
) & DBDMA_SRST
))
299 /* books says that a software reset should be done to the MAC, as
300 well. This true??? */
302 if (ncr885e_debug
> 3)
303 printk( KERN_INFO
"%s: reset complete\n", dev
->name
);
308 /* configure the 53C885 chip.
310 The DBDMA command descriptors on the 53C885 can be programmed to
311 branch, interrupt or pause conditionally or always by using the
312 interrupt, branch and wait select registers. */
315 ncr885e_config( struct net_device
*dev
)
318 unsigned long ioaddr
= dev
->base_addr
;
320 if (ncr885e_debug
> 3)
321 printk( KERN_INFO
"%s: Configuring 53C885.\n", dev
->name
);
323 ncr885e_reset( dev
);
325 /* The 53C885 can be programmed to perform conditional DBDMA
326 branches, interrupts or waits.
328 Neither channel makes use of "wait", as it requires that the
329 DBDMA engine to be restarted. Don't go there. The rx channel
330 will branch upon the successful reception of a packet ('EOP' in
331 the xfer_status field). The branch address is to the STOP
332 DBDMA command descriptor, which shuts down the rx channel until
333 the interrupt is serviced. */
335 /* cause tx channel to stop after "status received" */
336 outl( 0, ioaddr
+ TX_INT_SELECT
);
337 outl( (TX_WAIT_STAT_RECV
<< 16) | TX_WAIT_STAT_RECV
,
338 ioaddr
+ TX_WAIT_SELECT
);
339 outl( 0, ioaddr
+ TX_BRANCH_SELECT
);
341 /* cause rx channel to branch to the STOP descriptor on "End-of-Packet" */
343 outl( (RX_INT_SELECT_EOP
<< 16) | RX_INT_SELECT_EOP
,
344 ioaddr
+ RX_INT_SELECT
);
346 outl( 0, ioaddr
+ RX_INT_SELECT
);
349 outl( 0, ioaddr
+ RX_WAIT_SELECT
);
351 outl( (RX_WAIT_SELECT_EOP
<< 16) | RX_WAIT_SELECT_EOP
,
352 ioaddr
+ RX_WAIT_SELECT
);
355 outl( 0, ioaddr
+ RX_BRANCH_SELECT
);
357 outl( (RX_BRANCH_SELECT_EOP
<< 16) | RX_BRANCH_SELECT_EOP
,
358 ioaddr
+ RX_BRANCH_SELECT
);
361 /* configure DBDMA */
362 outl( (DBDMA_BE
| DBDMA_DPMRLE
| DBDMA_TDPCE
|
363 DBDMA_DDPE
| DBDMA_TDPE
|
364 (DBDMA_BURST_4
<< DBDMA_TX_BST_SHIFT
) |
365 (DBDMA_BURST_4
<< DBDMA_RX_BST_SHIFT
) |
366 (DBDMA_TX_ARBITRATION_DEFAULT
) |
367 (DBDMA_RX_ARBITRATION_DEFAULT
)), ioaddr
+ DBDMA_CONTROL
);
369 outl( 0, ioaddr
+ TX_THRESHOLD
);
371 /* disable MAC loopback */
372 outl( (MAC_CONFIG_ITXA
| MAC_CONFIG_RXEN
| MAC_CONFIG_RETRYL
|
373 MAC_CONFIG_PADEN
| (0x18 << 16)),
374 ioaddr
+ MAC_CONFIG
);
377 outl( (MAC_CONFIG_ITXA
| MAC_CONFIG_RXEN
| MAC_CONFIG_RETRYL
|
378 MAC_CONFIG_PADEN
| ( 0x18 << 16)), ioaddr
+ MAC_CONFIG
);
380 outw( (0x1018), ioaddr
+ NBTOB_INTP_GAP
);
382 /* clear and enable interrupts */
383 inw( ioaddr
+ INTERRUPT_CLEAR
);
384 ncr885e_enable( dev
);
386 /* and enable them in the chip */
387 outl( (INTERRUPT_INTE
|INTERRUPT_TX_MASK
|INTERRUPT_RX_MASK
)<<16,
388 ioaddr
+ INTERRUPT_ENABLE
- 2);
390 if (ncr885e_debug
> 3)
391 printk( KERN_INFO
"%s: 53C885 config complete.\n", dev
->name
);
399 transmit interrupt */
402 ncr885e_tx( struct net_device
*dev
)
405 struct ncr885e_private
*sp
= (struct ncr885e_private
*) dev
->priv
;
406 volatile struct dbdma_cmd
*cp
, *dp
;
407 unsigned short txbits
, xfer
;
410 del_timer( &sp
->tx_timeout
);
412 if (ncr885e_debug
> 3)
413 printk( KERN_INFO
"%s: ncr885e_tx: active=%d, dirty=%d, current=%d\n",
414 dev
->name
, sp
->tx_active
, sp
->tx_dirty
, sp
->tx_current
);
416 sp
->timeout_active
= 0;
419 cp
= sp
->tx_cmds
+ (i
*3);
423 xfer
= inw( &dp
->xfer_status
);
424 txbits
= inw( &sp
->tx_status
[i
] );
426 if (ncr885e_debug
> 4) {
427 show_dbdma_cmd( cp
);
428 show_dbdma_cmd( dp
);
431 /* get xmit result */
432 txbits
= inw( &sp
->tx_status
[i
] );
434 if (ncr885e_debug
> 3)
435 printk( KERN_INFO
"%s: tx xfer=%04x, txbits=%04x\n", dev
->name
,
438 /* look for any channel status (?) */
441 dev_kfree_skb( sp
->tx_skbufs
[i
] );
444 if ( txbits
& TX_STATUS_TXOK
) {
445 sp
->stats
.tx_packets
++;
446 sp
->stats
.tx_bytes
+= inw( &cp
->req_count
);
449 /* dropped packets */
450 if ( txbits
& (TX_STATUS_TDLC
|TX_STATUS_TDEC
) ) {
451 sp
->stats
.tx_dropped
++;
454 /* add the collisions */
455 sp
->stats
.collisions
+= ( txbits
& 0x04 );
464 /* rx interrupt handling */
466 ncr885e_rx( struct net_device
*dev
)
469 struct ncr885e_private
*sp
= (struct ncr885e_private
*) dev
->priv
;
470 volatile struct dbdma_cmd
*cp
;
473 unsigned short status
;
474 unsigned char *data
, *stats
;
475 unsigned long rxbits
, ioaddr
= dev
->base_addr
;
478 cp
= sp
->rx_cmds
+ (i
*2);
480 if (ncr885e_debug
> 3)
481 printk( KERN_INFO
"%s: ncr885e_rx dirty=%d, current=%d (cp@%p)\n",
482 dev
->name
, sp
->rx_dirty
, sp
->rx_current
, cp
);
484 nb
= inw( &cp
->req_count
) - inw( &cp
->res_count
);
485 status
= inw( &cp
->xfer_status
);
487 if (ncr885e_debug
> 3)
488 printk( KERN_INFO
"%s: (rx %d) bytes=%d, xfer_status=%04x\n",
489 dev
->name
, i
, nb
, status
);
493 skb
= sp
->rx_skbufs
[i
];
495 stats
= data
+ nb
- 3;
496 rxbits
= (stats
[0]|stats
[1]<<8|stats
[2]<<16);
498 if (ncr885e_debug
> 3)
499 printk( KERN_INFO
" rx_bits=%06lx\n", rxbits
);
502 skb_put( skb
, nb
-3 );
503 skb
->protocol
= eth_type_trans( skb
, dev
);
505 sp
->rx_skbufs
[i
] = 0;
507 if ( rxbits
& RX_STATUS_RXOK
) {
508 sp
->stats
.rx_packets
++;
509 sp
->stats
.rx_bytes
+= nb
;
512 if ( rxbits
& RX_STATUS_MCAST
)
513 sp
->stats
.multicast
++;
517 sp
->rx_dirty
= sp
->rx_current
;
519 if ( ++sp
->rx_current
>= NR_RX_RING
)
522 /* fix up the one we just trashed */
523 cp
= sp
->rx_cmds
+ (sp
->rx_dirty
* 2);
525 skb
= dev_alloc_skb( RX_BUFLEN
+ 2 );
527 skb_reserve( skb
, 2 );
528 sp
->rx_skbufs
[sp
->rx_dirty
] = skb
;
531 if (ncr885e_debug
> 2)
532 printk( KERN_INFO
"%s: ncr885e_rx: using ring index %d, filling cp @ %p\n",
533 dev
->name
, sp
->rx_current
, cp
);
535 outw( RX_BUFLEN
, &cp
->req_count
);
536 outw( 0, &cp
->res_count
);
538 outl( virt_to_bus( data
), &cp
->phy_addr
);
539 outw( 0, &cp
->xfer_status
);
541 cp
= sp
->rx_cmds
+ (sp
->rx_current
* 2);
544 outl( virt_to_bus( cp
), ioaddr
+ RX_CMD_PTR_LO
);
545 outl( (RX_DBDMA_ENABLE
<< 16)|RX_CHANNEL_RUN
,
546 ioaddr
+ RX_CHANNEL_CONTROL
);
552 ncr885e_misc_ints( struct net_device
*dev
, unsigned short status
)
555 struct ncr885e_private
*sp
= (struct ncr885e_private
*) dev
->priv
;
556 struct dbdma_cmd
*cp
;
557 unsigned long ioaddr
= dev
->base_addr
;
559 if (ncr885e_debug
> 1)
560 printk( KERN_INFO
"miscellaneous interrupt handled; status=%02x\n",
563 /* various transmit errors */
565 (INTERRUPT_PPET
| INTERRUPT_PBFT
| INTERRUPT_IIDT
) ) {
567 /* illegal instruction in tx dma */
568 if ( status
& INTERRUPT_IIDT
) {
570 cp
= (struct dbdma_cmd
*) bus_to_virt( inl( ioaddr
+ TX_CMD_PTR_LO
));
571 printk( KERN_INFO
"%s: tx illegal insn:\n", dev
->name
);
572 printk( KERN_INFO
" tx DBDMA - cmd = %p, status = %04x\n",
573 cp
, inw( ioaddr
+ TX_CHANNEL_STATUS
));
574 printk( KERN_INFO
" command = %04x, phy_addr=%08x, req_count=%04x\n",
575 inw( &cp
->command
), inw( &cp
->phy_addr
), inw( &cp
->req_count
));
578 if ( status
& INTERRUPT_PPET
)
579 printk( KERN_INFO
"%s: tx PCI parity error\n", dev
->name
);
581 if ( status
& INTERRUPT_PBFT
)
582 printk( KERN_INFO
"%s: tx PCI bus fault\n", dev
->name
);
585 /* look for rx errors */
587 (INTERRUPT_PPER
| INTERRUPT_PBFR
| INTERRUPT_IIDR
)) {
589 /* illegal instruction in rx dma */
590 if ( status
& INTERRUPT_IIDR
) {
592 cmd
= inl( ioaddr
+ RX_CMD_PTR_LO
);
594 printk( KERN_ERR
"%s: rx illegal DMA instruction:\n", dev
->name
);
595 printk( KERN_ERR
" channel status=%04x,\n",
596 inl( ioaddr
+ RX_CHANNEL_STATUS
));
598 show_dbdma_cmd( bus_to_virt( inl( ioaddr
+ RX_CMD_PTR_LO
)));
599 printk( KERN_ERR
" instr (%08x) %08x %08x %08x\n",
600 (int) cmd
, cmd
[0], cmd
[1], cmd
[2] );
604 /* PCI parity error */
605 if ( status
& INTERRUPT_PPER
)
606 printk( KERN_INFO
"%s: rx PCI parity error\n", dev
->name
);
608 if ( status
& INTERRUPT_PBFR
)
609 printk( KERN_INFO
"%s: rx PCI bus fault\n", dev
->name
);
611 sp
->stats
.rx_errors
++;
614 if ( status
& INTERRUPT_WI
) {
615 printk( KERN_INFO
"%s: link pulse\n", dev
->name
);
618 /* bump any counters */
625 ncr885e_interrupt( int irq
, void *dev_id
, struct pt_regs
*regs
)
628 struct net_device
*dev
= (struct net_device
*) dev_id
;
629 struct ncr885e_private
*sp
;
630 unsigned short status
;
634 printk( KERN_ERR
"symba: Interrupt IRQ %d for unknown device\n", irq
);
638 ioaddr
= dev
->base_addr
;
639 sp
= (struct ncr885e_private
*) dev
->priv
;
640 spin_lock( &sp
->lock
);
642 if ( dev
->interrupt
) {
643 printk( KERN_ERR
"%s: Re-entering interrupt handler...\n",
648 status
= inw( ioaddr
+ INTERRUPT_CLEAR
);
650 if (ncr885e_debug
> 2)
651 printk( KERN_INFO
"%s: 53C885 interrupt 0x%02x\n", dev
->name
, status
);
653 /* handle non-tx and rx interrupts first */
654 if ( status
& ~(INTERRUPT_DIT
|INTERRUPT_DIR
))
655 ncr885e_misc_ints( dev
, status
);
657 /* look for tx interrupt: more to transmit, DBDMA stopped, or tx done */
658 if ( ( status
& INTERRUPT_DIT
) ) {
660 if (ncr885e_debug
> 2)
661 printk( KERN_INFO
"%s: tx int; int=%02x, chan stat=%02x\n",
662 dev
->name
, status
, inw( ioaddr
+ TX_CHANNEL_STATUS
));
665 del_timer( &sp
->tx_timeout
);
666 sp
->timeout_active
= 0;
669 outl( TX_DBDMA_ENABLE
<< 16, ioaddr
+ TX_CHANNEL_CONTROL
);
674 if ( status
& INTERRUPT_DIR
) {
676 if ( ncr885e_debug
> 2 )
677 printk( KERN_INFO
"%s: rx interrupt; int=%02x, rx channel stat=%02x\n",
678 dev
->name
, status
, inw( ioaddr
+ RX_CHANNEL_STATUS
));
681 outl( RX_DBDMA_ENABLE
<< 16, ioaddr
+ RX_CHANNEL_CONTROL
);
683 /* and handle the interrupt */
688 spin_unlock( &sp
->lock
);
694 /* doesn't set the address permanently, however... */
696 ncr885e_set_address( struct net_device
*dev
, void *addr
)
699 struct ncr885e_private
*sp
= (struct ncr885e_private
*) dev
->priv
;
700 struct sockaddr
*saddr
= addr
;
702 unsigned short reg
[3];
703 unsigned char *ioaddr
, *p
;
706 memcpy( dev
->dev_addr
, saddr
->sa_data
, dev
->addr_len
);
708 p
= (unsigned char *) dev
->dev_addr
;
709 printk( KERN_INFO
"%s: setting new MAC address - ", dev
->name
);
711 for( p
= (unsigned char *) dev
->dev_addr
, i
=0; i
< 6; i
++, p
++ )
712 printk("%c%2.2x", i
? ':' : ' ', *p
);
716 p
= (unsigned char *) ®
;
717 for( i
=0; i
< 6; i
++ )
718 p
[i
] = dev
->dev_addr
[i
];
721 printk("%s: Setting new mac address - ", dev
->name
);
722 for( i
=0; i
< 6; i
++ ) {
723 printk("%02x", i
? ':' : ' ', p
[i
] );
729 /* stop rx for the change */
730 outl( RX_DBDMA_ENABLE
<< 16, ioaddr
+ RX_CHANNEL_CONTROL
);
732 spin_lock_irqsave( &sp
->lock
, flags
);
734 ioaddr
= (unsigned char *) dev
->base_addr
;
736 for( i
= 0; i
< 3; i
++ ) {
737 reg
[i
] = ((reg
[i
] & 0xff) << 8) | ((reg
[i
] >> 8) & 0xff);
738 printk("%04x ", reg
[i
] );
739 outw( reg
[i
], ioaddr
+ STATION_ADDRESS_0
+ (i
*2));
743 spin_unlock_irqrestore( &sp
->lock
, flags
);
746 outl((RX_DBDMA_ENABLE
<< 16)|RX_CHANNEL_RUN
,
747 ioaddr
+ RX_CHANNEL_CONTROL
);
753 ncr885e_tx_timeout( unsigned long data
)
756 struct net_device
*dev
= (struct net_device
*) data
;
757 struct ncr885e_private
*sp
= (struct ncr885e_private
*) dev
->priv
;
758 unsigned long flags
, ioaddr
;
764 ioaddr
= dev
->base_addr
;
765 sp
->timeout_active
= 0;
768 /* if we weren't active, bail... */
769 if ( sp
->tx_active
== 0 ) {
770 printk( KERN_INFO
"%s: ncr885e_timeout...tx not active!\n", dev
->name
);
774 printk( KERN_ERR
"%s: 53C885 timed out. Resetting...\n", dev
->name
);
776 /* disable rx and tx DMA */
777 outl( (TX_DBDMA_ENABLE
<< 16), ioaddr
+ TX_CHANNEL_CONTROL
);
778 outl( (RX_DBDMA_ENABLE
<< 16), ioaddr
+ RX_CHANNEL_CONTROL
);
781 ncr885e_config( dev
);
782 ncr885e_enable( dev
);
784 /* clear the wedged skb in the tx ring */
786 ++sp
->stats
.tx_errors
;
788 if ( sp
->tx_skbufs
[i
] ) {
789 dev_kfree_skb( sp
->tx_skbufs
[i
] );
790 sp
->tx_skbufs
[i
] = 0;
793 /* start anew from the beginning of the ring buffer (why not?) */
799 outl( (RX_DBDMA_ENABLE
<< 16) | RX_CHANNEL_RUN
,
800 ioaddr
+ RX_CHANNEL_CONTROL
);
803 restore_flags( flags
);
807 ncr885e_set_timeout( struct net_device
*dev
)
810 struct ncr885e_private
*sp
= (struct ncr885e_private
*) dev
->priv
;
816 if ( sp
->timeout_active
)
817 del_timer( &sp
->tx_timeout
);
819 sp
->tx_timeout
.expires
= jiffies
+ TX_TIMEOUT
;
820 sp
->tx_timeout
.function
= ncr885e_tx_timeout
;
821 sp
->tx_timeout
.data
= (unsigned long) dev
;
822 add_timer( &sp
->tx_timeout
);
823 sp
->timeout_active
= 1;
824 restore_flags( flags
);
829 * The goal is to set up DBDMA such that the rx ring contains only
830 * one DMA descriptor per ring element and the tx ring has two (using
831 * the cool features of branch- and wait-select. However, I'm not sure
832 * if it's possible. For now, we plod through it with 3 descriptors
833 * for tx, and two for rx.
837 ncr885e_open( struct net_device
*dev
)
840 struct ncr885e_private
*sp
= (struct ncr885e_private
*) dev
->priv
;
841 unsigned long ioaddr
= dev
->base_addr
;
845 struct dbdma_cmd
*cp
;
848 /* allocate enough space for the tx and rx rings and a STOP descriptor */
849 size
= (sizeof( struct dbdma_cmd
) *
850 ((NR_TX_RING
* 3) + (NR_RX_RING
* 2) + 1));
852 cp
= kmalloc( size
, GFP_KERNEL
);
855 printk( KERN_ERR
"Insufficient memory (%d bytes) for DBDMA\n", size
);
859 spin_lock_init( &sp
->lock
);
860 spin_lock_irqsave( &sp
->lock
, flags
);
862 memset((char *) cp
, 0, size
);
866 outl( DBDMA_STOP
, &cp
->command
);
870 for( i
= 0; i
< NR_RX_RING
; i
++ ) {
872 cp
= sp
->rx_cmds
+ (i
*2);
873 skb
= dev_alloc_skb( RX_BUFLEN
+ 2 );
875 /* if there is insufficient memory, make this last ring use a
876 static buffer and leave the loop with that skb as final one */
878 printk( KERN_ERR
"%s: insufficient memory for rx ring buffer\n",
883 skb_reserve( skb
, 2 );
884 sp
->rx_skbufs
[i
] = skb
;
887 /* The DMA commands here are done such that an EOP is the only
888 way that we should get an interrupt. This means that we could
889 fill more than one skbuff before getting the interrupt at EOP. */
891 /* Handle rx DMA such that it always interrupts.... */
892 outw( (INPUT_MORE
|INTR_ALWAYS
), &cp
->command
);
893 outw( RX_BUFLEN
, &cp
->req_count
);
894 outw( 0, &cp
->res_count
);
895 outl( virt_to_bus( data
), &cp
->phy_addr
);
896 outl( virt_to_bus( sp
->stop_cmd
), &cp
->cmd_dep
);
897 outw( 0, &cp
->xfer_status
);
899 printk( KERN_INFO
"rx at %p\n", cp
);
900 show_dbdma_cmd( cp
);
904 outw( DBDMA_STOP
, &cp
->command
);
908 /* initialize to all rx buffers are available, fill limit is the end */
912 /* fill the tx ring */
915 for( i
= 0; i
< NR_TX_RING
; i
++ ) {
917 /* minimal setup for tx command */
918 cp
= sp
->tx_cmds
+ (i
*3);
919 outw( OUTPUT_LAST
, &cp
->command
);
920 if (ncr885e_debug
> 3) {
921 printk( KERN_INFO
"tx OUTPUT_LAST at %p\n", cp
);
922 show_dbdma_cmd( cp
);
925 /* full setup for the status cmd */
927 outw( INPUT_LAST
|INTR_ALWAYS
|WAIT_IFCLR
, &cp
->command
);
928 outl( virt_to_bus( &sp
->tx_status
[i
] ), &cp
->phy_addr
);
929 outw( 2, &cp
->req_count
);
930 if ( ncr885e_debug
> 3) {
931 printk( KERN_INFO
"tx INPUT_LAST cmd at %p\n", cp
);
932 show_dbdma_cmd( cp
);
936 outw( DBDMA_STOP
, &cp
->command
);
940 /* chain the last tx DMA command to the STOP cmd */
941 outw((INPUT_LAST
|INTR_ALWAYS
|BR_ALWAYS
), &cp
->command
);
942 outl( virt_to_bus( sp
->stop_cmd
), &cp
->cmd_dep
);
948 spin_unlock_irqrestore( &sp
->lock
, flags
);
950 /* the order seems important here for some reason. If the MPIC isn't
951 enabled before the ethernet chip is enabled, shrapnel from the
952 bootloader causes us to receive interrupts even though we've not
953 yet enabled the tx channel. Go figure. It'd be better to configure
954 the chip in the probe1() routine, but then we don't see interrupts
955 at all. Everything looks all right on the logic analyzer, but... */
957 ncr885e_config( dev
);
959 /* enable ethernet interrupts */
960 if ( request_irq( dev
->irq
, &ncr885e_interrupt
, SA_SHIRQ
, chipname
, dev
)) {
961 printk( KERN_ERR
"%s: can't get irq %d\n", dev
->name
, dev
->irq
);
965 (void) inw( ioaddr
+ INTERRUPT_CLEAR
);
967 ncr885e_enable( dev
);
970 outl( virt_to_bus( sp
->rx_cmds
), ioaddr
+ RX_CMD_PTR_LO
);
971 outl( (RX_DBDMA_ENABLE
<< 16)|RX_CHANNEL_RUN
,
972 ioaddr
+ RX_CHANNEL_CONTROL
);
984 ncr885e_xmit_start( struct sk_buff
*skb
, struct net_device
*dev
)
987 struct ncr885e_private
*sp
= (struct ncr885e_private
*) dev
->priv
;
988 volatile struct dbdma_cmd
*cp
, *dp
;
989 unsigned long flags
, ioaddr
= dev
->base_addr
;
990 int len
, next
, fill
, entry
;
992 if ( ncr885e_debug
> 3)
993 printk( KERN_INFO
"%s: xmit_start len=%d, dirty=%d, current=%d, active=%d\n",
994 dev
->name
, skb
->len
, sp
->tx_dirty
, sp
->tx_current
, sp
->tx_active
);
996 spin_lock_irqsave( &sp
->lock
, flags
);
998 /* find the free slot in the ring buffer */
999 fill
= sp
->tx_current
;
1002 if ( next
>= NR_TX_RING
)
1005 /* mark ourselves as busy, even if we have too many packets waiting */
1008 /* see if it's necessary to defer this packet */
1009 if ( sp
->tx_active
>= MAX_TX_ACTIVE
) {
1010 spin_unlock_irqrestore( &sp
->lock
, flags
);
1014 sp
->tx_active
++; /* bump "active tx" count */
1015 sp
->tx_current
= next
; /* and show that we've used this buffer */
1016 sp
->tx_dirty
= fill
; /* and mark this one to get picked up */
1020 if ( len
> ETH_FRAME_LEN
) {
1021 printk( KERN_DEBUG
"%s: xmit frame too long (%d)\n", dev
->name
, len
);
1022 len
= ETH_FRAME_LEN
;
1025 /* get index into the tx DBDMA chain */
1027 sp
->tx_skbufs
[fill
] = skb
;
1028 cp
= sp
->tx_cmds
+ entry
;
1031 /* update the rest of the OUTPUT_MORE descriptor */
1032 outw( len
, &cp
->req_count
);
1033 outl( virt_to_bus( skb
->data
), &cp
->phy_addr
);
1034 outw( 0, &cp
->xfer_status
);
1035 outw( 0, &cp
->res_count
);
1037 /* and finish off the INPUT_MORE */
1038 outw( 0, &dp
->xfer_status
);
1039 outw( 0, &dp
->res_count
);
1040 sp
->tx_status
[fill
] = 0;
1041 outl( virt_to_bus( &sp
->tx_status
[fill
] ), &dp
->phy_addr
);
1043 if ( ncr885e_debug
> 2 )
1044 printk(KERN_INFO
"%s: xmit_start: active %d, tx_current %d, tx_dirty %d\n",
1045 dev
->name
, sp
->tx_active
, sp
->tx_current
, sp
->tx_dirty
);
1047 if ( ncr885e_debug
> 4 ) {
1048 show_dbdma_cmd( cp
);
1049 show_dbdma_cmd( dp
);
1053 /* restart the tx DMA engine */
1054 outl( virt_to_bus( cp
), ioaddr
+ TX_CMD_PTR_LO
);
1055 outl( (TX_DBDMA_ENABLE
<< 16)|TX_CHANNEL_RUN
,
1056 ioaddr
+ TX_CHANNEL_CONTROL
);
1058 ncr885e_set_timeout( dev
);
1060 spin_unlock_irqrestore( &sp
->lock
, flags
);
1061 dev
->trans_start
= jiffies
;
1067 ncr885e_close(struct net_device
*dev
)
1071 struct ncr885e_private
*np
= (struct ncr885e_private
*) dev
->priv
;
1072 unsigned long ioaddr
= dev
->base_addr
;
1077 spin_lock( &np
->lock
);
1079 printk(KERN_INFO
"%s: NCR885E Ethernet closing...\n", dev
->name
);
1081 if (ncr885e_debug
> 1)
1082 printk(KERN_DEBUG
"%s: Shutting down Ethernet chip\n", dev
->name
);
1084 ncr885e_disable(dev
);
1086 del_timer(&np
->tx_timeout
);
1088 /* flip off rx and tx */
1089 outl( (RX_DBDMA_ENABLE
<< 16), ioaddr
+ RX_CHANNEL_CONTROL
);
1090 outl( (TX_DBDMA_ENABLE
<< 16), ioaddr
+ TX_CHANNEL_CONTROL
);
1092 /* free up the IRQ */
1093 free_irq( dev
->irq
, dev
);
1095 for( i
= 0; i
< NR_RX_RING
; i
++ ) {
1096 if (np
->rx_skbufs
[i
])
1097 dev_kfree_skb( np
->rx_skbufs
[i
] );
1098 np
->rx_skbufs
[i
] = 0;
1101 for (i
= 0; i
< NR_TX_RING
; i
++) {
1102 if (np
->tx_skbufs
[i
])
1103 dev_kfree_skb(np
->tx_skbufs
[i
]);
1104 np
->tx_skbufs
[i
] = 0;
1107 spin_unlock( &np
->lock
);
1118 * multicast promiscuous mode isn't used here. Allow code in the
1119 * IP stack to determine which multicast packets are good or bad....
1120 * (this avoids having to use the hash table registers)
1123 ncr885e_set_multicast( struct net_device
*dev
)
1126 int ioaddr
= dev
->base_addr
;
1128 if ( ncr885e_debug
> 3 )
1129 printk("%s: set_multicast: dev->flags = %x, AF=%04x\n",
1130 dev
->name
, dev
->flags
, inw( ioaddr
+ ADDRESS_FILTER
));
1132 if ( dev
->flags
& IFF_PROMISC
) {
1133 printk( KERN_INFO
"%s: Promiscuous mode enabled.\n", dev
->name
);
1134 outw( ADDRESS_RPPRO
, ioaddr
+ ADDRESS_FILTER
);
1137 /* accept all multicast packets without checking the mc_list. */
1138 else if ( dev
->flags
& IFF_ALLMULTI
) {
1139 printk( KERN_INFO
"%s: Enabling all multicast packets.\n",
1141 outw( ADDRESS_RPPRM
, ioaddr
+ ADDRESS_FILTER
);
1144 /* enable broadcast rx */
1146 outw( ADDRESS_RPABC
, ioaddr
+ ADDRESS_FILTER
);
1150 static struct net_device_stats
*
1151 ncr885e_stats( struct net_device
*dev
)
1154 struct ncr885e_private
*np
= (struct ncr885e_private
*) dev
->priv
;
1159 /* By this function, we're certain that we have a 885 Ethernet controller
1160 * so we finish setting it up and wrap up all the required Linux ethernet
1165 ncr885e_probe1( struct net_device
*dev
, unsigned long ioaddr
, unsigned char irq
)
1168 struct ncr885e_private
*sp
;
1169 unsigned short station_addr
[3], val
;
1173 dev
= init_etherdev( dev
, 0 );
1175 /* construct private data for the 885 ethernet */
1176 dev
->priv
= kmalloc( sizeof( struct ncr885e_private
), GFP_KERNEL
);
1178 if ( dev
->priv
== NULL
)
1181 sp
= (struct ncr885e_private
*) dev
->priv
;
1182 memset( sp
, 0, sizeof( struct ncr885e_private
));
1184 /* snag the station address and display it */
1185 for( i
= 0; i
< 3; i
++ ) {
1186 val
= inw( ioaddr
+ STATION_ADDRESS_0
+ (i
*2));
1187 station_addr
[i
] = ((val
>> 8) & 0xff) | ((val
<< 8) & 0xff00);
1190 printk( KERN_INFO
"%s: %s at %08lx,", dev
->name
, chipname
, ioaddr
);
1192 p
= (unsigned char *) &station_addr
;
1194 for( i
=0; i
< 6; i
++ ) {
1195 dev
->dev_addr
[i
] = *p
;
1196 printk("%c%2.2x", i
? ':' : ' ', dev
->dev_addr
[i
] );
1200 printk(", IRQ %d.\n", irq
);
1202 request_region( ioaddr
, NCR885E_TOTAL_SIZE
, dev
->name
);
1204 /* set up a timer */
1205 init_timer( &sp
->tx_timeout
);
1206 sp
->timeout_active
= 0;
1208 dev
->base_addr
= ioaddr
;
1213 /* everything else */
1214 dev
->open
= ncr885e_open
;
1215 dev
->stop
= ncr885e_close
;
1216 dev
->get_stats
= ncr885e_stats
;
1217 dev
->hard_start_xmit
= ncr885e_xmit_start
;
1218 dev
->set_multicast_list
= ncr885e_set_multicast
;
1219 dev
->set_mac_address
= ncr885e_set_address
;
1224 /* Since the NCR 53C885 is a multi-function chip, I'm not worrying about
1225 * trying to get the the device(s) in slot order. For our (Synergy's)
1226 * purpose, there's just a single 53C885 on the board and we don't
1227 * worry about the rest.
1230 int __init
ncr885e_probe( struct net_device
*dev
)
1232 struct pci_dev
*pdev
= NULL
;
1233 unsigned int ioaddr
, chips
= 0;
1235 unsigned char irq
, latency
;
1237 while(( pdev
= pci_find_device( PCI_VENDOR_ID_NCR
,
1238 PCI_DEVICE_ID_NCR_53C885_ETHERNET
,
1241 if ( !print_version
) {
1243 printk( KERN_INFO
"%s", version
);
1247 pci_read_config_dword( pdev
, PCI_BASE_ADDRESS_0
, &ioaddr
);
1248 pci_read_config_byte( pdev
, PCI_INTERRUPT_LINE
, &irq
);
1251 /* Adjust around the Grackle... */
1252 #ifdef CONFIG_GEMINI
1253 ioaddr
|= 0xfe000000;
1256 if ( check_region( ioaddr
, NCR885E_TOTAL_SIZE
))
1259 /* finish off the probe */
1260 if ( !(ncr885e_probe1( dev
, ioaddr
, irq
))) {
1264 /* Access is via I/O space, bus master enabled... */
1265 pci_read_config_word( pdev
, PCI_COMMAND
, &cmd
);
1267 if ( !(cmd
& PCI_COMMAND_MASTER
) ) {
1268 printk( KERN_INFO
" PCI master bit not set! Now setting.\n");
1269 cmd
|= PCI_COMMAND_MASTER
;
1270 pci_write_config_word( pdev
, PCI_COMMAND
, cmd
);
1273 if ( !(cmd
& PCI_COMMAND_IO
) ) {
1274 printk( KERN_INFO
" Enabling I/O space.\n" );
1275 cmd
|= PCI_COMMAND_IO
;
1276 pci_write_config_word( pdev
, PCI_COMMAND
, cmd
);
1279 pci_read_config_byte( pdev
, PCI_LATENCY_TIMER
, &latency
);
1281 if ( latency
< 10 ) {
1282 printk( KERN_INFO
" PCI latency timer (CFLT) is unreasonably"
1283 " low at %d. Setting to 255.\n", latency
);
1284 pci_write_config_byte( pdev
, PCI_LATENCY_TIMER
, 255 );
1295 /* debugging to peek at dma descriptors */
1297 show_dbdma_cmd( volatile struct dbdma_cmd
*cmd
)
1300 printk( KERN_INFO
" cmd %04x, physaddr %08x, req_count %04x\n",
1301 inw( &cmd
->command
), inl( &cmd
->phy_addr
), inw( &cmd
->req_count
));
1302 printk( KERN_INFO
" res_count %04x, xfer_status %04x, branch %08x\n",
1303 inw( &cmd
->res_count
), inw( &cmd
->xfer_status
),inl( &cmd
->cmd_dep
));
1308 read_eeprom( unsigned int ioaddr
, int location
)
1314 outb( (location
& 0xff), ioaddr
+ EE_WORD_ADDR
);
1316 /* take spillover from location in control reg */
1317 outb(EE_CONTROL_RND_READB
| (location
& (0x7<<8)), ioaddr
+ EE_CONTROL
);
1320 while( (inb( ioaddr
+ EE_STATUS
) & EE_SEB
) &&
1326 if ( inb( ioaddr
+ EE_STATUS
) & EE_SEE
) {
1327 printk("%s: Serial EEPROM read error\n", chipname
);
1332 val
= inb( ioaddr
+ EE_READ_DATA
);
1338 #ifdef NCR885E_DEBUG_MII
1340 show_mii( unsigned long ioaddr
)
1343 int phyctrl
, phystat
, phyadvert
, phypartner
, phyexpan
;
1345 phyctrl
= read_mii( ioaddr
, MII_AUTO_NEGOTIATION_CONTROL
);
1346 phystat
= read_mii( ioaddr
, MII_AUTO_NEGOTIATION_STATUS
);
1347 phyadvert
= read_mii( ioaddr
, MII_AUTO_NEGOTIATION_ADVERTISEMENT
);
1348 phypartner
= read_mii( ioaddr
, MII_AUTO_NEGOTIATION_LINK_PARTNER
);
1349 phyexpan
= read_mii( ioaddr
, MII_AUTO_NEGOTIATION_EXPANSION
);
1351 printk( KERN_INFO
"PHY: advert=%d %s, partner=%s %s, link=%d, %s%s\n",
1352 (phyadvert
& MANATECH_100BASETX_FULL_DUPLEX
? 100 : 10),
1353 (phyctrl
& MANC_AUTO_NEGOTIATION_ENABLE
? "auto" : "fixed"),
1354 (phypartner
& MANLP_ACKNOWLEDGE
?
1355 (phypartner
& MANATECH_100BASETX_FULL_DUPLEX
? "100" : "10") :
1357 (phyexpan
& MANE_LINK_PARTNER_AUTO_ABLE
? "auto" : "fixed"),
1358 (phyctrl
& MANC_PHY_SPEED_100
? 100 : 10),
1359 (phystat
& MANS_LINK_STATUS
? "up" : "down"),
1360 (phyexpan
& MANE_PARALLEL_DETECTION_FAULT
? " PD-fault" : "" ));
1366 read_mii( unsigned long ioaddr
, int reg
)
1374 while( inw( ioaddr
+ MII_INDICATOR
) & MII_BUSY
) {
1376 if ( timeout
-- < 0 ) {
1377 printk( KERN_INFO
"Timed out waiting for MII\n" );
1382 outw( (1<<8) + reg
, ioaddr
+ MII_ADDRESS
);
1383 outw( MIIM_RSTAT
, ioaddr
+ MIIM_COMMAND
);
1386 while( inw( ioaddr
+ MII_INDICATOR
) & MII_BUSY
) {
1387 if ( timeout
-- < 0 ) {
1388 printk( KERN_INFO
"Timed out waiting for MII\n" );
1393 return( inw( ioaddr
+ MII_READ_DATA
));
1397 write_mii( unsigned long ioaddr
, int reg
, int data
)
1402 printk( KERN_INFO
"MII indicator: %02x\n", inw( ioaddr
+ MII_INDICATOR
));
1404 while( inw( ioaddr
+ MII_INDICATOR
) & MII_BUSY
) {
1405 if ( timeout
-- <= 0 ) {
1406 printk( KERN_INFO
"Timeout waiting to write to MII\n" );
1412 outw( (1<<8) + reg
, ioaddr
+ MII_ADDRESS
);
1413 outw( data
, ioaddr
+ MII_WRITE_DATA
);
1418 #endif /* NCR885E_DEBUG_MII */
1421 #if defined(LINUX_VERSION_CODE) && LINUX_VERSION_CODE > 0x20118
1422 MODULE_AUTHOR("dan@synergymicro.com");
1423 MODULE_DESCRIPTION("Symbios 53C885 Ethernet driver");
1424 MODULE_PARM(debug
, "i");
1427 static int debug
= 1;
1433 ncr885e_debug
= debug
;
1435 return ncr885e_probe( NULL
);
1439 cleanup_module(void)
1441 struct ncr885e_private
*np
;
1445 unregister_netdev( root_dev
);
1446 np
= (struct ncr885e_private
*) root_dev
->priv
;
1447 release_region( root_dev
->base_addr
, NCR885E_TOTAL_SIZE
);
1448 kfree( root_dev
->priv
);
1456 * compile-command: "gcc -DMODULE -DMODVERSIONS -D__KERNEL__ -I../../include -Wall -Wstrict-prototypes -O6 -c symba.c"