Annotation of Gnu-Mach/linux/src/drivers/net/hp100.c, revision 1.1.1.2

1.1       root        1: /*
                      2: ** hp100.c 
                      3: ** HP CASCADE Architecture Driver for 100VG-AnyLan Network Adapters
                      4: **
1.1.1.2 ! root        5: ** $Id: hp100.c,v 1.1.4.1 2005/06/02 18:52:39 ams Exp $
1.1       root        6: **
                      7: ** Based on the HP100 driver written by Jaroslav Kysela <[email protected]>
                      8: ** Extended for new busmaster capable chipsets by 
                      9: ** Siegfried "Frieder" Loeffler (dg1sek) <[email protected]>
                     10: **
                     11: ** Maintained by: Jaroslav Kysela <[email protected]>
                     12: ** 
                     13: ** This driver has only been tested with
                     14: ** -- HP J2585B 10/100 Mbit/s PCI Busmaster
                     15: ** -- HP J2585A 10/100 Mbit/s PCI 
                     16: ** -- HP J2970  10 Mbit/s PCI Combo 10base-T/BNC
                     17: ** -- HP J2973  10 Mbit/s PCI 10base-T
                     18: ** -- HP J2573  10/100 ISA
                     19: ** -- Compex ReadyLink ENET100-VG4  10/100 Mbit/s PCI / EISA
                     20: ** -- Compex FreedomLine 100/VG  10/100 Mbit/s ISA / EISA / PCI
                     21: ** 
                     22: ** but it should also work with the other CASCADE based adapters.
                     23: **
                     24: ** TODO:
                     25: **       -  J2573 seems to hang sometimes when in shared memory mode.
                     26: **       -  Mode for Priority TX
                     27: **       -  Check PCI registers, performance might be improved?
                     28: **       -  To reduce interrupt load in busmaster, one could switch off
                     29: **          the interrupts that are used to refill the queues whenever the
                     30: **          queues are filled up to more than a certain threshold.
                     31: **       -  some updates for EISA version of card
                     32: **
                     33: **
                     34: ** This source/code is public free; you can distribute it and/or modify 
                     35: ** it under terms of the GNU General Public License (published by the
                     36: ** Free Software Foundation) either version two of this License, or any 
                     37: ** later version.
                     38: **
                     39: ** 1.55 -> 1.56
                     40: **   - removed printk in misc. interrupt and update statistics to allow
                     41: **     monitoring of card status
                     42: **   - timing changes in xmit routines, relogin to 100VG hub added when
                     43: **     driver does reset
                     44: **   - included fix for Compex FreedomLine PCI adapter
                     45: ** 
                     46: ** 1.54 -> 1.55
                     47: **   - fixed bad initialization in init_module
                     48: **   - added Compex FreedomLine adapter
                     49: **   - some fixes in card initialization
                     50: **
                     51: ** 1.53 -> 1.54
                     52: **   - added hardware multicast filter support (doesn't work)
                     53: **   - little changes in hp100_sense_lan routine 
                     54: **     - added support for Coax and AUI (J2970)
                     55: **   - fix for multiple cards and hp100_mode parameter (insmod)
                     56: **   - fix for shared IRQ 
                     57: **
                     58: ** 1.52 -> 1.53
                     59: **   - fixed bug in multicast support
                     60: **
                     61: */
                     62: 
                     63: #define HP100_DEFAULT_PRIORITY_TX 0 
                     64: 
                     65: #undef HP100_DEBUG
                     66: #undef HP100_DEBUG_B           /* Trace  */
                     67: #undef HP100_DEBUG_BM          /* Debug busmaster code (PDL stuff) */
                     68: 
                     69: #undef HP100_DEBUG_TRAINING    /* Debug login-to-hub procedure */
                     70: #undef HP100_DEBUG_TX   
                     71: #undef HP100_DEBUG_IRQ 
                     72: #undef HP100_DEBUG_RX 
                     73: 
                     74: #undef HP100_MULTICAST_FILTER  /* Need to be debugged... */
                     75: 
                     76: #include <linux/version.h>
                     77: #include <linux/module.h>
                     78: #include <linux/kernel.h>
                     79: #include <linux/sched.h>
                     80: #include <linux/string.h>
                     81: #include <linux/errno.h>
                     82: #include <linux/ioport.h>
                     83: #include <linux/malloc.h>
                     84: #include <linux/interrupt.h>
                     85: #include <linux/pci.h>
                     86: #include <linux/bios32.h>
                     87: #include <asm/bitops.h>
                     88: #include <asm/io.h>
                     89: 
                     90: #include <linux/netdevice.h>
                     91: #include <linux/etherdevice.h>
                     92: #include <linux/skbuff.h>
                     93: 
                     94: #include <linux/types.h>
                     95: #include <linux/config.h>  /* for CONFIG_PCI */
                     96: #include <linux/delay.h>
                     97: 
                     98: #if LINUX_VERSION_CODE < 0x020100
                     99: #define ioremap vremap
                    100: #define iounmap vfree
                    101: typedef struct enet_statistics hp100_stats_t;
                    102: #else
                    103: #define LINUX_2_1
                    104: typedef struct net_device_stats hp100_stats_t;
                    105: #endif
                    106: 
                    107: #ifndef __initfunc
                    108: #define __initfunc(__initarg) __initarg
                    109: #else
                    110: #include <linux/init.h>
                    111: #endif
                    112: 
                    113: #include "hp100.h"
                    114: 
                    115: /*
                    116:  *  defines
                    117:  */
                    118: 
                    119: #define HP100_BUS_ISA     0
                    120: #define HP100_BUS_EISA    1
                    121: #define HP100_BUS_PCI     2
                    122: 
                    123: #ifndef PCI_DEVICE_ID_HP_J2585B
                    124: #define PCI_DEVICE_ID_HP_J2585B 0x1031
                    125: #endif
                    126: #ifndef PCI_VENDOR_ID_COMPEX
                    127: #define PCI_VENDOR_ID_COMPEX 0x11f6
                    128: #endif
                    129: #ifndef PCI_DEVICE_ID_COMPEX_ENET100VG4
                    130: #define PCI_DEVICE_ID_COMPEX_ENET100VG4 0x0112
                    131: #endif
                    132: #ifndef PCI_VENDOR_ID_COMPEX2
                    133: #define PCI_VENDOR_ID_COMPEX2 0x101a
                    134: #endif
                    135: #ifndef PCI_DEVICE_ID_COMPEX2_100VG
                    136: #define PCI_DEVICE_ID_COMPEX2_100VG 0x0005
                    137: #endif
                    138: 
                    139: #define HP100_REGION_SIZE  0x20 /* for ioports */
                    140: 
                    141: #define HP100_MAX_PACKET_SIZE  (1536+4)
                    142: #define HP100_MIN_PACKET_SIZE  60
                    143: 
                    144: #ifndef HP100_DEFAULT_RX_RATIO
                    145: /* default - 75% onboard memory on the card are used for RX packets */
                    146: #define HP100_DEFAULT_RX_RATIO  75
                    147: #endif
                    148: 
                    149: #ifndef HP100_DEFAULT_PRIORITY_TX
                    150: /* default - don't enable transmit outgoing packets as priority */
                    151: #define HP100_DEFAULT_PRIORITY_TX 0
                    152: #endif
                    153: 
                    154: /*
                    155:  *  structures
                    156:  */
                    157: 
                    158: struct hp100_eisa_id {
                    159:   u_int id;
                    160:   const char *name;
                    161:   u_char bus;
                    162: };
                    163: 
                    164: struct hp100_pci_id {
                    165:   u_short vendor;
                    166:   u_short device;
                    167: };
                    168: 
                    169: struct hp100_private {
                    170:   struct hp100_eisa_id *id;
                    171:   u_short chip;
                    172:   u_short soft_model;
                    173:   u_int memory_size; 
                    174:   u_int virt_memory_size;
                    175:   u_short rx_ratio;       /* 1 - 99 */
                    176:   u_short priority_tx;    /* != 0 - priority tx */
                    177:   u_short mode;           /* PIO, Shared Mem or Busmaster */
                    178:   u_char bus;
                    179:   u_char pci_bus;
                    180:   u_char pci_device_fn;
                    181:   short mem_mapped;      /* memory mapped access */
                    182:   u_int *mem_ptr_virt;    /* virtual memory mapped area, maybe NULL */
                    183:   u_int *mem_ptr_phys;   /* physical memory mapped area */
                    184:   short lan_type;        /* 10Mb/s, 100Mb/s or -1 (error) */
                    185:   int hub_status;        /* was login to hub successful? */
                    186:   u_char mac1_mode;
                    187:   u_char mac2_mode;
                    188:   u_char hash_bytes[ 8 ];
                    189:   hp100_stats_t stats;
                    190: 
                    191:   /* Rings for busmaster mode: */
                    192:   hp100_ring_t *rxrhead;  /* Head (oldest) index into rxring */
                    193:   hp100_ring_t *rxrtail;  /* Tail (newest) index into rxring */
                    194:   hp100_ring_t *txrhead;  /* Head (oldest) index into txring */
                    195:   hp100_ring_t *txrtail;  /* Tail (newest) index into txring */
                    196: 
                    197:   hp100_ring_t rxring[ MAX_RX_PDL ];
                    198:   hp100_ring_t txring[ MAX_TX_PDL ];
                    199: 
                    200:   u_int *page_vaddr;      /* Virtual address of allocated page */
                    201:   u_int *page_vaddr_algn; /* Aligned virtual address of allocated page */
                    202:   int rxrcommit;          /* # Rx PDLs commited to adapter */
                    203:   int txrcommit;          /* # Tx PDLs commited to adapter */
                    204: };
                    205: 
                    206: /*
                    207:  *  variables
                    208:  */
                    209: 
                    210: static struct hp100_eisa_id hp100_eisa_ids[] = {
                    211: 
                    212:   /* 10/100 EISA card with revision A Cascade chip */
                    213:   { 0x80F1F022, "HP J2577 rev A", HP100_BUS_EISA },
                    214: 
                    215:   /* 10/100 ISA card with revision A Cascade chip */
                    216:   { 0x50F1F022, "HP J2573 rev A", HP100_BUS_ISA },
                    217: 
                    218:   /* 10 only EISA card with Cascade chip */
                    219:   { 0x2019F022, "HP 27248B",      HP100_BUS_EISA },
                    220: 
                    221:   /* 10/100 EISA card with Cascade chip */
                    222:   { 0x4019F022, "HP J2577",       HP100_BUS_EISA },
                    223: 
                    224:   /* 10/100 ISA card with Cascade chip */
                    225:   { 0x5019F022, "HP J2573",       HP100_BUS_ISA },
                    226: 
                    227:   /* 10/100 PCI card - old J2585A */
                    228:   { 0x1030103c, "HP J2585A",       HP100_BUS_PCI },
                    229: 
                    230:   /* 10/100 PCI card - new J2585B - master capable */
                    231:   { 0x1041103c, "HP J2585B",      HP100_BUS_PCI },
                    232: 
                    233:   /* 10 Mbit Combo Adapter */
                    234:   { 0x1042103c, "HP J2970",       HP100_BUS_PCI },
                    235: 
                    236:   /* 10 Mbit 10baseT Adapter */
                    237:   { 0x1040103c, "HP J2973",       HP100_BUS_PCI },
                    238: 
                    239:   /* 10/100 EISA card from Compex */
                    240:   { 0x0103180e, "ReadyLink ENET100-VG4", HP100_BUS_EISA },
                    241: 
                    242:   /* 10/100 EISA card from Compex - FreedomLine (sq5bpf) */
                    243:   /* Note: [email protected] reported that same ID have ISA */
                    244:   /*       version of adapter, too... */
                    245:   { 0x0104180e, "FreedomLine 100/VG", HP100_BUS_EISA },
                    246: 
                    247:   /* 10/100 PCI card from Compex - FreedomLine
                    248:    *
                    249:    * I think this card doesn't like aic7178 scsi controller, but
                    250:    * I haven't tested this much. It works fine on diskless machines.
                    251:    *                            Jacek Lipkowski <[email protected]>
                    252:    */
                    253:   { 0x021211f6, "FreedomLine 100/VG", HP100_BUS_PCI },
                    254:   
                    255:   /* 10/100 PCI card from Compex (J2585A compatible) */
                    256:   { 0x011211f6, "ReadyLink ENET100-VG4", HP100_BUS_PCI }
                    257: 
                    258: };
                    259: 
                    260: #define HP100_EISA_IDS_SIZE    (sizeof(hp100_eisa_ids)/sizeof(struct hp100_eisa_id))
                    261: 
                    262: static struct hp100_pci_id hp100_pci_ids[] = {
                    263:   { PCI_VENDOR_ID_HP,          PCI_DEVICE_ID_HP_J2585A },
                    264:   { PCI_VENDOR_ID_HP,          PCI_DEVICE_ID_HP_J2585B },
                    265:   { PCI_VENDOR_ID_COMPEX,      PCI_DEVICE_ID_COMPEX_ENET100VG4 },
                    266:   { PCI_VENDOR_ID_COMPEX2,     PCI_DEVICE_ID_COMPEX2_100VG }
                    267: };
                    268: 
                    269: #define HP100_PCI_IDS_SIZE     (sizeof(hp100_pci_ids)/sizeof(struct hp100_pci_id))
                    270: 
                    271: static int hp100_rx_ratio = HP100_DEFAULT_RX_RATIO;
                    272: static int hp100_priority_tx = HP100_DEFAULT_PRIORITY_TX;
                    273: static int hp100_mode = 1;
                    274: 
                    275: #ifdef LINUX_2_1
                    276: MODULE_PARM( hp100_rx_ratio, "1i" );
                    277: MODULE_PARM( hp100_priority_tx, "1i" );
                    278: MODULE_PARM( hp100_mode, "1i" );
                    279: #endif
                    280: 
                    281: /*
                    282:  *  prototypes
                    283:  */
                    284: 
                    285: static int  hp100_probe1( struct device *dev, int ioaddr, u_char bus, u_char pci_bus, u_char pci_device_fn  );
                    286: static int  hp100_open( struct device *dev );
                    287: static int  hp100_close( struct device *dev );
                    288: static int  hp100_start_xmit( struct sk_buff *skb, struct device *dev );
                    289: static int  hp100_start_xmit_bm (struct sk_buff *skb, struct device *dev );
                    290: static void hp100_rx( struct device *dev );
                    291: static hp100_stats_t *hp100_get_stats( struct device *dev );
                    292: static void hp100_misc_interrupt( struct device *dev );
                    293: static void hp100_update_stats( struct device *dev );
                    294: static void hp100_clear_stats( int ioaddr );
                    295: static void hp100_set_multicast_list( struct device *dev);
                    296: static void hp100_interrupt( int irq, void *dev_id, struct pt_regs *regs );
                    297: static void hp100_start_interface( struct device *dev );
                    298: static void hp100_stop_interface( struct device *dev );
                    299: static void hp100_load_eeprom( struct device *dev, u_short ioaddr );
                    300: static int  hp100_sense_lan( struct device *dev );
                    301: static int  hp100_login_to_vg_hub( struct device *dev, u_short force_relogin );
                    302: static int  hp100_down_vg_link( struct device *dev );
                    303: static void hp100_cascade_reset( struct device *dev, u_short enable );
                    304: static void hp100_BM_shutdown( struct device *dev );
                    305: static void hp100_mmuinit( struct device *dev );
                    306: static void hp100_init_pdls( struct device *dev );
                    307: static int  hp100_init_rxpdl( struct device *dev, register hp100_ring_t *ringptr, register u_int *pdlptr);
                    308: static int  hp100_init_txpdl( struct device *dev, register hp100_ring_t *ringptr, register u_int *pdlptr);
                    309: static void hp100_rxfill( struct device *dev );
                    310: static void hp100_hwinit( struct device *dev );
                    311: static void hp100_clean_txring( struct device *dev );
                    312: #ifdef HP100_DEBUG
                    313: static void hp100_RegisterDump( struct device *dev );
                    314: #endif
                    315: 
                    316: /* TODO: This function should not really be needed in a good design... */
                    317: static void wait( void )
                    318: {
                    319:   udelay( 1000 );
                    320: }
                    321: 
                    322: /*
                    323:  *  probe functions
                    324:  *  These functions should - if possible - avoid doing write operations
                    325:  *  since this could cause problems when the card is not installed.
                    326:  */
                    327:  
                    328: __initfunc(int hp100_probe( struct device *dev ))
                    329: {
                    330:   int base_addr = dev ? dev -> base_addr : 0;
                    331:   int ioaddr = 0;
                    332: #ifdef CONFIG_PCI
                    333:   int pci_start_index = 0;
                    334: #endif
                    335: 
                    336: #ifdef HP100_DEBUG_B
                    337:   hp100_outw( 0x4200, TRACE );
                    338:   printk( "hp100: %s: probe\n", dev->name );
                    339: #endif
                    340: 
                    341:   if ( base_addr > 0xff )      /* Check a single specified location. */
                    342:     {
                    343:       if ( check_region( base_addr, HP100_REGION_SIZE ) ) return -EINVAL;
                    344:       if ( base_addr < 0x400 )
                    345:         return hp100_probe1( dev, base_addr, HP100_BUS_ISA, 0, 0 );
                    346:       if ( EISA_bus && base_addr >= 0x1c38 && ( (base_addr - 0x1c38) & 0x3ff ) == 0 )
                    347:         return hp100_probe1( dev, base_addr, HP100_BUS_EISA, 0, 0 );
                    348: #ifdef CONFIG_PCI
                    349:       printk( "hp100: %s: You may specify card # in i/o address parameter for PCI bus...", dev->name );
                    350:       return hp100_probe1( dev, base_addr, HP100_BUS_PCI, 0, 0 );
                    351: #else
                    352:       return -ENODEV;
                    353: #endif
                    354:     }
                    355:   else
                    356: #ifdef CONFIG_PCI
                    357:     if ( base_addr > 0 && base_addr < 8 + 1 )
                    358:       pci_start_index = 0x100 | ( base_addr - 1 );
                    359:     else
                    360: #endif
                    361:       if ( base_addr != 0 ) return -ENXIO;
                    362: 
                    363:   /* at first - scan PCI bus(es) */
                    364: 
                    365: #ifdef CONFIG_PCI
                    366:   if ( pcibios_present() )
                    367:     {
                    368:       int pci_index;
                    369: 
                    370: #ifdef HP100_DEBUG_PCI
                    371:       printk( "hp100: %s: PCI BIOS is present, checking for devices..\n", dev->name );
                    372: #endif
                    373:       for ( pci_index = pci_start_index & 7; pci_index < 8; pci_index++ )
                    374:         {
                    375:           u_char pci_bus, pci_device_fn;
                    376:           u_short pci_command;
                    377:           int pci_id_index;
                    378: 
                    379:          for ( pci_id_index = 0; pci_id_index < HP100_PCI_IDS_SIZE; pci_id_index++ )
                    380:             if ( pcibios_find_device( hp100_pci_ids[ pci_id_index ].vendor,
                    381:                                      hp100_pci_ids[ pci_id_index ].device,
                    382:                                       pci_index, &pci_bus,
                    383:                                       &pci_device_fn ) == 0 ) goto __pci_found;
                    384:           break;
                    385: 
                    386:          __pci_found:
                    387:           pcibios_read_config_dword( pci_bus, pci_device_fn,
                    388:                                      PCI_BASE_ADDRESS_0, &ioaddr );
                    389: 
                    390:           ioaddr &= ~3;    /* remove I/O space marker in bit 0. */
                    391: 
                    392:           if ( check_region( ioaddr, HP100_REGION_SIZE ) ) continue;
                    393: 
                    394:           pcibios_read_config_word( pci_bus, pci_device_fn,
                    395:                                     PCI_COMMAND, &pci_command );
                    396:           if ( !( pci_command & PCI_COMMAND_IO ) )
                    397:             {
                    398: #ifdef HP100_DEBUG
                    399:               printk( "hp100: %s: PCI I/O Bit has not been set. Setting...\n", dev->name );
                    400: #endif
                    401:               pci_command |= PCI_COMMAND_IO;
                    402:               pcibios_write_config_word( pci_bus, pci_device_fn,
                    403:                                          PCI_COMMAND, pci_command );
                    404:             }
                    405:           if ( !( pci_command & PCI_COMMAND_MASTER ) )
                    406:             {
                    407: #ifdef HP100_DEBUG
                    408:               printk( "hp100: %s: PCI Master Bit has not been set. Setting...\n", dev->name );
                    409: #endif
                    410:               pci_command |= PCI_COMMAND_MASTER;
                    411:               pcibios_write_config_word( pci_bus, pci_device_fn,
                    412:                                          PCI_COMMAND, pci_command );
                    413:             }
                    414: #ifdef HP100_DEBUG
                    415:           printk( "hp100: %s: PCI adapter found at 0x%x\n", dev->name, ioaddr );
                    416: #endif
                    417:          if ( hp100_probe1( dev, ioaddr, HP100_BUS_PCI, pci_bus, pci_device_fn ) == 0 )
                    418:            return 0;
                    419:         }
                    420:     }
                    421:   if ( pci_start_index > 0 ) return -ENODEV;
                    422: #endif /* CONFIG_PCI */
                    423: 
                    424:   /* Second: Probe all EISA possible port regions (if EISA bus present) */
                    425:   for ( ioaddr = 0x1c38; EISA_bus && ioaddr < 0x10000; ioaddr += 0x400 )
                    426:     {
                    427:       if ( check_region( ioaddr, HP100_REGION_SIZE ) ) continue;
                    428:       if ( hp100_probe1( dev, ioaddr, HP100_BUS_EISA, 0, 0 ) == 0 ) return 0;
                    429:     }
                    430: 
                    431:   /* Third Probe all ISA possible port regions */
                    432:   for ( ioaddr = 0x100; ioaddr < 0x400; ioaddr += 0x20 )
                    433:     {
                    434:       if ( check_region( ioaddr, HP100_REGION_SIZE ) ) continue;
                    435:       if ( hp100_probe1( dev, ioaddr, HP100_BUS_ISA, 0, 0 ) == 0 ) return 0;
                    436:     }
                    437: 
                    438:   return -ENODEV;
                    439: }
                    440: 
                    441: 
                    442: __initfunc(static int hp100_probe1( struct device *dev, int ioaddr, u_char bus, u_char pci_bus, u_char pci_device_fn ))
                    443: {
                    444:   int i;
                    445: 
                    446:   u_char uc, uc_1;
                    447:   u_int eisa_id;
                    448:   u_int chip;
                    449:   u_int memory_size = 0, virt_memory_size = 0;
                    450:   u_short local_mode, lsw;
                    451:   short mem_mapped;
                    452:   u_int *mem_ptr_phys, *mem_ptr_virt;
                    453:   struct hp100_private *lp;
                    454:   struct hp100_eisa_id *eid;
                    455: 
                    456: #ifdef HP100_DEBUG_B
                    457:   hp100_outw( 0x4201, TRACE );
                    458:   printk("hp100: %s: probe1\n",dev->name);
                    459: #endif
                    460: 
                    461:   if ( dev == NULL )
                    462:     {
                    463: #ifdef HP100_DEBUG
                    464:       printk( "hp100_probe1: %s: dev == NULL ?\n", dev->name );
                    465: #endif
                    466:       return EIO;
                    467:     }
                    468:   
                    469:   if ( hp100_inw( HW_ID ) != HP100_HW_ID_CASCADE ) 
                    470:     {
                    471:       return -ENODEV;
                    472:     }
                    473:   else
                    474:     {
                    475:       chip = hp100_inw( PAGING ) & HP100_CHIPID_MASK;
                    476: #ifdef HP100_DEBUG
                    477:       if ( chip == HP100_CHIPID_SHASTA )
                    478:         printk("hp100: %s: Shasta Chip detected. (This is a pre 802.12 chip)\n", dev->name);
                    479:       else if ( chip == HP100_CHIPID_RAINIER )
                    480:         printk("hp100: %s: Rainier Chip detected. (This is a pre 802.12 chip)\n", dev->name);
                    481:       else if ( chip == HP100_CHIPID_LASSEN )
                    482:         printk("hp100: %s: Lassen Chip detected.\n", dev->name);
                    483:       else
                    484:         printk("hp100: %s: Warning: Unknown CASCADE chip (id=0x%.4x).\n",dev->name,chip);
                    485: #endif 
                    486:     }
                    487: 
                    488:   dev->base_addr = ioaddr;
                    489: 
                    490:   hp100_page( ID_MAC_ADDR );
                    491:   for ( i = uc = eisa_id = 0; i < 4; i++ )
                    492:     {
                    493:       eisa_id >>= 8;
                    494:       uc_1 = hp100_inb( BOARD_ID + i );
                    495:       eisa_id |= uc_1 << 24;
                    496:       uc += uc_1;
                    497:     }
                    498:   uc += hp100_inb( BOARD_ID + 4 );
                    499: 
                    500:   if ( uc != 0xff )    /* bad checksum? */
                    501:     {
                    502:       printk("hp100_probe: %s: bad EISA ID checksum at base port 0x%x\n", dev->name, ioaddr );
                    503:       return -ENODEV;
                    504:     }
                    505: 
                    506:   for ( i=0; i < HP100_EISA_IDS_SIZE; i++)
                    507:     if ( hp100_eisa_ids[ i ].id == eisa_id )
                    508:       break;
                    509:   if ( i >= HP100_EISA_IDS_SIZE ) {
                    510:     for ( i = 0; i < HP100_EISA_IDS_SIZE; i++)
                    511:       if ( ( hp100_eisa_ids[ i ].id & 0xf0ffffff ) == ( eisa_id & 0xf0ffffff ) )
                    512:         break;
                    513:     if ( i >= HP100_EISA_IDS_SIZE ) {
                    514:       printk( "hp100_probe: %s: card at port 0x%x isn't known (id = 0x%x)\n", dev -> name, ioaddr, eisa_id );
                    515:         return -ENODEV;
                    516:     }
                    517:   }
                    518:   eid = &hp100_eisa_ids[ i ];
                    519:   if ( ( eid->id & 0x0f000000 ) < ( eisa_id & 0x0f000000 ) )
                    520:     {
                    521:       printk( "hp100_probe: %s: newer version of card %s at port 0x%x - unsupported\n",
                    522:              dev->name, eid->name, ioaddr );
                    523:       return -ENODEV;
                    524:     }
                    525: 
                    526:   for ( i = uc = 0; i < 7; i++ )
                    527:     uc += hp100_inb( LAN_ADDR + i );
                    528:   if ( uc != 0xff )
                    529:     {
                    530:       printk("hp100_probe: %s: bad lan address checksum (card %s at port 0x%x)\n",
                    531:             dev->name, eid->name, ioaddr );
                    532:       return -EIO;
                    533:     }
                    534: 
                    535:   /* Make sure, that all registers are correctly updated... */
                    536: 
                    537:   hp100_load_eeprom( dev, ioaddr );
                    538:   wait();
                    539: 
                    540:   /*
                    541:    * Determine driver operation mode
                    542:    *
                    543:    * Use the variable "hp100_mode" upon insmod or as kernel parameter to
                    544:    * force driver modes:
                    545:    * hp100_mode=1 -> default, use busmaster mode if configured.
                    546:    * hp100_mode=2 -> enable shared memory mode 
                    547:    * hp100_mode=3 -> force use of i/o mapped mode.
                    548:    * hp100_mode=4 -> same as 1, but re-set the enable bit on the card.
                    549:    */
                    550: 
                    551:   /*
                    552:    * LSW values:
                    553:    *   0x2278 -> J2585B, PnP shared memory mode
                    554:    *   0x2270 -> J2585B, shared memory mode, 0xdc000
                    555:    *   0xa23c -> J2585B, I/O mapped mode
                    556:    *   0x2240 -> EISA COMPEX, BusMaster (Shasta Chip)
                    557:    *   0x2220 -> EISA HP, I/O (Shasta Chip)
                    558:    *   0x2260 -> EISA HP, BusMaster (Shasta Chip)
                    559:    */
                    560: 
                    561: #if 0
                    562:   local_mode = 0x2270;
                    563:   hp100_outw(0xfefe,OPTION_LSW);
                    564:   hp100_outw(local_mode|HP100_SET_LB|HP100_SET_HB,OPTION_LSW);
                    565: #endif
                    566: 
                    567:   /* hp100_mode value maybe used in future by another card */
                    568:   local_mode=hp100_mode;
                    569:   if ( local_mode < 1 || local_mode > 4 )
                    570:     local_mode = 1;            /* default */
                    571: #ifdef HP100_DEBUG
                    572:   printk( "hp100: %s: original LSW = 0x%x\n", dev->name, hp100_inw(OPTION_LSW) );
                    573: #endif
                    574: 
                    575:   if(local_mode==3)
                    576:     {
                    577:       hp100_outw(HP100_MEM_EN|HP100_RESET_LB, OPTION_LSW);
                    578:       hp100_outw(HP100_IO_EN|HP100_SET_LB, OPTION_LSW);
                    579:       hp100_outw(HP100_BM_WRITE|HP100_BM_READ|HP100_RESET_HB, OPTION_LSW);
                    580:       printk("hp100: %s: IO mapped mode forced.\n", dev->name);
                    581:     }
                    582:   else if(local_mode==2)
                    583:     {
                    584:       hp100_outw(HP100_MEM_EN|HP100_SET_LB, OPTION_LSW);
                    585:       hp100_outw(HP100_IO_EN |HP100_SET_LB, OPTION_LSW);
                    586:       hp100_outw(HP100_BM_WRITE|HP100_BM_READ|HP100_RESET_HB, OPTION_LSW);
                    587:       printk("hp100: %s: Shared memory mode requested.\n", dev->name);
                    588:     } 
                    589:   else if(local_mode==4)
                    590:     {
                    591:       if(chip==HP100_CHIPID_LASSEN)
                    592:        {
                    593:          hp100_outw(HP100_BM_WRITE|
                    594:                     HP100_BM_READ | HP100_SET_HB, OPTION_LSW);
                    595:          hp100_outw(HP100_IO_EN   | 
                    596:                     HP100_MEM_EN  | HP100_RESET_LB, OPTION_LSW);
                    597:          printk("hp100: %s: Busmaster mode requested.\n",dev->name);
                    598:        }
                    599:       local_mode=1;
                    600:     }
                    601:                
                    602:   if(local_mode==1) /* default behaviour */
                    603:     {
                    604:       lsw = hp100_inw(OPTION_LSW);
                    605:     
                    606:       if ( (lsw & HP100_IO_EN) &&
                    607:           (~lsw & HP100_MEM_EN) &&
                    608:           (~lsw & (HP100_BM_WRITE|HP100_BM_READ)) )
                    609:        {
                    610: #ifdef HP100_DEBUG
                    611:          printk("hp100: %s: IO_EN bit is set on card.\n",dev->name);
                    612: #endif
                    613:          local_mode=3;
                    614:        }
                    615:       else if ( chip == HP100_CHIPID_LASSEN &&
                    616:                ( lsw & (HP100_BM_WRITE|HP100_BM_READ) ) ==
                    617:                        (HP100_BM_WRITE|HP100_BM_READ) )
                    618:        {
                    619:          printk("hp100: %s: Busmaster mode enabled.\n",dev->name);
                    620:          hp100_outw(HP100_MEM_EN|HP100_IO_EN|HP100_RESET_LB, OPTION_LSW);
                    621:        }
                    622:       else
                    623:        {
                    624: #ifdef HP100_DEBUG
                    625:          printk("hp100: %s: Card not configured for BM or BM not supported with this card.\n", dev->name );
                    626:          printk("hp100: %s: Trying shared memory mode.\n", dev->name);
                    627: #endif
                    628:          /* In this case, try shared memory mode */
                    629:          local_mode=2;
                    630:          hp100_outw(HP100_MEM_EN|HP100_SET_LB, OPTION_LSW);
                    631:          /* hp100_outw(HP100_IO_EN|HP100_RESET_LB, OPTION_LSW); */
                    632:        }
                    633:     }
                    634: 
                    635: #ifdef HP100_DEBUG
                    636:   printk( "hp100: %s: new LSW = 0x%x\n", dev->name, hp100_inw(OPTION_LSW) );
                    637: #endif
                    638: 
                    639:   /* Check for shared memory on the card, eventually remap it */
                    640:   hp100_page( HW_MAP );
                    641:   mem_mapped = (( hp100_inw( OPTION_LSW ) & ( HP100_MEM_EN ) ) != 0);
                    642:   mem_ptr_phys = mem_ptr_virt = NULL;
                    643:   memory_size = (8192<<( (hp100_inb(SRAM)>>5)&0x07));
                    644:   virt_memory_size = 0;
                    645: 
                    646:   /* For memory mapped or busmaster mode, we want the memory address */
                    647:   if ( mem_mapped || (local_mode==1))
                    648:     {
                    649:       mem_ptr_phys = (u_int *)( hp100_inw( MEM_MAP_LSW ) | 
                    650:                                ( hp100_inw( MEM_MAP_MSW ) << 16 ) );
1.1.1.2 ! root      651:       mem_ptr_phys = (u_int *) ((u_int) mem_ptr_phys & ~0x1fff);  /* 8k alignment */
1.1       root      652:       if ( bus == HP100_BUS_ISA && ( (u_long)mem_ptr_phys & ~0xfffff ) != 0 )
                    653:         {
                    654:          printk("hp100: %s: Can only use programmed i/o mode.\n", dev->name);
                    655:           mem_ptr_phys = NULL;
                    656:           mem_mapped = 0;
                    657:          local_mode=3; /* Use programmed i/o */
                    658:         }
                    659:                                                
                    660:       /* We do not need access to shared memory in busmaster mode */
                    661:       /* However in slave mode we need to remap high (>1GB) card memory  */
                    662:       if(local_mode!=1) /* = not busmaster */
                    663:        {
                    664:          if ( bus == HP100_BUS_PCI && mem_ptr_phys >= (u_int *)0x100000 )
                    665:            {
                    666:              /* We try with smaller memory sizes, if ioremap fails */
                    667:              for(virt_memory_size = memory_size; virt_memory_size>16383; virt_memory_size>>=1)
                    668:                {
                    669:                  if((mem_ptr_virt=ioremap((u_long)mem_ptr_phys,virt_memory_size))==NULL)
                    670:                    {
                    671: #ifdef HP100_DEBUG
                    672:                      printk( "hp100: %s: ioremap for 0x%x bytes high PCI memory at 0x%lx failed\n", dev->name, virt_memory_size, (u_long)mem_ptr_phys );
                    673: #endif
                    674:                    }   
                    675:                  else
                    676:                    {
                    677: #ifdef HP100_DEBUG
                    678:                      printk( "hp100: %s: remapped 0x%x bytes high PCI memory at 0x%lx to 0x%lx.\n", dev->name, virt_memory_size, (u_long)mem_ptr_phys, (u_long)mem_ptr_virt);
                    679: #endif
                    680:                      break;
                    681:                    }
                    682:                }
                    683:                                                                                                                
                    684:              if(mem_ptr_virt==NULL) /* all ioremap tries failed */
                    685:                {
                    686:                  printk("hp100: %s: Failed to ioremap the PCI card memory. Will have to use i/o mapped mode.\n", dev->name);
                    687:                  local_mode=3;
                    688:                  virt_memory_size = 0;
                    689:                }
                    690:            }
                    691:        }
                    692:                                                
                    693:     }
                    694: 
                    695:   if(local_mode==3) /* io mapped forced */
                    696:     {
                    697:       mem_mapped = 0;
                    698:       mem_ptr_phys = mem_ptr_virt = NULL;
                    699:       printk("hp100: %s: Using (slow) programmed i/o mode.\n", dev->name);
                    700:     }
                    701: 
                    702:   /* Initialise the "private" data structure for this card. */
                    703:   if ( (dev->priv=kmalloc(sizeof(struct hp100_private), GFP_KERNEL)) == NULL)
                    704:     return -ENOMEM;
                    705:   memset( dev->priv, 0, sizeof(struct hp100_private) );
                    706: 
                    707:   lp = (struct hp100_private *)dev->priv;
                    708:   lp->id = eid;
                    709:   lp->chip = chip;
                    710:   lp->mode = local_mode;
                    711:   lp->pci_bus = pci_bus;
                    712:   lp->bus = bus;
                    713:   lp->pci_device_fn = pci_device_fn;
                    714:   lp->priority_tx = hp100_priority_tx;
                    715:   lp->rx_ratio = hp100_rx_ratio;
                    716:   lp->mem_ptr_phys = mem_ptr_phys;
                    717:   lp->mem_ptr_virt = mem_ptr_virt;
                    718:   hp100_page( ID_MAC_ADDR );
                    719:   lp->soft_model = hp100_inb( SOFT_MODEL );
                    720:   lp->mac1_mode = HP100_MAC1MODE3;
                    721:   lp->mac2_mode = HP100_MAC2MODE3;
                    722:   memset( &lp->hash_bytes, 0x00, 8 );
                    723: 
                    724:   dev->base_addr = ioaddr;
                    725: 
                    726:   lp->memory_size = memory_size;
                    727:   lp->virt_memory_size = virt_memory_size;
                    728:   lp->rx_ratio = hp100_rx_ratio; /* can be conf'd with insmod */
                    729: 
                    730:   /* memory region for programmed i/o */
                    731:   request_region( dev->base_addr, HP100_REGION_SIZE, eid->name );
                    732: 
                    733:   dev->open = hp100_open;
                    734:   dev->stop = hp100_close;
                    735: 
                    736:   if (lp->mode==1) /* busmaster */
                    737:     dev->hard_start_xmit = hp100_start_xmit_bm;
                    738:   else
                    739:     dev->hard_start_xmit = hp100_start_xmit;
                    740: 
                    741:   dev->get_stats = hp100_get_stats;
                    742:   dev->set_multicast_list = &hp100_set_multicast_list;
                    743: 
                    744:   /* Ask the card for which IRQ line it is configured */
                    745:   hp100_page( HW_MAP );
                    746:   dev->irq = hp100_inb( IRQ_CHANNEL ) & HP100_IRQMASK;
                    747:   if ( dev->irq == 2 )
                    748:     dev->irq = 9;
                    749: 
                    750:   if(lp->mode==1) /* busmaster */
                    751:     dev->dma=4; 
                    752: 
                    753:   /* Ask the card for its MAC address and store it for later use. */
                    754:   hp100_page( ID_MAC_ADDR );
                    755:   for ( i = uc = 0; i < 6; i++ )
                    756:     dev->dev_addr[ i ] = hp100_inb( LAN_ADDR + i );
                    757: 
                    758:   /* Reset statistics (counters) */
                    759:   hp100_clear_stats( ioaddr );
                    760: 
                    761:   ether_setup( dev );
                    762: 
                    763:   /* If busmaster mode is wanted, a dma-capable memory area is needed for
                    764:    * the rx and tx PDLs 
                    765:    * PCI cards can access the whole PC memory. Therefore GFP_DMA is not
                    766:    * needed for the allocation of the memory area. 
                    767:    */
                    768: 
                    769:   /* TODO: We do not need this with old cards, where PDLs are stored
                    770:    * in the cards shared memory area. But currently, busmaster has been
                    771:    * implemented/tested only with the lassen chip anyway... */
                    772:   if(lp->mode==1) /* busmaster */
                    773:     {
                    774:       /* Get physically continous memory for TX & RX PDLs    */
                    775:       if ( (lp->page_vaddr=kmalloc(MAX_RINGSIZE+0x0f,GFP_KERNEL) ) == NULL)
                    776:         return -ENOMEM;
                    777:       lp->page_vaddr_algn=((u_int *) ( ((u_int)(lp->page_vaddr)+0x0f) &~0x0f));
                    778:       memset(lp->page_vaddr, 0, MAX_RINGSIZE+0x0f);
                    779: 
                    780: #ifdef HP100_DEBUG_BM
                    781:       printk("hp100: %s: Reserved DMA memory from 0x%x to 0x%x\n",
                    782:             dev->name,
                    783:              (u_int)lp->page_vaddr_algn,
                    784:              (u_int)lp->page_vaddr_algn+MAX_RINGSIZE);
                    785: #endif
                    786:       lp->rxrcommit  = lp->txrcommit = 0;
                    787:       lp->rxrhead    = lp->rxrtail   = &(lp->rxring[0]);
                    788:       lp->txrhead    = lp->txrtail   = &(lp->txring[0]); 
                    789:     }
                    790: 
                    791:   /* Initialise the card. */
                    792:   /* (I'm not really sure if it's a good idea to do this during probing, but 
                    793:    * like this it's assured that the lan connection type can be sensed
                    794:    * correctly)
                    795:    */
                    796:   hp100_hwinit( dev );
                    797: 
                    798:   /* Try to find out which kind of LAN the card is connected to. */
                    799:   lp->lan_type = hp100_sense_lan( dev );
                    800:      
                    801:   /* Print out a message what about what we think we have probed. */
                    802:   printk( "hp100: %s: %s at 0x%x, IRQ %d, ",
                    803:           dev->name, lp->id->name, ioaddr, dev->irq );
                    804:   switch ( bus ) {
                    805:   case HP100_BUS_EISA: printk( "EISA" ); break;
                    806:   case HP100_BUS_PCI:  printk( "PCI" );  break;
                    807:   default:     printk( "ISA" );  break;
                    808:   }
                    809:   printk( " bus, %dk SRAM (rx/tx %d%%).\n",
                    810:           lp->memory_size >> 10, lp->rx_ratio );
                    811: 
                    812:   if ( lp->mode==2 ) /* memory mapped */ 
                    813:     {
                    814:       printk( "hp100: %s: Memory area at 0x%lx-0x%lx",
                    815:               dev->name,(u_long)mem_ptr_phys,
                    816:               ((u_long)mem_ptr_phys+(mem_ptr_phys>(u_int *)0x100000?(u_long)lp->memory_size:16*1024))-1 );
                    817:       if ( mem_ptr_virt )
                    818:        printk( " (virtual base 0x%lx)", (u_long)mem_ptr_virt );
                    819:       printk( ".\n" );
                    820: 
                    821:       /* Set for info when doing ifconfig */
                    822:       dev->mem_start = (u_long)mem_ptr_phys;
                    823:       dev->mem_end = (u_long)mem_ptr_phys+(u_long)lp->memory_size;
                    824:     }
                    825:   printk( "hp100: %s: ", dev->name );
                    826:   if ( lp->lan_type != HP100_LAN_ERR )
                    827:     printk( "Adapter is attached to " );
                    828:   switch ( lp->lan_type ) {
                    829:   case HP100_LAN_100:
                    830:     printk( "100Mb/s Voice Grade AnyLAN network.\n" );
                    831:     break;
                    832:   case HP100_LAN_10:
                    833:     printk( "10Mb/s network.\n" );
                    834:     break;
                    835:   default:
                    836:     printk( "Warning! Link down.\n" );
                    837:   }
                    838: 
                    839:   return 0;
                    840: }
                    841: 
                    842: 
                    843: /* This procedure puts the card into a stable init state */
                    844: static void hp100_hwinit( struct device *dev )
                    845: {
                    846:   int ioaddr = dev->base_addr;
                    847:   struct hp100_private *lp = (struct hp100_private *)dev->priv;
                    848: 
                    849: #ifdef HP100_DEBUG_B
                    850:   hp100_outw( 0x4202, TRACE );
                    851:   printk("hp100: %s: hwinit\n", dev->name);
                    852: #endif
                    853: 
                    854:   /* Initialise the card. -------------------------------------------- */
                    855: 
                    856:   /* Clear all pending Ints and disable Ints */
                    857:   hp100_page( PERFORMANCE );
                    858:   hp100_outw( 0xfefe, IRQ_MASK );    /* mask off all ints */
                    859:   hp100_outw( 0xffff, IRQ_STATUS );  /* clear all pending ints */
                    860: 
                    861:   hp100_outw( HP100_INT_EN | HP100_RESET_LB, OPTION_LSW );
                    862:   hp100_outw( HP100_TRI_INT | HP100_SET_HB, OPTION_LSW );
                    863: 
                    864:   if(lp->mode==1)
                    865:     { 
                    866:       hp100_BM_shutdown( dev ); /* disables BM, puts cascade in reset */
                    867:       wait();
                    868:     }
                    869:   else
                    870:     {
                    871:       hp100_outw( HP100_INT_EN | HP100_RESET_LB, OPTION_LSW );
                    872:       hp100_cascade_reset( dev, TRUE );
                    873:       hp100_page( MAC_CTRL );
                    874:       hp100_andb( ~(HP100_RX_EN|HP100_TX_EN), MAC_CFG_1); 
                    875:     }
                    876:                
                    877:   /* Initiate EEPROM reload */
                    878:   hp100_load_eeprom( dev, 0 );
                    879:                
                    880:   wait();
                    881:                
                    882:   /* Go into reset again. */
                    883:   hp100_cascade_reset( dev, TRUE );
                    884:                
                    885:   /* Set Option Registers to a safe state  */
                    886:   hp100_outw( HP100_DEBUG_EN |
                    887:               HP100_RX_HDR   |
                    888:               HP100_EE_EN    |
                    889:               HP100_BM_WRITE |
                    890:               HP100_BM_READ  | HP100_RESET_HB |
                    891:               HP100_FAKE_INT |
                    892:               HP100_INT_EN   |
                    893:              HP100_MEM_EN   |
                    894:               HP100_IO_EN    | HP100_RESET_LB, OPTION_LSW);
                    895:                
                    896:   hp100_outw( HP100_TRI_INT  |
                    897:               HP100_MMAP_DIS | HP100_SET_HB, OPTION_LSW );
                    898: 
                    899:   hp100_outb( HP100_PRIORITY_TX |
                    900:               HP100_ADV_NXT_PKT |
                    901:               HP100_TX_CMD      | HP100_RESET_LB, OPTION_MSW );
                    902: 
                    903:   /* TODO: Configure MMU for Ram Test. */
                    904:   /* TODO: Ram Test. */
                    905: 
                    906:   /* Re-check if adapter is still at same i/o location      */
                    907:   /* (If the base i/o in eeprom has been changed but the    */
                    908:   /* registers had not been changed, a reload of the eeprom */
                    909:   /* would move the adapter to the address stored in eeprom */
                    910:   
                    911:   /* TODO: Code to implement. */
                    912:                
                    913:   /* Until here it was code from HWdiscover procedure. */
                    914:   /* Next comes code from mmuinit procedure of SCO BM driver which is
                    915:    * called from HWconfigure in the SCO driver.  */
                    916: 
                    917:   /* Initialise MMU, eventually switch on Busmaster Mode, initialise 
                    918:    * multicast filter...
                    919:    */
                    920:   hp100_mmuinit( dev );
                    921: 
                    922:   /* We don't turn the interrupts on here - this is done by start_interface. */
                    923:   wait(); /* TODO: Do we really need this? */
                    924: 
                    925:   /* Enable Hardware (e.g. unreset) */
                    926:   hp100_cascade_reset( dev, FALSE );
                    927: 
                    928:   /* ------- initialisation complete ----------- */
                    929: 
                    930:   /* Finally try to log in the Hub if there may be a VG connection. */
                    931:   if( lp->lan_type != HP100_LAN_10 )
                    932:     hp100_login_to_vg_hub( dev, FALSE ); /* relogin */
                    933: }
                    934: 
                    935: 
                    936: /* 
                    937:  * mmuinit - Reinitialise Cascade MMU and MAC settings.
                    938:  * Note: Must already be in reset and leaves card in reset. 
                    939:  */
                    940: static void hp100_mmuinit( struct device *dev )
                    941: {
                    942:   int ioaddr = dev->base_addr;
                    943:   struct hp100_private *lp = (struct hp100_private *)dev->priv;
                    944:   int i;
                    945: 
                    946: #ifdef HP100_DEBUG_B
                    947:   hp100_outw( 0x4203, TRACE );
                    948:   printk("hp100: %s: mmuinit\n",dev->name);
                    949: #endif
                    950: 
                    951: #ifdef HP100_DEBUG
                    952:   if( 0!=(hp100_inw(OPTION_LSW)&HP100_HW_RST) )
                    953:     {
                    954:       printk("hp100: %s: Not in reset when entering mmuinit. Fix me.\n",dev->name);
                    955:       return;
                    956:     }
                    957: #endif
                    958: 
                    959:   /* Make sure IRQs are masked off and ack'ed. */
                    960:   hp100_page( PERFORMANCE );
                    961:   hp100_outw( 0xfefe, IRQ_MASK );  /* mask off all ints */
                    962:   hp100_outw( 0xffff, IRQ_STATUS );  /* ack IRQ */
                    963: 
                    964:   /*
                    965:    * Enable Hardware 
                    966:    * - Clear Debug En, Rx Hdr Pipe, EE En, I/O En, Fake Int and Intr En
                    967:    * - Set Tri-State Int, Bus Master Rd/Wr, and Mem Map Disable
                    968:    * - Clear Priority, Advance Pkt and Xmit Cmd
                    969:    */
                    970: 
                    971:   hp100_outw( HP100_DEBUG_EN |
                    972:               HP100_RX_HDR   |
                    973:               HP100_EE_EN    | HP100_RESET_HB |
                    974:               HP100_IO_EN    |
                    975:               HP100_FAKE_INT |
                    976:               HP100_INT_EN   | HP100_RESET_LB, OPTION_LSW );
                    977:        
                    978:   hp100_outw( HP100_TRI_INT | HP100_SET_HB, OPTION_LSW);
                    979:                
                    980:   if(lp->mode==1) /* busmaster */
                    981:     {
                    982:       hp100_outw( HP100_BM_WRITE | 
                    983:                  HP100_BM_READ  |
                    984:                  HP100_MMAP_DIS | HP100_SET_HB, OPTION_LSW );
                    985:     }
                    986:   else if(lp->mode==2) /* memory mapped */
                    987:     {
                    988:       hp100_outw( HP100_BM_WRITE |
                    989:                  HP100_BM_READ  | HP100_RESET_HB, OPTION_LSW );
                    990:       hp100_outw( HP100_MMAP_DIS | HP100_RESET_HB, OPTION_LSW );
                    991:       hp100_outw( HP100_MEM_EN | HP100_SET_LB, OPTION_LSW );
                    992:       hp100_outw( HP100_IO_EN | HP100_SET_LB, OPTION_LSW );
                    993:     }
                    994:   else if( lp->mode==3 ) /* i/o mapped mode */
                    995:     {
                    996:       hp100_outw( HP100_MMAP_DIS | HP100_SET_HB | 
                    997:                   HP100_IO_EN    | HP100_SET_LB, OPTION_LSW );
                    998:     }
                    999: 
                   1000:   hp100_page( HW_MAP );
                   1001:   hp100_outb( 0, EARLYRXCFG );
                   1002:   hp100_outw( 0, EARLYTXCFG );
                   1003:   
                   1004:   /*
                   1005:    * Enable Bus Master mode
                   1006:    */
                   1007:   if(lp->mode==1) /* busmaster */
                   1008:     {
                   1009:       /* Experimental: Set some PCI configuration bits */
                   1010:       hp100_page( HW_MAP );
                   1011:       hp100_andb( ~HP100_PDL_USE3, MODECTRL1 ); /* BM engine read maximum */
                   1012:       hp100_andb( ~HP100_TX_DUALQ, MODECTRL1 ); /* No Queue for Priority TX */
                   1013: 
                   1014:       /* PCI Bus failures should result in a Misc. Interrupt */
                   1015:       hp100_orb( HP100_EN_BUS_FAIL, MODECTRL2);
                   1016:                                        
                   1017:       hp100_outw( HP100_BM_READ | HP100_BM_WRITE | HP100_SET_HB, OPTION_LSW );
                   1018:       hp100_page( HW_MAP );                                    
                   1019:       /* Use Burst Mode and switch on PAGE_CK */
                   1020:       hp100_orb( HP100_BM_BURST_RD |
                   1021:                  HP100_BM_BURST_WR, BM);
                   1022:       if((lp->chip==HP100_CHIPID_RAINIER)||(lp->chip==HP100_CHIPID_SHASTA))
                   1023:        hp100_orb( HP100_BM_PAGE_CK, BM );
                   1024:       hp100_orb( HP100_BM_MASTER, BM );                
                   1025:     }
                   1026:   else /* not busmaster */
                   1027:     {
                   1028:       hp100_page(HW_MAP);
                   1029:       hp100_andb(~HP100_BM_MASTER, BM );
                   1030:     }
                   1031: 
                   1032:   /*
                   1033:    * Divide card memory into regions for Rx, Tx and, if non-ETR chip, PDLs
                   1034:    */  
                   1035:   hp100_page( MMU_CFG );
                   1036:   if(lp->mode==1) /* only needed for Busmaster */
                   1037:     {
                   1038:       int xmit_stop, recv_stop;
                   1039: 
                   1040:       if((lp->chip==HP100_CHIPID_RAINIER)||(lp->chip==HP100_CHIPID_SHASTA))
                   1041:         {
                   1042:           int pdl_stop;
                   1043:           
                   1044:           /*
                   1045:            * Each pdl is 508 bytes long. (63 frags * 4 bytes for address and
                   1046:            * 4 bytes for header). We will leave NUM_RXPDLS * 508 (rounded
                   1047:            * to the next higher 1k boundary) bytes for the rx-pdl's
                   1048:           * Note: For non-etr chips the transmit stop register must be
                   1049:           * programmed on a 1k boundary, i.e. bits 9:0 must be zero. 
                   1050:           */
                   1051:           pdl_stop  = lp->memory_size;
                   1052:           xmit_stop = ( pdl_stop-508*(MAX_RX_PDL)-16 )& ~(0x03ff);
                   1053:           recv_stop = ( xmit_stop * (lp->rx_ratio)/100 ) &~(0x03ff);
                   1054:           hp100_outw( (pdl_stop>>4)-1, PDL_MEM_STOP );
                   1055: #ifdef HP100_DEBUG_BM
                   1056:           printk("hp100: %s: PDL_STOP = 0x%x\n", dev->name, pdl_stop);
                   1057: #endif
                   1058:         }
                   1059:       else /* ETR chip (Lassen) in busmaster mode */
                   1060:         {
                   1061:           xmit_stop = ( lp->memory_size ) - 1;
                   1062:           recv_stop = ( ( lp->memory_size * lp->rx_ratio ) / 100 ) & ~(0x03ff);
                   1063:         }
                   1064: 
                   1065:       hp100_outw( xmit_stop>>4 , TX_MEM_STOP );
                   1066:       hp100_outw( recv_stop>>4 , RX_MEM_STOP );
                   1067: #ifdef HP100_DEBUG_BM
                   1068:       printk("hp100: %s: TX_STOP  = 0x%x\n",dev->name,xmit_stop>>4);
                   1069:       printk("hp100: %s: RX_STOP  = 0x%x\n",dev->name,recv_stop>>4);
                   1070: #endif
                   1071:     }  
                   1072:   else /* Slave modes (memory mapped and programmed io)  */
                   1073:     {
                   1074:       hp100_outw( (((lp->memory_size*lp->rx_ratio)/100)>>4), RX_MEM_STOP );
                   1075:       hp100_outw( ((lp->memory_size - 1 )>>4), TX_MEM_STOP );  
                   1076: #ifdef HP100_DEBUG
                   1077:       printk("hp100: %s: TX_MEM_STOP: 0x%x\n", dev->name,hp100_inw(TX_MEM_STOP));
                   1078:       printk("hp100: %s: RX_MEM_STOP: 0x%x\n", dev->name,hp100_inw(RX_MEM_STOP));
                   1079: #endif
                   1080:     }
                   1081: 
                   1082:   /* Write MAC address into page 1 */
                   1083:   hp100_page( MAC_ADDRESS );
                   1084:   for ( i = 0; i < 6; i++ )
                   1085:     hp100_outb( dev->dev_addr[ i ], MAC_ADDR + i );
                   1086:   
                   1087:   /* Zero the multicast hash registers */
                   1088:   for ( i = 0; i < 8; i++ )
                   1089:     hp100_outb( 0x0, HASH_BYTE0 + i );  
                   1090:   
                   1091:   /* Set up MAC defaults */
                   1092:   hp100_page( MAC_CTRL );
                   1093:  
                   1094:   /* Go to LAN Page and zero all filter bits */
                   1095:   /* Zero accept error, accept multicast, accept broadcast and accept */
                   1096:   /* all directed packet bits */
                   1097:   hp100_andb( ~(HP100_RX_EN|
                   1098:                HP100_TX_EN|
                   1099:                HP100_ACC_ERRORED|
                   1100:                HP100_ACC_MC|
                   1101:                HP100_ACC_BC|
                   1102:                HP100_ACC_PHY),   MAC_CFG_1 );
                   1103: 
                   1104:   hp100_outb( 0x00, MAC_CFG_2 );
                   1105: 
                   1106:   /* Zero the frame format bit. This works around a training bug in the */
                   1107:   /* new hubs. */
                   1108:   hp100_outb( 0x00, VG_LAN_CFG_2); /* (use 802.3) */   
                   1109: 
                   1110:   if(lp->priority_tx)
                   1111:     hp100_outb( HP100_PRIORITY_TX | HP100_SET_LB, OPTION_MSW );
                   1112:   else
                   1113:     hp100_outb( HP100_PRIORITY_TX | HP100_RESET_LB, OPTION_MSW );
                   1114:        
                   1115:   hp100_outb( HP100_ADV_NXT_PKT |
                   1116:              HP100_TX_CMD      | HP100_RESET_LB, OPTION_MSW );
                   1117:        
                   1118:   /* If busmaster, initialize the PDLs */
                   1119:   if(lp->mode==1)
                   1120:     hp100_init_pdls( dev );
                   1121: 
                   1122:   /* Go to performance page and initalize isr and imr registers */
                   1123:   hp100_page( PERFORMANCE );
                   1124:   hp100_outw( 0xfefe, IRQ_MASK );  /* mask off all ints */
                   1125:   hp100_outw( 0xffff, IRQ_STATUS );  /* ack IRQ */
                   1126: }
                   1127: 
                   1128: 
                   1129: /*
                   1130:  *  open/close functions
                   1131:  */
                   1132: 
                   1133: static int hp100_open( struct device *dev )
                   1134: {
                   1135:   struct hp100_private *lp = (struct hp100_private *)dev->priv;
                   1136: #ifdef HP100_DEBUG_B
                   1137:   int ioaddr=dev->base_addr;
                   1138: #endif
                   1139: 
                   1140: #ifdef HP100_DEBUG_B
                   1141:   hp100_outw( 0x4204, TRACE );
                   1142:   printk("hp100: %s: open\n",dev->name);
                   1143: #endif
                   1144:                
                   1145:   /* New: if bus is PCI or EISA, interrupts might be shared interrupts */
                   1146:   if ( request_irq(dev->irq, hp100_interrupt,
                   1147:                   lp->bus==HP100_BUS_PCI||lp->bus==HP100_BUS_EISA?SA_SHIRQ:SA_INTERRUPT,
                   1148:                   lp->id->name, dev))
                   1149:     {
                   1150:       printk( "hp100: %s: unable to get IRQ %d\n", dev->name, dev->irq );
                   1151:       return -EAGAIN;
                   1152:     }
                   1153: 
                   1154:   MOD_INC_USE_COUNT;
                   1155: 
                   1156:   dev->tbusy = 0;
                   1157:   dev->trans_start = jiffies;
                   1158:   dev->interrupt = 0;
                   1159:   dev->start = 1;
                   1160: 
                   1161:   lp->lan_type = hp100_sense_lan( dev );
                   1162:   lp->mac1_mode = HP100_MAC1MODE3;
                   1163:   lp->mac2_mode = HP100_MAC2MODE3;
                   1164:   memset( &lp->hash_bytes, 0x00, 8 );
                   1165: 
                   1166:   hp100_stop_interface( dev );
                   1167:  
                   1168:   hp100_hwinit( dev );
                   1169: 
                   1170:   hp100_start_interface( dev ); /* sets mac modes, enables interrupts */
                   1171: 
                   1172:   return 0;
                   1173: }
                   1174: 
                   1175: 
                   1176: /* The close function is called when the interface is to be brought down */
                   1177: static int hp100_close( struct device *dev )
                   1178: {
                   1179:   int ioaddr = dev->base_addr;
                   1180:   struct hp100_private *lp = (struct hp100_private *)dev->priv;
                   1181: 
                   1182: #ifdef HP100_DEBUG_B
                   1183:   hp100_outw( 0x4205, TRACE );
                   1184:   printk("hp100: %s: close\n", dev->name);
                   1185: #endif
                   1186: 
                   1187:   hp100_page( PERFORMANCE );
                   1188:   hp100_outw( 0xfefe, IRQ_MASK );    /* mask off all IRQs */
                   1189: 
                   1190:   hp100_stop_interface( dev );
                   1191: 
                   1192:   if ( lp->lan_type == HP100_LAN_100 ) 
                   1193:     lp->hub_status=hp100_login_to_vg_hub( dev, FALSE );
                   1194: 
                   1195:   dev->tbusy = 1;
                   1196:   dev->start = 0;
                   1197: 
                   1198:   free_irq( dev->irq, dev );
                   1199: 
                   1200: #ifdef HP100_DEBUG
                   1201:   printk( "hp100: %s: close LSW = 0x%x\n", dev->name, hp100_inw(OPTION_LSW) );
                   1202: #endif
                   1203: 
                   1204:   MOD_DEC_USE_COUNT;
                   1205:   return 0;
                   1206: }
                   1207: 
                   1208: 
                   1209: /*
                   1210:  * Configure the PDL Rx rings and LAN 
                   1211:  */
                   1212: static void hp100_init_pdls( struct device *dev )
                   1213: {
                   1214:   struct hp100_private *lp = (struct hp100_private *)dev->priv;
                   1215:   hp100_ring_t         *ringptr;
                   1216:   u_int                *pageptr;
                   1217:   int                  i;
                   1218: 
                   1219: #ifdef HP100_DEBUG_B
                   1220:   int ioaddr = dev->base_addr;
                   1221: #endif
                   1222: 
                   1223: #ifdef HP100_DEBUG_B
                   1224:   hp100_outw( 0x4206, TRACE );
                   1225:   printk("hp100: %s: init pdls\n", dev->name);
                   1226: #endif
                   1227: 
                   1228:   if(0==lp->page_vaddr_algn)
                   1229:     printk("hp100: %s: Warning: lp->page_vaddr_algn not initialised!\n",dev->name);
                   1230:   else
                   1231:     {
                   1232:       /* pageptr shall point into the DMA accessible memory region  */
                   1233:       /* we use this pointer to status the upper limit of allocated */
                   1234:       /* memory in the allocated page. */
                   1235:       /* note: align the pointers to the pci cache line size */
                   1236:       memset(lp->page_vaddr_algn, 0, MAX_RINGSIZE); /* Zero  Rx/Tx ring page */
                   1237:       pageptr=lp->page_vaddr_algn;
                   1238:                                                
                   1239:       lp->rxrcommit =0;
                   1240:       ringptr = lp->rxrhead = lp-> rxrtail = &(lp->rxring[0]);
                   1241:       
                   1242:       /* Initialise Rx Ring */
                   1243:       for (i=MAX_RX_PDL-1; i>=0; i--)
                   1244:         {
                   1245:           lp->rxring[i].next = ringptr;
                   1246:           ringptr=&(lp->rxring[i]);
                   1247:           pageptr+=hp100_init_rxpdl(dev, ringptr, pageptr);
                   1248:         }
                   1249:       
                   1250:       /* Initialise Tx Ring */
                   1251:       lp->txrcommit = 0;
                   1252:       ringptr = lp->txrhead = lp->txrtail = &(lp->txring[0]);
                   1253:       for (i=MAX_TX_PDL-1; i>=0; i--)
                   1254:         {
                   1255:           lp->txring[i].next = ringptr;
                   1256:           ringptr=&(lp->txring[i]);
                   1257:           pageptr+=hp100_init_txpdl(dev, ringptr, pageptr);
                   1258:         }
                   1259:     }
                   1260: }
                   1261: 
                   1262: 
                   1263: /* These functions "format" the entries in the pdl structure   */
                   1264: /* They return how much memory the fragments need.            */
                   1265: static int hp100_init_rxpdl( struct device *dev, register hp100_ring_t *ringptr, register u32 *pdlptr )
                   1266: {
                   1267:   /* pdlptr is starting adress for this pdl */
                   1268: 
                   1269:   if( 0!=( ((unsigned)pdlptr) & 0xf) )
                   1270:     printk("hp100: %s: Init rxpdl: Unaligned pdlptr 0x%x.\n",dev->name,(unsigned)pdlptr);
                   1271: 
                   1272:   ringptr->pdl       = pdlptr+1; 
                   1273:   ringptr->pdl_paddr = virt_to_bus(pdlptr+1);
                   1274:   ringptr->skb       = (void *) NULL; 
                   1275: 
                   1276:   /* 
                   1277:    * Write address and length of first PDL Fragment (which is used for
                   1278:    * storing the RX-Header
                   1279:    * We use the 4 bytes _before_ the PDH in the pdl memory area to 
                   1280:    * store this information. (PDH is at offset 0x04)
                   1281:    */
                   1282:   /* Note that pdlptr+1 and not pdlptr is the pointer to the PDH */
                   1283: 
                   1284:   *(pdlptr+2) =(u_int) virt_to_bus(pdlptr);  /* Address Frag 1 */ 
                   1285:   *(pdlptr+3) = 4;                           /* Length  Frag 1 */
                   1286: 
                   1287:   return( ( ((MAX_RX_FRAG*2+2)+3) /4)*4 );
                   1288: }
                   1289: 
                   1290: 
                   1291: static int hp100_init_txpdl( struct device *dev, register hp100_ring_t *ringptr, register u32 *pdlptr )
                   1292: {
                   1293:   if( 0!=( ((unsigned)pdlptr) & 0xf) )
                   1294:     printk("hp100: %s: Init txpdl: Unaligned pdlptr 0x%x.\n",dev->name,(unsigned) pdlptr);
                   1295: 
                   1296:   ringptr->pdl       = pdlptr; /* +1; */  
                   1297:   ringptr->pdl_paddr = virt_to_bus(pdlptr); /* +1 */
                   1298:   ringptr->skb = (void *) NULL;
                   1299:   
                   1300:   return((((MAX_TX_FRAG*2+2)+3)/4)*4);
                   1301: }
                   1302: 
                   1303: 
                   1304: /*
                   1305:  * hp100_build_rx_pdl allocates an skb_buff of maximum size plus two bytes 
                   1306:  * for possible odd word alignment rounding up to next dword and set PDL
                   1307:  * address for fragment#2 
                   1308:  * Returns: 0 if unable to allocate skb_buff
                   1309:  *          1 if successful
                   1310:  */
                   1311: int hp100_build_rx_pdl( hp100_ring_t *ringptr, struct device *dev )
                   1312: {
                   1313: #ifdef HP100_DEBUG_B
                   1314:   int ioaddr = dev->base_addr;
                   1315: #endif
                   1316: #ifdef HP100_DEBUG_BM
                   1317:   u_int *p;
                   1318: #endif
                   1319: 
                   1320: #ifdef HP100_DEBUG_B
                   1321:   hp100_outw( 0x4207, TRACE );
                   1322:   printk("hp100: %s: build rx pdl\n", dev->name);
                   1323: #endif
                   1324: 
                   1325:   /* Allocate skb buffer of maximum size */
                   1326:   /* Note: This depends on the alloc_skb functions allocating more 
                   1327:    * space than requested, i.e. aligning to 16bytes */
                   1328: 
                   1329:   ringptr->skb = dev_alloc_skb( ((MAX_ETHER_SIZE+2+3)/4)*4 );
                   1330:                
                   1331:   if(NULL!=ringptr->skb)
                   1332:     {
                   1333:       /* 
                   1334:        * Reserve 2 bytes at the head of the buffer to land the IP header
                   1335:        * on a long word boundary (According to the Network Driver section
                   1336:        * in the Linux KHG, this should help to increase performance.)
                   1337:        */
                   1338:       skb_reserve(ringptr->skb, 2);
                   1339: 
                   1340:       ringptr->skb->dev=dev; 
                   1341:       ringptr->skb->data=(u_char *)skb_put(ringptr->skb, MAX_ETHER_SIZE );
                   1342:                                                
                   1343:       /* ringptr->pdl points to the beginning of the PDL, i.e. the PDH */
                   1344:       /* Note: 1st Fragment is used for the 4 byte packet status
                   1345:        * (receive header). Its PDL entries are set up by init_rxpdl. So 
                   1346:        * here we only have to set up the PDL fragment entries for the data
                   1347:        * part. Those 4 bytes will be stored in the DMA memory region 
                   1348:        * directly before the PDL. 
                   1349:        */
                   1350: #ifdef HP100_DEBUG_BM
                   1351:       printk("hp100: %s: build_rx_pdl: PDH@0x%x, skb->data (len %d) at 0x%x\n",
                   1352:             dev->name,
                   1353:             (u_int) ringptr->pdl,
                   1354:             ((MAX_ETHER_SIZE+2+3)/4)*4,
                   1355:             (unsigned int) ringptr->skb->data);
                   1356: #endif
                   1357: 
                   1358:       ringptr->pdl[0] = 0x00020000;                          /* Write PDH */
                   1359:       ringptr->pdl[3] = ((u_int)virt_to_bus(ringptr->skb->data)); 
                   1360:       ringptr->pdl[4] = MAX_ETHER_SIZE;                 /* Length of Data */
                   1361:                                                
                   1362: #ifdef HP100_DEBUG_BM
                   1363:       for(p=(ringptr->pdl); p<(ringptr->pdl+5); p++)
                   1364:         printk("hp100: %s: Adr 0x%.8x = 0x%.8x\n",dev->name,(u_int) p,(u_int) *p );
                   1365: #endif
                   1366:       return(1);
                   1367:     }
                   1368:   /* else: */
                   1369:   /* alloc_skb failed (no memory) -> still can receive the header
                   1370:    * fragment into PDL memory. make PDL safe by clearing msgptr and
                   1371:    * making the PDL only 1 fragment (i.e. the 4 byte packet status)
                   1372:    */
                   1373: #ifdef HP100_DEBUG_BM
                   1374:   printk("hp100: %s: build_rx_pdl: PDH@0x%x, No space for skb.\n",
                   1375:         dev->name,
                   1376:         (u_int) ringptr->pdl);
                   1377: #endif
                   1378: 
                   1379:   ringptr->pdl[0]=0x00010000;   /* PDH: Count=1 Fragment */
                   1380: 
                   1381:   return(0);
                   1382: }
                   1383: 
                   1384: 
                   1385: /*
                   1386:  *  hp100_rxfill - attempt to fill the Rx Ring will empty skb's
                   1387:  *
                   1388:  * Makes assumption that skb's are always contiguous memory areas and
                   1389:  * therefore PDLs contain only 2 physical fragments.
                   1390:  * -  While the number of Rx PDLs with buffers is less than maximum
                   1391:  *      a.  Get a maximum packet size skb
                   1392:  *      b.  Put the physical address of the buffer into the PDL.
                   1393:  *      c.  Output physical address of PDL to adapter.
                   1394:  */
                   1395: static void hp100_rxfill( struct device *dev )
                   1396: {
                   1397:   int ioaddr=dev->base_addr; 
                   1398: 
                   1399:   struct hp100_private  *lp      = (struct hp100_private *)dev->priv;
                   1400:   hp100_ring_t    *ringptr;
                   1401: 
                   1402: #ifdef HP100_DEBUG_B
                   1403:   hp100_outw( 0x4208, TRACE );
                   1404:   printk("hp100: %s: rxfill\n",dev->name);
                   1405: #endif
                   1406:                
                   1407:   hp100_page( PERFORMANCE );
                   1408: 
                   1409:   while (lp->rxrcommit < MAX_RX_PDL)
                   1410:     {
                   1411:       /*
                   1412:       ** Attempt to get a buffer and build a Rx PDL.
                   1413:       */
                   1414:       ringptr = lp->rxrtail;
                   1415:       if (0 == hp100_build_rx_pdl( ringptr, dev ))
                   1416:         {
                   1417:           return;      /* None available, return */
                   1418:         }
                   1419:       
                   1420:       /* Hand this PDL over to the card */
                   1421:       /* Note: This needs performance page selected! */
                   1422: #ifdef HP100_DEBUG_BM
                   1423:       printk("hp100: %s: rxfill: Hand to card: pdl #%d @0x%x phys:0x%x, buffer: 0x%x\n",
                   1424:             dev->name,
                   1425:              lp->rxrcommit,
                   1426:              (u_int)ringptr->pdl,
                   1427:              (u_int)ringptr->pdl_paddr,
                   1428:              (u_int)ringptr->pdl[3]);
                   1429: #endif
                   1430: 
                   1431:       hp100_outl( (u32)ringptr->pdl_paddr, RX_PDA); 
                   1432:       
                   1433:       lp->rxrcommit += 1;
                   1434:       lp->rxrtail = ringptr->next;
                   1435:     }
                   1436: }
                   1437: 
                   1438: 
                   1439: /*
                   1440:  * BM_shutdown - shutdown bus mastering and leave chip in reset state
                   1441:  */
                   1442: 
                   1443: static void hp100_BM_shutdown( struct device *dev )
                   1444: {
                   1445:   int ioaddr = dev->base_addr;
                   1446:   struct hp100_private *lp = (struct hp100_private *)dev->priv;
                   1447:   unsigned long time;
                   1448: 
                   1449: #ifdef HP100_DEBUG_B
                   1450:   hp100_outw( 0x4209, TRACE );
                   1451:   printk("hp100: %s: bm shutdown\n",dev->name);
                   1452: #endif
                   1453: 
                   1454:   hp100_page( PERFORMANCE );
                   1455:   hp100_outw( 0xfefe, IRQ_MASK ); /* mask off all ints */
                   1456:   hp100_outw( 0xffff, IRQ_STATUS ); /* Ack all ints */
                   1457: 
                   1458:   /* Ensure Interrupts are off */
                   1459:   hp100_outw( HP100_INT_EN | HP100_RESET_LB , OPTION_LSW );
                   1460: 
                   1461:   /* Disable all MAC activity */
                   1462:   hp100_page( MAC_CTRL );
                   1463:   hp100_andb( ~(HP100_RX_EN | HP100_TX_EN), MAC_CFG_1 );  /* stop rx/tx */
                   1464: 
                   1465:   /* If cascade MMU is not already in reset */
                   1466:   if (0 != (hp100_inw(OPTION_LSW)&HP100_HW_RST) )
                   1467:     {
                   1468:       /* Wait 1.3ms (10Mb max packet time) to ensure MAC is idle so
                   1469:        * MMU pointers will not be reset out from underneath
                   1470:        */
                   1471:       hp100_page( MAC_CTRL );
                   1472:       for(time=0; time<5000; time++)
                   1473:         {
                   1474:           if( (hp100_inb(MAC_CFG_1)&(HP100_TX_IDLE|HP100_RX_IDLE))==
                   1475:               (HP100_TX_IDLE|HP100_RX_IDLE) ) break;
                   1476:         }
                   1477:       
                   1478:       /* Shutdown algorithm depends on the generation of Cascade */
                   1479:       if( lp->chip==HP100_CHIPID_LASSEN )
                   1480:         { /* ETR shutdown/reset */
                   1481:           /* Disable Busmaster mode and wait for bit to go to zero. */
                   1482:           hp100_page(HW_MAP);
                   1483:           hp100_andb( ~HP100_BM_MASTER, BM );
                   1484:           /* 100 ms timeout */
                   1485:           for(time=0; time<32000; time++)
                   1486:             {
                   1487:               if ( 0 == (hp100_inb( BM ) & HP100_BM_MASTER) ) break;
                   1488:             }
                   1489:         }
                   1490:       else
                   1491:         { /* Shasta or Rainier Shutdown/Reset */
                   1492:           /* To ensure all bus master inloading activity has ceased,
                   1493:            * wait for no Rx PDAs or no Rx packets on card. 
                   1494:            */
                   1495:           hp100_page( PERFORMANCE );
                   1496:           /* 100 ms timeout */
                   1497:           for(time=0; time<10000; time++)
                   1498:             {
                   1499:               /* RX_PDL: PDLs not executed. */
                   1500:               /* RX_PKT_CNT: RX'd packets on card. */
                   1501:               if ( (hp100_inb( RX_PDL ) == 0) &&
                   1502:                    (hp100_inb( RX_PKT_CNT ) == 0) ) break;
                   1503:             }
                   1504:           
                   1505:           if(time>=10000)
                   1506:             printk("hp100: %s: BM shutdown error.\n", dev->name);
                   1507:           
                   1508:           /* To ensure all bus master outloading activity has ceased,
                   1509:            * wait until the Tx PDA count goes to zero or no more Tx space
                   1510:            * available in the Tx region of the card. 
                   1511:            */
                   1512:           /* 100 ms timeout */
                   1513:           for(time=0; time<10000; time++) {
                   1514:             if ( (0 == hp100_inb( TX_PKT_CNT )) &&
                   1515:                  (0 != (hp100_inb( TX_MEM_FREE )&HP100_AUTO_COMPARE))) break;
                   1516:           } 
                   1517:           
                   1518:           /* Disable Busmaster mode */
                   1519:           hp100_page(HW_MAP);
                   1520:           hp100_andb( ~HP100_BM_MASTER, BM );
                   1521:         } /* end of shutdown procedure for non-etr parts */  
                   1522:                                                
                   1523:       hp100_cascade_reset( dev, TRUE );
                   1524:     }
                   1525:   hp100_page( PERFORMANCE );
                   1526:   /* hp100_outw( HP100_BM_READ | HP100_BM_WRITE | HP100_RESET_HB, OPTION_LSW ); */
                   1527:   /* Busmaster mode should be shut down now. */
                   1528: }
                   1529: 
                   1530: 
                   1531: 
                   1532: /* 
                   1533:  *  transmit functions
                   1534:  */
                   1535: 
                   1536: /* tx function for busmaster mode */
                   1537: static int hp100_start_xmit_bm( struct sk_buff *skb, struct device *dev )
                   1538: {
                   1539:   unsigned long flags;
                   1540:   int i, ok_flag;
                   1541:   int ioaddr = dev->base_addr;
                   1542:   struct hp100_private *lp = (struct hp100_private *)dev->priv;
                   1543:   hp100_ring_t *ringptr;
                   1544: 
                   1545: #ifdef HP100_DEBUG_B
                   1546:   hp100_outw( 0x4210, TRACE );
                   1547:   printk("hp100: %s: start_xmit_bm\n",dev->name);
                   1548: #endif
                   1549: 
                   1550:   if ( skb==NULL )
                   1551:     {
                   1552: #ifndef LINUX_2_1
                   1553:       dev_tint( dev );
                   1554: #endif
                   1555:       return 0;
                   1556:     }
                   1557:        
                   1558:   if ( skb->len <= 0 ) return 0;
                   1559:        
                   1560:   /* Get Tx ring tail pointer */
                   1561:   if( lp->txrtail->next==lp->txrhead )
                   1562:     {
                   1563:       /* No memory. */
                   1564: #ifdef HP100_DEBUG
                   1565:       printk("hp100: %s: start_xmit_bm: No TX PDL available.\n", dev->name);
                   1566: #endif
                   1567:       /* not waited long enough since last tx? */
                   1568:       if ( jiffies - dev->trans_start < HZ ) return -EAGAIN;
                   1569: 
                   1570:       if ( lp->lan_type < 0 ) /* no LAN type detected yet? */
                   1571:        {
                   1572:          hp100_stop_interface( dev );
                   1573:          if ( ( lp->lan_type = hp100_sense_lan( dev ) ) < 0 )
                   1574:            {
                   1575:              printk( "hp100: %s: no connection found - check wire\n", dev->name );
                   1576:              hp100_start_interface( dev );  /* 10Mb/s RX pkts maybe handled */
                   1577:              return -EIO;
                   1578:            }
                   1579:          if ( lp->lan_type == HP100_LAN_100 )
                   1580:            lp->hub_status = hp100_login_to_vg_hub( dev, FALSE ); /* relogin */
                   1581:          hp100_start_interface( dev );
                   1582:        }
                   1583:                                
                   1584:       if ( lp->lan_type == HP100_LAN_100 && lp->hub_status < 0 )
                   1585:        /* we have a 100Mb/s adapter but it isn't connected to hub */
                   1586:        {
                   1587:          printk( "hp100: %s: login to 100Mb/s hub retry\n", dev->name );
                   1588:          hp100_stop_interface( dev );
                   1589:          lp->hub_status = hp100_login_to_vg_hub( dev, FALSE );
                   1590:          hp100_start_interface( dev );
                   1591:        }
                   1592:       else
                   1593:        {
                   1594:          hp100_ints_off();
                   1595:          i = hp100_sense_lan( dev );
                   1596:          hp100_ints_on();
                   1597:          if ( i == HP100_LAN_ERR )
                   1598:            printk( "hp100: %s: link down detected\n", dev->name );
                   1599:          else
                   1600:            if ( lp->lan_type != i ) /* cable change! */
                   1601:              {
                   1602:                /* it's very hard - all network setting must be changed!!! */
                   1603:                printk( "hp100: %s: cable change 10Mb/s <-> 100Mb/s detected\n", dev->name );
                   1604:                lp->lan_type = i;
                   1605:                hp100_stop_interface( dev );
                   1606:                if ( lp->lan_type == HP100_LAN_100 )
                   1607:                  lp->hub_status = hp100_login_to_vg_hub( dev, FALSE );
                   1608:                hp100_start_interface( dev );
                   1609:              }
                   1610:            else
                   1611:              {
                   1612:                printk( "hp100: %s: interface reset\n", dev->name );
                   1613:                hp100_stop_interface( dev );
                   1614:                if ( lp->lan_type == HP100_LAN_100 )
                   1615:                  lp->hub_status = hp100_login_to_vg_hub( dev, FALSE );
                   1616:                hp100_start_interface( dev );
                   1617:              }
                   1618:        }
                   1619: 
                   1620:       dev->trans_start = jiffies;
                   1621:       return -EAGAIN;
                   1622:     }
                   1623:        
                   1624:   /*
                   1625:    * we have to turn int's off before modifying this, otherwise
                   1626:    * a tx_pdl_cleanup could occur at the same time
                   1627:    */
                   1628:   save_flags( flags );
                   1629:   cli();
                   1630:   ringptr=lp->txrtail;
                   1631:   lp->txrtail=ringptr->next;
                   1632:        
                   1633:   /* Check whether packet has minimal packet size */
                   1634:   ok_flag = skb->len >= HP100_MIN_PACKET_SIZE;
                   1635:   i = ok_flag ? skb->len : HP100_MIN_PACKET_SIZE;
                   1636:                                        
                   1637:   ringptr->skb=skb;
                   1638:   ringptr->pdl[0]=((1<<16) | i);                /* PDH: 1 Fragment & length */
                   1639:   ringptr->pdl[1]=(u32)virt_to_bus(skb->data);  /* 1st Frag: Adr. of data */
                   1640:   if(lp->chip==HP100_CHIPID_SHASTA)
                   1641:     {
                   1642:       /* TODO:Could someone who has the EISA card please check if this works? */
                   1643:       ringptr->pdl[2]=i;
                   1644:     }
                   1645:   else /* Lassen */
                   1646:     {
                   1647:       /* In the PDL, don't use the padded size but the real packet size: */
                   1648:       ringptr->pdl[2]=skb->len;              /* 1st Frag: Length of frag */
                   1649:     }
                   1650: 
                   1651:   /* Hand this PDL to the card. */
                   1652:   hp100_outl( ringptr->pdl_paddr, TX_PDA_L ); /* Low Prio. Queue */
                   1653:        
                   1654:   lp->txrcommit++;
                   1655:   restore_flags( flags );
                   1656:        
                   1657:   /* Update statistics */      
                   1658:   lp->stats.tx_packets++;
                   1659: #ifdef LINUX_2_1
                   1660:   lp->stats.tx_bytes += skb->len;
                   1661: #endif
                   1662:   dev->trans_start = jiffies;
                   1663:        
                   1664:   return 0;
                   1665: }
                   1666: 
                   1667: 
                   1668: /* clean_txring checks if packets have been sent by the card by reading
                   1669:  * the TX_PDL register from the performance page and comparing it to the
                   1670:  * number of commited packets. It then frees the skb's of the packets that
                   1671:  * obviously have been sent to the network.
                   1672:  *
                   1673:  * Needs the PERFORMANCE page selected. 
                   1674:  */
                   1675: static void hp100_clean_txring( struct device *dev )
                   1676: {
                   1677:   struct hp100_private *lp = (struct hp100_private *)dev->priv;
                   1678:   int    ioaddr = dev->base_addr;
                   1679:   int    donecount;
                   1680: 
                   1681: #ifdef HP100_DEBUG_B
                   1682:   hp100_outw( 0x4211, TRACE );
                   1683:   printk("hp100: %s: clean txring\n", dev->name);
                   1684: #endif
                   1685: 
                   1686:   /* How many PDLs have been transmitted? */
                   1687:   donecount=(lp->txrcommit)-hp100_inb(TX_PDL);
                   1688: 
                   1689: #ifdef HP100_DEBUG
                   1690:   if(donecount>MAX_TX_PDL)
                   1691:     printk("hp100: %s: Warning: More PDLs transmitted than commited to card???\n",dev->name);
                   1692: #endif
                   1693: 
                   1694:   for( ; 0!=donecount; donecount-- )
                   1695:     {
                   1696: #ifdef HP100_DEBUG_BM
                   1697:       printk("hp100: %s: Free skb: data @0x%.8x txrcommit=0x%x TXPDL=0x%x, done=0x%x\n",
                   1698:              dev->name,
                   1699:             (u_int) lp->txrhead->skb->data,
                   1700:             lp->txrcommit,
                   1701:             hp100_inb(TX_PDL),
                   1702:             donecount);
                   1703: #endif
                   1704: #ifdef LINUX_2_1
                   1705:       dev_kfree_skb( lp->txrhead->skb );
                   1706: #else
                   1707:       dev_kfree_skb( lp->txrhead->skb, FREE_WRITE );
                   1708: #endif
                   1709:       lp->txrhead->skb=(void *)NULL;
                   1710:       lp->txrhead=lp->txrhead->next;
                   1711:       lp->txrcommit--;
                   1712:     }
                   1713: }
                   1714: 
                   1715: 
                   1716: /* tx function for slave modes */
                   1717: static int hp100_start_xmit( struct sk_buff *skb, struct device *dev )
                   1718: {
                   1719:   int i, ok_flag;
                   1720:   int ioaddr = dev->base_addr;
                   1721:   u_short val;
                   1722:   struct hp100_private *lp = (struct hp100_private *)dev->priv;
                   1723: 
                   1724: #ifdef HP100_DEBUG_B
                   1725:   hp100_outw( 0x4212, TRACE );
                   1726:   printk("hp100: %s: start_xmit\n", dev->name);
                   1727: #endif
                   1728: 
                   1729:   if ( skb==NULL )
                   1730:     {
                   1731: #ifndef LINUX_2_1
                   1732:       dev_tint( dev );
                   1733: #endif
                   1734:       return 0;
                   1735:     }
                   1736:        
                   1737:   if ( skb->len <= 0 ) return 0;
                   1738:        
                   1739:   if ( lp->lan_type < 0 ) /* no LAN type detected yet? */
                   1740:     {
                   1741:       hp100_stop_interface( dev );
                   1742:       if ( ( lp->lan_type = hp100_sense_lan( dev ) ) < 0 )
                   1743:         {
                   1744:           printk( "hp100: %s: no connection found - check wire\n", dev->name );
                   1745:           hp100_start_interface( dev );  /* 10Mb/s RX packets maybe handled */
                   1746:           return -EIO;
                   1747:         }
                   1748:       if ( lp->lan_type == HP100_LAN_100 )
                   1749:         lp->hub_status = hp100_login_to_vg_hub( dev, FALSE ); /* relogin */
                   1750:       hp100_start_interface( dev );
                   1751:     }
                   1752: 
                   1753:   /* If there is not enough free memory on the card... */
                   1754:   i=hp100_inl(TX_MEM_FREE)&0x7fffffff;
                   1755:   if ( !(((i/2)-539)>(skb->len+16) && (hp100_inb(TX_PKT_CNT)<255)) )
                   1756:     {
                   1757: #ifdef HP100_DEBUG
                   1758:       printk( "hp100: %s: start_xmit: tx free mem = 0x%x\n", dev->name, i );
                   1759: #endif
                   1760:       /* not waited long enough since last failed tx try? */
                   1761:       if ( jiffies - dev->trans_start < HZ ) 
                   1762:        {
                   1763: #ifdef HP100_DEBUG
                   1764:          printk("hp100: %s: trans_start timing problem\n", dev->name);
                   1765: #endif
                   1766:          return -EAGAIN;
                   1767:        }
                   1768:       if ( lp->lan_type == HP100_LAN_100 && lp->hub_status < 0 )
                   1769:        /* we have a 100Mb/s adapter but it isn't connected to hub */
                   1770:         {
                   1771:           printk( "hp100: %s: login to 100Mb/s hub retry\n", dev->name );
                   1772:           hp100_stop_interface( dev );
                   1773:           lp->hub_status = hp100_login_to_vg_hub( dev, FALSE );
                   1774:           hp100_start_interface( dev );
                   1775:         }
                   1776:       else
                   1777:         {
                   1778:           hp100_ints_off();
                   1779:           i = hp100_sense_lan( dev );
                   1780:           hp100_ints_on();
                   1781:           if ( i == HP100_LAN_ERR )
                   1782:             printk( "hp100: %s: link down detected\n", dev->name );
                   1783:          else
                   1784:            if ( lp->lan_type != i ) /* cable change! */
                   1785:              {
                   1786:                /* it's very hard - all network setting must be changed!!! */
                   1787:                printk( "hp100: %s: cable change 10Mb/s <-> 100Mb/s detected\n", dev->name );
                   1788:                lp->lan_type = i;
                   1789:                hp100_stop_interface( dev );
                   1790:                if ( lp->lan_type == HP100_LAN_100 )
                   1791:                  lp->hub_status = hp100_login_to_vg_hub( dev, FALSE );
                   1792:                hp100_start_interface( dev );
                   1793:              }
                   1794:            else
                   1795:              {
                   1796:                printk( "hp100: %s: interface reset\n", dev->name );
                   1797:                hp100_stop_interface( dev );
                   1798:                if ( lp->lan_type == HP100_LAN_100 )
                   1799:                  lp->hub_status = hp100_login_to_vg_hub( dev, FALSE );
                   1800:                hp100_start_interface( dev );
                   1801:                udelay(1000);
                   1802:              }
                   1803:         }
                   1804:       dev->trans_start = jiffies;
                   1805:       return -EAGAIN;
                   1806:     }
                   1807: 
                   1808:   for ( i=0; i<6000 && ( hp100_inb( OPTION_MSW ) & HP100_TX_CMD ); i++ )
                   1809:     {
                   1810: #ifdef HP100_DEBUG_TX
                   1811:       printk( "hp100: %s: start_xmit: busy\n", dev->name );
                   1812: #endif
                   1813:     }
                   1814:        
                   1815:   hp100_ints_off();
                   1816:   val = hp100_inw( IRQ_STATUS );
                   1817:   /* Ack / clear the interrupt TX_COMPLETE interrupt - this interrupt is set
                   1818:    * when the current packet being transmitted on the wire is completed. */
                   1819:   hp100_outw( HP100_TX_COMPLETE, IRQ_STATUS ); 
                   1820: #ifdef HP100_DEBUG_TX
                   1821:   printk("hp100: %s: start_xmit: irq_status=0x%.4x, irqmask=0x%.4x, len=%d\n",dev->name,val,hp100_inw(IRQ_MASK),(int)skb->len );
                   1822: #endif
                   1823: 
                   1824:   ok_flag = skb->len >= HP100_MIN_PACKET_SIZE;
                   1825:   i = ok_flag ? skb->len : HP100_MIN_PACKET_SIZE;
                   1826: 
                   1827:   hp100_outw( i, DATA32 );       /* tell card the total packet length */
                   1828:   hp100_outw( i, FRAGMENT_LEN ); /* and first/only fragment length    */
                   1829:        
                   1830:   if ( lp->mode==2 ) /* memory mapped */
                   1831:     {
                   1832:       if ( lp->mem_ptr_virt ) /* high pci memory was remapped */
                   1833:        {
                   1834:          /* Note: The J2585B needs alignment to 32bits here!  */
                   1835:          memcpy( lp->mem_ptr_virt, skb->data, ( skb->len + 3 ) & ~3 );
                   1836:          if ( !ok_flag )
                   1837:            memset( lp->mem_ptr_virt, 0, HP100_MIN_PACKET_SIZE - skb->len );
                   1838:        }
                   1839:       else
                   1840:        {
                   1841:          /* Note: The J2585B needs alignment to 32bits here!  */
                   1842:          memcpy_toio( lp->mem_ptr_phys, skb->data, (skb->len + 3) & ~3 );
                   1843:          if ( !ok_flag )
                   1844:            memset_io( lp->mem_ptr_phys, 0, HP100_MIN_PACKET_SIZE - skb->len );
                   1845:        }
                   1846:     }
                   1847:   else /* programmed i/o */
                   1848:     {
                   1849:       outsl( ioaddr + HP100_REG_DATA32, skb->data, ( skb->len + 3 ) >> 2 );
                   1850:       if ( !ok_flag )
                   1851:        for ( i = ( skb->len + 3 ) & ~3; i < HP100_MIN_PACKET_SIZE; i += 4 )
                   1852:          hp100_outl( 0, DATA32 );
                   1853:     }
                   1854:        
                   1855:   hp100_outb( HP100_TX_CMD | HP100_SET_LB, OPTION_MSW ); /* send packet */
                   1856:        
                   1857:   lp->stats.tx_packets++;
                   1858: #ifdef LINUX_2_1
                   1859:   lp->stats.tx_bytes += skb->len;
                   1860: #endif
                   1861:   dev->trans_start=jiffies;
                   1862:   hp100_ints_on();
                   1863:        
                   1864: #ifdef LINUX_2_1
                   1865:   dev_kfree_skb( skb );
                   1866: #else
                   1867:   dev_kfree_skb( skb, FREE_WRITE );
                   1868: #endif
                   1869:        
                   1870: #ifdef HP100_DEBUG_TX
                   1871:   printk( "hp100: %s: start_xmit: end\n", dev->name );
                   1872: #endif
                   1873:        
                   1874:   return 0;
                   1875: }
                   1876: 
                   1877: 
                   1878: /*
                   1879:  * Receive Function (Non-Busmaster mode)
                   1880:  * Called when an "Receive Packet" interrupt occurs, i.e. the receive 
                   1881:  * packet counter is non-zero.
                   1882:  * For non-busmaster, this function does the whole work of transfering
                   1883:  * the packet to the host memory and then up to higher layers via skb
                   1884:  * and netif_rx. 
                   1885:  */
                   1886: 
                   1887: static void hp100_rx( struct device *dev )
                   1888: {
                   1889:   int packets, pkt_len;
                   1890:   int ioaddr = dev->base_addr;
                   1891:   struct hp100_private *lp = (struct hp100_private *)dev->priv;
                   1892:   u_int header;
                   1893:   struct sk_buff *skb;
                   1894: 
                   1895: #ifdef DEBUG_B
                   1896:   hp100_outw( 0x4213, TRACE );
                   1897:   printk("hp100: %s: rx\n", dev->name);
                   1898: #endif
                   1899: 
                   1900:   /* First get indication of received lan packet */
                   1901:   /* RX_PKT_CND indicates the number of packets which have been fully */
                   1902:   /* received onto the card but have not been fully transfered of the card */
                   1903:   packets = hp100_inb( RX_PKT_CNT );
                   1904: #ifdef HP100_DEBUG_RX
                   1905:   if ( packets > 1 )
                   1906:     printk( "hp100: %s: rx: waiting packets = %d\n", dev->name,packets );
                   1907: #endif
                   1908: 
                   1909:   while ( packets-- > 0 )
                   1910:     {
                   1911:       /* If ADV_NXT_PKT is still set, we have to wait until the card has */
                   1912:       /* really advanced to the next packet. */
                   1913:       for (pkt_len=0; pkt_len<6000 &&(hp100_inb(OPTION_MSW)&HP100_ADV_NXT_PKT);
                   1914:           pkt_len++ )
                   1915:         {
                   1916: #ifdef HP100_DEBUG_RX
                   1917:           printk( "hp100: %s: rx: busy, remaining packets = %d\n", dev->name, packets );
                   1918: #endif    
                   1919:         }
                   1920: 
                   1921:       /* First we get the header, which contains information about the */
                   1922:       /* actual length of the received packet. */
                   1923:       if( lp->mode==2 ) /* memory mapped mode */
                   1924:         {
                   1925:           if ( lp->mem_ptr_virt )    /* if memory was remapped */
                   1926:             header = *(__u32 *)lp->mem_ptr_virt;
                   1927:           else
                   1928:             header = readl( lp->mem_ptr_phys );
                   1929:         }
                   1930:       else /* programmed i/o */
                   1931:         header = hp100_inl( DATA32 );
                   1932:       
                   1933:       pkt_len = ((header & HP100_PKT_LEN_MASK) + 3) & ~3;
                   1934: 
                   1935: #ifdef HP100_DEBUG_RX
                   1936:       printk( "hp100: %s: rx: new packet - length=%d, errors=0x%x, dest=0x%x\n",
                   1937:              dev->name,
                   1938:               header & HP100_PKT_LEN_MASK, (header>>16)&0xfff8,
                   1939:               (header>>16)&7);
                   1940: #endif
                   1941:     
                   1942:       /* Now we allocate the skb and transfer the data into it. */  
                   1943:       skb = dev_alloc_skb( pkt_len );
                   1944:       if ( skb == NULL ) /* Not enough memory->drop packet */
                   1945:        {
                   1946: #ifdef HP100_DEBUG
                   1947:          printk( "hp100: %s: rx: couldn't allocate a sk_buff of size %d\n", dev->name, pkt_len );
                   1948: #endif
                   1949:          lp->stats.rx_dropped++;
                   1950:        }
                   1951:       else /* skb successfully allocated */
                   1952:        {
                   1953:          u_char *ptr;
                   1954:       
                   1955:          skb->dev = dev;
                   1956:       
                   1957:          /* ptr to start of the sk_buff data area */
                   1958:          ptr = (u_char *)skb_put( skb, pkt_len );
                   1959:       
                   1960:          /* Now transfer the data from the card into that area */
                   1961:          if ( lp->mode==2 )
                   1962:             {
                   1963:               if ( lp->mem_ptr_virt )
                   1964:                 memcpy( ptr, lp->mem_ptr_virt, pkt_len );
                   1965:               /* Note alignment to 32bit transfers */
                   1966:               else
                   1967:                 memcpy_fromio( ptr, lp->mem_ptr_phys, pkt_len );
                   1968:             }
                   1969:          else /* io mapped */
                   1970:            insl( ioaddr + HP100_REG_DATA32, ptr, pkt_len >> 2 );
                   1971:       
                   1972:          skb->protocol = eth_type_trans( skb, dev );
                   1973: 
                   1974:          netif_rx( skb );
                   1975:          lp->stats.rx_packets++;
                   1976: #ifdef LINUX_2_1
                   1977:          lp->stats.rx_bytes += skb->len;
                   1978: #endif
                   1979:       
                   1980: #ifdef HP100_DEBUG_RX
                   1981:          printk( "hp100: %s: rx: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
                   1982:                  dev->name,
                   1983:                  ptr[ 0 ], ptr[ 1 ], ptr[ 2 ], ptr[ 3 ], ptr[ 4 ], ptr[ 5 ],
                   1984:                  ptr[ 6 ], ptr[ 7 ], ptr[ 8 ], ptr[ 9 ], ptr[ 10 ], ptr[ 11 ] );
                   1985: #endif
                   1986:        }
                   1987:   
                   1988:       /* Indicate the card that we have got the packet */
                   1989:       hp100_outb( HP100_ADV_NXT_PKT | HP100_SET_LB, OPTION_MSW );
                   1990: 
                   1991:       switch ( header & 0x00070000 ) {
                   1992:       case (HP100_MULTI_ADDR_HASH<<16):
                   1993:       case (HP100_MULTI_ADDR_NO_HASH<<16):
                   1994:        lp->stats.multicast++; break;
                   1995:       }
                   1996:     } /* end of while(there are packets) loop */
                   1997: #ifdef HP100_DEBUG_RX
                   1998:   printk( "hp100_rx: %s: end\n", dev->name );
                   1999: #endif
                   2000: }
                   2001: 
                   2002: 
                   2003: /* 
                   2004:  * Receive Function for Busmaster Mode
                   2005:  */
                   2006: static void hp100_rx_bm( struct device *dev )
                   2007: {
                   2008:   int ioaddr = dev->base_addr;
                   2009:   struct hp100_private *lp = (struct hp100_private *)dev->priv;
                   2010:   hp100_ring_t *ptr;
                   2011:   u_int header;
                   2012:   int pkt_len;
                   2013: 
                   2014: #ifdef HP100_DEBUG_B
                   2015:   hp100_outw( 0x4214, TRACE );
                   2016:   printk("hp100: %s: rx_bm\n", dev->name);
                   2017: #endif
                   2018: 
                   2019: #ifdef HP100_DEBUG
                   2020:   if(0==lp->rxrcommit)
                   2021:     {
                   2022:       printk("hp100: %s: rx_bm called although no PDLs were committed to adapter?\n", dev->name); 
                   2023:       return;
                   2024:     }
                   2025:   else
                   2026: 
                   2027:     /* RX_PKT_CNT states how many PDLs are currently formatted and available to 
                   2028:      * the cards BM engine */
                   2029:     if( (hp100_inw(RX_PKT_CNT)&0x00ff) >= lp->rxrcommit)
                   2030:       {
                   2031:        printk("hp100: %s: More packets received than commited? RX_PKT_CNT=0x%x, commit=0x%x\n", dev->name, hp100_inw(RX_PKT_CNT)&0x00ff, lp->rxrcommit);
                   2032:        return;
                   2033:       }
                   2034: #endif
                   2035: 
                   2036:   while( (lp->rxrcommit > hp100_inb(RX_PDL)) )
                   2037:     {
                   2038:       /*
                   2039:        * The packet was received into the pdl pointed to by lp->rxrhead (
                   2040:        * the oldest pdl in the ring 
                   2041:        */
                   2042:                                                
                   2043:       /* First we get the header, which contains information about the */
                   2044:       /* actual length of the received packet. */
                   2045:       
                   2046:       ptr=lp->rxrhead;
                   2047:       
                   2048:       header = *(ptr->pdl-1);
                   2049:       pkt_len = (header & HP100_PKT_LEN_MASK);
                   2050: 
                   2051: #ifdef HP100_DEBUG_BM
                   2052:       printk( "hp100: %s: rx_bm: header@0x%x=0x%x length=%d, errors=0x%x, dest=0x%x\n",
                   2053:              dev->name,
                   2054:               (u_int) (ptr->pdl-1),(u_int) header,
                   2055:               pkt_len, 
                   2056:               (header>>16)&0xfff8,
                   2057:               (header>>16)&7);
                   2058:       printk( "hp100: %s: RX_PDL_COUNT:0x%x TX_PDL_COUNT:0x%x, RX_PKT_CNT=0x%x PDH=0x%x, Data@0x%x len=0x%x\n",
                   2059:              dev->name,
                   2060:              hp100_inb( RX_PDL ),
                   2061:              hp100_inb( TX_PDL ),
                   2062:              hp100_inb( RX_PKT_CNT ),
                   2063:              (u_int) *(ptr->pdl),
                   2064:              (u_int) *(ptr->pdl+3),
                   2065:              (u_int) *(ptr->pdl+4));
                   2066: #endif
                   2067:       
                   2068:       if( (pkt_len>=MIN_ETHER_SIZE) &&
                   2069:           (pkt_len<=MAX_ETHER_SIZE) )  
                   2070:         {
                   2071:          if(ptr->skb==NULL)
                   2072:            {
                   2073:              printk("hp100: %s: rx_bm: skb null\n", dev->name);
                   2074:              /* can happen if we only allocated room for the pdh due to memory shortage. */
                   2075:              lp->stats.rx_dropped++;
                   2076:            }
                   2077:          else
                   2078:            {
                   2079:              skb_trim( ptr->skb, pkt_len );     /* Shorten it */
                   2080:              ptr->skb->protocol = eth_type_trans( ptr->skb, dev );
                   2081:                                                                                                                
                   2082:              netif_rx( ptr->skb );              /* Up and away... */
                   2083: 
                   2084:              lp->stats.rx_packets++;
                   2085: #ifdef LINUX_2_1
                   2086:              lp->stats.rx_bytes += ptr->skb->len;
                   2087: #endif
                   2088:            }
                   2089: 
                   2090:           switch ( header & 0x00070000 ) {
                   2091:           case (HP100_MULTI_ADDR_HASH<<16):
                   2092:           case (HP100_MULTI_ADDR_NO_HASH<<16):
                   2093:             lp->stats.multicast++; break;
                   2094:           }
                   2095:         }
                   2096:       else
                   2097:         {
                   2098: #ifdef HP100_DEBUG
                   2099:           printk("hp100: %s: rx_bm: Received bad packet (length=%d)\n",dev->name,pkt_len);
                   2100: #endif
                   2101:          if(ptr->skb!=NULL)
                   2102: #ifdef LINUX_2_1
                   2103:            dev_kfree_skb( ptr->skb );
                   2104: #else
                   2105:            dev_kfree_skb( ptr->skb, FREE_READ );                                       
                   2106: #endif
                   2107:           lp->stats.rx_errors++;
                   2108:         }
                   2109:                                                
                   2110:       lp->rxrhead=lp->rxrhead->next;
                   2111: 
                   2112:       /* Allocate a new rx PDL (so lp->rxrcommit stays the same) */
                   2113:       if (0 == hp100_build_rx_pdl( lp->rxrtail, dev ))
                   2114:         {
                   2115:          /* No space for skb, header can still be received. */
                   2116: #ifdef HP100_DEBUG
                   2117:           printk("hp100: %s: rx_bm: No space for new PDL.\n", dev->name);
                   2118: #endif
                   2119:          return;
                   2120:         } 
                   2121:       else
                   2122:         { /* successfully allocated new PDL - put it in ringlist at tail. */
                   2123:          hp100_outl((u32)lp->rxrtail->pdl_paddr, RX_PDA);
                   2124:           lp->rxrtail=lp->rxrtail->next;
                   2125:        }
                   2126:                                                
                   2127:     }
                   2128: }
                   2129: 
                   2130: 
                   2131: 
                   2132: /*
                   2133:  *  statistics
                   2134:  */
                   2135: static hp100_stats_t *hp100_get_stats( struct device *dev )
                   2136: {
                   2137:   int ioaddr = dev->base_addr;
                   2138: 
                   2139: #ifdef HP100_DEBUG_B
                   2140:   hp100_outw( 0x4215, TRACE );
                   2141: #endif
                   2142: 
                   2143:   hp100_ints_off();
                   2144:   hp100_update_stats( dev );
                   2145:   hp100_ints_on();
                   2146:   return &((struct hp100_private *)dev->priv)->stats;
                   2147: }
                   2148: 
                   2149: static void hp100_update_stats( struct device *dev )
                   2150: {
                   2151:   int ioaddr = dev->base_addr;
                   2152:   u_short val;
                   2153:   struct hp100_private *lp = (struct hp100_private *)dev->priv;
                   2154: 
                   2155: #ifdef HP100_DEBUG_B
                   2156:   hp100_outw( 0x4216, TRACE );
                   2157:   printk("hp100: %s: update-stats\n", dev->name);
                   2158: #endif
                   2159: 
                   2160:   /* Note: Statistics counters clear when read. */
                   2161:   hp100_page( MAC_CTRL ); 
                   2162:   val = hp100_inw( DROPPED ) & 0x0fff;
                   2163:   lp->stats.rx_errors += val;
                   2164:   lp->stats.rx_over_errors += val;
                   2165:   val = hp100_inb( CRC );
                   2166:   lp->stats.rx_errors += val;
                   2167:   lp->stats.rx_crc_errors += val;
                   2168:   val = hp100_inb( ABORT );
                   2169:   lp->stats.tx_errors += val;
                   2170:   lp->stats.tx_aborted_errors += val;
                   2171:   hp100_page( PERFORMANCE );
                   2172: }
                   2173: 
                   2174: static void hp100_misc_interrupt( struct device *dev )
                   2175: {
                   2176:   struct hp100_private *lp = (struct hp100_private *)dev->priv;
                   2177: 
                   2178: #ifdef HP100_DEBUG_B
                   2179:   hp100_outw( 0x4216, TRACE );
                   2180:   printk("hp100: %s: misc_interrupt\n", dev->name);
                   2181: #endif
                   2182: 
                   2183:   /* Note: Statistics counters clear when read. */
                   2184:   lp->stats.rx_errors++;
                   2185:   lp->stats.tx_errors++;
                   2186: }
                   2187: 
                   2188: static void hp100_clear_stats( int ioaddr )
                   2189: {
                   2190:   unsigned long flags;
                   2191: 
                   2192: #ifdef HP100_DEBUG_B
                   2193:   hp100_outw( 0x4217, TRACE );
                   2194:   printk("hp100: %s: clear_stats\n", dev->name);
                   2195: #endif
                   2196: 
                   2197:   save_flags( flags );
                   2198:   cli();
                   2199:   hp100_page( MAC_CTRL );    /* get all statistics bytes */
                   2200:   hp100_inw( DROPPED );
                   2201:   hp100_inb( CRC );
                   2202:   hp100_inb( ABORT );
                   2203:   hp100_page( PERFORMANCE );
                   2204:   restore_flags( flags );
                   2205: }
                   2206: 
                   2207: 
                   2208: /*
                   2209:  *  multicast setup
                   2210:  */
                   2211: 
                   2212: /*
                   2213:  *  Set or clear the multicast filter for this adapter.
                   2214:  */
                   2215:                                                           
                   2216: static void hp100_set_multicast_list( struct device *dev )
                   2217: {
                   2218:   unsigned long flags;
                   2219:   int ioaddr = dev->base_addr;
                   2220:   struct hp100_private *lp = (struct hp100_private *)dev->priv;
                   2221: 
                   2222: #ifdef HP100_DEBUG_B
                   2223:   hp100_outw( 0x4218, TRACE );
                   2224:   printk("hp100: %s: set_mc_list\n", dev->name);
                   2225: #endif
                   2226: 
                   2227:   save_flags( flags );
                   2228:   cli();
                   2229:   hp100_ints_off();
                   2230:   hp100_page( MAC_CTRL );
                   2231:   hp100_andb( ~(HP100_RX_EN | HP100_TX_EN), MAC_CFG_1 );  /* stop rx/tx */
                   2232: 
                   2233:   if ( dev->flags & IFF_PROMISC )
                   2234:     {
                   2235:       lp->mac2_mode = HP100_MAC2MODE6;  /* promiscuous mode = get all good */
                   2236:       lp->mac1_mode = HP100_MAC1MODE6;  /* packets on the net */
                   2237:       memset( &lp->hash_bytes, 0xff, 8 );
                   2238:     }
                   2239:   else if ( dev->mc_count || (dev->flags&IFF_ALLMULTI) )
                   2240:     {
                   2241:       lp->mac2_mode = HP100_MAC2MODE5;  /* multicast mode = get packets for */
                   2242:       lp->mac1_mode = HP100_MAC1MODE5;  /* me, broadcasts and all multicasts */
                   2243: #ifdef HP100_MULTICAST_FILTER          /* doesn't work!!! */
                   2244:       if ( dev -> flags & IFF_ALLMULTI )
                   2245:         {
                   2246:           /* set hash filter to receive all multicast packets */
                   2247:           memset( &lp->hash_bytes, 0xff, 8 );
                   2248:         }
                   2249:        else
                   2250:         {
                   2251:           int i, j, idx;
                   2252:           u_char *addrs;
                   2253:           struct dev_mc_list *dmi;
                   2254: 
                   2255:           memset( &lp->hash_bytes, 0x00, 8 );
                   2256: #ifdef HP100_DEBUG
                   2257:           printk("hp100: %s: computing hash filter - mc_count = %i\n", dev -> name, dev -> mc_count );
                   2258: #endif 
                   2259:           for ( i = 0, dmi = dev -> mc_list; i < dev -> mc_count; i++, dmi = dmi -> next )
                   2260:             {
                   2261:               addrs = dmi -> dmi_addr;
                   2262:               if ( ( *addrs & 0x01 ) == 0x01 ) /* multicast address? */
                   2263:                 {
                   2264: #ifdef HP100_DEBUG
                   2265:                   printk("hp100: %s: multicast = %02x:%02x:%02x:%02x:%02x:%02x, ",
                   2266:                        dev -> name,
                   2267:                        addrs[ 0 ], addrs[ 1 ], addrs[ 2 ],
                   2268:                        addrs[ 3 ], addrs[ 4 ], addrs[ 5 ] );
                   2269: #endif 
                   2270:                   for ( j = idx = 0; j < 6; j++ )
                   2271:                     {
                   2272:                       idx ^= *addrs++ & 0x3f;
                   2273:                       printk( ":%02x:", idx );
                   2274:                     }
                   2275: #ifdef HP100_DEBUG
                   2276:                   printk("idx = %i\n", idx );
                   2277: #endif
                   2278:                  lp->hash_bytes[ idx >> 3 ] |= ( 1 << ( idx & 7 ) );
                   2279:                 }
                   2280:             }
                   2281:         }
                   2282: #else
                   2283:       memset( &lp->hash_bytes, 0xff, 8 );
                   2284: #endif
                   2285:     }
                   2286:   else
                   2287:     {
                   2288:       lp->mac2_mode = HP100_MAC2MODE3;  /* normal mode = get packets for me */
                   2289:       lp->mac1_mode = HP100_MAC1MODE3;  /* and broadcasts */
                   2290:       memset( &lp->hash_bytes, 0x00, 8 );
                   2291:     }
                   2292: 
                   2293:   if ( ( (hp100_inb(MAC_CFG_1) & 0x0f)!=lp->mac1_mode ) ||
                   2294:         ( hp100_inb(MAC_CFG_2)!=lp->mac2_mode ) ) 
                   2295:     {
                   2296:       int i;
                   2297:     
                   2298:       hp100_outb( lp->mac2_mode, MAC_CFG_2 );
                   2299:       hp100_andb( HP100_MAC1MODEMASK, MAC_CFG_1 ); /* clear mac1 mode bits */
                   2300:       hp100_orb( lp->mac1_mode, MAC_CFG_1 );       /* and set the new mode */
                   2301: 
                   2302:       hp100_page( MAC_ADDRESS );
                   2303:       for ( i = 0; i < 8; i++ )
                   2304:         hp100_outb( lp->hash_bytes[ i ], HASH_BYTE0 + i );
                   2305: #ifdef HP100_DEBUG
                   2306:       printk("hp100: %s: mac1 = 0x%x, mac2 = 0x%x, multicast hash = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", 
                   2307:                dev->name, lp->mac1_mode, lp->mac2_mode,
                   2308:                lp->hash_bytes[ 0 ], lp->hash_bytes[ 1 ],
                   2309:                lp->hash_bytes[ 2 ], lp->hash_bytes[ 3 ],
                   2310:                lp->hash_bytes[ 4 ], lp->hash_bytes[ 5 ],
                   2311:                lp->hash_bytes[ 6 ], lp->hash_bytes[ 7 ]
                   2312:                );
                   2313: #endif 
                   2314: 
                   2315:       if(lp->lan_type==HP100_LAN_100)
                   2316:         {
                   2317: #ifdef HP100_DEBUG
                   2318:          printk("hp100: %s: 100VG MAC settings have changed - relogin.\n", dev->name);
                   2319: #endif 
                   2320:          lp->hub_status=hp100_login_to_vg_hub( dev, TRUE );  /* force a relogin to the hub */
                   2321:         }
                   2322:     }
                   2323:    else
                   2324:     {
                   2325:       int i;
                   2326:       u_char old_hash_bytes[ 8 ];
                   2327: 
                   2328:       hp100_page( MAC_ADDRESS );
                   2329:       for ( i = 0; i < 8; i++ )
                   2330:         old_hash_bytes[ i ] = hp100_inb( HASH_BYTE0 + i );
                   2331:       if ( memcmp( old_hash_bytes, &lp->hash_bytes, 8 ) )
                   2332:         {
                   2333:           for ( i = 0; i < 8; i++ )
                   2334:             hp100_outb( lp->hash_bytes[ i ], HASH_BYTE0 + i );
                   2335: #ifdef HP100_DEBUG
                   2336:           printk("hp100: %s: multicast hash = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", 
                   2337:                dev->name,
                   2338:                lp->hash_bytes[ 0 ], lp->hash_bytes[ 1 ],
                   2339:                lp->hash_bytes[ 2 ], lp->hash_bytes[ 3 ],
                   2340:                lp->hash_bytes[ 4 ], lp->hash_bytes[ 5 ],
                   2341:                lp->hash_bytes[ 6 ], lp->hash_bytes[ 7 ]
                   2342:                );
                   2343: #endif 
                   2344: 
                   2345:           if(lp->lan_type==HP100_LAN_100)
                   2346:             {
                   2347: #ifdef HP100_DEBUG
                   2348:              printk("hp100: %s: 100VG MAC settings have changed - relogin.\n", dev->name);
                   2349: #endif 
                   2350:              lp->hub_status=hp100_login_to_vg_hub( dev, TRUE );  /* force a relogin to the hub */
                   2351:             }
                   2352:         }
                   2353:     }
                   2354: 
                   2355:   hp100_page( MAC_CTRL );
                   2356:   hp100_orb( HP100_RX_EN | HP100_RX_IDLE |              /* enable rx */
                   2357:             HP100_TX_EN | HP100_TX_IDLE, MAC_CFG_1 );  /* enable tx */
                   2358: 
                   2359:   hp100_page( PERFORMANCE );
                   2360:   hp100_ints_on();
                   2361:   restore_flags( flags );
                   2362: }
                   2363: 
                   2364: 
                   2365: /*
                   2366:  *  hardware interrupt handling
                   2367:  */
                   2368: 
                   2369: static void hp100_interrupt( int irq, void *dev_id, struct pt_regs *regs )
                   2370: {
                   2371:   struct device *dev = (struct device *)dev_id;
                   2372:   struct hp100_private *lp = (struct hp100_private *)dev->priv;
                   2373: 
                   2374:   int ioaddr;
                   2375:   u_int val;
                   2376: 
                   2377:   if ( dev == NULL ) return;
                   2378:   ioaddr = dev->base_addr;
                   2379: 
                   2380:   if ( dev->interrupt )
                   2381:     printk( "hp100: %s: re-entering the interrupt handler\n", dev->name );
                   2382:   hp100_ints_off();
                   2383:   dev->interrupt = 1;          /* mark that we are inside the handler */
                   2384: 
                   2385: #ifdef HP100_DEBUG_B
                   2386:   hp100_outw( 0x4219, TRACE );
                   2387: #endif
                   2388: 
                   2389:   /*  hp100_page( PERFORMANCE ); */
                   2390:   val = hp100_inw( IRQ_STATUS );
                   2391: #ifdef HP100_DEBUG_IRQ
                   2392:   printk( "hp100: %s: mode=%x,IRQ_STAT=0x%.4x,RXPKTCNT=0x%.2x RXPDL=0x%.2x TXPKTCNT=0x%.2x TXPDL=0x%.2x\n",
                   2393:          dev->name,
                   2394:           lp->mode,
                   2395:          (u_int)val,
                   2396:           hp100_inb( RX_PKT_CNT ),
                   2397:           hp100_inb( RX_PDL ),
                   2398:          hp100_inb( TX_PKT_CNT ),
                   2399:          hp100_inb( TX_PDL )
                   2400:          );
                   2401: #endif
                   2402: 
                   2403:   if(val==0) /* might be a shared interrupt */ 
                   2404:     {
                   2405:       dev->interrupt=0;
                   2406:       hp100_ints_on();
                   2407:       return;
                   2408:     }
                   2409:   /* We're only interested in those interrupts we really enabled. */
                   2410:   /* val &= hp100_inw( IRQ_MASK ); */
                   2411: 
                   2412:   /* 
                   2413:    * RX_PDL_FILL_COMPL is set whenever a RX_PDL has been executed. A RX_PDL 
                   2414:    * is considered executed whenever the RX_PDL data structure is no longer 
                   2415:    * needed.
                   2416:    */
                   2417:   if ( val & HP100_RX_PDL_FILL_COMPL )
                   2418:     {
                   2419:       if(lp->mode==1)
                   2420:        hp100_rx_bm( dev );
                   2421:       else
                   2422:        {
                   2423:          printk("hp100: %s: rx_pdl_fill_compl interrupt although not busmaster?\n", dev->name);
                   2424:        }
                   2425:     }
                   2426:                
                   2427:   /* 
                   2428:    * The RX_PACKET interrupt is set, when the receive packet counter is
                   2429:    * non zero. We use this interrupt for receiving in slave mode. In
                   2430:    * busmaster mode, we use it to make sure we did not miss any rx_pdl_fill
                   2431:    * interrupts. If rx_pdl_fill_compl is not set and rx_packet is set, then
                   2432:    * we somehow have missed a rx_pdl_fill_compl interrupt.
                   2433:    */
                   2434: 
                   2435:   if ( val & HP100_RX_PACKET  ) /* Receive Packet Counter is non zero */
                   2436:     {
                   2437:       if(lp->mode!=1) /* non busmaster */
                   2438:         hp100_rx( dev );
                   2439:       else if ( !(val & HP100_RX_PDL_FILL_COMPL ))
                   2440:        {
                   2441:          /* Shouldnt happen - maybe we missed a RX_PDL_FILL Interrupt?  */
                   2442:          hp100_rx_bm( dev );
                   2443:        }
                   2444:     }
                   2445: 
                   2446:   /*
                   2447:    * Ack. that we have noticed the interrupt and thereby allow next one.
                   2448:    * Note that this is now done after the slave rx function, since first
                   2449:    * acknowledging and then setting ADV_NXT_PKT caused an extra interrupt
                   2450:    * on the J2573.
                   2451:    */
                   2452:   hp100_outw( val, IRQ_STATUS );
                   2453: 
                   2454:   /*
                   2455:    * RX_ERROR is set when a packet is dropped due to no memory resources on 
                   2456:    * the card or when a RCV_ERR occurs. 
                   2457:    * TX_ERROR is set when a TX_ABORT condition occurs in the MAC->exists  
                   2458:    * only in the 802.3 MAC and happens when 16 collisions occur during a TX 
                   2459:    */
                   2460:   if ( val & ( HP100_TX_ERROR | HP100_RX_ERROR ) )
                   2461:     {
                   2462: #ifdef HP100_DEBUG_IRQ
                   2463:       printk("hp100: %s: TX/RX Error IRQ\n", dev->name);
                   2464: #endif
                   2465:       hp100_update_stats( dev );
                   2466:       if(lp->mode==1)
                   2467:        {
                   2468:          hp100_rxfill( dev );
                   2469:          hp100_clean_txring( dev );
                   2470:        }
                   2471:     }
                   2472:                                
                   2473:   /* 
                   2474:    * RX_PDA_ZERO is set when the PDA count goes from non-zero to zero. 
                   2475:    */
                   2476:   if ( (lp->mode==1)&&(val &(HP100_RX_PDA_ZERO)) )
                   2477:     hp100_rxfill( dev );
                   2478:                
                   2479:   /* 
                   2480:    * HP100_TX_COMPLETE interrupt occurs when packet transmitted on wire 
                   2481:    * is completed 
                   2482:    */
                   2483:   if ( (lp->mode==1) && ( val & ( HP100_TX_COMPLETE )) )
                   2484:     hp100_clean_txring( dev );
                   2485: 
                   2486:   /* 
                   2487:    * MISC_ERROR is set when either the LAN link goes down or a detected
                   2488:    * bus error occurs.
                   2489:    */
                   2490:   if ( val & HP100_MISC_ERROR ) /* New for J2585B */
                   2491:     {
                   2492: #ifdef HP100_DEBUG_IRQ
                   2493:       printk("hp100: %s: Misc. Error Interrupt - Check cabling.\n", dev->name);
                   2494: #endif
                   2495:       if(lp->mode==1)
                   2496:        {
                   2497:          hp100_clean_txring( dev );
                   2498:          hp100_rxfill( dev );
                   2499:        }
                   2500:       hp100_misc_interrupt( dev );
                   2501:     }
                   2502:        
                   2503:   dev->interrupt = 0;
                   2504:   hp100_ints_on();
                   2505: }
                   2506: 
                   2507: 
                   2508: /*
                   2509:  *  some misc functions
                   2510:  */
                   2511: 
                   2512: static void hp100_start_interface( struct device *dev )
                   2513: {
                   2514:   unsigned long flags;
                   2515:   int ioaddr = dev->base_addr;
                   2516:   struct hp100_private *lp = (struct hp100_private *)dev->priv;
                   2517: 
                   2518: #ifdef HP100_DEBUG_B
                   2519:   hp100_outw( 0x4220, TRACE );
                   2520:   printk("hp100: %s: hp100_start_interface\n",dev->name);
                   2521: #endif
                   2522: 
                   2523:   save_flags( flags );
                   2524:   cli();
                   2525: 
                   2526:   /* Ensure the adapter does not want to request an interrupt when */
                   2527:   /* enabling the IRQ line to be active on the bus (i.e. not tri-stated) */
                   2528:   hp100_page( PERFORMANCE );
                   2529:   hp100_outw( 0xfefe, IRQ_MASK );  /* mask off all ints */
                   2530:   hp100_outw( 0xffff, IRQ_STATUS );  /* ack all IRQs */
                   2531:   hp100_outw( HP100_FAKE_INT|HP100_INT_EN|HP100_RESET_LB, OPTION_LSW);
                   2532:   /* Un Tri-state int. TODO: Check if shared interrupts can be realised? */
                   2533:   hp100_outw( HP100_TRI_INT | HP100_RESET_HB, OPTION_LSW ); 
                   2534: 
                   2535:   if(lp->mode==1)
                   2536:     {
                   2537:       /* Make sure BM bit is set... */
                   2538:       hp100_page(HW_MAP);
                   2539:       hp100_orb( HP100_BM_MASTER, BM );
                   2540:       hp100_rxfill( dev );
                   2541:     }
                   2542:   else if(lp->mode==2)
                   2543:     {
                   2544:       /* Enable memory mapping. Note: Don't do this when busmaster. */
                   2545:       hp100_outw( HP100_MMAP_DIS | HP100_RESET_HB, OPTION_LSW );
                   2546:     }
                   2547: 
                   2548:   hp100_page(PERFORMANCE);
                   2549:   hp100_outw( 0xfefe, IRQ_MASK );  /* mask off all ints */
                   2550:   hp100_outw( 0xffff, IRQ_STATUS );  /* ack IRQ */
                   2551: 
                   2552:   /* enable a few interrupts: */
                   2553:   if(lp->mode==1) /* busmaster mode */
                   2554:     {
                   2555:       hp100_outw( HP100_RX_PDL_FILL_COMPL |
                   2556:                  HP100_RX_PDA_ZERO  |  
                   2557:                  HP100_RX_ERROR     |  
                   2558:                  /* HP100_RX_PACKET    | */    
                   2559:                  /* HP100_RX_EARLY_INT |  */     HP100_SET_HB  |  
                   2560:                  /* HP100_TX_PDA_ZERO  |  */
                   2561:                  HP100_TX_COMPLETE  |  
                   2562:                  /* HP100_MISC_ERROR   |  */
                   2563:                  HP100_TX_ERROR     | HP100_SET_LB, IRQ_MASK );
                   2564:     } 
                   2565:   else
                   2566:     {  
                   2567:       hp100_outw( HP100_RX_PACKET  |
                   2568:                  HP100_RX_ERROR   | HP100_SET_HB |
                   2569:                   HP100_TX_ERROR   | HP100_SET_LB , IRQ_MASK );
                   2570:     }
                   2571:        
                   2572:   /* Enable MAC Tx and RX, set MAC modes, ... */
                   2573:   hp100_set_multicast_list( dev );
                   2574: 
                   2575:   restore_flags( flags );
                   2576: }
                   2577: 
                   2578: 
                   2579: static void hp100_stop_interface( struct device *dev )
                   2580: {
                   2581:   struct hp100_private *lp = (struct hp100_private *)dev->priv; 
                   2582:   int ioaddr = dev->base_addr;
                   2583:   u_int val;
                   2584: 
                   2585: #ifdef HP100_DEBUG_B
                   2586:   printk("hp100: %s: hp100_stop_interface\n",dev->name);
                   2587:   hp100_outw( 0x4221, TRACE );
                   2588: #endif
                   2589: 
                   2590:   if (lp->mode==1) 
                   2591:     hp100_BM_shutdown( dev );
                   2592:   else
                   2593:     {
                   2594:       /* Note: MMAP_DIS will be reenabled by start_interface */
                   2595:       hp100_outw( HP100_INT_EN | HP100_RESET_LB | 
                   2596:                   HP100_TRI_INT | HP100_MMAP_DIS | HP100_SET_HB, OPTION_LSW );
                   2597:       val = hp100_inw( OPTION_LSW );
                   2598:    
                   2599:       hp100_page( MAC_CTRL );
                   2600:       hp100_andb( ~(HP100_RX_EN | HP100_TX_EN), MAC_CFG_1 );
                   2601: 
                   2602:       if ( !(val & HP100_HW_RST) ) return; /* If reset, imm. return ... */
                   2603:       /* ... else: busy wait until idle */
                   2604:       for ( val = 0; val < 6000; val++ )
                   2605:        if ( ( hp100_inb( MAC_CFG_1 ) & (HP100_TX_IDLE | HP100_RX_IDLE) ) ==
                   2606:             (HP100_TX_IDLE | HP100_RX_IDLE) )
                   2607:          {
                   2608:            hp100_page(PERFORMANCE);
                   2609:            return;
                   2610:          }
                   2611:       printk( "hp100: %s: hp100_stop_interface - timeout\n", dev->name );
                   2612:       hp100_page(PERFORMANCE);
                   2613:     }
                   2614: }
                   2615: 
                   2616: 
                   2617: static void hp100_load_eeprom( struct device *dev, u_short probe_ioaddr )
                   2618: {
                   2619:   int i;
                   2620:   int ioaddr = probe_ioaddr > 0 ? probe_ioaddr : dev->base_addr;
                   2621: 
                   2622: #ifdef HP100_DEBUG_B
                   2623:   hp100_outw( 0x4222, TRACE );
                   2624: #endif
                   2625: 
                   2626:   hp100_page( EEPROM_CTRL );
                   2627:   hp100_andw( ~HP100_EEPROM_LOAD, EEPROM_CTRL );
                   2628:   hp100_orw( HP100_EEPROM_LOAD, EEPROM_CTRL );
                   2629:   for ( i = 0; i < 10000; i++ )
                   2630:     if ( !( hp100_inb( OPTION_MSW ) & HP100_EE_LOAD ) ) return;
                   2631:   printk( "hp100: %s: hp100_load_eeprom - timeout\n", dev->name );
                   2632: }
                   2633: 
                   2634: 
                   2635: /*  Sense connection status.
                   2636:  *  return values: LAN_10  - Connected to 10Mbit/s network
                   2637:  *                 LAN_100 - Connected to 100Mbit/s network
                   2638:  *                 LAN_ERR - not connected or 100Mbit/s Hub down
                   2639:  */
                   2640: static int hp100_sense_lan( struct device *dev )
                   2641: {
                   2642:   int ioaddr = dev->base_addr;
                   2643:   u_short val_VG, val_10;
                   2644:   struct hp100_private *lp = (struct hp100_private *)dev->priv;
                   2645: 
                   2646: #ifdef HP100_DEBUG_B
                   2647:   hp100_outw( 0x4223, TRACE );
                   2648: #endif
                   2649: 
                   2650:   hp100_page( MAC_CTRL );
                   2651:   val_10 = hp100_inb( 10_LAN_CFG_1 );
                   2652:   val_VG = hp100_inb( VG_LAN_CFG_1 );
                   2653:   hp100_page( PERFORMANCE );
                   2654: #ifdef HP100_DEBUG
                   2655:   printk( "hp100: %s: sense_lan: val_VG = 0x%04x, val_10 = 0x%04x\n", dev->name, val_VG, val_10 );
                   2656: #endif
                   2657: 
                   2658:   if ( val_10 & HP100_LINK_BEAT_ST )   /* 10Mb connection is active */
                   2659:     return HP100_LAN_10;
                   2660: 
                   2661:   if ( val_10 & HP100_AUI_ST )         /* have we BNC or AUI onboard? */
                   2662:     {
                   2663:       val_10 |= HP100_AUI_SEL | HP100_LOW_TH;
                   2664:       hp100_page( MAC_CTRL );
                   2665:       hp100_outb( val_10, 10_LAN_CFG_1 );
                   2666:       hp100_page( PERFORMANCE );
                   2667:       return HP100_LAN_10;
                   2668:     }
                   2669: 
                   2670:   if ( (lp->id->id == 0x02019F022) || 
                   2671:        (lp->id->id == 0x01042103c) ||
                   2672:        (lp->id->id == 0x01040103c) )
                   2673:     return HP100_LAN_ERR; /* Those cards don't have a 100 Mbit connector */
                   2674: 
                   2675:   if ( val_VG & HP100_LINK_CABLE_ST ) /* Can hear the HUBs tone. */ 
                   2676:     return HP100_LAN_100;
                   2677:   return HP100_LAN_ERR;
                   2678: }
                   2679: 
                   2680: 
                   2681: 
                   2682: static int hp100_down_vg_link( struct device *dev )
                   2683: {
                   2684:   struct hp100_private *lp = (struct hp100_private *)dev->priv;
                   2685:   int ioaddr = dev->base_addr;
                   2686:   unsigned long time;
                   2687:   long savelan, newlan;
                   2688: 
                   2689: #ifdef HP100_DEBUG_B
                   2690:   hp100_outw( 0x4224, TRACE );
                   2691:   printk("hp100: %s: down_vg_link\n", dev->name);
                   2692: #endif
                   2693: 
                   2694:   hp100_page( MAC_CTRL );
                   2695:   time=jiffies+(HZ/4);
                   2696:   do{
                   2697:     if ( hp100_inb( VG_LAN_CFG_1 ) & HP100_LINK_CABLE_ST ) break;
                   2698:   } while (time>jiffies);
                   2699: 
                   2700:   if ( jiffies >= time )       /* no signal->no logout */
                   2701:     return 0;
                   2702: 
                   2703:   /* Drop the VG Link by clearing the link up cmd and load addr.*/
                   2704: 
                   2705:   hp100_andb( ~( HP100_LOAD_ADDR| HP100_LINK_CMD), VG_LAN_CFG_1); 
                   2706:   hp100_orb( HP100_VG_SEL, VG_LAN_CFG_1); 
                   2707: 
                   2708:   /* Conditionally stall for >250ms on Link-Up Status (to go down) */
                   2709:   time=jiffies+(HZ/2);
                   2710:   do{
                   2711:     if ( !(hp100_inb( VG_LAN_CFG_1) & HP100_LINK_UP_ST) ) break;
                   2712:   } while(time>jiffies);
                   2713: 
                   2714: #ifdef HP100_DEBUG
                   2715:   if (jiffies>=time)
                   2716:     printk("hp100: %s: down_vg_link: Link does not go down?\n", dev->name);
                   2717: #endif
                   2718: 
                   2719:   /* To prevent condition where Rev 1 VG MAC and old hubs do not complete */
                   2720:   /* logout under traffic (even though all the status bits are cleared),  */
                   2721:   /* do this workaround to get the Rev 1 MAC in its idle state */
                   2722:   if ( lp->chip==HP100_CHIPID_LASSEN )
                   2723:     {
                   2724:       /* Reset VG MAC to insure it leaves the logoff state even if */
                   2725:       /* the Hub is still emitting tones */
                   2726:       hp100_andb(~HP100_VG_RESET, VG_LAN_CFG_1);
                   2727:       udelay(1500); /* wait for >1ms */
                   2728:       hp100_orb(HP100_VG_RESET, VG_LAN_CFG_1); /* Release Reset */
                   2729:       udelay(1500);
                   2730:     }
                   2731: 
                   2732:   /* New: For lassen, switch to 10 Mbps mac briefly to clear training ACK */
                   2733:   /* to get the VG mac to full reset. This is not req.d with later chips */
                   2734:   /* Note: It will take the between 1 and 2 seconds for the VG mac to be */
                   2735:   /* selected again! This will be left to the connect hub function to */
                   2736:   /* perform if desired.  */
                   2737:   if (lp->chip==HP100_CHIPID_LASSEN)
                   2738:     {
                   2739:       /* Have to write to 10 and 100VG control registers simultaneously */
                   2740:       savelan=newlan=hp100_inl(10_LAN_CFG_1); /* read 10+100 LAN_CFG regs */
                   2741:       newlan &= ~(HP100_VG_SEL<<16);
                   2742:       newlan |= (HP100_DOT3_MAC)<<8;
                   2743:       hp100_andb( ~HP100_AUTO_MODE, MAC_CFG_3); /* Autosel off */
                   2744:       hp100_outl(newlan, 10_LAN_CFG_1);
                   2745: 
                   2746:       /* Conditionally stall for 5sec on VG selected. */
                   2747:       time=jiffies+(HZ*5);
                   2748:       do{
                   2749:         if( !(hp100_inb(MAC_CFG_4) & HP100_MAC_SEL_ST) ) break;
                   2750:       } while(time>jiffies);
                   2751: 
                   2752:       hp100_orb( HP100_AUTO_MODE, MAC_CFG_3); /* Autosel back on */
                   2753:       hp100_outl(savelan, 10_LAN_CFG_1);
                   2754:     }
                   2755: 
                   2756:   time=jiffies+(3*HZ); /* Timeout 3s */
                   2757:   do {
                   2758:     if ( (hp100_inb( VG_LAN_CFG_1 )&HP100_LINK_CABLE_ST) == 0) break;
                   2759:   } while (time>jiffies);
                   2760:   
                   2761:   if(time<=jiffies)
                   2762:     {
                   2763: #ifdef HP100_DEBUG
                   2764:       printk( "hp100: %s: down_vg_link: timeout\n", dev->name );
                   2765: #endif
                   2766:       return -EIO;
                   2767:     }
                   2768:   
                   2769:   time=jiffies+(2*HZ); /* This seems to take a while.... */
                   2770:   do {} while (time>jiffies);
                   2771:   
                   2772:   return 0;
                   2773: }
                   2774: 
                   2775: 
                   2776: static int hp100_login_to_vg_hub( struct device *dev, u_short force_relogin )
                   2777: {
                   2778:   int ioaddr = dev->base_addr;
                   2779:   struct hp100_private *lp = (struct hp100_private *)dev->priv;
                   2780:   u_short val=0;
                   2781:   unsigned long time;
                   2782:   int startst;
                   2783: 
                   2784: #ifdef HP100_DEBUG_B
                   2785:   hp100_outw( 0x4225, TRACE );
                   2786:   printk("hp100: %s: login_to_vg_hub\n", dev->name);
                   2787: #endif
                   2788: 
                   2789:   /* Initiate a login sequence iff VG MAC is enabled and either Load Address
                   2790:    * bit is zero or the force relogin flag is set (e.g. due to MAC address or
                   2791:    * promiscuous mode change)
                   2792:    */
                   2793:   hp100_page( MAC_CTRL );
                   2794:   startst=hp100_inb( VG_LAN_CFG_1 );
                   2795:   if((force_relogin==TRUE)||(hp100_inb( MAC_CFG_4 )&HP100_MAC_SEL_ST))
                   2796:     {
                   2797: #ifdef HP100_DEBUG_TRAINING
                   2798:       printk("hp100: %s: Start training\n", dev->name);
                   2799: #endif
                   2800: 
                   2801:       /* Ensure VG Reset bit is 1 (i.e., do not reset)*/
                   2802:       hp100_orb( HP100_VG_RESET , VG_LAN_CFG_1 );
                   2803: 
                   2804:       /* If Lassen AND auto-select-mode AND VG tones were sensed on */
                   2805:       /* entry then temporarily put them into force 100Mbit mode */
                   2806:       if((lp->chip==HP100_CHIPID_LASSEN)&&( startst & HP100_LINK_CABLE_ST ) )
                   2807:         hp100_andb( ~HP100_DOT3_MAC, 10_LAN_CFG_2 );
                   2808:                                                
                   2809:       /* Drop the VG link by zeroing Link Up Command and Load Address  */
                   2810:       hp100_andb( ~(HP100_LINK_CMD/* |HP100_LOAD_ADDR */), VG_LAN_CFG_1);
                   2811: 
                   2812: #ifdef HP100_DEBUG_TRAINING
                   2813:       printk("hp100: %s: Bring down the link\n", dev->name);
                   2814: #endif
                   2815: 
                   2816:       /* Wait for link to drop */
                   2817:       time = jiffies + (HZ/10); 
                   2818:       do {
                   2819:         if (~(hp100_inb( VG_LAN_CFG_1 )& HP100_LINK_UP_ST) ) break;
                   2820:       } while (time>jiffies);
                   2821: 
                   2822:       /* Start an addressed training and optionally request promiscuous port */
                   2823:       if ( (dev->flags) & IFF_PROMISC )
                   2824:        {
                   2825:          hp100_orb( HP100_PROM_MODE, VG_LAN_CFG_2);
                   2826:          if(lp->chip==HP100_CHIPID_LASSEN)
                   2827:            hp100_orw( HP100_MACRQ_PROMSC, TRAIN_REQUEST );
                   2828:        }
                   2829:       else
                   2830:        {
                   2831:          hp100_andb( ~HP100_PROM_MODE, VG_LAN_CFG_2);
                   2832:          /* For ETR parts we need to reset the prom. bit in the training
                   2833:           * register, otherwise promiscious mode won't be disabled.
                   2834:           */
                   2835:          if(lp->chip==HP100_CHIPID_LASSEN)
                   2836:            {
                   2837:              hp100_andw( ~HP100_MACRQ_PROMSC, TRAIN_REQUEST );
                   2838:            }
                   2839:        }
                   2840: 
                   2841:       /* With ETR parts, frame format request bits can be set. */
                   2842:       if(lp->chip==HP100_CHIPID_LASSEN)
                   2843:         hp100_orb( HP100_MACRQ_FRAMEFMT_EITHER, TRAIN_REQUEST);
                   2844: 
                   2845:       hp100_orb( HP100_LINK_CMD|HP100_LOAD_ADDR|HP100_VG_RESET, VG_LAN_CFG_1);
                   2846: 
                   2847:       /* Note: Next wait could be omitted for Hood and earlier chips under */
                   2848:       /* certain circumstances */
                   2849:       /* TODO: check if hood/earlier and skip wait. */
                   2850: 
                   2851:       /* Wait for either short timeout for VG tones or long for login    */
                   2852:       /* Wait for the card hardware to signalise link cable status ok... */
                   2853:       hp100_page( MAC_CTRL );
                   2854:       time = jiffies + ( 1*HZ ); /* 1 sec timeout for cable st */
                   2855:       do {
                   2856:         if ( hp100_inb( VG_LAN_CFG_1 ) & HP100_LINK_CABLE_ST ) break;
                   2857:       } while ( jiffies < time );
                   2858:       
                   2859:       if ( jiffies >= time )
                   2860:        {
                   2861: #ifdef HP100_DEBUG_TRAINING
                   2862:          printk( "hp100: %s: Link cable status not ok? Training aborted.\n", dev->name );
                   2863: #endif  
                   2864:        }
                   2865:       else
                   2866:        {
                   2867: #ifdef HP100_DEBUG_TRAINING
                   2868:          printk( "hp100: %s: HUB tones detected. Trying to train.\n", dev->name);
                   2869: #endif
                   2870: 
                   2871:          time = jiffies + ( 2*HZ ); /* again a timeout */
                   2872:          do {
                   2873:            val = hp100_inb( VG_LAN_CFG_1 );
                   2874:            if ( (val & ( HP100_LINK_UP_ST )) )
                   2875:              {
                   2876: #ifdef HP100_DEBUG_TRAINING
                   2877:                printk( "hp100: %s: Passed training.\n", dev->name);
                   2878: #endif
                   2879:                break;
                   2880:              }
                   2881:          } while ( time > jiffies );
                   2882:        }
                   2883:       
                   2884:       /* If LINK_UP_ST is set, then we are logged into the hub. */
                   2885:       if ( (jiffies<=time) && (val & HP100_LINK_UP_ST) )
                   2886:         {
                   2887: #ifdef HP100_DEBUG_TRAINING
                   2888:           printk( "hp100: %s: Successfully logged into the HUB.\n", dev->name);
                   2889:           if(lp->chip==HP100_CHIPID_LASSEN)
                   2890:             {
                   2891:              val = hp100_inw(TRAIN_ALLOW);
                   2892:               printk( "hp100: %s: Card supports 100VG MAC Version \"%s\" ",
                   2893:                      dev->name,(hp100_inw(TRAIN_REQUEST)&HP100_CARD_MACVER) ? "802.12" : "Pre");
                   2894:              printk( "Driver will use MAC Version \"%s\"\n",
                   2895:                       ( val & HP100_HUB_MACVER) ? "802.12" : "Pre" ); 
                   2896:               printk( "hp100: %s: Frame format is %s.\n",dev->name,(val&HP100_MALLOW_FRAMEFMT)?"802.5":"802.3");
                   2897:             }
                   2898: #endif
                   2899:         }
                   2900:       else
                   2901:         {
                   2902:           /* If LINK_UP_ST is not set, login was not successful */
                   2903:           printk("hp100: %s: Problem logging into the HUB.\n",dev->name);
                   2904:           if(lp->chip==HP100_CHIPID_LASSEN)
                   2905:             {
                   2906:               /* Check allowed Register to find out why there is a problem. */
                   2907:               val = hp100_inw( TRAIN_ALLOW ); /* wont work on non-ETR card */
                   2908: #ifdef HP100_DEBUG_TRAINING
                   2909:               printk("hp100: %s: MAC Configuration requested: 0x%04x, HUB allowed: 0x%04x\n", dev->name, hp100_inw(TRAIN_REQUEST), val);
                   2910: #endif
                   2911:               if ( val & HP100_MALLOW_ACCDENIED )
                   2912:                 printk("hp100: %s: HUB access denied.\n", dev->name);
                   2913:               if ( val & HP100_MALLOW_CONFIGURE )
                   2914:                 printk("hp100: %s: MAC Configuration is incompatible with the Network.\n", dev->name);
                   2915:               if ( val & HP100_MALLOW_DUPADDR )
                   2916:                 printk("hp100: %s: Duplicate MAC Address on the Network.\n", dev->name);
                   2917:             }
                   2918:         }
                   2919:       
                   2920:       /* If we have put the chip into forced 100 Mbit mode earlier, go back */
                   2921:       /* to auto-select mode */
                   2922:       
                   2923:       if( (lp->chip==HP100_CHIPID_LASSEN)&&(startst & HP100_LINK_CABLE_ST) )
                   2924:         {
                   2925:           hp100_page( MAC_CTRL );
                   2926:           hp100_orb( HP100_DOT3_MAC, 10_LAN_CFG_2 );
                   2927:         }
                   2928:      
                   2929:       val=hp100_inb(VG_LAN_CFG_1);
                   2930: 
                   2931:       /* Clear the MISC_ERROR Interrupt, which might be generated when doing the relogin */
                   2932:       hp100_page(PERFORMANCE);
                   2933:       hp100_outw( HP100_MISC_ERROR, IRQ_STATUS);
                   2934:                                        
                   2935:       if (val&HP100_LINK_UP_ST)
                   2936:         return(0); /* login was ok */
                   2937:       else
                   2938:         {
                   2939:           printk("hp100: %s: Training failed.\n", dev->name);
                   2940:           hp100_down_vg_link( dev );
                   2941:           return -EIO;
                   2942:         }
                   2943:     }
                   2944:   /* no forced relogin & already link there->no training. */
                   2945:   return -EIO;
                   2946: }
                   2947: 
                   2948: 
                   2949: static void hp100_cascade_reset( struct device *dev, u_short enable )
                   2950: {
                   2951:   int ioaddr = dev->base_addr;
                   2952:   struct hp100_private *lp = (struct hp100_private *)dev->priv;
                   2953:   int i;
                   2954: 
                   2955: #ifdef HP100_DEBUG_B
                   2956:   hp100_outw( 0x4226, TRACE );
                   2957:   printk("hp100: %s: cascade_reset\n", dev->name);
                   2958: #endif
                   2959: 
                   2960:   if (enable==TRUE) 
                   2961:     {
                   2962:       hp100_outw( HP100_HW_RST | HP100_RESET_LB, OPTION_LSW );
                   2963:       if(lp->chip==HP100_CHIPID_LASSEN)
                   2964:        {
                   2965:          /* Lassen requires a PCI transmit fifo reset */
                   2966:          hp100_page( HW_MAP );
                   2967:          hp100_andb( ~HP100_PCI_RESET, PCICTRL2 );
                   2968:          hp100_orb( HP100_PCI_RESET, PCICTRL2 );
                   2969:          /* Wait for min. 300 ns */
                   2970:          /* we cant use jiffies here, because it may be */
                   2971:          /* that we have disabled the timer... */
                   2972:          for (i=0; i<0xffff; i++);
                   2973:          hp100_andb( ~HP100_PCI_RESET, PCICTRL2 );
                   2974:          hp100_page( PERFORMANCE );
                   2975:        }       
                   2976:     }
                   2977:   else
                   2978:     { /* bring out of reset */
                   2979:       hp100_outw(HP100_HW_RST|HP100_SET_LB, OPTION_LSW);
                   2980:       for (i=0; i<0xffff; i++ );
                   2981:       hp100_page(PERFORMANCE);
                   2982:     }
                   2983: }
                   2984: 
                   2985: #ifdef HP100_DEBUG             
                   2986: void hp100_RegisterDump( struct device *dev )
                   2987: {
                   2988:   int ioaddr=dev->base_addr;
                   2989:   int Page;
                   2990:   int Register;
                   2991: 
                   2992:   /* Dump common registers */
                   2993:   printk("hp100: %s: Cascade Register Dump\n", dev->name);
                   2994:   printk("hardware id #1: 0x%.2x\n",hp100_inb(HW_ID));
                   2995:   printk("hardware id #2/paging: 0x%.2x\n",hp100_inb(PAGING));
                   2996:   printk("option #1: 0x%.4x\n",hp100_inw(OPTION_LSW));
                   2997:   printk("option #2: 0x%.4x\n",hp100_inw(OPTION_MSW));
                   2998: 
                   2999:   /* Dump paged registers */
                   3000:   for (Page = 0; Page < 8; Page++) 
                   3001:     {
                   3002:       /* Dump registers */
                   3003:       printk("page: 0x%.2x\n",Page);
                   3004:       outw( Page, ioaddr+0x02);
                   3005:       for (Register = 0x8; Register < 0x22; Register += 2)
                   3006:        {
                   3007:          /* Display Register contents except data port */
                   3008:          if (((Register != 0x10) && (Register != 0x12)) || (Page > 0))
                   3009:            {
                   3010:              printk("0x%.2x = 0x%.4x\n",Register,inw(ioaddr+Register));
                   3011:            }
                   3012:        }
                   3013:     }
                   3014:   hp100_page(PERFORMANCE);
                   3015: }
                   3016: #endif
                   3017: 
                   3018: 
                   3019: 
                   3020: /*
                   3021:  *  module section
                   3022:  */
                   3023:  
                   3024: #ifdef MODULE
                   3025: 
                   3026: /* Parameters set by insmod */
                   3027: int hp100_port[5] = { 0, -1, -1, -1, -1 };
                   3028: #ifdef LINUX_2_1
                   3029: MODULE_PARM(hp100_port, "1-5i");
                   3030: #endif
                   3031: 
                   3032: #ifdef LINUX_2_1
                   3033: char hp100_name[5][IFNAMSIZ] = { "", "", "", "", "" };
                   3034: MODULE_PARM(hp100_name, "1-5c" __MODULE_STRING(IFNAMSIZ));
                   3035: #else
                   3036: static char devname[5][IFNAMSIZ] = { "", "", "", "", "" };
                   3037: static char *hp100_name[5] = { devname[0], devname[1],
                   3038:                                devname[2], devname[3],
                   3039:                                devname[4] };
                   3040: #endif
                   3041: 
                   3042: /* List of devices */
                   3043: static struct device *hp100_devlist[5] = { NULL, NULL, NULL, NULL, NULL };
                   3044: 
                   3045: /*
                   3046:  * Note: if you have more than five 100vg cards in your pc, feel free to
                   3047:  * increase this value 
                   3048:  */
                   3049: 
                   3050: /*
                   3051:  * Note: to register three eisa or pci devices, use:
                   3052:  * option hp100 hp100_port=0,0,0
                   3053:  *        to register one card at io 0x280 as eth239, use:
                   3054:  * option hp100 hp100_port=0x280 hp100_name=eth239
                   3055:  */
                   3056: 
                   3057: int init_module( void )
                   3058: {
                   3059:   int  i, cards;
                   3060: 
                   3061:   if (hp100_port == 0 && !EISA_bus && !pcibios_present())
                   3062:     printk("hp100: You should not use auto-probing with insmod!\n");
                   3063: 
                   3064:   /* Loop on all possible base addresses */
                   3065:   i = -1; cards = 0;
                   3066:   while((hp100_port[++i] != -1) && (i < 5))
                   3067:     {
                   3068:       /* Create device and set basics args */
                   3069:       hp100_devlist[i] = kmalloc(sizeof(struct device), GFP_KERNEL);
                   3070:       memset(hp100_devlist[i], 0x00, sizeof(struct device));
                   3071:       hp100_devlist[i]->name = hp100_name[i];
                   3072:       hp100_devlist[i]->base_addr = hp100_port[i];
                   3073:       hp100_devlist[i]->init = &hp100_probe;
                   3074: 
                   3075:       /* Try to create the device */
                   3076:       if(register_netdev(hp100_devlist[i]) != 0)
                   3077:        {
                   3078:          /* DeAllocate everything */
                   3079:          /* Note: if dev->priv is mallocated, there is no way to fail */
                   3080:          kfree_s(hp100_devlist[i], sizeof(struct device));
                   3081:          hp100_devlist[i] = (struct device *) NULL;
                   3082:        }
                   3083:        else
                   3084:         cards++;
                   3085:     }                  /* Loop over all devices */
                   3086: 
                   3087:   return cards > 0 ? 0 : -ENODEV;
                   3088: }
                   3089: 
                   3090: void cleanup_module( void )
                   3091: {
                   3092:   int          i;
                   3093: 
                   3094:   /* TODO: Check if all skb's are released/freed. */
                   3095:   for(i = 0; i < 5; i++)
                   3096:     if(hp100_devlist[i] != (struct device *) NULL)
                   3097:       {
                   3098:        unregister_netdev( hp100_devlist[i] );
                   3099:        release_region( hp100_devlist[i]->base_addr, HP100_REGION_SIZE );
                   3100:        if( ((struct hp100_private *)hp100_devlist[i]->priv)->mode==1 ) /* busmaster */
                   3101:          kfree_s( ((struct hp100_private *)hp100_devlist[i]->priv)->page_vaddr, MAX_RINGSIZE+0x0f); 
                   3102:        if ( ((struct hp100_private *)hp100_devlist[i]->priv) -> mem_ptr_virt )
                   3103:          iounmap( ((struct hp100_private *)hp100_devlist[i]->priv) -> mem_ptr_virt );
                   3104:        kfree_s( hp100_devlist[i]->priv, sizeof( struct hp100_private ) );
                   3105:        hp100_devlist[i]->priv = NULL;
                   3106:        kfree_s(hp100_devlist[i], sizeof(struct device));
                   3107:        hp100_devlist[i] = (struct device *) NULL;
                   3108:       }
                   3109: }
                   3110: 
                   3111: #endif         /* MODULE */
                   3112: 
                   3113: 
                   3114: 
                   3115: /*
                   3116:  * Local variables:
                   3117:  *  compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c hp100.c"
                   3118:  *  c-indent-level: 2
                   3119:  *  tab-width: 8
                   3120:  * End:
                   3121:  */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.