00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 static const char *version =
00014 "ncr885e.c:v0.8 11/30/98 dan@synergymicro.com\n";
00015
00016 #include <linux/config.h>
00017
00018 #ifdef MODULE
00019 #ifdef MODVERSIONS
00020 #include <linux/modversions.h>
00021 #endif
00022 #include <linux/module.h>
00023 #include <linux/version.h>
00024 #else
00025 #define MOD_INC_USE_COUNT
00026 #define MOD_DEC_USE_COUNT
00027 #endif
00028
00029 #include <linux/kernel.h>
00030 #include <linux/sched.h>
00031 #include <linux/timer.h>
00032 #include <linux/ptrace.h>
00033 #include <linux/malloc.h>
00034 #include <linux/netdevice.h>
00035 #include <linux/pci.h>
00036 #include <linux/malloc.h>
00037 #include <linux/delay.h>
00038 #include <linux/ioport.h>
00039 #include <linux/errno.h>
00040 #include <linux/init.h>
00041 #include <asm/io.h>
00042 #include <asm/dbdma.h>
00043 #include <asm/uaccess.h>
00044
00045 #include <linux/etherdevice.h>
00046 #include <linux/skbuff.h>
00047
00048 #include "ncr885e.h"
00049 #include "ncr885_debug.h"
00050
00051 static const char *chipname = "ncr885e";
00052
00053
00054 #if 0
00055 #define DEBUG_FUNC 0x0001
00056 #define DEBUG_PACKET 0x0002
00057 #define DEBUG_CMD 0x0004
00058 #define DEBUG_CHANNEL 0x0008
00059 #define DEBUG_INT 0x0010
00060 #define DEBUG_RX 0x0020
00061 #define DEBUG_TX 0x0040
00062 #define DEBUG_DMA 0x0080
00063 #define DEBUG_MAC 0x0100
00064 #define DEBUG_DRIVER 0x0200
00065 #define DEBUG_ALL 0x1fff
00066 #endif
00067
00068 #ifdef DEBUG_NCR885E
00069 #define NCR885E_DEBUG 0
00070 #else
00071 #define NCR885E_DEBUG 0
00072 #endif
00073
00074
00075 #ifndef PCI_DEVICE_ID_NCR_53C885_ETHERNET
00076 #define PCI_DEVICE_ID_NCR_53C885_ETHERNET 0x0701
00077 #endif
00078
00079 #define NR_RX_RING 8
00080 #define NR_TX_RING 8
00081 #define MAX_TX_ACTIVE (NR_TX_RING-1)
00082 #define NCMDS_TX NR_TX_RING
00083
00084 #define RX_BUFLEN (ETH_FRAME_LEN + 8)
00085 #define TX_TIMEOUT 5*HZ
00086
00087 #define NCR885E_TOTAL_SIZE 0xe0
00088
00089 #define TXSR (1<<6)
00090 #define TXABORT (1<<7)
00091 #define EOP (1<<7)
00092
00093 int ncr885e_debug = NCR885E_DEBUG;
00094 static int print_version = 0;
00095
00096 struct ncr885e_private {
00097
00098
00099 struct dbdma_cmd *head;
00100 struct dbdma_cmd *tx_cmds;
00101 struct dbdma_cmd *rx_cmds;
00102 struct dbdma_cmd *stop_cmd;
00103
00104 struct sk_buff *tx_skbufs[NR_TX_RING];
00105 struct sk_buff *rx_skbufs[NR_RX_RING];
00106
00107 int rx_current;
00108 int rx_dirty;
00109
00110 int tx_dirty;
00111 int tx_current;
00112
00113 unsigned short tx_status[NR_TX_RING];
00114
00115 unsigned char tx_fullup;
00116 unsigned char tx_active;
00117
00118 struct net_device_stats stats;
00119
00120 struct device *dev;
00121
00122 struct timer_list tx_timeout;
00123 int timeout_active;
00124
00125 spinlock_t lock;
00126 };
00127
00128 #ifdef MODULE
00129 static struct device *root_dev = NULL;
00130 #endif
00131
00132
00133 static int ncr885e_open( struct device *dev );
00134 static int ncr885e_close( struct device *dev );
00135 static void ncr885e_rx( struct device *dev );
00136 static void ncr885e_tx( struct device *dev );
00137 static int ncr885e_probe1( struct device *dev, unsigned long ioaddr,
00138 unsigned char irq );
00139 static int ncr885e_xmit_start( struct sk_buff *skb, struct device *dev );
00140 static struct net_device_stats *ncr885e_stats( struct device *dev );
00141 static void ncr885e_set_multicast( struct device *dev );
00142 static void ncr885e_config( struct device *dev );
00143 static int ncr885e_set_address( struct device *dev, void *addr );
00144 static void ncr885e_interrupt( int irq, void *dev_id, struct pt_regs *regs );
00145 static void show_dbdma_cmd( volatile struct dbdma_cmd *cmd );
00146 #if 0
00147 static int read_eeprom( unsigned int ioadddr, int location );
00148 #endif
00149
00150 #ifdef NCR885E_DEBUG_MII
00151 static void show_mii( unsigned long ioaddr );
00152 static int read_mii( unsigned long ioaddr, int reg );
00153 static void write_mii( unsigned long ioaddr, int reg, int data );
00154 #endif
00155
00156 #define TX_RESET_FLAGS (TX_CHANNEL_RUN|TX_CHANNEL_PAUSE|TX_CHANNEL_WAKE)
00157 #define RX_RESET_FLAGS (RX_CHANNEL_RUN|RX_CHANNEL_PAUSE|RX_CHANNEL_WAKE)
00158
00159
00160 #if 0
00161 static int
00162 debug_ioctl( struct device *dev, struct ifreq *req, int cmd )
00163 {
00164 unsigned long ioaddr = dev->base_addr;
00165 struct ncr885e_private *sp = (struct ncr885e_private *) dev->priv;
00166 struct ncr885e_private *data;
00167 struct ncr885e_regs *regs;
00168 unsigned long flags;
00169
00170 union {
00171 struct ncr885e_regs dump;
00172 struct ncr885e_private priv;
00173 } temp;
00174
00175 switch( cmd ) {
00176
00177
00178 case NCR885E_GET_PRIV:
00179
00180 data = (struct ncr885e_private *) &req->ifr_data;
00181
00182 if ( verify_area(VERIFY_WRITE, &req->ifr_data,
00183 sizeof( struct ncr885e_private )))
00184 return -EFAULT;
00185
00186 memcpy((char *) &temp.priv, sp, sizeof( struct ncr885e_private ));
00187 copy_to_user( data, (char *) &temp.priv, sizeof( struct ncr885e_private));
00188 break;
00189
00190 case NCR885E_GET_REGS:
00191
00192 regs = (struct ncr885e_regs *) &req->ifr_data;
00193
00194 if ( verify_area( VERIFY_WRITE, &req->ifr_data,
00195 sizeof( struct ncr885e_regs )))
00196 return -EFAULT;
00197
00198 spin_lock_irqsave( &sp->lock, flags );
00199
00200 temp.dump.tx_status = inl( ioaddr + TX_CHANNEL_STATUS );
00201 temp.dump.rx_status = inl( ioaddr + RX_CHANNEL_STATUS );
00202 temp.dump.mac_config = inl( ioaddr + MAC_CONFIG );
00203 temp.dump.tx_control = inl( ioaddr + TX_CHANNEL_CONTROL );
00204 temp.dump.rx_control = inl( ioaddr + RX_CHANNEL_CONTROL );
00205 temp.dump.tx_cmd_ptr = inl( ioaddr + TX_CMD_PTR_LO );
00206 temp.dump.rx_cmd_ptr = inl( ioaddr + RX_CMD_PTR_LO );
00207 temp.dump.int_status = inl( ioaddr + INTERRUPT_STATUS_REG );
00208
00209 spin_unlock_irqrestore( &sp->lock, flags );
00210 copy_to_user( regs, (char *) &temp.dump, sizeof( struct ncr885e_regs ));
00211
00212 break;
00213
00214 default:
00215 return -EOPNOTSUPP;
00216 }
00217 return 0;
00218 }
00219 #endif
00220
00221
00222 static inline void
00223 ncr885e_enable( struct device *dev )
00224
00225 {
00226 unsigned long ioaddr = dev->base_addr;
00227 unsigned short reg;
00228
00229 reg = inw(ioaddr + INTERRUPT_ENABLE);
00230 outw(reg | INTERRUPT_INTE, ioaddr + INTERRUPT_ENABLE);
00231 }
00232
00233
00234 static inline void
00235 ncr885e_disable( struct device *dev )
00236
00237 {
00238 unsigned long ioaddr = dev->base_addr;
00239 unsigned short reg;
00240
00241 reg = inw( ioaddr + INTERRUPT_ENABLE );
00242 outw( reg & ~INTERRUPT_INTE, ioaddr + INTERRUPT_ENABLE );
00243 }
00244
00245
00246 static inline void
00247 ncr885e_reset( struct device *dev )
00248
00249 {
00250 unsigned short reg;
00251 unsigned long cntl;
00252 int i;
00253 unsigned long ioaddr = dev->base_addr;
00254
00255 if (ncr885e_debug > 1)
00256 printk( KERN_INFO "%s: Resetting 53C885...\n", dev->name );
00257
00258
00259 ncr885e_disable( dev );
00260
00261
00262 reg = inw( ioaddr + MAC_CONFIG );
00263 outw( reg & ~MAC_CONFIG_RXEN, ioaddr + MAC_CONFIG );
00264
00265 for( i=0; i < 100; i++ ) {
00266
00267 if ( !(inw( ioaddr + MAC_CONFIG ) & MAC_CONFIG_RXEN ))
00268 break;
00269 udelay( 10 );
00270 }
00271
00272 reg = inw( ioaddr + MAC_CONFIG );
00273 outw( reg | MAC_CONFIG_SRST, ioaddr + MAC_CONFIG );
00274 outw( reg, ioaddr + MAC_CONFIG );
00275
00276
00277 outl( TX_DBDMA_ENABLE << 16, ioaddr + TX_CHANNEL_CONTROL );
00278 outl( RX_DBDMA_ENABLE << 16, ioaddr + RX_CHANNEL_CONTROL );
00279
00280 for( i=0; i < 100; i++ ) {
00281
00282 if ( !(inw( ioaddr + TX_CHANNEL_STATUS ) & TX_DBDMA_ENABLE ) &&
00283 !(inw( ioaddr + RX_CHANNEL_STATUS ) & RX_DBDMA_ENABLE ))
00284 break;
00285 udelay( 10 );
00286 }
00287
00288
00289 cntl = inl( ioaddr + DBDMA_CONTROL );
00290 outl( cntl | DBDMA_SRST, ioaddr + DBDMA_CONTROL );
00291
00292 for( i=0; i < 100; i++ ) {
00293
00294 if ( !(inl( ioaddr + DBDMA_CONTROL ) & DBDMA_SRST ))
00295 break;
00296 udelay( 10 );
00297 }
00298
00299
00300
00301
00302 if (ncr885e_debug > 3)
00303 printk( KERN_INFO "%s: reset complete\n", dev->name );
00304
00305 }
00306
00307
00308
00309
00310
00311
00312
00313
00314 static void
00315 ncr885e_config( struct device *dev )
00316
00317 {
00318 unsigned long ioaddr = dev->base_addr;
00319
00320 if (ncr885e_debug > 3)
00321 printk( KERN_INFO "%s: Configuring 53C885.\n", dev->name );
00322
00323 ncr885e_reset( dev );
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336 outl( 0, ioaddr + TX_INT_SELECT );
00337 outl( (TX_WAIT_STAT_RECV << 16) | TX_WAIT_STAT_RECV,
00338 ioaddr + TX_WAIT_SELECT );
00339 outl( 0, ioaddr + TX_BRANCH_SELECT );
00340
00341
00342 #if 0
00343 outl( (RX_INT_SELECT_EOP << 16) | RX_INT_SELECT_EOP,
00344 ioaddr + RX_INT_SELECT );
00345 #else
00346 outl( 0, ioaddr + RX_INT_SELECT );
00347 #endif
00348 #if 0
00349 outl( 0, ioaddr + RX_WAIT_SELECT );
00350 #else
00351 outl( (RX_WAIT_SELECT_EOP << 16) | RX_WAIT_SELECT_EOP,
00352 ioaddr + RX_WAIT_SELECT );
00353 #endif
00354 #if 1
00355 outl( 0, ioaddr + RX_BRANCH_SELECT );
00356 #else
00357 outl( (RX_BRANCH_SELECT_EOP << 16) | RX_BRANCH_SELECT_EOP,
00358 ioaddr + RX_BRANCH_SELECT );
00359 #endif
00360
00361
00362 outl( (DBDMA_BE | DBDMA_DPMRLE | DBDMA_TDPCE |
00363 DBDMA_DDPE | DBDMA_TDPE |
00364 (DBDMA_BURST_4 << DBDMA_TX_BST_SHIFT) |
00365 (DBDMA_BURST_4 << DBDMA_RX_BST_SHIFT) |
00366 (DBDMA_TX_ARBITRATION_DEFAULT) |
00367 (DBDMA_RX_ARBITRATION_DEFAULT)), ioaddr + DBDMA_CONTROL );
00368
00369 outl( 0, ioaddr + TX_THRESHOLD );
00370
00371
00372 outl( (MAC_CONFIG_ITXA | MAC_CONFIG_RXEN | MAC_CONFIG_RETRYL |
00373 MAC_CONFIG_PADEN | (0x18 << 16)),
00374 ioaddr + MAC_CONFIG );
00375
00376
00377 outl( (MAC_CONFIG_ITXA | MAC_CONFIG_RXEN | MAC_CONFIG_RETRYL |
00378 MAC_CONFIG_PADEN | ( 0x18 << 16)), ioaddr + MAC_CONFIG );
00379
00380 outw( (0x1018), ioaddr + NBTOB_INTP_GAP );
00381
00382
00383 inw( ioaddr + INTERRUPT_CLEAR );
00384 ncr885e_enable( dev );
00385
00386
00387 outl( (INTERRUPT_INTE|INTERRUPT_TX_MASK|INTERRUPT_RX_MASK)<<16,
00388 ioaddr + INTERRUPT_ENABLE - 2);
00389
00390 if (ncr885e_debug > 3)
00391 printk( KERN_INFO "%s: 53C885 config complete.\n", dev->name );
00392
00393 return;
00394 }
00395
00396
00397
00398
00399
00400
00401 static void
00402 ncr885e_tx( struct device *dev )
00403
00404 {
00405 struct ncr885e_private *sp = (struct ncr885e_private *) dev->priv;
00406 volatile struct dbdma_cmd *cp, *dp;
00407 unsigned short txbits, xfer;
00408 int i;
00409
00410 del_timer( &sp->tx_timeout );
00411
00412 if (ncr885e_debug > 3)
00413 printk( KERN_INFO "%s: ncr885e_tx: active=%d, dirty=%d, current=%d\n",
00414 dev->name, sp->tx_active, sp->tx_dirty, sp->tx_current );
00415
00416 sp->timeout_active = 0;
00417
00418 i = sp->tx_dirty;
00419 cp = sp->tx_cmds + (i*3);
00420 dp = cp+1;
00421 sp->tx_active--;
00422
00423 xfer = inw( &dp->xfer_status );
00424 txbits = inw( &sp->tx_status[i] );
00425
00426 if (ncr885e_debug > 4) {
00427 show_dbdma_cmd( cp );
00428 show_dbdma_cmd( dp );
00429 }
00430
00431
00432 txbits = inw( &sp->tx_status[i] );
00433
00434 if (ncr885e_debug > 3)
00435 printk( KERN_INFO "%s: tx xfer=%04x, txbits=%04x\n", dev->name,
00436 xfer, txbits );
00437
00438
00439 if ( xfer ) {
00440
00441 dev_kfree_skb( sp->tx_skbufs[i] );
00442 mark_bh( NET_BH );
00443
00444 if ( txbits & TX_STATUS_TXOK ) {
00445 sp->stats.tx_packets++;
00446 sp->stats.tx_bytes += inw( &cp->req_count );
00447 }
00448
00449
00450 if ( txbits & (TX_STATUS_TDLC|TX_STATUS_TDEC) ) {
00451 sp->stats.tx_dropped++;
00452 }
00453
00454
00455 sp->stats.collisions += ( txbits & 0x04 );
00456
00457 }
00458
00459 dev->tbusy = 0;
00460
00461 return;
00462 }
00463
00464
00465 static void
00466 ncr885e_rx( struct device *dev )
00467
00468 {
00469 struct ncr885e_private *sp = (struct ncr885e_private *) dev->priv;
00470 volatile struct dbdma_cmd *cp;
00471 struct sk_buff *skb;
00472 int i, nb;
00473 unsigned short status;
00474 unsigned char *data, *stats;
00475 unsigned long rxbits, ioaddr = dev->base_addr;
00476
00477 i = sp->rx_current;
00478 cp = sp->rx_cmds + (i*2);
00479
00480 if (ncr885e_debug > 3)
00481 printk( KERN_INFO "%s: ncr885e_rx dirty=%d, current=%d (cp@%p)\n",
00482 dev->name, sp->rx_dirty, sp->rx_current, cp );
00483
00484 nb = inw( &cp->req_count ) - inw( &cp->res_count );
00485 status = inw( &cp->xfer_status );
00486
00487 if (ncr885e_debug > 3)
00488 printk( KERN_INFO "%s: (rx %d) bytes=%d, xfer_status=%04x\n",
00489 dev->name, i, nb, status );
00490
00491 if ( status ) {
00492
00493 skb = sp->rx_skbufs[i];
00494 data = skb->data;
00495 stats = data + nb - 3;
00496 rxbits = (stats[0]|stats[1]<<8|stats[2]<<16);
00497
00498 if (ncr885e_debug > 3)
00499 printk( KERN_INFO " rx_bits=%06lx\n", rxbits );
00500
00501 skb->dev = dev;
00502 skb_put( skb, nb-3 );
00503 skb->protocol = eth_type_trans( skb, dev );
00504 netif_rx( skb );
00505 sp->rx_skbufs[i] = 0;
00506
00507 if ( rxbits & RX_STATUS_RXOK ) {
00508 sp->stats.rx_packets++;
00509 sp->stats.rx_bytes += nb;
00510 }
00511
00512 if ( rxbits & RX_STATUS_MCAST )
00513 sp->stats.multicast++;
00514
00515 }
00516
00517 sp->rx_dirty = sp->rx_current;
00518
00519 if ( ++sp->rx_current >= NR_RX_RING )
00520 sp->rx_current = 0;
00521
00522
00523 cp = sp->rx_cmds + (sp->rx_dirty * 2);
00524
00525 skb = dev_alloc_skb( RX_BUFLEN + 2 );
00526 if ( skb != 0 ) {
00527 skb_reserve( skb, 2 );
00528 sp->rx_skbufs[sp->rx_dirty] = skb;
00529 }
00530
00531 if (ncr885e_debug > 2)
00532 printk( KERN_INFO "%s: ncr885e_rx: using ring index %d, filling cp @ %p\n",
00533 dev->name, sp->rx_current, cp );
00534
00535 outw( RX_BUFLEN, &cp->req_count );
00536 outw( 0, &cp->res_count );
00537 data = skb->data;
00538 outl( virt_to_bus( data ), &cp->phy_addr );
00539 outw( 0, &cp->xfer_status );
00540
00541 cp = sp->rx_cmds + (sp->rx_current * 2);
00542
00543
00544 outl( virt_to_bus( cp ), ioaddr + RX_CMD_PTR_LO );
00545 outl( (RX_DBDMA_ENABLE << 16)|RX_CHANNEL_RUN,
00546 ioaddr + RX_CHANNEL_CONTROL );
00547
00548 return;
00549 }
00550
00551 static void
00552 ncr885e_misc_ints( struct device *dev, unsigned short status )
00553
00554 {
00555 struct ncr885e_private *sp = (struct ncr885e_private *) dev->priv;
00556 struct dbdma_cmd *cp;
00557 unsigned long ioaddr = dev->base_addr;
00558
00559 if (ncr885e_debug > 1)
00560 printk( KERN_INFO "miscellaneous interrupt handled; status=%02x\n",
00561 status );
00562
00563
00564 if ( status &
00565 (INTERRUPT_PPET | INTERRUPT_PBFT | INTERRUPT_IIDT) ) {
00566
00567
00568 if ( status & INTERRUPT_IIDT ) {
00569
00570 cp = (struct dbdma_cmd *) bus_to_virt( inl( ioaddr + TX_CMD_PTR_LO ));
00571 printk( KERN_INFO "%s: tx illegal insn:\n", dev->name );
00572 printk( KERN_INFO " tx DBDMA - cmd = %p, status = %04x\n",
00573 cp, inw( ioaddr + TX_CHANNEL_STATUS ));
00574 printk( KERN_INFO " command = %04x, phy_addr=%08x, req_count=%04x\n",
00575 inw( &cp->command ), inw( &cp->phy_addr ), inw( &cp->req_count ));
00576 }
00577
00578 if ( status & INTERRUPT_PPET )
00579 printk( KERN_INFO "%s: tx PCI parity error\n", dev->name );
00580
00581 if ( status & INTERRUPT_PBFT )
00582 printk( KERN_INFO "%s: tx PCI bus fault\n", dev->name );
00583 }
00584
00585
00586 if ( status &
00587 (INTERRUPT_PPER | INTERRUPT_PBFR | INTERRUPT_IIDR)) {
00588
00589
00590 if ( status & INTERRUPT_IIDR ) {
00591 #if 0
00592 cmd = inl( ioaddr + RX_CMD_PTR_LO );
00593 #endif
00594 printk( KERN_ERR "%s: rx illegal DMA instruction:\n", dev->name );
00595 printk( KERN_ERR " channel status=%04x,\n",
00596 inl( ioaddr + RX_CHANNEL_STATUS ));
00597 #if 0
00598 show_dbdma_cmd( bus_to_virt( inl( ioaddr + RX_CMD_PTR_LO )));
00599 printk( KERN_ERR " instr (%08x) %08x %08x %08x\n",
00600 (int) cmd, cmd[0], cmd[1], cmd[2] );
00601 #endif
00602 }
00603
00604
00605 if ( status & INTERRUPT_PPER )
00606 printk( KERN_INFO "%s: rx PCI parity error\n", dev->name );
00607
00608 if ( status & INTERRUPT_PBFR )
00609 printk( KERN_INFO "%s: rx PCI bus fault\n", dev->name );
00610
00611 sp->stats.rx_errors++;
00612 }
00613
00614 if ( status & INTERRUPT_WI ) {
00615 printk( KERN_INFO "%s: link pulse\n", dev->name );
00616 }
00617
00618
00619
00620
00621 return;
00622 }
00623
00624 static void
00625 ncr885e_interrupt( int irq, void *dev_id, struct pt_regs *regs )
00626
00627 {
00628 struct device *dev = (struct device *) dev_id;
00629 struct ncr885e_private *sp;
00630 unsigned short status;
00631 int ioaddr;
00632
00633 if ( dev == NULL ) {
00634 printk( KERN_ERR "symba: Interrupt IRQ %d for unknown device\n", irq );
00635 return;
00636 }
00637
00638 ioaddr = dev->base_addr;
00639 sp = (struct ncr885e_private *) dev->priv;
00640 spin_lock( &sp->lock );
00641
00642 if ( dev->interrupt ) {
00643 printk( KERN_ERR "%s: Re-entering interrupt handler...\n",
00644 dev->name );
00645 }
00646
00647 dev->interrupt = 1;
00648 status = inw( ioaddr + INTERRUPT_CLEAR );
00649
00650 if (ncr885e_debug > 2)
00651 printk( KERN_INFO "%s: 53C885 interrupt 0x%02x\n", dev->name, status );
00652
00653
00654 if ( status & ~(INTERRUPT_DIT|INTERRUPT_DIR))
00655 ncr885e_misc_ints( dev, status );
00656
00657
00658 if ( ( status & INTERRUPT_DIT ) ) {
00659
00660 if (ncr885e_debug > 2)
00661 printk( KERN_INFO "%s: tx int; int=%02x, chan stat=%02x\n",
00662 dev->name, status, inw( ioaddr + TX_CHANNEL_STATUS ));
00663
00664
00665 del_timer( &sp->tx_timeout );
00666 sp->timeout_active = 0;
00667
00668
00669 outl( TX_DBDMA_ENABLE << 16, ioaddr + TX_CHANNEL_CONTROL );
00670
00671 ncr885e_tx( dev );
00672 }
00673
00674 if ( status & INTERRUPT_DIR ) {
00675
00676 if ( ncr885e_debug > 2 )
00677 printk( KERN_INFO "%s: rx interrupt; int=%02x, rx channel stat=%02x\n",
00678 dev->name, status, inw( ioaddr + RX_CHANNEL_STATUS ));
00679
00680
00681 outl( RX_DBDMA_ENABLE << 16, ioaddr + RX_CHANNEL_CONTROL );
00682
00683
00684 ncr885e_rx( dev );
00685 }
00686
00687 dev->interrupt = 0;
00688 spin_unlock( &sp->lock );
00689
00690 return;
00691 }
00692
00693
00694
00695 static int
00696 ncr885e_set_address( struct device *dev, void *addr )
00697
00698 {
00699 struct ncr885e_private *sp = (struct ncr885e_private *) dev->priv;
00700 struct sockaddr *saddr = addr;
00701 unsigned long flags;
00702 unsigned short reg[3];
00703 unsigned char *ioaddr, *p;
00704 int i;
00705
00706 memcpy( dev->dev_addr, saddr->sa_data, dev->addr_len );
00707
00708 p = (unsigned char *) dev->dev_addr;
00709 printk( KERN_INFO "%s: setting new MAC address - ", dev->name );
00710 #if 0
00711 for( p = (unsigned char *) dev->dev_addr, i=0; i < 6; i++, p++ )
00712 printk("%c%2.2x", i ? ':' : ' ', *p );
00713 #endif
00714
00715
00716 p = (unsigned char *) ®
00717 for( i=0; i < 6; i++ )
00718 p[i] = dev->dev_addr[i];
00719
00720 #if 0
00721 printk("%s: Setting new mac address - ", dev->name );
00722 for( i=0; i < 6; i++ ) {
00723 printk("%02x", i ? ':' : ' ', p[i] );
00724 }
00725
00726 printk("\n");
00727 #endif
00728
00729
00730 outl( RX_DBDMA_ENABLE << 16, ioaddr + RX_CHANNEL_CONTROL );
00731
00732 spin_lock_irqsave( &sp->lock, flags );
00733
00734 ioaddr = (unsigned char *) dev->base_addr;
00735
00736 for( i = 0; i < 3; i++ ) {
00737 reg[i] = ((reg[i] & 0xff) << 8) | ((reg[i] >> 8) & 0xff);
00738 printk("%04x ", reg[i] );
00739 outw( reg[i], ioaddr + STATION_ADDRESS_0 + (i*2));
00740 }
00741 printk("\n");
00742
00743 spin_unlock_irqrestore( &sp->lock, flags );
00744
00745
00746 outl((RX_DBDMA_ENABLE << 16)|RX_CHANNEL_RUN,
00747 ioaddr + RX_CHANNEL_CONTROL );
00748
00749 return 0;
00750 }
00751
00752 static void
00753 ncr885e_tx_timeout( unsigned long data )
00754
00755 {
00756 struct device *dev = (struct device *) data;
00757 struct ncr885e_private *sp = (struct ncr885e_private *) dev->priv;
00758 unsigned long flags, ioaddr;
00759 int i;
00760
00761 save_flags( flags );
00762 cli();
00763
00764 ioaddr = dev->base_addr;
00765 sp->timeout_active = 0;
00766 i = sp->tx_dirty;
00767
00768
00769 if ( sp->tx_active == 0 ) {
00770 printk( KERN_INFO "%s: ncr885e_timeout...tx not active!\n", dev->name );
00771 goto out;
00772 }
00773
00774 printk( KERN_ERR "%s: 53C885 timed out. Resetting...\n", dev->name );
00775
00776
00777 outl( (TX_DBDMA_ENABLE << 16), ioaddr + TX_CHANNEL_CONTROL );
00778 outl( (RX_DBDMA_ENABLE << 16), ioaddr + RX_CHANNEL_CONTROL );
00779
00780
00781 ncr885e_config( dev );
00782 ncr885e_enable( dev );
00783
00784
00785 sp->tx_active = 0;
00786 ++sp->stats.tx_errors;
00787
00788 if ( sp->tx_skbufs[i] ) {
00789 dev_kfree_skb( sp->tx_skbufs[i] );
00790 sp->tx_skbufs[i] = 0;
00791 }
00792
00793
00794 sp->tx_current = 0;
00795 dev->tbusy = 0;
00796 mark_bh( NET_BH );
00797
00798
00799 outl( (RX_DBDMA_ENABLE << 16) | RX_CHANNEL_RUN,
00800 ioaddr + RX_CHANNEL_CONTROL );
00801 out:
00802
00803 restore_flags( flags );
00804 }
00805
00806 static inline void
00807 ncr885e_set_timeout( struct device *dev )
00808
00809 {
00810 struct ncr885e_private *sp = (struct ncr885e_private *) dev->priv;
00811 unsigned long flags;
00812
00813 save_flags(flags);
00814 cli();
00815
00816 if ( sp->timeout_active )
00817 del_timer( &sp->tx_timeout );
00818
00819 sp->tx_timeout.expires = jiffies + TX_TIMEOUT;
00820 sp->tx_timeout.function = ncr885e_tx_timeout;
00821 sp->tx_timeout.data = (unsigned long) dev;
00822 add_timer( &sp->tx_timeout );
00823 sp->timeout_active = 1;
00824 restore_flags( flags );
00825 }
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836 static int
00837 ncr885e_open( struct device *dev )
00838
00839 {
00840 struct ncr885e_private *sp = (struct ncr885e_private *) dev->priv;
00841 unsigned long ioaddr = dev->base_addr;
00842 struct sk_buff *skb;
00843 int i, size;
00844 char *data;
00845 struct dbdma_cmd *cp;
00846 unsigned long flags;
00847
00848
00849 size = (sizeof( struct dbdma_cmd ) *
00850 ((NR_TX_RING * 3) + (NR_RX_RING * 2) + 1));
00851
00852 cp = kmalloc( size, GFP_KERNEL );
00853
00854 if ( cp == 0 ) {
00855 printk( KERN_ERR "Insufficient memory (%d bytes) for DBDMA\n", size );
00856 return -ENOMEM;
00857 }
00858
00859 spin_lock_init( &sp->lock );
00860 spin_lock_irqsave( &sp->lock, flags );
00861
00862 memset((char *) cp, 0, size );
00863 sp->head = cp;
00864
00865 sp->stop_cmd = cp;
00866 outl( DBDMA_STOP, &cp->command );
00867
00868 sp->rx_cmds = ++cp;
00869
00870 for( i = 0; i < NR_RX_RING; i++ ) {
00871
00872 cp = sp->rx_cmds + (i*2);
00873 skb = dev_alloc_skb( RX_BUFLEN + 2 );
00874
00875
00876
00877 if ( skb == 0 ) {
00878 printk( KERN_ERR "%s: insufficient memory for rx ring buffer\n",
00879 dev->name );
00880 break;
00881 }
00882
00883 skb_reserve( skb, 2 );
00884 sp->rx_skbufs[i] = skb;
00885 data = skb->data;
00886
00887
00888
00889
00890
00891
00892 outw( (INPUT_MORE|INTR_ALWAYS), &cp->command );
00893 outw( RX_BUFLEN, &cp->req_count );
00894 outw( 0, &cp->res_count );
00895 outl( virt_to_bus( data ), &cp->phy_addr );
00896 outl( virt_to_bus( sp->stop_cmd ), &cp->cmd_dep );
00897 outw( 0, &cp->xfer_status );
00898 #if 0
00899 printk( KERN_INFO "rx at %p\n", cp );
00900 show_dbdma_cmd( cp );
00901 #endif
00902 ++cp;
00903
00904 outw( DBDMA_STOP, &cp->command );
00905
00906 }
00907
00908
00909 sp->rx_dirty = 0;
00910 sp->rx_current = 0;
00911
00912
00913 sp->tx_cmds = cp+1;
00914
00915 for( i = 0; i < NR_TX_RING; i++ ) {
00916
00917
00918 cp = sp->tx_cmds + (i*3);
00919 outw( OUTPUT_LAST, &cp->command );
00920 if (ncr885e_debug > 3) {
00921 printk( KERN_INFO "tx OUTPUT_LAST at %p\n", cp );
00922 show_dbdma_cmd( cp );
00923 }
00924
00925
00926 cp++;
00927 outw( INPUT_LAST|INTR_ALWAYS|WAIT_IFCLR, &cp->command );
00928 outl( virt_to_bus( &sp->tx_status[i] ), &cp->phy_addr );
00929 outw( 2, &cp->req_count );
00930 if ( ncr885e_debug > 3) {
00931 printk( KERN_INFO "tx INPUT_LAST cmd at %p\n", cp );
00932 show_dbdma_cmd( cp );
00933 }
00934
00935 ++cp;
00936 outw( DBDMA_STOP, &cp->command );
00937
00938 }
00939 #if 0
00940
00941 outw((INPUT_LAST|INTR_ALWAYS|BR_ALWAYS), &cp->command );
00942 outl( virt_to_bus( sp->stop_cmd ), &cp->cmd_dep );
00943 #endif
00944 sp->tx_active = 0;
00945 sp->tx_current = 0;
00946 sp->tx_dirty = 0;
00947
00948 spin_unlock_irqrestore( &sp->lock, flags );
00949
00950
00951
00952
00953
00954
00955
00956
00957 ncr885e_config( dev );
00958
00959
00960 if ( request_irq( dev->irq, &ncr885e_interrupt, SA_SHIRQ, chipname, dev )) {
00961 printk( KERN_ERR "%s: can't get irq %d\n", dev->name, dev->irq );
00962 return -EAGAIN;
00963 }
00964
00965 (void) inw( ioaddr + INTERRUPT_CLEAR );
00966
00967 ncr885e_enable( dev );
00968
00969
00970 outl( virt_to_bus( sp->rx_cmds ), ioaddr + RX_CMD_PTR_LO );
00971 outl( (RX_DBDMA_ENABLE << 16)|RX_CHANNEL_RUN,
00972 ioaddr + RX_CHANNEL_CONTROL );
00973
00974 dev->start = 1;
00975 dev->tbusy = 0;
00976 dev->interrupt = 0;
00977
00978 MOD_INC_USE_COUNT;
00979
00980 return 0;
00981 }
00982
00983 static int
00984 ncr885e_xmit_start( struct sk_buff *skb, struct device *dev )
00985
00986 {
00987 struct ncr885e_private *sp = (struct ncr885e_private *) dev->priv;
00988 volatile struct dbdma_cmd *cp, *dp;
00989 unsigned long flags, ioaddr = dev->base_addr;
00990 int len, next, fill, entry;
00991
00992 if ( ncr885e_debug > 3)
00993 printk( KERN_INFO "%s: xmit_start len=%d, dirty=%d, current=%d, active=%d\n",
00994 dev->name, skb->len, sp->tx_dirty, sp->tx_current, sp->tx_active );
00995
00996 spin_lock_irqsave( &sp->lock, flags );
00997
00998
00999 fill = sp->tx_current;
01000 next = fill + 1;
01001
01002 if ( next >= NR_TX_RING )
01003 next = 0;
01004
01005
01006 dev->tbusy = 1;
01007
01008
01009 if ( sp->tx_active >= MAX_TX_ACTIVE ) {
01010 spin_unlock_irqrestore( &sp->lock, flags );
01011 return -1;
01012 }
01013
01014 sp->tx_active++;
01015 sp->tx_current = next;
01016 sp->tx_dirty = fill;
01017
01018 len = skb->len;
01019
01020 if ( len > ETH_FRAME_LEN ) {
01021 printk( KERN_DEBUG "%s: xmit frame too long (%d)\n", dev->name, len );
01022 len = ETH_FRAME_LEN;
01023 }
01024
01025
01026 entry = fill * 3;
01027 sp->tx_skbufs[fill] = skb;
01028 cp = sp->tx_cmds + entry;
01029 dp = cp + 1;
01030
01031
01032 outw( len, &cp->req_count );
01033 outl( virt_to_bus( skb->data ), &cp->phy_addr );
01034 outw( 0, &cp->xfer_status );
01035 outw( 0, &cp->res_count );
01036
01037
01038 outw( 0, &dp->xfer_status );
01039 outw( 0, &dp->res_count );
01040 sp->tx_status[fill] = 0;
01041 outl( virt_to_bus( &sp->tx_status[fill] ), &dp->phy_addr );
01042
01043 if ( ncr885e_debug > 2 )
01044 printk(KERN_INFO "%s: xmit_start: active %d, tx_current %d, tx_dirty %d\n",
01045 dev->name, sp->tx_active, sp->tx_current, sp->tx_dirty );
01046
01047 if ( ncr885e_debug > 4 ) {
01048 show_dbdma_cmd( cp );
01049 show_dbdma_cmd( dp );
01050 }
01051
01052
01053
01054 outl( virt_to_bus( cp ), ioaddr + TX_CMD_PTR_LO );
01055 outl( (TX_DBDMA_ENABLE << 16)|TX_CHANNEL_RUN,
01056 ioaddr + TX_CHANNEL_CONTROL );
01057
01058 ncr885e_set_timeout( dev );
01059
01060 spin_unlock_irqrestore( &sp->lock, flags );
01061 dev->trans_start = jiffies;
01062
01063 return 0;
01064 }
01065
01066 static int
01067 ncr885e_close(struct device *dev)
01068
01069 {
01070 int i;
01071 struct ncr885e_private *np = (struct ncr885e_private *) dev->priv;
01072 unsigned long ioaddr = dev->base_addr;
01073
01074 dev->start = 0;
01075 dev->tbusy = 1;
01076
01077 spin_lock( &np->lock );
01078
01079 printk(KERN_INFO "%s: NCR885E Ethernet closing...\n", dev->name );
01080
01081 if (ncr885e_debug > 1)
01082 printk(KERN_DEBUG "%s: Shutting down Ethernet chip\n", dev->name);
01083
01084 ncr885e_disable(dev);
01085
01086 del_timer(&np->tx_timeout);
01087
01088
01089 outl( (RX_DBDMA_ENABLE << 16), ioaddr + RX_CHANNEL_CONTROL );
01090 outl( (TX_DBDMA_ENABLE << 16), ioaddr + TX_CHANNEL_CONTROL );
01091
01092
01093 free_irq( dev->irq, dev );
01094
01095 for( i = 0; i < NR_RX_RING; i++ ) {
01096 if (np->rx_skbufs[i])
01097 dev_kfree_skb( np->rx_skbufs[i] );
01098 np->rx_skbufs[i] = 0;
01099 }
01100 #if 0
01101 for (i = 0; i < NR_TX_RING; i++) {
01102 if (np->tx_skbufs[i])
01103 dev_kfree_skb(np->tx_skbufs[i]);
01104 np->tx_skbufs[i] = 0;
01105 }
01106 #endif
01107 spin_unlock( &np->lock );
01108
01109 kfree( np->head );
01110
01111 MOD_DEC_USE_COUNT;
01112
01113 return 0;
01114 }
01115
01116
01117
01118
01119
01120
01121
01122 static void
01123 ncr885e_set_multicast( struct device *dev )
01124
01125 {
01126 int ioaddr = dev->base_addr;
01127
01128 if ( ncr885e_debug > 3 )
01129 printk("%s: set_multicast: dev->flags = %x, AF=%04x\n",
01130 dev->name, dev->flags, inw( ioaddr + ADDRESS_FILTER ));
01131
01132 if ( dev->flags & IFF_PROMISC ) {
01133 printk( KERN_INFO "%s: Promiscuous mode enabled.\n", dev->name );
01134 outw( ADDRESS_RPPRO, ioaddr + ADDRESS_FILTER );
01135 }
01136
01137
01138 else if ( dev->flags & IFF_ALLMULTI ) {
01139 printk( KERN_INFO "%s: Enabling all multicast packets.\n",
01140 dev->name );
01141 outw( ADDRESS_RPPRM, ioaddr + ADDRESS_FILTER );
01142 }
01143
01144
01145 else {
01146 outw( ADDRESS_RPABC, ioaddr + ADDRESS_FILTER );
01147 }
01148 }
01149
01150 static struct net_device_stats *
01151 ncr885e_stats( struct device *dev )
01152
01153 {
01154 struct ncr885e_private *np = (struct ncr885e_private *) dev->priv;
01155
01156 return &np->stats;
01157 }
01158
01159
01160
01161
01162
01163
01164 static int
01165 ncr885e_probe1( struct device *dev, unsigned long ioaddr, unsigned char irq )
01166
01167 {
01168 struct ncr885e_private *sp;
01169 unsigned short station_addr[3], val;
01170 unsigned char *p;
01171 int i;
01172
01173 dev = init_etherdev( dev, 0 );
01174
01175
01176 dev->priv = kmalloc( sizeof( struct ncr885e_private ), GFP_KERNEL );
01177
01178 if ( dev->priv == NULL )
01179 return -ENOMEM;
01180
01181 sp = (struct ncr885e_private *) dev->priv;
01182 memset( sp, 0, sizeof( struct ncr885e_private ));
01183
01184
01185 for( i = 0; i < 3; i++ ) {
01186 val = inw( ioaddr + STATION_ADDRESS_0 + (i*2));
01187 station_addr[i] = ((val >> 8) & 0xff) | ((val << 8) & 0xff00);
01188 }
01189
01190 printk( KERN_INFO "%s: %s at %08lx,", dev->name, chipname, ioaddr );
01191
01192 p = (unsigned char *) &station_addr;
01193
01194 for( i=0; i < 6; i++ ) {
01195 dev->dev_addr[i] = *p;
01196 printk("%c%2.2x", i ? ':' : ' ', dev->dev_addr[i] );
01197 p++;
01198 }
01199
01200 printk(", IRQ %d.\n", irq );
01201
01202 request_region( ioaddr, NCR885E_TOTAL_SIZE, dev->name );
01203
01204
01205 init_timer( &sp->tx_timeout );
01206 sp->timeout_active = 0;
01207
01208 dev->base_addr = ioaddr;
01209 dev->irq = irq;
01210
01211 ether_setup( dev );
01212
01213
01214 dev->open = ncr885e_open;
01215 dev->stop = ncr885e_close;
01216 dev->get_stats = ncr885e_stats;
01217 dev->hard_start_xmit = ncr885e_xmit_start;
01218 dev->set_multicast_list = ncr885e_set_multicast;
01219 dev->set_mac_address = ncr885e_set_address;
01220
01221 return 0;
01222 }
01223
01224
01225
01226
01227
01228
01229
01230 int __init ncr885e_probe( struct device *dev )
01231 {
01232 struct pci_dev *pdev = NULL;
01233 unsigned int ioaddr, chips = 0;
01234 unsigned short cmd;
01235 unsigned char irq, latency;
01236
01237 while(( pdev = pci_find_device( PCI_VENDOR_ID_NCR,
01238 PCI_DEVICE_ID_NCR_53C885_ETHERNET,
01239 pdev )) != NULL ) {
01240
01241 if ( !print_version ) {
01242 print_version++;
01243 printk( KERN_INFO "%s", version );
01244 }
01245
01246
01247 pci_read_config_dword( pdev, PCI_BASE_ADDRESS_0, &ioaddr );
01248 pci_read_config_byte( pdev, PCI_INTERRUPT_LINE, &irq );
01249
01250 ioaddr &= ~3;
01251
01252 #ifdef CONFIG_GEMINI
01253 ioaddr |= 0xfe000000;
01254 #endif
01255
01256 if ( check_region( ioaddr, NCR885E_TOTAL_SIZE ))
01257 continue;
01258
01259
01260 if ( !(ncr885e_probe1( dev, ioaddr, irq ))) {
01261
01262 chips++;
01263
01264
01265 pci_read_config_word( pdev, PCI_COMMAND, &cmd );
01266
01267 if ( !(cmd & PCI_COMMAND_MASTER) ) {
01268 printk( KERN_INFO " PCI master bit not set! Now setting.\n");
01269 cmd |= PCI_COMMAND_MASTER;
01270 pci_write_config_word( pdev, PCI_COMMAND, cmd );
01271 }
01272
01273 if ( !(cmd & PCI_COMMAND_IO) ) {
01274 printk(