File: /usr/src/linux/drivers/net/hp100.c

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