* add p cc
[mascara-docs.git] / i386 / linux / linux-2.3.21 / drivers / net / hp100.c
blob9baf82381e4f89af5071c09c90ebab557b3992a0
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>
11 ** Maintained by: Jaroslav Kysela <perex@jcu.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.
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
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.
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.
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.
49 ** 1.56 -> 1.57
50 ** - updates for new PCI interface for 2.1 kernels
52 ** 1.55 -> 1.56
53 ** - removed printk in misc. interrupt and update statistics to allow
54 ** monitoring of card status
55 ** - timing changes in xmit routines, relogin to 100VG hub added when
56 ** driver does reset
57 ** - included fix for Compex FreedomLine PCI adapter
58 **
59 ** 1.54 -> 1.55
60 ** - fixed bad initialization in init_module
61 ** - added Compex FreedomLine adapter
62 ** - some fixes in card initialization
64 ** 1.53 -> 1.54
65 ** - added hardware multicast filter support (doesn't work)
66 ** - little changes in hp100_sense_lan routine
67 ** - added support for Coax and AUI (J2970)
68 ** - fix for multiple cards and hp100_mode parameter (insmod)
69 ** - fix for shared IRQ
71 ** 1.52 -> 1.53
72 ** - fixed bug in multicast support
76 #define HP100_DEFAULT_PRIORITY_TX 0
78 #undef HP100_DEBUG
79 #undef HP100_DEBUG_B /* Trace */
80 #undef HP100_DEBUG_BM /* Debug busmaster code (PDL stuff) */
82 #undef HP100_DEBUG_TRAINING /* Debug login-to-hub procedure */
83 #undef HP100_DEBUG_TX
84 #undef HP100_DEBUG_IRQ
85 #undef HP100_DEBUG_RX
87 #undef HP100_MULTICAST_FILTER /* Need to be debugged... */
89 #include <linux/version.h>
90 #include <linux/module.h>
91 #include <linux/kernel.h>
92 #include <linux/sched.h>
93 #include <linux/string.h>
94 #include <linux/errno.h>
95 #include <linux/ioport.h>
96 #include <linux/malloc.h>
97 #include <linux/interrupt.h>
98 #include <linux/pci.h>
99 #include <asm/bitops.h>
100 #include <asm/io.h>
102 #include <linux/netdevice.h>
103 #include <linux/etherdevice.h>
104 #include <linux/skbuff.h>
106 #include <linux/types.h>
107 #include <linux/config.h> /* for CONFIG_PCI */
108 #include <linux/delay.h>
109 #include <linux/init.h>
111 #if LINUX_VERSION_CODE >= 0x020100
112 #define LINUX_2_1
113 typedef struct net_device_stats hp100_stats_t;
114 EXPORT_NO_SYMBOLS;
115 #else
116 #include <linux/bios32.h>
117 #define ioremap vremap
118 #define iounmap vfree
119 typedef struct enet_statistics hp100_stats_t;
120 #endif
122 #include "hp100.h"
125 * defines
128 #define HP100_BUS_ISA 0
129 #define HP100_BUS_EISA 1
130 #define HP100_BUS_PCI 2
132 #ifndef PCI_DEVICE_ID_HP_J2585B
133 #define PCI_DEVICE_ID_HP_J2585B 0x1031
134 #endif
135 #ifndef PCI_VENDOR_ID_COMPEX
136 #define PCI_VENDOR_ID_COMPEX 0x11f6
137 #endif
138 #ifndef PCI_DEVICE_ID_COMPEX_ENET100VG4
139 #define PCI_DEVICE_ID_COMPEX_ENET100VG4 0x0112
140 #endif
141 #ifndef PCI_VENDOR_ID_COMPEX2
142 #define PCI_VENDOR_ID_COMPEX2 0x101a
143 #endif
144 #ifndef PCI_DEVICE_ID_COMPEX2_100VG
145 #define PCI_DEVICE_ID_COMPEX2_100VG 0x0005
146 #endif
148 #define HP100_REGION_SIZE 0x20 /* for ioports */
150 #define HP100_MAX_PACKET_SIZE (1536+4)
151 #define HP100_MIN_PACKET_SIZE 60
153 #ifndef HP100_DEFAULT_RX_RATIO
154 /* default - 75% onboard memory on the card are used for RX packets */
155 #define HP100_DEFAULT_RX_RATIO 75
156 #endif
158 #ifndef HP100_DEFAULT_PRIORITY_TX
159 /* default - don't enable transmit outgoing packets as priority */
160 #define HP100_DEFAULT_PRIORITY_TX 0
161 #endif
164 * structures
167 struct hp100_eisa_id {
168 u_int id;
169 const char *name;
170 u_char bus;
173 struct hp100_pci_id {
174 u_short vendor;
175 u_short device;
178 struct hp100_private {
179 struct hp100_eisa_id *id;
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 #ifndef LINUX_2_1
189 u_char pci_bus;
190 u_char pci_device_fn;
191 #else
192 struct pci_dev *pci_dev;
193 #endif
194 short mem_mapped; /* memory mapped access */
195 u_int *mem_ptr_virt; /* virtual memory mapped area, maybe NULL */
196 u_int *mem_ptr_phys; /* physical memory mapped area */
197 short lan_type; /* 10Mb/s, 100Mb/s or -1 (error) */
198 int hub_status; /* was login to hub successful? */
199 u_char mac1_mode;
200 u_char mac2_mode;
201 u_char hash_bytes[ 8 ];
202 hp100_stats_t stats;
204 /* Rings for busmaster mode: */
205 hp100_ring_t *rxrhead; /* Head (oldest) index into rxring */
206 hp100_ring_t *rxrtail; /* Tail (newest) index into rxring */
207 hp100_ring_t *txrhead; /* Head (oldest) index into txring */
208 hp100_ring_t *txrtail; /* Tail (newest) index into txring */
210 hp100_ring_t rxring[ MAX_RX_PDL ];
211 hp100_ring_t txring[ MAX_TX_PDL ];
213 u_int *page_vaddr; /* Virtual address of allocated page */
214 u_int *page_vaddr_algn; /* Aligned virtual address of allocated page */
215 int rxrcommit; /* # Rx PDLs commited to adapter */
216 int txrcommit; /* # Tx PDLs commited to adapter */
220 * variables
223 static struct hp100_eisa_id hp100_eisa_ids[] = {
225 /* 10/100 EISA card with revision A Cascade chip */
226 { 0x80F1F022, "HP J2577 rev A", HP100_BUS_EISA },
228 /* 10/100 ISA card with revision A Cascade chip */
229 { 0x50F1F022, "HP J2573 rev A", HP100_BUS_ISA },
231 /* 10 only EISA card with Cascade chip */
232 { 0x2019F022, "HP 27248B", HP100_BUS_EISA },
234 /* 10/100 EISA card with Cascade chip */
235 { 0x4019F022, "HP J2577", HP100_BUS_EISA },
237 /* 10/100 ISA card with Cascade chip */
238 { 0x5019F022, "HP J2573", HP100_BUS_ISA },
240 /* 10/100 PCI card - old J2585A */
241 { 0x1030103c, "HP J2585A", HP100_BUS_PCI },
243 /* 10/100 PCI card - new J2585B - master capable */
244 { 0x1041103c, "HP J2585B", HP100_BUS_PCI },
246 /* 10 Mbit Combo Adapter */
247 { 0x1042103c, "HP J2970", HP100_BUS_PCI },
249 /* 10 Mbit 10baseT Adapter */
250 { 0x1040103c, "HP J2973", HP100_BUS_PCI },
252 /* 10/100 EISA card from Compex */
253 { 0x0103180e, "ReadyLink ENET100-VG4", HP100_BUS_EISA },
255 /* 10/100 EISA card from Compex - FreedomLine (sq5bpf) */
256 /* Note: plhbrod@mbox.vol.cz reported that same ID have ISA */
257 /* version of adapter, too... */
258 { 0x0104180e, "FreedomLine 100/VG", HP100_BUS_EISA },
260 /* 10/100 PCI card from Compex - FreedomLine
262 * I think this card doesn't like aic7178 scsi controller, but
263 * I haven't tested this much. It works fine on diskless machines.
264 * Jacek Lipkowski <sq5bpf@acid.ch.pw.edu.pl>
266 { 0x021211f6, "FreedomLine 100/VG", HP100_BUS_PCI },
268 /* 10/100 PCI card from Compex (J2585A compatible) */
269 { 0x011211f6, "ReadyLink ENET100-VG4", HP100_BUS_PCI }
273 #define HP100_EISA_IDS_SIZE (sizeof(hp100_eisa_ids)/sizeof(struct hp100_eisa_id))
275 static struct hp100_pci_id hp100_pci_ids[] = {
276 { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_J2585A },
277 { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_J2585B },
278 { PCI_VENDOR_ID_COMPEX, PCI_DEVICE_ID_COMPEX_ENET100VG4 },
279 { PCI_VENDOR_ID_COMPEX2, PCI_DEVICE_ID_COMPEX2_100VG }
282 #define HP100_PCI_IDS_SIZE (sizeof(hp100_pci_ids)/sizeof(struct hp100_pci_id))
284 static int hp100_rx_ratio = HP100_DEFAULT_RX_RATIO;
285 static int hp100_priority_tx = HP100_DEFAULT_PRIORITY_TX;
286 static int hp100_mode = 1;
288 #ifdef LINUX_2_1
289 MODULE_PARM( hp100_rx_ratio, "1i" );
290 MODULE_PARM( hp100_priority_tx, "1i" );
291 MODULE_PARM( hp100_mode, "1i" );
292 #endif
295 * prototypes
298 #ifdef LINUX_2_1
299 static int hp100_probe1( struct net_device *dev, int ioaddr, u_char bus, struct pci_dev *pci_dev );
300 #else
301 static int hp100_probe1( struct net_device *dev, int ioaddr, u_char bus, u_char pci_bus, u_char pci_device_fn );
302 #endif
303 static int hp100_open( struct net_device *dev );
304 static int hp100_close( struct net_device *dev );
305 static int hp100_start_xmit( struct sk_buff *skb, struct net_device *dev );
306 static int hp100_start_xmit_bm (struct sk_buff *skb, struct net_device *dev );
307 static void hp100_rx( struct net_device *dev );
308 static hp100_stats_t *hp100_get_stats( struct net_device *dev );
309 static void hp100_misc_interrupt( struct net_device *dev );
310 static void hp100_update_stats( struct net_device *dev );
311 static void hp100_clear_stats( int ioaddr );
312 static void hp100_set_multicast_list( struct net_device *dev);
313 static void hp100_interrupt( int irq, void *dev_id, struct pt_regs *regs );
314 static void hp100_start_interface( struct net_device *dev );
315 static void hp100_stop_interface( struct net_device *dev );
316 static void hp100_load_eeprom( struct net_device *dev, u_short ioaddr );
317 static int hp100_sense_lan( struct net_device *dev );
318 static int hp100_login_to_vg_hub( struct net_device *dev, u_short force_relogin );
319 static int hp100_down_vg_link( struct net_device *dev );
320 static void hp100_cascade_reset( struct net_device *dev, u_short enable );
321 static void hp100_BM_shutdown( struct net_device *dev );
322 static void hp100_mmuinit( struct net_device *dev );
323 static void hp100_init_pdls( struct net_device *dev );
324 static int hp100_init_rxpdl( struct net_device *dev, register hp100_ring_t *ringptr, register u_int *pdlptr);
325 static int hp100_init_txpdl( struct net_device *dev, register hp100_ring_t *ringptr, register u_int *pdlptr);
326 static void hp100_rxfill( struct net_device *dev );
327 static void hp100_hwinit( struct net_device *dev );
328 static void hp100_clean_txring( struct net_device *dev );
329 #ifdef HP100_DEBUG
330 static void hp100_RegisterDump( struct net_device *dev );
331 #endif
333 /* TODO: This function should not really be needed in a good design... */
334 static void wait( void )
336 mdelay(1);
340 * probe functions
341 * These functions should - if possible - avoid doing write operations
342 * since this could cause problems when the card is not installed.
345 int __init hp100_probe( struct net_device *dev )
347 int base_addr = dev ? dev -> base_addr : 0;
348 int ioaddr = 0;
349 #ifdef CONFIG_PCI
350 int pci_start_index = 0;
351 #endif
353 #ifdef HP100_DEBUG_B
354 hp100_outw( 0x4200, TRACE );
355 printk( "hp100: %s: probe\n", dev->name );
356 #endif
358 if ( base_addr > 0xff ) /* Check a single specified location. */
360 if ( check_region( base_addr, HP100_REGION_SIZE ) ) return -EINVAL;
361 if ( base_addr < 0x400 )
362 #ifdef LINUX_2_1
363 return hp100_probe1( dev, base_addr, HP100_BUS_ISA, NULL );
364 #else
365 return hp100_probe1( dev, base_addr, HP100_BUS_ISA, 0, 0 );
366 #endif
367 if ( EISA_bus && base_addr >= 0x1c38 && ( (base_addr - 0x1c38) & 0x3ff ) == 0 )
368 #ifdef LINUX_2_1
369 return hp100_probe1( dev, base_addr, HP100_BUS_EISA, NULL );
370 #else
371 return hp100_probe1( dev, base_addr, HP100_BUS_EISA, 0, 0 );
372 #endif
373 #ifdef CONFIG_PCI
374 #ifdef LINUX_2_1
375 printk( "hp100: %s: You must specify card # in i/o address parameter for PCI bus...", dev->name );
376 #else
377 printk( "hp100: %s: You may specify card # in i/o address parameter for PCI bus...", dev->name );
378 return hp100_probe1( dev, base_addr, HP100_BUS_PCI, 0, 0 );
379 #endif
380 #else
381 return -ENODEV;
382 #endif
384 else
385 #ifdef CONFIG_PCI
386 if ( base_addr > 0 && base_addr < 8 + 1 )
387 pci_start_index = 0x100 | ( base_addr - 1 );
388 else
389 #endif
390 if ( base_addr != 0 ) return -ENXIO;
392 /* at first - scan PCI bus(es) */
394 #ifdef CONFIG_PCI
395 if ( pcibios_present() )
397 int pci_index;
398 #ifdef LINUX_2_1
399 struct pci_dev *pci_dev = NULL;
400 int pci_id_index;
401 u_short pci_command;
402 #endif
404 #ifdef HP100_DEBUG_PCI
405 printk( "hp100: %s: PCI BIOS is present, checking for devices..\n", dev->name );
406 #endif
407 #ifdef LINUX_2_1
408 pci_index = 0;
409 for ( pci_id_index = 0; pci_id_index < HP100_PCI_IDS_SIZE; pci_id_index++ ) {
410 while ( (pci_dev = pci_find_device( hp100_pci_ids[ pci_id_index ].vendor,
411 hp100_pci_ids[ pci_id_index ].device,
412 pci_dev )) != NULL ) {
413 if ( pci_index < (pci_start_index & 7) ) {
414 pci_index++;
415 continue;
417 /* found... */
418 ioaddr = pci_dev ->resource[ 0 ].start;
419 if ( check_region( ioaddr, HP100_REGION_SIZE ) ) continue;
420 pci_read_config_word( pci_dev, PCI_COMMAND, &pci_command );
421 if ( !( pci_command & PCI_COMMAND_IO ) ) {
422 #ifdef HP100_DEBUG
423 printk( "hp100: %s: PCI I/O Bit has not been set. Setting...\n", dev->name );
424 #endif
425 pci_command |= PCI_COMMAND_IO;
426 pci_write_config_word( pci_dev, PCI_COMMAND, pci_command );
428 if ( !( pci_command & PCI_COMMAND_MASTER ) ) {
429 #ifdef HP100_DEBUG
430 printk( "hp100: %s: PCI Master Bit has not been set. Setting...\n", dev->name );
431 #endif
432 pci_command |= PCI_COMMAND_MASTER;
433 pci_write_config_word( pci_dev, PCI_COMMAND, pci_command );
435 #ifdef HP100_DEBUG
436 printk( "hp100: %s: PCI adapter found at 0x%x\n", dev->name, ioaddr );
437 #endif
438 if ( hp100_probe1( dev, ioaddr, HP100_BUS_PCI, pci_dev ) == 0 )
439 return 0;
442 #else /* old PCI interface */
443 for ( pci_index = pci_start_index & 7; pci_index < 8; pci_index++ )
445 u_char pci_bus, pci_device_fn;
446 u_short pci_command;
447 int pci_id_index;
449 for ( pci_id_index = 0; pci_id_index < HP100_PCI_IDS_SIZE; pci_id_index++ )
450 if ( pcibios_find_device( hp100_pci_ids[ pci_id_index ].vendor,
451 hp100_pci_ids[ pci_id_index ].device,
452 pci_index, &pci_bus,
453 &pci_device_fn ) == 0 ) goto __pci_found;
454 break;
456 __pci_found:
457 pcibios_read_config_dword( pci_bus, pci_device_fn,
458 PCI_BASE_ADDRESS_0, &ioaddr );
460 ioaddr &= ~3; /* remove I/O space marker in bit 0. */
462 if ( check_region( ioaddr, HP100_REGION_SIZE ) ) continue;
464 pcibios_read_config_word( pci_bus, pci_device_fn,
465 PCI_COMMAND, &pci_command );
466 if ( !( pci_command & PCI_COMMAND_IO ) )
468 #ifdef HP100_DEBUG
469 printk( "hp100: %s: PCI I/O Bit has not been set. Setting...\n", dev->name );
470 #endif
471 pci_command |= PCI_COMMAND_IO;
472 pcibios_write_config_word( pci_bus, pci_device_fn,
473 PCI_COMMAND, pci_command );
475 if ( !( pci_command & PCI_COMMAND_MASTER ) )
477 #ifdef HP100_DEBUG
478 printk( "hp100: %s: PCI Master Bit has not been set. Setting...\n", dev->name );
479 #endif
480 pci_command |= PCI_COMMAND_MASTER;
481 pcibios_write_config_word( pci_bus, pci_device_fn,
482 PCI_COMMAND, pci_command );
484 #ifdef HP100_DEBUG
485 printk( "hp100: %s: PCI adapter found at 0x%x\n", dev->name, ioaddr );
486 #endif
487 if ( hp100_probe1( dev, ioaddr, HP100_BUS_PCI, pci_bus, pci_device_fn ) == 0 )
488 return 0;
490 #endif
492 if ( pci_start_index > 0 ) return -ENODEV;
493 #endif /* CONFIG_PCI */
495 /* Second: Probe all EISA possible port regions (if EISA bus present) */
496 for ( ioaddr = 0x1c38; EISA_bus && ioaddr < 0x10000; ioaddr += 0x400 )
498 if ( check_region( ioaddr, HP100_REGION_SIZE ) ) continue;
499 #ifdef LINUX_2_1
500 if ( hp100_probe1( dev, ioaddr, HP100_BUS_EISA, NULL ) == 0 ) return 0;
501 #else
502 if ( hp100_probe1( dev, ioaddr, HP100_BUS_EISA, 0, 0 ) == 0 ) return 0;
503 #endif
506 /* Third Probe all ISA possible port regions */
507 for ( ioaddr = 0x100; ioaddr < 0x400; ioaddr += 0x20 )
509 if ( check_region( ioaddr, HP100_REGION_SIZE ) ) continue;
510 #ifdef LINUX_2_1
511 if ( hp100_probe1( dev, ioaddr, HP100_BUS_ISA, NULL ) == 0 ) return 0;
512 #else
513 if ( hp100_probe1( dev, ioaddr, HP100_BUS_ISA, 0, 0 ) == 0 ) return 0;
514 #endif
517 return -ENODEV;
521 #ifdef LINUX_2_1
522 static int __init hp100_probe1( struct net_device *dev, int ioaddr, u_char bus, struct pci_dev *pci_dev )
523 #else
524 static int __init hp100_probe1( struct net_device *dev, int ioaddr, u_char bus, u_char pci_bus, u_char pci_device_fn )
525 #endif
527 int i;
529 u_char uc, uc_1;
530 u_int eisa_id;
531 u_int chip;
532 u_int memory_size = 0, virt_memory_size = 0;
533 u_short local_mode, lsw;
534 short mem_mapped;
535 u_int *mem_ptr_phys, *mem_ptr_virt;
536 struct hp100_private *lp;
537 struct hp100_eisa_id *eid;
539 #ifdef HP100_DEBUG_B
540 hp100_outw( 0x4201, TRACE );
541 printk("hp100: %s: probe1\n",dev->name);
542 #endif
544 if ( dev == NULL )
546 #ifdef HP100_DEBUG
547 printk( "hp100_probe1: %s: dev == NULL ?\n", dev->name );
548 #endif
549 return EIO;
552 if ( hp100_inw( HW_ID ) != HP100_HW_ID_CASCADE )
554 return -ENODEV;
556 else
558 chip = hp100_inw( PAGING ) & HP100_CHIPID_MASK;
559 #ifdef HP100_DEBUG
560 if ( chip == HP100_CHIPID_SHASTA )
561 printk("hp100: %s: Shasta Chip detected. (This is a pre 802.12 chip)\n", dev->name);
562 else if ( chip == HP100_CHIPID_RAINIER )
563 printk("hp100: %s: Rainier Chip detected. (This is a pre 802.12 chip)\n", dev->name);
564 else if ( chip == HP100_CHIPID_LASSEN )
565 printk("hp100: %s: Lassen Chip detected.\n", dev->name);
566 else
567 printk("hp100: %s: Warning: Unknown CASCADE chip (id=0x%.4x).\n",dev->name,chip);
568 #endif
571 dev->base_addr = ioaddr;
573 hp100_page( ID_MAC_ADDR );
574 for ( i = uc = eisa_id = 0; i < 4; i++ )
576 eisa_id >>= 8;
577 uc_1 = hp100_inb( BOARD_ID + i );
578 eisa_id |= uc_1 << 24;
579 uc += uc_1;
581 uc += hp100_inb( BOARD_ID + 4 );
583 if ( uc != 0xff ) /* bad checksum? */
585 printk("hp100_probe: %s: bad EISA ID checksum at base port 0x%x\n", dev->name, ioaddr );
586 return -ENODEV;
589 for ( i=0; i < HP100_EISA_IDS_SIZE; i++)
590 if ( hp100_eisa_ids[ i ].id == eisa_id )
591 break;
592 if ( i >= HP100_EISA_IDS_SIZE ) {
593 for ( i = 0; i < HP100_EISA_IDS_SIZE; i++)
594 if ( ( hp100_eisa_ids[ i ].id & 0xf0ffffff ) == ( eisa_id & 0xf0ffffff ) )
595 break;
596 if ( i >= HP100_EISA_IDS_SIZE ) {
597 printk( "hp100_probe: %s: card at port 0x%x isn't known (id = 0x%x)\n", dev -> name, ioaddr, eisa_id );
598 return -ENODEV;
601 eid = &hp100_eisa_ids[ i ];
602 if ( ( eid->id & 0x0f000000 ) < ( eisa_id & 0x0f000000 ) )
604 printk( "hp100_probe: %s: newer version of card %s at port 0x%x - unsupported\n",
605 dev->name, eid->name, ioaddr );
606 return -ENODEV;
609 for ( i = uc = 0; i < 7; i++ )
610 uc += hp100_inb( LAN_ADDR + i );
611 if ( uc != 0xff )
613 printk("hp100_probe: %s: bad lan address checksum (card %s at port 0x%x)\n",
614 dev->name, eid->name, ioaddr );
615 return -EIO;
618 /* Make sure, that all registers are correctly updated... */
620 hp100_load_eeprom( dev, ioaddr );
621 wait();
624 * Determine driver operation mode
626 * Use the variable "hp100_mode" upon insmod or as kernel parameter to
627 * force driver modes:
628 * hp100_mode=1 -> default, use busmaster mode if configured.
629 * hp100_mode=2 -> enable shared memory mode
630 * hp100_mode=3 -> force use of i/o mapped mode.
631 * hp100_mode=4 -> same as 1, but re-set the enable bit on the card.
635 * LSW values:
636 * 0x2278 -> J2585B, PnP shared memory mode
637 * 0x2270 -> J2585B, shared memory mode, 0xdc000
638 * 0xa23c -> J2585B, I/O mapped mode
639 * 0x2240 -> EISA COMPEX, BusMaster (Shasta Chip)
640 * 0x2220 -> EISA HP, I/O (Shasta Chip)
641 * 0x2260 -> EISA HP, BusMaster (Shasta Chip)
644 #if 0
645 local_mode = 0x2270;
646 hp100_outw(0xfefe,OPTION_LSW);
647 hp100_outw(local_mode|HP100_SET_LB|HP100_SET_HB,OPTION_LSW);
648 #endif
650 /* hp100_mode value maybe used in future by another card */
651 local_mode=hp100_mode;
652 if ( local_mode < 1 || local_mode > 4 )
653 local_mode = 1; /* default */
654 #ifdef HP100_DEBUG
655 printk( "hp100: %s: original LSW = 0x%x\n", dev->name, hp100_inw(OPTION_LSW) );
656 #endif
658 if(local_mode==3)
660 hp100_outw(HP100_MEM_EN|HP100_RESET_LB, OPTION_LSW);
661 hp100_outw(HP100_IO_EN|HP100_SET_LB, OPTION_LSW);
662 hp100_outw(HP100_BM_WRITE|HP100_BM_READ|HP100_RESET_HB, OPTION_LSW);
663 printk("hp100: %s: IO mapped mode forced.\n", dev->name);
665 else if(local_mode==2)
667 hp100_outw(HP100_MEM_EN|HP100_SET_LB, OPTION_LSW);
668 hp100_outw(HP100_IO_EN |HP100_SET_LB, OPTION_LSW);
669 hp100_outw(HP100_BM_WRITE|HP100_BM_READ|HP100_RESET_HB, OPTION_LSW);
670 printk("hp100: %s: Shared memory mode requested.\n", dev->name);
672 else if(local_mode==4)
674 if(chip==HP100_CHIPID_LASSEN)
676 hp100_outw(HP100_BM_WRITE|
677 HP100_BM_READ | HP100_SET_HB, OPTION_LSW);
678 hp100_outw(HP100_IO_EN |
679 HP100_MEM_EN | HP100_RESET_LB, OPTION_LSW);
680 printk("hp100: %s: Busmaster mode requested.\n",dev->name);
682 local_mode=1;
685 if(local_mode==1) /* default behaviour */
687 lsw = hp100_inw(OPTION_LSW);
689 if ( (lsw & HP100_IO_EN) &&
690 (~lsw & HP100_MEM_EN) &&
691 (~lsw & (HP100_BM_WRITE|HP100_BM_READ)) )
693 #ifdef HP100_DEBUG
694 printk("hp100: %s: IO_EN bit is set on card.\n",dev->name);
695 #endif
696 local_mode=3;
698 else if ( chip == HP100_CHIPID_LASSEN &&
699 ( lsw & (HP100_BM_WRITE|HP100_BM_READ) ) ==
700 (HP100_BM_WRITE|HP100_BM_READ) )
702 printk("hp100: %s: Busmaster mode enabled.\n",dev->name);
703 hp100_outw(HP100_MEM_EN|HP100_IO_EN|HP100_RESET_LB, OPTION_LSW);
705 else
707 #ifdef HP100_DEBUG
708 printk("hp100: %s: Card not configured for BM or BM not supported with this card.\n", dev->name );
709 printk("hp100: %s: Trying shared memory mode.\n", dev->name);
710 #endif
711 /* In this case, try shared memory mode */
712 local_mode=2;
713 hp100_outw(HP100_MEM_EN|HP100_SET_LB, OPTION_LSW);
714 /* hp100_outw(HP100_IO_EN|HP100_RESET_LB, OPTION_LSW); */
718 #ifdef HP100_DEBUG
719 printk( "hp100: %s: new LSW = 0x%x\n", dev->name, hp100_inw(OPTION_LSW) );
720 #endif
722 /* Check for shared memory on the card, eventually remap it */
723 hp100_page( HW_MAP );
724 mem_mapped = (( hp100_inw( OPTION_LSW ) & ( HP100_MEM_EN ) ) != 0);
725 mem_ptr_phys = mem_ptr_virt = NULL;
726 memory_size = (8192<<( (hp100_inb(SRAM)>>5)&0x07));
727 virt_memory_size = 0;
729 /* For memory mapped or busmaster mode, we want the memory address */
730 if ( mem_mapped || (local_mode==1))
732 mem_ptr_phys = (u_int *)( hp100_inw( MEM_MAP_LSW ) |
733 ( hp100_inw( MEM_MAP_MSW ) << 16 ) );
734 (u_int)mem_ptr_phys &= ~0x1fff; /* 8k alignment */
736 if ( bus == HP100_BUS_ISA && ( (u_long)mem_ptr_phys & ~0xfffff ) != 0 )
738 printk("hp100: %s: Can only use programmed i/o mode.\n", dev->name);
739 mem_ptr_phys = NULL;
740 mem_mapped = 0;
741 local_mode=3; /* Use programmed i/o */
744 /* We do not need access to shared memory in busmaster mode */
745 /* However in slave mode we need to remap high (>1GB) card memory */
746 if(local_mode!=1) /* = not busmaster */
748 if ( bus == HP100_BUS_PCI && mem_ptr_phys >= (u_int *)0x100000 )
750 /* We try with smaller memory sizes, if ioremap fails */
751 for(virt_memory_size = memory_size; virt_memory_size>16383; virt_memory_size>>=1)
753 if((mem_ptr_virt=ioremap((u_long)mem_ptr_phys,virt_memory_size))==NULL)
755 #ifdef HP100_DEBUG
756 printk( "hp100: %s: ioremap for 0x%x bytes high PCI memory at 0x%lx failed\n", dev->name, virt_memory_size, (u_long)mem_ptr_phys );
757 #endif
759 else
761 #ifdef HP100_DEBUG
762 printk( "hp100: %s: remapped 0x%x bytes high PCI memory at 0x%lx to 0x%lx.\n", dev->name, virt_memory_size, (u_long)mem_ptr_phys, (u_long)mem_ptr_virt);
763 #endif
764 break;
768 if(mem_ptr_virt==NULL) /* all ioremap tries failed */
770 printk("hp100: %s: Failed to ioremap the PCI card memory. Will have to use i/o mapped mode.\n", dev->name);
771 local_mode=3;
772 virt_memory_size = 0;
779 if(local_mode==3) /* io mapped forced */
781 mem_mapped = 0;
782 mem_ptr_phys = mem_ptr_virt = NULL;
783 printk("hp100: %s: Using (slow) programmed i/o mode.\n", dev->name);
786 /* Initialise the "private" data structure for this card. */
787 if ( (dev->priv=kmalloc(sizeof(struct hp100_private), GFP_KERNEL)) == NULL)
788 return -ENOMEM;
790 lp = (struct hp100_private *)dev->priv;
791 memset( lp, 0, sizeof( struct hp100_private ) );
792 lp->id = eid;
793 lp->chip = chip;
794 lp->mode = local_mode;
795 lp->bus = bus;
796 #ifdef LINUX_2_1
797 lp->pci_dev = pci_dev;
798 #else
799 lp->pci_bus = pci_bus;
800 lp->pci_device_fn = pci_device_fn;
801 #endif
802 lp->priority_tx = hp100_priority_tx;
803 lp->rx_ratio = hp100_rx_ratio;
804 lp->mem_ptr_phys = mem_ptr_phys;
805 lp->mem_ptr_virt = mem_ptr_virt;
806 hp100_page( ID_MAC_ADDR );
807 lp->soft_model = hp100_inb( SOFT_MODEL );
808 lp->mac1_mode = HP100_MAC1MODE3;
809 lp->mac2_mode = HP100_MAC2MODE3;
810 memset( &lp->hash_bytes, 0x00, 8 );
812 dev->base_addr = ioaddr;
814 lp->memory_size = memory_size;
815 lp->virt_memory_size = virt_memory_size;
816 lp->rx_ratio = hp100_rx_ratio; /* can be conf'd with insmod */
818 /* memory region for programmed i/o */
819 request_region( dev->base_addr, HP100_REGION_SIZE, eid->name );
821 dev->open = hp100_open;
822 dev->stop = hp100_close;
824 if (lp->mode==1) /* busmaster */
825 dev->hard_start_xmit = hp100_start_xmit_bm;
826 else
827 dev->hard_start_xmit = hp100_start_xmit;
829 dev->get_stats = hp100_get_stats;
830 dev->set_multicast_list = &hp100_set_multicast_list;
832 /* Ask the card for which IRQ line it is configured */
833 #ifdef LINUX_2_1
834 if ( bus == HP100_BUS_PCI ) {
835 dev->irq = pci_dev->irq;
836 } else {
837 #endif
838 hp100_page( HW_MAP );
839 dev->irq = hp100_inb( IRQ_CHANNEL ) & HP100_IRQMASK;
840 if ( dev->irq == 2 )
841 dev->irq = 9;
842 #ifdef LINUX_2_1
844 #endif
846 if(lp->mode==1) /* busmaster */
847 dev->dma=4;
849 /* Ask the card for its MAC address and store it for later use. */
850 hp100_page( ID_MAC_ADDR );
851 for ( i = uc = 0; i < 6; i++ )
852 dev->dev_addr[ i ] = hp100_inb( LAN_ADDR + i );
854 /* Reset statistics (counters) */
855 hp100_clear_stats( ioaddr );
857 ether_setup( dev );
859 /* If busmaster mode is wanted, a dma-capable memory area is needed for
860 * the rx and tx PDLs
861 * PCI cards can access the whole PC memory. Therefore GFP_DMA is not
862 * needed for the allocation of the memory area.
865 /* TODO: We do not need this with old cards, where PDLs are stored
866 * in the cards shared memory area. But currently, busmaster has been
867 * implemented/tested only with the lassen chip anyway... */
868 if(lp->mode==1) /* busmaster */
870 /* Get physically continous memory for TX & RX PDLs */
871 if ( (lp->page_vaddr=kmalloc(MAX_RINGSIZE+0x0f,GFP_KERNEL) ) == NULL)
872 return -ENOMEM;
873 lp->page_vaddr_algn=((u_int *) ( ((u_int)(lp->page_vaddr)+0x0f) &~0x0f));
874 memset(lp->page_vaddr, 0, MAX_RINGSIZE+0x0f);
876 #ifdef HP100_DEBUG_BM
877 printk("hp100: %s: Reserved DMA memory from 0x%x to 0x%x\n",
878 dev->name,
879 (u_int)lp->page_vaddr_algn,
880 (u_int)lp->page_vaddr_algn+MAX_RINGSIZE);
881 #endif
882 lp->rxrcommit = lp->txrcommit = 0;
883 lp->rxrhead = lp->rxrtail = &(lp->rxring[0]);
884 lp->txrhead = lp->txrtail = &(lp->txring[0]);
887 /* Initialise the card. */
888 /* (I'm not really sure if it's a good idea to do this during probing, but
889 * like this it's assured that the lan connection type can be sensed
890 * correctly)
892 hp100_hwinit( dev );
894 /* Try to find out which kind of LAN the card is connected to. */
895 lp->lan_type = hp100_sense_lan( dev );
897 /* Print out a message what about what we think we have probed. */
898 printk( "hp100: %s: %s at 0x%x, IRQ %d, ",
899 dev->name, lp->id->name, ioaddr, dev->irq );
900 switch ( bus ) {
901 case HP100_BUS_EISA: printk( "EISA" ); break;
902 case HP100_BUS_PCI: printk( "PCI" ); break;
903 default: printk( "ISA" ); break;
905 printk( " bus, %dk SRAM (rx/tx %d%%).\n",
906 lp->memory_size >> 10, lp->rx_ratio );
908 if ( lp->mode==2 ) /* memory mapped */
910 printk( "hp100: %s: Memory area at 0x%lx-0x%lx",
911 dev->name,(u_long)mem_ptr_phys,
912 ((u_long)mem_ptr_phys+(mem_ptr_phys>(u_int *)0x100000?(u_long)lp->memory_size:16*1024))-1 );
913 if ( mem_ptr_virt )
914 printk( " (virtual base 0x%lx)", (u_long)mem_ptr_virt );
915 printk( ".\n" );
917 /* Set for info when doing ifconfig */
918 dev->mem_start = (u_long)mem_ptr_phys;
919 dev->mem_end = (u_long)mem_ptr_phys+(u_long)lp->memory_size;
921 printk( "hp100: %s: ", dev->name );
922 if ( lp->lan_type != HP100_LAN_ERR )
923 printk( "Adapter is attached to " );
924 switch ( lp->lan_type ) {
925 case HP100_LAN_100:
926 printk( "100Mb/s Voice Grade AnyLAN network.\n" );
927 break;
928 case HP100_LAN_10:
929 printk( "10Mb/s network.\n" );
930 break;
931 default:
932 printk( "Warning! Link down.\n" );
935 return 0;
939 /* This procedure puts the card into a stable init state */
940 static void hp100_hwinit( struct net_device *dev )
942 int ioaddr = dev->base_addr;
943 struct hp100_private *lp = (struct hp100_private *)dev->priv;
945 #ifdef HP100_DEBUG_B
946 hp100_outw( 0x4202, TRACE );
947 printk("hp100: %s: hwinit\n", dev->name);
948 #endif
950 /* Initialise the card. -------------------------------------------- */
952 /* Clear all pending Ints and disable Ints */
953 hp100_page( PERFORMANCE );
954 hp100_outw( 0xfefe, IRQ_MASK ); /* mask off all ints */
955 hp100_outw( 0xffff, IRQ_STATUS ); /* clear all pending ints */
957 hp100_outw( HP100_INT_EN | HP100_RESET_LB, OPTION_LSW );
958 hp100_outw( HP100_TRI_INT | HP100_SET_HB, OPTION_LSW );
960 if(lp->mode==1)
962 hp100_BM_shutdown( dev ); /* disables BM, puts cascade in reset */
963 wait();
965 else
967 hp100_outw( HP100_INT_EN | HP100_RESET_LB, OPTION_LSW );
968 hp100_cascade_reset( dev, TRUE );
969 hp100_page( MAC_CTRL );
970 hp100_andb( ~(HP100_RX_EN|HP100_TX_EN), MAC_CFG_1);
973 /* Initiate EEPROM reload */
974 hp100_load_eeprom( dev, 0 );
976 wait();
978 /* Go into reset again. */
979 hp100_cascade_reset( dev, TRUE );
981 /* Set Option Registers to a safe state */
982 hp100_outw( HP100_DEBUG_EN |
983 HP100_RX_HDR |
984 HP100_EE_EN |
985 HP100_BM_WRITE |
986 HP100_BM_READ | HP100_RESET_HB |
987 HP100_FAKE_INT |
988 HP100_INT_EN |
989 HP100_MEM_EN |
990 HP100_IO_EN | HP100_RESET_LB, OPTION_LSW);
992 hp100_outw( HP100_TRI_INT |
993 HP100_MMAP_DIS | HP100_SET_HB, OPTION_LSW );
995 hp100_outb( HP100_PRIORITY_TX |
996 HP100_ADV_NXT_PKT |
997 HP100_TX_CMD | HP100_RESET_LB, OPTION_MSW );
999 /* TODO: Configure MMU for Ram Test. */
1000 /* TODO: Ram Test. */
1002 /* Re-check if adapter is still at same i/o location */
1003 /* (If the base i/o in eeprom has been changed but the */
1004 /* registers had not been changed, a reload of the eeprom */
1005 /* would move the adapter to the address stored in eeprom */
1007 /* TODO: Code to implement. */
1009 /* Until here it was code from HWdiscover procedure. */
1010 /* Next comes code from mmuinit procedure of SCO BM driver which is
1011 * called from HWconfigure in the SCO driver. */
1013 /* Initialise MMU, eventually switch on Busmaster Mode, initialise
1014 * multicast filter...
1016 hp100_mmuinit( dev );
1018 /* We don't turn the interrupts on here - this is done by start_interface. */
1019 wait(); /* TODO: Do we really need this? */
1021 /* Enable Hardware (e.g. unreset) */
1022 hp100_cascade_reset( dev, FALSE );
1024 /* ------- initialisation complete ----------- */
1026 /* Finally try to log in the Hub if there may be a VG connection. */
1027 if( lp->lan_type != HP100_LAN_10 )
1028 hp100_login_to_vg_hub( dev, FALSE ); /* relogin */
1033 * mmuinit - Reinitialise Cascade MMU and MAC settings.
1034 * Note: Must already be in reset and leaves card in reset.
1036 static void hp100_mmuinit( struct net_device *dev )
1038 int ioaddr = dev->base_addr;
1039 struct hp100_private *lp = (struct hp100_private *)dev->priv;
1040 int i;
1042 #ifdef HP100_DEBUG_B
1043 hp100_outw( 0x4203, TRACE );
1044 printk("hp100: %s: mmuinit\n",dev->name);
1045 #endif
1047 #ifdef HP100_DEBUG
1048 if( 0!=(hp100_inw(OPTION_LSW)&HP100_HW_RST) )
1050 printk("hp100: %s: Not in reset when entering mmuinit. Fix me.\n",dev->name);
1051 return;
1053 #endif
1055 /* Make sure IRQs are masked off and ack'ed. */
1056 hp100_page( PERFORMANCE );
1057 hp100_outw( 0xfefe, IRQ_MASK ); /* mask off all ints */
1058 hp100_outw( 0xffff, IRQ_STATUS ); /* ack IRQ */
1061 * Enable Hardware
1062 * - Clear Debug En, Rx Hdr Pipe, EE En, I/O En, Fake Int and Intr En
1063 * - Set Tri-State Int, Bus Master Rd/Wr, and Mem Map Disable
1064 * - Clear Priority, Advance Pkt and Xmit Cmd
1067 hp100_outw( HP100_DEBUG_EN |
1068 HP100_RX_HDR |
1069 HP100_EE_EN | HP100_RESET_HB |
1070 HP100_IO_EN |
1071 HP100_FAKE_INT |
1072 HP100_INT_EN | HP100_RESET_LB, OPTION_LSW );
1074 hp100_outw( HP100_TRI_INT | HP100_SET_HB, OPTION_LSW);
1076 if(lp->mode==1) /* busmaster */
1078 hp100_outw( HP100_BM_WRITE |
1079 HP100_BM_READ |
1080 HP100_MMAP_DIS | HP100_SET_HB, OPTION_LSW );
1082 else if(lp->mode==2) /* memory mapped */
1084 hp100_outw( HP100_BM_WRITE |
1085 HP100_BM_READ | HP100_RESET_HB, OPTION_LSW );
1086 hp100_outw( HP100_MMAP_DIS | HP100_RESET_HB, OPTION_LSW );
1087 hp100_outw( HP100_MEM_EN | HP100_SET_LB, OPTION_LSW );
1088 hp100_outw( HP100_IO_EN | HP100_SET_LB, OPTION_LSW );
1090 else if( lp->mode==3 ) /* i/o mapped mode */
1092 hp100_outw( HP100_MMAP_DIS | HP100_SET_HB |
1093 HP100_IO_EN | HP100_SET_LB, OPTION_LSW );
1096 hp100_page( HW_MAP );
1097 hp100_outb( 0, EARLYRXCFG );
1098 hp100_outw( 0, EARLYTXCFG );
1101 * Enable Bus Master mode
1103 if(lp->mode==1) /* busmaster */
1105 /* Experimental: Set some PCI configuration bits */
1106 hp100_page( HW_MAP );
1107 hp100_andb( ~HP100_PDL_USE3, MODECTRL1 ); /* BM engine read maximum */
1108 hp100_andb( ~HP100_TX_DUALQ, MODECTRL1 ); /* No Queue for Priority TX */
1110 /* PCI Bus failures should result in a Misc. Interrupt */
1111 hp100_orb( HP100_EN_BUS_FAIL, MODECTRL2);
1113 hp100_outw( HP100_BM_READ | HP100_BM_WRITE | HP100_SET_HB, OPTION_LSW );
1114 hp100_page( HW_MAP );
1115 /* Use Burst Mode and switch on PAGE_CK */
1116 hp100_orb( HP100_BM_BURST_RD |
1117 HP100_BM_BURST_WR, BM);
1118 if((lp->chip==HP100_CHIPID_RAINIER)||(lp->chip==HP100_CHIPID_SHASTA))
1119 hp100_orb( HP100_BM_PAGE_CK, BM );
1120 hp100_orb( HP100_BM_MASTER, BM );
1122 else /* not busmaster */
1124 hp100_page(HW_MAP);
1125 hp100_andb(~HP100_BM_MASTER, BM );
1129 * Divide card memory into regions for Rx, Tx and, if non-ETR chip, PDLs
1131 hp100_page( MMU_CFG );
1132 if(lp->mode==1) /* only needed for Busmaster */
1134 int xmit_stop, recv_stop;
1136 if((lp->chip==HP100_CHIPID_RAINIER)||(lp->chip==HP100_CHIPID_SHASTA))
1138 int pdl_stop;
1141 * Each pdl is 508 bytes long. (63 frags * 4 bytes for address and
1142 * 4 bytes for header). We will leave NUM_RXPDLS * 508 (rounded
1143 * to the next higher 1k boundary) bytes for the rx-pdl's
1144 * Note: For non-etr chips the transmit stop register must be
1145 * programmed on a 1k boundary, i.e. bits 9:0 must be zero.
1147 pdl_stop = lp->memory_size;
1148 xmit_stop = ( pdl_stop-508*(MAX_RX_PDL)-16 )& ~(0x03ff);
1149 recv_stop = ( xmit_stop * (lp->rx_ratio)/100 ) &~(0x03ff);
1150 hp100_outw( (pdl_stop>>4)-1, PDL_MEM_STOP );
1151 #ifdef HP100_DEBUG_BM
1152 printk("hp100: %s: PDL_STOP = 0x%x\n", dev->name, pdl_stop);
1153 #endif
1155 else /* ETR chip (Lassen) in busmaster mode */
1157 xmit_stop = ( lp->memory_size ) - 1;
1158 recv_stop = ( ( lp->memory_size * lp->rx_ratio ) / 100 ) & ~(0x03ff);
1161 hp100_outw( xmit_stop>>4 , TX_MEM_STOP );
1162 hp100_outw( recv_stop>>4 , RX_MEM_STOP );
1163 #ifdef HP100_DEBUG_BM
1164 printk("hp100: %s: TX_STOP = 0x%x\n",dev->name,xmit_stop>>4);
1165 printk("hp100: %s: RX_STOP = 0x%x\n",dev->name,recv_stop>>4);
1166 #endif
1168 else /* Slave modes (memory mapped and programmed io) */
1170 hp100_outw( (((lp->memory_size*lp->rx_ratio)/100)>>4), RX_MEM_STOP );
1171 hp100_outw( ((lp->memory_size - 1 )>>4), TX_MEM_STOP );
1172 #ifdef HP100_DEBUG
1173 printk("hp100: %s: TX_MEM_STOP: 0x%x\n", dev->name,hp100_inw(TX_MEM_STOP));
1174 printk("hp100: %s: RX_MEM_STOP: 0x%x\n", dev->name,hp100_inw(RX_MEM_STOP));
1175 #endif
1178 /* Write MAC address into page 1 */
1179 hp100_page( MAC_ADDRESS );
1180 for ( i = 0; i < 6; i++ )
1181 hp100_outb( dev->dev_addr[ i ], MAC_ADDR + i );
1183 /* Zero the multicast hash registers */
1184 for ( i = 0; i < 8; i++ )
1185 hp100_outb( 0x0, HASH_BYTE0 + i );
1187 /* Set up MAC defaults */
1188 hp100_page( MAC_CTRL );
1190 /* Go to LAN Page and zero all filter bits */
1191 /* Zero accept error, accept multicast, accept broadcast and accept */
1192 /* all directed packet bits */
1193 hp100_andb( ~(HP100_RX_EN|
1194 HP100_TX_EN|
1195 HP100_ACC_ERRORED|
1196 HP100_ACC_MC|
1197 HP100_ACC_BC|
1198 HP100_ACC_PHY), MAC_CFG_1 );
1200 hp100_outb( 0x00, MAC_CFG_2 );
1202 /* Zero the frame format bit. This works around a training bug in the */
1203 /* new hubs. */
1204 hp100_outb( 0x00, VG_LAN_CFG_2); /* (use 802.3) */
1206 if(lp->priority_tx)
1207 hp100_outb( HP100_PRIORITY_TX | HP100_SET_LB, OPTION_MSW );
1208 else
1209 hp100_outb( HP100_PRIORITY_TX | HP100_RESET_LB, OPTION_MSW );
1211 hp100_outb( HP100_ADV_NXT_PKT |
1212 HP100_TX_CMD | HP100_RESET_LB, OPTION_MSW );
1214 /* If busmaster, initialize the PDLs */
1215 if(lp->mode==1)
1216 hp100_init_pdls( dev );
1218 /* Go to performance page and initalize isr and imr registers */
1219 hp100_page( PERFORMANCE );
1220 hp100_outw( 0xfefe, IRQ_MASK ); /* mask off all ints */
1221 hp100_outw( 0xffff, IRQ_STATUS ); /* ack IRQ */
1226 * open/close functions
1229 static int hp100_open( struct net_device *dev )
1231 struct hp100_private *lp = (struct hp100_private *)dev->priv;
1232 #ifdef HP100_DEBUG_B
1233 int ioaddr=dev->base_addr;
1234 #endif
1236 #ifdef HP100_DEBUG_B
1237 hp100_outw( 0x4204, TRACE );
1238 printk("hp100: %s: open\n",dev->name);
1239 #endif
1241 /* New: if bus is PCI or EISA, interrupts might be shared interrupts */
1242 if ( request_irq(dev->irq, hp100_interrupt,
1243 lp->bus==HP100_BUS_PCI||lp->bus==HP100_BUS_EISA?SA_SHIRQ:SA_INTERRUPT,
1244 lp->id->name, dev))
1246 printk( "hp100: %s: unable to get IRQ %d\n", dev->name, dev->irq );
1247 return -EAGAIN;
1250 MOD_INC_USE_COUNT;
1252 dev->tbusy = 0;
1253 dev->trans_start = jiffies;
1254 dev->interrupt = 0;
1255 dev->start = 1;
1257 lp->lan_type = hp100_sense_lan( dev );
1258 lp->mac1_mode = HP100_MAC1MODE3;
1259 lp->mac2_mode = HP100_MAC2MODE3;
1260 memset( &lp->hash_bytes, 0x00, 8 );
1262 hp100_stop_interface( dev );
1264 hp100_hwinit( dev );
1266 hp100_start_interface( dev ); /* sets mac modes, enables interrupts */
1268 return 0;
1272 /* The close function is called when the interface is to be brought down */
1273 static int hp100_close( struct net_device *dev )
1275 int ioaddr = dev->base_addr;
1276 struct hp100_private *lp = (struct hp100_private *)dev->priv;
1278 #ifdef HP100_DEBUG_B
1279 hp100_outw( 0x4205, TRACE );
1280 printk("hp100: %s: close\n", dev->name);
1281 #endif
1283 hp100_page( PERFORMANCE );
1284 hp100_outw( 0xfefe, IRQ_MASK ); /* mask off all IRQs */
1286 hp100_stop_interface( dev );
1288 if ( lp->lan_type == HP100_LAN_100 )
1289 lp->hub_status=hp100_login_to_vg_hub( dev, FALSE );
1291 dev->tbusy = 1;
1292 dev->start = 0;
1294 free_irq( dev->irq, dev );
1296 #ifdef HP100_DEBUG
1297 printk( "hp100: %s: close LSW = 0x%x\n", dev->name, hp100_inw(OPTION_LSW) );
1298 #endif
1300 MOD_DEC_USE_COUNT;
1301 return 0;
1306 * Configure the PDL Rx rings and LAN
1308 static void hp100_init_pdls( struct net_device *dev )
1310 struct hp100_private *lp = (struct hp100_private *)dev->priv;
1311 hp100_ring_t *ringptr;
1312 u_int *pageptr;
1313 int i;
1315 #ifdef HP100_DEBUG_B
1316 int ioaddr = dev->base_addr;
1317 #endif
1319 #ifdef HP100_DEBUG_B
1320 hp100_outw( 0x4206, TRACE );
1321 printk("hp100: %s: init pdls\n", dev->name);
1322 #endif
1324 if(0==lp->page_vaddr_algn)
1325 printk("hp100: %s: Warning: lp->page_vaddr_algn not initialised!\n",dev->name);
1326 else
1328 /* pageptr shall point into the DMA accessible memory region */
1329 /* we use this pointer to status the upper limit of allocated */
1330 /* memory in the allocated page. */
1331 /* note: align the pointers to the pci cache line size */
1332 memset(lp->page_vaddr_algn, 0, MAX_RINGSIZE); /* Zero Rx/Tx ring page */
1333 pageptr=lp->page_vaddr_algn;
1335 lp->rxrcommit =0;
1336 ringptr = lp->rxrhead = lp-> rxrtail = &(lp->rxring[0]);
1338 /* Initialise Rx Ring */
1339 for (i=MAX_RX_PDL-1; i>=0; i--)
1341 lp->rxring[i].next = ringptr;
1342 ringptr=&(lp->rxring[i]);
1343 pageptr+=hp100_init_rxpdl(dev, ringptr, pageptr);
1346 /* Initialise Tx Ring */
1347 lp->txrcommit = 0;
1348 ringptr = lp->txrhead = lp->txrtail = &(lp->txring[0]);
1349 for (i=MAX_TX_PDL-1; i>=0; i--)
1351 lp->txring[i].next = ringptr;
1352 ringptr=&(lp->txring[i]);
1353 pageptr+=hp100_init_txpdl(dev, ringptr, pageptr);
1359 /* These functions "format" the entries in the pdl structure */
1360 /* They return how much memory the fragments need. */
1361 static int hp100_init_rxpdl( struct net_device *dev, register hp100_ring_t *ringptr, register u32 *pdlptr )
1363 /* pdlptr is starting address for this pdl */
1365 if( 0!=( ((unsigned)pdlptr) & 0xf) )
1366 printk("hp100: %s: Init rxpdl: Unaligned pdlptr 0x%x.\n",dev->name,(unsigned)pdlptr);
1368 ringptr->pdl = pdlptr+1;
1369 ringptr->pdl_paddr = virt_to_bus(pdlptr+1);
1370 ringptr->skb = (void *) NULL;
1373 * Write address and length of first PDL Fragment (which is used for
1374 * storing the RX-Header
1375 * We use the 4 bytes _before_ the PDH in the pdl memory area to
1376 * store this information. (PDH is at offset 0x04)
1378 /* Note that pdlptr+1 and not pdlptr is the pointer to the PDH */
1380 *(pdlptr+2) =(u_int) virt_to_bus(pdlptr); /* Address Frag 1 */
1381 *(pdlptr+3) = 4; /* Length Frag 1 */
1383 return( ( ((MAX_RX_FRAG*2+2)+3) /4)*4 );
1387 static int hp100_init_txpdl( struct net_device *dev, register hp100_ring_t *ringptr, register u32 *pdlptr )
1389 if( 0!=( ((unsigned)pdlptr) & 0xf) )
1390 printk("hp100: %s: Init txpdl: Unaligned pdlptr 0x%x.\n",dev->name,(unsigned) pdlptr);
1392 ringptr->pdl = pdlptr; /* +1; */
1393 ringptr->pdl_paddr = virt_to_bus(pdlptr); /* +1 */
1394 ringptr->skb = (void *) NULL;
1396 return((((MAX_TX_FRAG*2+2)+3)/4)*4);
1401 * hp100_build_rx_pdl allocates an skb_buff of maximum size plus two bytes
1402 * for possible odd word alignment rounding up to next dword and set PDL
1403 * address for fragment#2
1404 * Returns: 0 if unable to allocate skb_buff
1405 * 1 if successful
1407 int hp100_build_rx_pdl( hp100_ring_t *ringptr, struct net_device *dev )
1409 #ifdef HP100_DEBUG_B
1410 int ioaddr = dev->base_addr;
1411 #endif
1412 #ifdef HP100_DEBUG_BM
1413 u_int *p;
1414 #endif
1416 #ifdef HP100_DEBUG_B
1417 hp100_outw( 0x4207, TRACE );
1418 printk("hp100: %s: build rx pdl\n", dev->name);
1419 #endif
1421 /* Allocate skb buffer of maximum size */
1422 /* Note: This depends on the alloc_skb functions allocating more
1423 * space than requested, i.e. aligning to 16bytes */
1425 ringptr->skb = dev_alloc_skb( ((MAX_ETHER_SIZE+2+3)/4)*4 );
1427 if(NULL!=ringptr->skb)
1430 * Reserve 2 bytes at the head of the buffer to land the IP header
1431 * on a long word boundary (According to the Network Driver section
1432 * in the Linux KHG, this should help to increase performance.)
1434 skb_reserve(ringptr->skb, 2);
1436 ringptr->skb->dev=dev;
1437 ringptr->skb->data=(u_char *)skb_put(ringptr->skb, MAX_ETHER_SIZE );
1439 /* ringptr->pdl points to the beginning of the PDL, i.e. the PDH */
1440 /* Note: 1st Fragment is used for the 4 byte packet status
1441 * (receive header). Its PDL entries are set up by init_rxpdl. So
1442 * here we only have to set up the PDL fragment entries for the data
1443 * part. Those 4 bytes will be stored in the DMA memory region
1444 * directly before the PDL.
1446 #ifdef HP100_DEBUG_BM
1447 printk("hp100: %s: build_rx_pdl: PDH@0x%x, skb->data (len %d) at 0x%x\n",
1448 dev->name,
1449 (u_int) ringptr->pdl,
1450 ((MAX_ETHER_SIZE+2+3)/4)*4,
1451 (unsigned int) ringptr->skb->data);
1452 #endif
1454 ringptr->pdl[0] = 0x00020000; /* Write PDH */
1455 ringptr->pdl[3] = ((u_int)virt_to_bus(ringptr->skb->data));
1456 ringptr->pdl[4] = MAX_ETHER_SIZE; /* Length of Data */
1458 #ifdef HP100_DEBUG_BM
1459 for(p=(ringptr->pdl); p<(ringptr->pdl+5); p++)
1460 printk("hp100: %s: Adr 0x%.8x = 0x%.8x\n",dev->name,(u_int) p,(u_int) *p );
1461 #endif
1462 return(1);
1464 /* else: */
1465 /* alloc_skb failed (no memory) -> still can receive the header
1466 * fragment into PDL memory. make PDL safe by clearing msgptr and
1467 * making the PDL only 1 fragment (i.e. the 4 byte packet status)
1469 #ifdef HP100_DEBUG_BM
1470 printk("hp100: %s: build_rx_pdl: PDH@0x%x, No space for skb.\n",
1471 dev->name,
1472 (u_int) ringptr->pdl);
1473 #endif
1475 ringptr->pdl[0]=0x00010000; /* PDH: Count=1 Fragment */
1477 return(0);
1482 * hp100_rxfill - attempt to fill the Rx Ring will empty skb's
1484 * Makes assumption that skb's are always contiguous memory areas and
1485 * therefore PDLs contain only 2 physical fragments.
1486 * - While the number of Rx PDLs with buffers is less than maximum
1487 * a. Get a maximum packet size skb
1488 * b. Put the physical address of the buffer into the PDL.
1489 * c. Output physical address of PDL to adapter.
1491 static void hp100_rxfill( struct net_device *dev )
1493 int ioaddr=dev->base_addr;
1495 struct hp100_private *lp = (struct hp100_private *)dev->priv;
1496 hp100_ring_t *ringptr;
1498 #ifdef HP100_DEBUG_B
1499 hp100_outw( 0x4208, TRACE );
1500 printk("hp100: %s: rxfill\n",dev->name);
1501 #endif
1503 hp100_page( PERFORMANCE );
1505 while (lp->rxrcommit < MAX_RX_PDL)
1508 ** Attempt to get a buffer and build a Rx PDL.
1510 ringptr = lp->rxrtail;
1511 if (0 == hp100_build_rx_pdl( ringptr, dev ))
1513 return; /* None available, return */
1516 /* Hand this PDL over to the card */
1517 /* Note: This needs performance page selected! */
1518 #ifdef HP100_DEBUG_BM
1519 printk("hp100: %s: rxfill: Hand to card: pdl #%d @0x%x phys:0x%x, buffer: 0x%x\n",
1520 dev->name,
1521 lp->rxrcommit,
1522 (u_int)ringptr->pdl,
1523 (u_int)ringptr->pdl_paddr,
1524 (u_int)ringptr->pdl[3]);
1525 #endif
1527 hp100_outl( (u32)ringptr->pdl_paddr, RX_PDA);
1529 lp->rxrcommit += 1;
1530 lp->rxrtail = ringptr->next;
1536 * BM_shutdown - shutdown bus mastering and leave chip in reset state
1539 static void hp100_BM_shutdown( struct net_device *dev )
1541 int ioaddr = dev->base_addr;
1542 struct hp100_private *lp = (struct hp100_private *)dev->priv;
1543 unsigned long time;
1545 #ifdef HP100_DEBUG_B
1546 hp100_outw( 0x4209, TRACE );
1547 printk("hp100: %s: bm shutdown\n",dev->name);
1548 #endif
1550 hp100_page( PERFORMANCE );
1551 hp100_outw( 0xfefe, IRQ_MASK ); /* mask off all ints */
1552 hp100_outw( 0xffff, IRQ_STATUS ); /* Ack all ints */
1554 /* Ensure Interrupts are off */
1555 hp100_outw( HP100_INT_EN | HP100_RESET_LB , OPTION_LSW );
1557 /* Disable all MAC activity */
1558 hp100_page( MAC_CTRL );
1559 hp100_andb( ~(HP100_RX_EN | HP100_TX_EN), MAC_CFG_1 ); /* stop rx/tx */
1561 /* If cascade MMU is not already in reset */
1562 if (0 != (hp100_inw(OPTION_LSW)&HP100_HW_RST) )
1564 /* Wait 1.3ms (10Mb max packet time) to ensure MAC is idle so
1565 * MMU pointers will not be reset out from underneath
1567 hp100_page( MAC_CTRL );
1568 for(time=0; time<5000; time++)
1570 if( (hp100_inb(MAC_CFG_1)&(HP100_TX_IDLE|HP100_RX_IDLE))==
1571 (HP100_TX_IDLE|HP100_RX_IDLE) ) break;
1574 /* Shutdown algorithm depends on the generation of Cascade */
1575 if( lp->chip==HP100_CHIPID_LASSEN )
1576 { /* ETR shutdown/reset */
1577 /* Disable Busmaster mode and wait for bit to go to zero. */
1578 hp100_page(HW_MAP);
1579 hp100_andb( ~HP100_BM_MASTER, BM );
1580 /* 100 ms timeout */
1581 for(time=0; time<32000; time++)
1583 if ( 0 == (hp100_inb( BM ) & HP100_BM_MASTER) ) break;
1586 else
1587 { /* Shasta or Rainier Shutdown/Reset */
1588 /* To ensure all bus master inloading activity has ceased,
1589 * wait for no Rx PDAs or no Rx packets on card.
1591 hp100_page( PERFORMANCE );
1592 /* 100 ms timeout */
1593 for(time=0; time<10000; time++)
1595 /* RX_PDL: PDLs not executed. */
1596 /* RX_PKT_CNT: RX'd packets on card. */
1597 if ( (hp100_inb( RX_PDL ) == 0) &&
1598 (hp100_inb( RX_PKT_CNT ) == 0) ) break;
1601 if(time>=10000)
1602 printk("hp100: %s: BM shutdown error.\n", dev->name);
1604 /* To ensure all bus master outloading activity has ceased,
1605 * wait until the Tx PDA count goes to zero or no more Tx space
1606 * available in the Tx region of the card.
1608 /* 100 ms timeout */
1609 for(time=0; time<10000; time++) {
1610 if ( (0 == hp100_inb( TX_PKT_CNT )) &&
1611 (0 != (hp100_inb( TX_MEM_FREE )&HP100_AUTO_COMPARE))) break;
1614 /* Disable Busmaster mode */
1615 hp100_page(HW_MAP);
1616 hp100_andb( ~HP100_BM_MASTER, BM );
1617 } /* end of shutdown procedure for non-etr parts */
1619 hp100_cascade_reset( dev, TRUE );
1621 hp100_page( PERFORMANCE );
1622 /* hp100_outw( HP100_BM_READ | HP100_BM_WRITE | HP100_RESET_HB, OPTION_LSW ); */
1623 /* Busmaster mode should be shut down now. */
1629 * transmit functions
1632 /* tx function for busmaster mode */
1633 static int hp100_start_xmit_bm( struct sk_buff *skb, struct net_device *dev )
1635 unsigned long flags;
1636 int i, ok_flag;
1637 int ioaddr = dev->base_addr;
1638 struct hp100_private *lp = (struct hp100_private *)dev->priv;
1639 hp100_ring_t *ringptr;
1641 #ifdef HP100_DEBUG_B
1642 hp100_outw( 0x4210, TRACE );
1643 printk("hp100: %s: start_xmit_bm\n",dev->name);
1644 #endif
1646 if ( skb==NULL )
1648 #ifndef LINUX_2_1
1649 dev_tint( dev );
1650 #endif
1651 return 0;
1654 if ( skb->len <= 0 ) return 0;
1656 /* Get Tx ring tail pointer */
1657 if( lp->txrtail->next==lp->txrhead )
1659 /* No memory. */
1660 #ifdef HP100_DEBUG
1661 printk("hp100: %s: start_xmit_bm: No TX PDL available.\n", dev->name);
1662 #endif
1663 /* not waited long enough since last tx? */
1664 if ( jiffies - dev->trans_start < HZ ) return -EAGAIN;
1666 if ( lp->lan_type < 0 ) /* no LAN type detected yet? */
1668 hp100_stop_interface( dev );
1669 if ( ( lp->lan_type = hp100_sense_lan( dev ) ) < 0 )
1671 printk( "hp100: %s: no connection found - check wire\n", dev->name );
1672 hp100_start_interface( dev ); /* 10Mb/s RX pkts maybe handled */
1673 return -EIO;
1675 if ( lp->lan_type == HP100_LAN_100 )
1676 lp->hub_status = hp100_login_to_vg_hub( dev, FALSE ); /* relogin */
1677 hp100_start_interface( dev );
1680 if ( lp->lan_type == HP100_LAN_100 && lp->hub_status < 0 )
1681 /* we have a 100Mb/s adapter but it isn't connected to hub */
1683 printk( "hp100: %s: login to 100Mb/s hub retry\n", dev->name );
1684 hp100_stop_interface( dev );
1685 lp->hub_status = hp100_login_to_vg_hub( dev, FALSE );
1686 hp100_start_interface( dev );
1688 else
1690 hp100_ints_off();
1691 i = hp100_sense_lan( dev );
1692 hp100_ints_on();
1693 if ( i == HP100_LAN_ERR )
1694 printk( "hp100: %s: link down detected\n", dev->name );
1695 else
1696 if ( lp->lan_type != i ) /* cable change! */
1698 /* it's very hard - all network setting must be changed!!! */
1699 printk( "hp100: %s: cable change 10Mb/s <-> 100Mb/s detected\n", dev->name );
1700 lp->lan_type = i;
1701 hp100_stop_interface( dev );
1702 if ( lp->lan_type == HP100_LAN_100 )
1703 lp->hub_status = hp100_login_to_vg_hub( dev, FALSE );
1704 hp100_start_interface( dev );
1706 else
1708 printk( "hp100: %s: interface reset\n", dev->name );
1709 hp100_stop_interface( dev );
1710 if ( lp->lan_type == HP100_LAN_100 )
1711 lp->hub_status = hp100_login_to_vg_hub( dev, FALSE );
1712 hp100_start_interface( dev );
1716 dev->trans_start = jiffies;
1717 return -EAGAIN;
1721 * we have to turn int's off before modifying this, otherwise
1722 * a tx_pdl_cleanup could occur at the same time
1724 save_flags( flags );
1725 cli();
1726 ringptr=lp->txrtail;
1727 lp->txrtail=ringptr->next;
1729 /* Check whether packet has minimal packet size */
1730 ok_flag = skb->len >= HP100_MIN_PACKET_SIZE;
1731 i = ok_flag ? skb->len : HP100_MIN_PACKET_SIZE;
1733 ringptr->skb=skb;
1734 ringptr->pdl[0]=((1<<16) | i); /* PDH: 1 Fragment & length */
1735 ringptr->pdl[1]=(u32)virt_to_bus(skb->data); /* 1st Frag: Adr. of data */
1736 if(lp->chip==HP100_CHIPID_SHASTA)
1738 /* TODO:Could someone who has the EISA card please check if this works? */
1739 ringptr->pdl[2]=i;
1741 else /* Lassen */
1743 /* In the PDL, don't use the padded size but the real packet size: */
1744 ringptr->pdl[2]=skb->len; /* 1st Frag: Length of frag */
1747 /* Hand this PDL to the card. */
1748 hp100_outl( ringptr->pdl_paddr, TX_PDA_L ); /* Low Prio. Queue */
1750 lp->txrcommit++;
1751 restore_flags( flags );
1753 /* Update statistics */
1754 lp->stats.tx_packets++;
1755 #ifdef LINUX_2_1
1756 lp->stats.tx_bytes += skb->len;
1757 #endif
1758 dev->trans_start = jiffies;
1760 return 0;
1764 /* clean_txring checks if packets have been sent by the card by reading
1765 * the TX_PDL register from the performance page and comparing it to the
1766 * number of commited packets. It then frees the skb's of the packets that
1767 * obviously have been sent to the network.
1769 * Needs the PERFORMANCE page selected.
1771 static void hp100_clean_txring( struct net_device *dev )
1773 struct hp100_private *lp = (struct hp100_private *)dev->priv;
1774 int ioaddr = dev->base_addr;
1775 int donecount;
1777 #ifdef HP100_DEBUG_B
1778 hp100_outw( 0x4211, TRACE );
1779 printk("hp100: %s: clean txring\n", dev->name);
1780 #endif
1782 /* How many PDLs have been transmitted? */
1783 donecount=(lp->txrcommit)-hp100_inb(TX_PDL);
1785 #ifdef HP100_DEBUG
1786 if(donecount>MAX_TX_PDL)
1787 printk("hp100: %s: Warning: More PDLs transmitted than commited to card???\n",dev->name);
1788 #endif
1790 for( ; 0!=donecount; donecount-- )
1792 #ifdef HP100_DEBUG_BM
1793 printk("hp100: %s: Free skb: data @0x%.8x txrcommit=0x%x TXPDL=0x%x, done=0x%x\n",
1794 dev->name,
1795 (u_int) lp->txrhead->skb->data,
1796 lp->txrcommit,
1797 hp100_inb(TX_PDL),
1798 donecount);
1799 #endif
1800 #ifdef LINUX_2_1
1801 dev_kfree_skb( lp->txrhead->skb );
1802 #else
1803 dev_kfree_skb( lp->txrhead->skb, FREE_WRITE );
1804 #endif
1805 lp->txrhead->skb=(void *)NULL;
1806 lp->txrhead=lp->txrhead->next;
1807 lp->txrcommit--;
1812 /* tx function for slave modes */
1813 static int hp100_start_xmit( struct sk_buff *skb, struct net_device *dev )
1815 int i, ok_flag;
1816 int ioaddr = dev->base_addr;
1817 u_short val;
1818 struct hp100_private *lp = (struct hp100_private *)dev->priv;
1820 #ifdef HP100_DEBUG_B
1821 hp100_outw( 0x4212, TRACE );
1822 printk("hp100: %s: start_xmit\n", dev->name);
1823 #endif
1825 if ( skb==NULL )
1827 #ifndef LINUX_2_1
1828 dev_tint( dev );
1829 #endif
1830 return 0;
1833 if ( skb->len <= 0 ) return 0;
1835 if ( lp->lan_type < 0 ) /* no LAN type detected yet? */
1837 hp100_stop_interface( dev );
1838 if ( ( lp->lan_type = hp100_sense_lan( dev ) ) < 0 )
1840 printk( "hp100: %s: no connection found - check wire\n", dev->name );
1841 hp100_start_interface( dev ); /* 10Mb/s RX packets maybe handled */
1842 return -EIO;
1844 if ( lp->lan_type == HP100_LAN_100 )
1845 lp->hub_status = hp100_login_to_vg_hub( dev, FALSE ); /* relogin */
1846 hp100_start_interface( dev );
1849 /* If there is not enough free memory on the card... */
1850 i=hp100_inl(TX_MEM_FREE)&0x7fffffff;
1851 if ( !(((i/2)-539)>(skb->len+16) && (hp100_inb(TX_PKT_CNT)<255)) )
1853 #ifdef HP100_DEBUG
1854 printk( "hp100: %s: start_xmit: tx free mem = 0x%x\n", dev->name, i );
1855 #endif
1856 /* not waited long enough since last failed tx try? */
1857 if ( jiffies - dev->trans_start < HZ )
1859 #ifdef HP100_DEBUG
1860 printk("hp100: %s: trans_start timing problem\n", dev->name);
1861 #endif
1862 return -EAGAIN;
1864 if ( lp->lan_type == HP100_LAN_100 && lp->hub_status < 0 )
1865 /* we have a 100Mb/s adapter but it isn't connected to hub */
1867 printk( "hp100: %s: login to 100Mb/s hub retry\n", dev->name );
1868 hp100_stop_interface( dev );
1869 lp->hub_status = hp100_login_to_vg_hub( dev, FALSE );
1870 hp100_start_interface( dev );
1872 else
1874 hp100_ints_off();
1875 i = hp100_sense_lan( dev );
1876 hp100_ints_on();
1877 if ( i == HP100_LAN_ERR )
1878 printk( "hp100: %s: link down detected\n", dev->name );
1879 else
1880 if ( lp->lan_type != i ) /* cable change! */
1882 /* it's very hard - all network setting must be changed!!! */
1883 printk( "hp100: %s: cable change 10Mb/s <-> 100Mb/s detected\n", dev->name );
1884 lp->lan_type = i;
1885 hp100_stop_interface( dev );
1886 if ( lp->lan_type == HP100_LAN_100 )
1887 lp->hub_status = hp100_login_to_vg_hub( dev, FALSE );
1888 hp100_start_interface( dev );
1890 else
1892 printk( "hp100: %s: interface reset\n", dev->name );
1893 hp100_stop_interface( dev );
1894 if ( lp->lan_type == HP100_LAN_100 )
1895 lp->hub_status = hp100_login_to_vg_hub( dev, FALSE );
1896 hp100_start_interface( dev );
1897 mdelay(1);
1900 dev->trans_start = jiffies;
1901 return -EAGAIN;
1904 for ( i=0; i<6000 && ( hp100_inb( OPTION_MSW ) & HP100_TX_CMD ); i++ )
1906 #ifdef HP100_DEBUG_TX
1907 printk( "hp100: %s: start_xmit: busy\n", dev->name );
1908 #endif
1911 hp100_ints_off();
1912 val = hp100_inw( IRQ_STATUS );
1913 /* Ack / clear the interrupt TX_COMPLETE interrupt - this interrupt is set
1914 * when the current packet being transmitted on the wire is completed. */
1915 hp100_outw( HP100_TX_COMPLETE, IRQ_STATUS );
1916 #ifdef HP100_DEBUG_TX
1917 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 );
1918 #endif
1920 ok_flag = skb->len >= HP100_MIN_PACKET_SIZE;
1921 i = ok_flag ? skb->len : HP100_MIN_PACKET_SIZE;
1923 hp100_outw( i, DATA32 ); /* tell card the total packet length */
1924 hp100_outw( i, FRAGMENT_LEN ); /* and first/only fragment length */
1926 if ( lp->mode==2 ) /* memory mapped */
1928 if ( lp->mem_ptr_virt ) /* high pci memory was remapped */
1930 /* Note: The J2585B needs alignment to 32bits here! */
1931 memcpy( lp->mem_ptr_virt, skb->data, ( skb->len + 3 ) & ~3 );
1932 if ( !ok_flag )
1933 memset( lp->mem_ptr_virt, 0, HP100_MIN_PACKET_SIZE - skb->len );
1935 else
1937 /* Note: The J2585B needs alignment to 32bits here! */
1938 memcpy_toio( lp->mem_ptr_phys, skb->data, (skb->len + 3) & ~3 );
1939 if ( !ok_flag )
1940 memset_io( lp->mem_ptr_phys, 0, HP100_MIN_PACKET_SIZE - skb->len );
1943 else /* programmed i/o */
1945 outsl( ioaddr + HP100_REG_DATA32, skb->data, ( skb->len + 3 ) >> 2 );
1946 if ( !ok_flag )
1947 for ( i = ( skb->len + 3 ) & ~3; i < HP100_MIN_PACKET_SIZE; i += 4 )
1948 hp100_outl( 0, DATA32 );
1951 hp100_outb( HP100_TX_CMD | HP100_SET_LB, OPTION_MSW ); /* send packet */
1953 lp->stats.tx_packets++;
1954 #ifdef LINUX_2_1
1955 lp->stats.tx_bytes += skb->len;
1956 #endif
1957 dev->trans_start=jiffies;
1958 hp100_ints_on();
1960 #ifdef LINUX_2_1
1961 dev_kfree_skb( skb );
1962 #else
1963 dev_kfree_skb( skb, FREE_WRITE );
1964 #endif
1966 #ifdef HP100_DEBUG_TX
1967 printk( "hp100: %s: start_xmit: end\n", dev->name );
1968 #endif
1970 return 0;
1975 * Receive Function (Non-Busmaster mode)
1976 * Called when an "Receive Packet" interrupt occurs, i.e. the receive
1977 * packet counter is non-zero.
1978 * For non-busmaster, this function does the whole work of transfering
1979 * the packet to the host memory and then up to higher layers via skb
1980 * and netif_rx.
1983 static void hp100_rx( struct net_device *dev )
1985 int packets, pkt_len;
1986 int ioaddr = dev->base_addr;
1987 struct hp100_private *lp = (struct hp100_private *)dev->priv;
1988 u_int header;
1989 struct sk_buff *skb;
1991 #ifdef DEBUG_B
1992 hp100_outw( 0x4213, TRACE );
1993 printk("hp100: %s: rx\n", dev->name);
1994 #endif
1996 /* First get indication of received lan packet */
1997 /* RX_PKT_CND indicates the number of packets which have been fully */
1998 /* received onto the card but have not been fully transfered of the card */
1999 packets = hp100_inb( RX_PKT_CNT );
2000 #ifdef HP100_DEBUG_RX
2001 if ( packets > 1 )
2002 printk( "hp100: %s: rx: waiting packets = %d\n", dev->name,packets );
2003 #endif
2005 while ( packets-- > 0 )
2007 /* If ADV_NXT_PKT is still set, we have to wait until the card has */
2008 /* really advanced to the next packet. */
2009 for (pkt_len=0; pkt_len<6000 &&(hp100_inb(OPTION_MSW)&HP100_ADV_NXT_PKT);
2010 pkt_len++ )
2012 #ifdef HP100_DEBUG_RX
2013 printk( "hp100: %s: rx: busy, remaining packets = %d\n", dev->name, packets );
2014 #endif
2017 /* First we get the header, which contains information about the */
2018 /* actual length of the received packet. */
2019 if( lp->mode==2 ) /* memory mapped mode */
2021 if ( lp->mem_ptr_virt ) /* if memory was remapped */
2022 header = *(__u32 *)lp->mem_ptr_virt;
2023 else
2024 header = readl( lp->mem_ptr_phys );
2026 else /* programmed i/o */
2027 header = hp100_inl( DATA32 );
2029 pkt_len = ((header & HP100_PKT_LEN_MASK) + 3) & ~3;
2031 #ifdef HP100_DEBUG_RX
2032 printk( "hp100: %s: rx: new packet - length=%d, errors=0x%x, dest=0x%x\n",
2033 dev->name,
2034 header & HP100_PKT_LEN_MASK, (header>>16)&0xfff8,
2035 (header>>16)&7);
2036 #endif
2038 /* Now we allocate the skb and transfer the data into it. */
2039 skb = dev_alloc_skb( pkt_len );
2040 if ( skb == NULL ) /* Not enough memory->drop packet */
2042 #ifdef HP100_DEBUG
2043 printk( "hp100: %s: rx: couldn't allocate a sk_buff of size %d\n", dev->name, pkt_len );
2044 #endif
2045 lp->stats.rx_dropped++;
2047 else /* skb successfully allocated */
2049 u_char *ptr;
2051 skb->dev = dev;
2053 /* ptr to start of the sk_buff data area */
2054 ptr = (u_char *)skb_put( skb, pkt_len );
2056 /* Now transfer the data from the card into that area */
2057 if ( lp->mode==2 )
2059 if ( lp->mem_ptr_virt )
2060 memcpy( ptr, lp->mem_ptr_virt, pkt_len );
2061 /* Note alignment to 32bit transfers */
2062 else
2063 memcpy_fromio( ptr, lp->mem_ptr_phys, pkt_len );
2065 else /* io mapped */
2066 insl( ioaddr + HP100_REG_DATA32, ptr, pkt_len >> 2 );
2068 skb->protocol = eth_type_trans( skb, dev );
2070 netif_rx( skb );
2071 lp->stats.rx_packets++;
2072 #ifdef LINUX_2_1
2073 lp->stats.rx_bytes += skb->len;
2074 #endif
2076 #ifdef HP100_DEBUG_RX
2077 printk( "hp100: %s: rx: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
2078 dev->name,
2079 ptr[ 0 ], ptr[ 1 ], ptr[ 2 ], ptr[ 3 ], ptr[ 4 ], ptr[ 5 ],
2080 ptr[ 6 ], ptr[ 7 ], ptr[ 8 ], ptr[ 9 ], ptr[ 10 ], ptr[ 11 ] );
2081 #endif
2084 /* Indicate the card that we have got the packet */
2085 hp100_outb( HP100_ADV_NXT_PKT | HP100_SET_LB, OPTION_MSW );
2087 switch ( header & 0x00070000 ) {
2088 case (HP100_MULTI_ADDR_HASH<<16):
2089 case (HP100_MULTI_ADDR_NO_HASH<<16):
2090 lp->stats.multicast++; break;
2092 } /* end of while(there are packets) loop */
2093 #ifdef HP100_DEBUG_RX
2094 printk( "hp100_rx: %s: end\n", dev->name );
2095 #endif
2100 * Receive Function for Busmaster Mode
2102 static void hp100_rx_bm( struct net_device *dev )
2104 int ioaddr = dev->base_addr;
2105 struct hp100_private *lp = (struct hp100_private *)dev->priv;
2106 hp100_ring_t *ptr;
2107 u_int header;
2108 int pkt_len;
2110 #ifdef HP100_DEBUG_B
2111 hp100_outw( 0x4214, TRACE );
2112 printk("hp100: %s: rx_bm\n", dev->name);
2113 #endif
2115 #ifdef HP100_DEBUG
2116 if(0==lp->rxrcommit)
2118 printk("hp100: %s: rx_bm called although no PDLs were committed to adapter?\n", dev->name);
2119 return;
2121 else
2123 /* RX_PKT_CNT states how many PDLs are currently formatted and available to
2124 * the cards BM engine */
2125 if( (hp100_inw(RX_PKT_CNT)&0x00ff) >= lp->rxrcommit)
2127 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);
2128 return;
2130 #endif
2132 while( (lp->rxrcommit > hp100_inb(RX_PDL)) )
2135 * The packet was received into the pdl pointed to by lp->rxrhead (
2136 * the oldest pdl in the ring
2139 /* First we get the header, which contains information about the */
2140 /* actual length of the received packet. */
2142 ptr=lp->rxrhead;
2144 header = *(ptr->pdl-1);
2145 pkt_len = (header & HP100_PKT_LEN_MASK);
2147 #ifdef HP100_DEBUG_BM
2148 printk( "hp100: %s: rx_bm: header@0x%x=0x%x length=%d, errors=0x%x, dest=0x%x\n",
2149 dev->name,
2150 (u_int) (ptr->pdl-1),(u_int) header,
2151 pkt_len,
2152 (header>>16)&0xfff8,
2153 (header>>16)&7);
2154 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",
2155 dev->name,
2156 hp100_inb( RX_PDL ),
2157 hp100_inb( TX_PDL ),
2158 hp100_inb( RX_PKT_CNT ),
2159 (u_int) *(ptr->pdl),
2160 (u_int) *(ptr->pdl+3),
2161 (u_int) *(ptr->pdl+4));
2162 #endif
2164 if( (pkt_len>=MIN_ETHER_SIZE) &&
2165 (pkt_len<=MAX_ETHER_SIZE) )
2167 if(ptr->skb==NULL)
2169 printk("hp100: %s: rx_bm: skb null\n", dev->name);
2170 /* can happen if we only allocated room for the pdh due to memory shortage. */
2171 lp->stats.rx_dropped++;
2173 else
2175 skb_trim( ptr->skb, pkt_len ); /* Shorten it */
2176 ptr->skb->protocol = eth_type_trans( ptr->skb, dev );
2178 netif_rx( ptr->skb ); /* Up and away... */
2180 lp->stats.rx_packets++;
2181 #ifdef LINUX_2_1
2182 lp->stats.rx_bytes += ptr->skb->len;
2183 #endif
2186 switch ( header & 0x00070000 ) {
2187 case (HP100_MULTI_ADDR_HASH<<16):
2188 case (HP100_MULTI_ADDR_NO_HASH<<16):
2189 lp->stats.multicast++; break;
2192 else
2194 #ifdef HP100_DEBUG
2195 printk("hp100: %s: rx_bm: Received bad packet (length=%d)\n",dev->name,pkt_len);
2196 #endif
2197 if(ptr->skb!=NULL)
2198 #ifdef LINUX_2_1
2199 dev_kfree_skb( ptr->skb );
2200 #else
2201 dev_kfree_skb( ptr->skb, FREE_READ );
2202 #endif
2203 lp->stats.rx_errors++;
2206 lp->rxrhead=lp->rxrhead->next;
2208 /* Allocate a new rx PDL (so lp->rxrcommit stays the same) */
2209 if (0 == hp100_build_rx_pdl( lp->rxrtail, dev ))
2211 /* No space for skb, header can still be received. */
2212 #ifdef HP100_DEBUG
2213 printk("hp100: %s: rx_bm: No space for new PDL.\n", dev->name);
2214 #endif
2215 return;
2217 else
2218 { /* successfully allocated new PDL - put it in ringlist at tail. */
2219 hp100_outl((u32)lp->rxrtail->pdl_paddr, RX_PDA);
2220 lp->rxrtail=lp->rxrtail->next;
2229 * statistics
2231 static hp100_stats_t *hp100_get_stats( struct net_device *dev )
2233 int ioaddr = dev->base_addr;
2235 #ifdef HP100_DEBUG_B
2236 hp100_outw( 0x4215, TRACE );
2237 #endif
2239 hp100_ints_off();
2240 hp100_update_stats( dev );
2241 hp100_ints_on();
2242 return &((struct hp100_private *)dev->priv)->stats;
2245 static void hp100_update_stats( struct net_device *dev )
2247 int ioaddr = dev->base_addr;
2248 u_short val;
2249 struct hp100_private *lp = (struct hp100_private *)dev->priv;
2251 #ifdef HP100_DEBUG_B
2252 hp100_outw( 0x4216, TRACE );
2253 printk("hp100: %s: update-stats\n", dev->name);
2254 #endif
2256 /* Note: Statistics counters clear when read. */
2257 hp100_page( MAC_CTRL );
2258 val = hp100_inw( DROPPED ) & 0x0fff;
2259 lp->stats.rx_errors += val;
2260 lp->stats.rx_over_errors += val;
2261 val = hp100_inb( CRC );
2262 lp->stats.rx_errors += val;
2263 lp->stats.rx_crc_errors += val;
2264 val = hp100_inb( ABORT );
2265 lp->stats.tx_errors += val;
2266 lp->stats.tx_aborted_errors += val;
2267 hp100_page( PERFORMANCE );
2270 static void hp100_misc_interrupt( struct net_device *dev )
2272 struct hp100_private *lp = (struct hp100_private *)dev->priv;
2274 #ifdef HP100_DEBUG_B
2275 hp100_outw( 0x4216, TRACE );
2276 printk("hp100: %s: misc_interrupt\n", dev->name);
2277 #endif
2279 /* Note: Statistics counters clear when read. */
2280 lp->stats.rx_errors++;
2281 lp->stats.tx_errors++;
2284 static void hp100_clear_stats( int ioaddr )
2286 unsigned long flags;
2288 #ifdef HP100_DEBUG_B
2289 hp100_outw( 0x4217, TRACE );
2290 printk("hp100: %s: clear_stats\n", dev->name);
2291 #endif
2293 save_flags( flags );
2294 cli();
2295 hp100_page( MAC_CTRL ); /* get all statistics bytes */
2296 hp100_inw( DROPPED );
2297 hp100_inb( CRC );
2298 hp100_inb( ABORT );
2299 hp100_page( PERFORMANCE );
2300 restore_flags( flags );
2305 * multicast setup
2309 * Set or clear the multicast filter for this adapter.
2312 static void hp100_set_multicast_list( struct net_device *dev )
2314 unsigned long flags;
2315 int ioaddr = dev->base_addr;
2316 struct hp100_private *lp = (struct hp100_private *)dev->priv;
2318 #ifdef HP100_DEBUG_B
2319 hp100_outw( 0x4218, TRACE );
2320 printk("hp100: %s: set_mc_list\n", dev->name);
2321 #endif
2323 save_flags( flags );
2324 cli();
2325 hp100_ints_off();
2326 hp100_page( MAC_CTRL );
2327 hp100_andb( ~(HP100_RX_EN | HP100_TX_EN), MAC_CFG_1 ); /* stop rx/tx */
2329 if ( dev->flags & IFF_PROMISC )
2331 lp->mac2_mode = HP100_MAC2MODE6; /* promiscuous mode = get all good */
2332 lp->mac1_mode = HP100_MAC1MODE6; /* packets on the net */
2333 memset( &lp->hash_bytes, 0xff, 8 );
2335 else if ( dev->mc_count || (dev->flags&IFF_ALLMULTI) )
2337 lp->mac2_mode = HP100_MAC2MODE5; /* multicast mode = get packets for */
2338 lp->mac1_mode = HP100_MAC1MODE5; /* me, broadcasts and all multicasts */
2339 #ifdef HP100_MULTICAST_FILTER /* doesn't work!!! */
2340 if ( dev -> flags & IFF_ALLMULTI )
2342 /* set hash filter to receive all multicast packets */
2343 memset( &lp->hash_bytes, 0xff, 8 );
2345 else
2347 int i, j, idx;
2348 u_char *addrs;
2349 struct dev_mc_list *dmi;
2351 memset( &lp->hash_bytes, 0x00, 8 );
2352 #ifdef HP100_DEBUG
2353 printk("hp100: %s: computing hash filter - mc_count = %i\n", dev -> name, dev -> mc_count );
2354 #endif
2355 for ( i = 0, dmi = dev -> mc_list; i < dev -> mc_count; i++, dmi = dmi -> next )
2357 addrs = dmi -> dmi_addr;
2358 if ( ( *addrs & 0x01 ) == 0x01 ) /* multicast address? */
2360 #ifdef HP100_DEBUG
2361 printk("hp100: %s: multicast = %02x:%02x:%02x:%02x:%02x:%02x, ",
2362 dev -> name,
2363 addrs[ 0 ], addrs[ 1 ], addrs[ 2 ],
2364 addrs[ 3 ], addrs[ 4 ], addrs[ 5 ] );
2365 #endif
2366 for ( j = idx = 0; j < 6; j++ )
2368 idx ^= *addrs++ & 0x3f;
2369 printk( ":%02x:", idx );
2371 #ifdef HP100_DEBUG
2372 printk("idx = %i\n", idx );
2373 #endif
2374 lp->hash_bytes[ idx >> 3 ] |= ( 1 << ( idx & 7 ) );
2378 #else
2379 memset( &lp->hash_bytes, 0xff, 8 );
2380 #endif
2382 else
2384 lp->mac2_mode = HP100_MAC2MODE3; /* normal mode = get packets for me */
2385 lp->mac1_mode = HP100_MAC1MODE3; /* and broadcasts */
2386 memset( &lp->hash_bytes, 0x00, 8 );
2389 if ( ( (hp100_inb(MAC_CFG_1) & 0x0f)!=lp->mac1_mode ) ||
2390 ( hp100_inb(MAC_CFG_2)!=lp->mac2_mode ) )
2392 int i;
2394 hp100_outb( lp->mac2_mode, MAC_CFG_2 );
2395 hp100_andb( HP100_MAC1MODEMASK, MAC_CFG_1 ); /* clear mac1 mode bits */
2396 hp100_orb( lp->mac1_mode, MAC_CFG_1 ); /* and set the new mode */
2398 hp100_page( MAC_ADDRESS );
2399 for ( i = 0; i < 8; i++ )
2400 hp100_outb( lp->hash_bytes[ i ], HASH_BYTE0 + i );
2401 #ifdef HP100_DEBUG
2402 printk("hp100: %s: mac1 = 0x%x, mac2 = 0x%x, multicast hash = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
2403 dev->name, lp->mac1_mode, lp->mac2_mode,
2404 lp->hash_bytes[ 0 ], lp->hash_bytes[ 1 ],
2405 lp->hash_bytes[ 2 ], lp->hash_bytes[ 3 ],
2406 lp->hash_bytes[ 4 ], lp->hash_bytes[ 5 ],
2407 lp->hash_bytes[ 6 ], lp->hash_bytes[ 7 ]
2409 #endif
2411 if(lp->lan_type==HP100_LAN_100)
2413 #ifdef HP100_DEBUG
2414 printk("hp100: %s: 100VG MAC settings have changed - relogin.\n", dev->name);
2415 #endif
2416 lp->hub_status=hp100_login_to_vg_hub( dev, TRUE ); /* force a relogin to the hub */
2419 else
2421 int i;
2422 u_char old_hash_bytes[ 8 ];
2424 hp100_page( MAC_ADDRESS );
2425 for ( i = 0; i < 8; i++ )
2426 old_hash_bytes[ i ] = hp100_inb( HASH_BYTE0 + i );
2427 if ( memcmp( old_hash_bytes, &lp->hash_bytes, 8 ) )
2429 for ( i = 0; i < 8; i++ )
2430 hp100_outb( lp->hash_bytes[ i ], HASH_BYTE0 + i );
2431 #ifdef HP100_DEBUG
2432 printk("hp100: %s: multicast hash = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
2433 dev->name,
2434 lp->hash_bytes[ 0 ], lp->hash_bytes[ 1 ],
2435 lp->hash_bytes[ 2 ], lp->hash_bytes[ 3 ],
2436 lp->hash_bytes[ 4 ], lp->hash_bytes[ 5 ],
2437 lp->hash_bytes[ 6 ], lp->hash_bytes[ 7 ]
2439 #endif
2441 if(lp->lan_type==HP100_LAN_100)
2443 #ifdef HP100_DEBUG
2444 printk("hp100: %s: 100VG MAC settings have changed - relogin.\n", dev->name);
2445 #endif
2446 lp->hub_status=hp100_login_to_vg_hub( dev, TRUE ); /* force a relogin to the hub */
2451 hp100_page( MAC_CTRL );
2452 hp100_orb( HP100_RX_EN | HP100_RX_IDLE | /* enable rx */
2453 HP100_TX_EN | HP100_TX_IDLE, MAC_CFG_1 ); /* enable tx */
2455 hp100_page( PERFORMANCE );
2456 hp100_ints_on();
2457 restore_flags( flags );
2462 * hardware interrupt handling
2465 static void hp100_interrupt( int irq, void *dev_id, struct pt_regs *regs )
2467 struct net_device *dev = (struct net_device *)dev_id;
2468 struct hp100_private *lp = (struct hp100_private *)dev->priv;
2470 int ioaddr;
2471 u_int val;
2473 if ( dev == NULL ) return;
2474 ioaddr = dev->base_addr;
2476 if ( dev->interrupt )
2477 printk( "hp100: %s: re-entering the interrupt handler\n", dev->name );
2478 hp100_ints_off();
2479 dev->interrupt = 1; /* mark that we are inside the handler */
2481 #ifdef HP100_DEBUG_B
2482 hp100_outw( 0x4219, TRACE );
2483 #endif
2485 /* hp100_page( PERFORMANCE ); */
2486 val = hp100_inw( IRQ_STATUS );
2487 #ifdef HP100_DEBUG_IRQ
2488 printk( "hp100: %s: mode=%x,IRQ_STAT=0x%.4x,RXPKTCNT=0x%.2x RXPDL=0x%.2x TXPKTCNT=0x%.2x TXPDL=0x%.2x\n",
2489 dev->name,
2490 lp->mode,
2491 (u_int)val,
2492 hp100_inb( RX_PKT_CNT ),
2493 hp100_inb( RX_PDL ),
2494 hp100_inb( TX_PKT_CNT ),
2495 hp100_inb( TX_PDL )
2497 #endif
2499 if(val==0) /* might be a shared interrupt */
2501 dev->interrupt=0;
2502 hp100_ints_on();
2503 return;
2505 /* We're only interested in those interrupts we really enabled. */
2506 /* val &= hp100_inw( IRQ_MASK ); */
2509 * RX_PDL_FILL_COMPL is set whenever a RX_PDL has been executed. A RX_PDL
2510 * is considered executed whenever the RX_PDL data structure is no longer
2511 * needed.
2513 if ( val & HP100_RX_PDL_FILL_COMPL )
2515 if(lp->mode==1)
2516 hp100_rx_bm( dev );
2517 else
2519 printk("hp100: %s: rx_pdl_fill_compl interrupt although not busmaster?\n", dev->name);
2524 * The RX_PACKET interrupt is set, when the receive packet counter is
2525 * non zero. We use this interrupt for receiving in slave mode. In
2526 * busmaster mode, we use it to make sure we did not miss any rx_pdl_fill
2527 * interrupts. If rx_pdl_fill_compl is not set and rx_packet is set, then
2528 * we somehow have missed a rx_pdl_fill_compl interrupt.
2531 if ( val & HP100_RX_PACKET ) /* Receive Packet Counter is non zero */
2533 if(lp->mode!=1) /* non busmaster */
2534 hp100_rx( dev );
2535 else if ( !(val & HP100_RX_PDL_FILL_COMPL ))
2537 /* Shouldnt happen - maybe we missed a RX_PDL_FILL Interrupt? */
2538 hp100_rx_bm( dev );
2543 * Ack. that we have noticed the interrupt and thereby allow next one.
2544 * Note that this is now done after the slave rx function, since first
2545 * acknowledging and then setting ADV_NXT_PKT caused an extra interrupt
2546 * on the J2573.
2548 hp100_outw( val, IRQ_STATUS );
2551 * RX_ERROR is set when a packet is dropped due to no memory resources on
2552 * the card or when a RCV_ERR occurs.
2553 * TX_ERROR is set when a TX_ABORT condition occurs in the MAC->exists
2554 * only in the 802.3 MAC and happens when 16 collisions occur during a TX
2556 if ( val & ( HP100_TX_ERROR | HP100_RX_ERROR ) )
2558 #ifdef HP100_DEBUG_IRQ
2559 printk("hp100: %s: TX/RX Error IRQ\n", dev->name);
2560 #endif
2561 hp100_update_stats( dev );
2562 if(lp->mode==1)
2564 hp100_rxfill( dev );
2565 hp100_clean_txring( dev );
2570 * RX_PDA_ZERO is set when the PDA count goes from non-zero to zero.
2572 if ( (lp->mode==1)&&(val &(HP100_RX_PDA_ZERO)) )
2573 hp100_rxfill( dev );
2576 * HP100_TX_COMPLETE interrupt occurs when packet transmitted on wire
2577 * is completed
2579 if ( (lp->mode==1) && ( val & ( HP100_TX_COMPLETE )) )
2580 hp100_clean_txring( dev );
2583 * MISC_ERROR is set when either the LAN link goes down or a detected
2584 * bus error occurs.
2586 if ( val & HP100_MISC_ERROR ) /* New for J2585B */
2588 #ifdef HP100_DEBUG_IRQ
2589 printk("hp100: %s: Misc. Error Interrupt - Check cabling.\n", dev->name);
2590 #endif
2591 if(lp->mode==1)
2593 hp100_clean_txring( dev );
2594 hp100_rxfill( dev );
2596 hp100_misc_interrupt( dev );
2599 dev->interrupt = 0;
2600 hp100_ints_on();
2605 * some misc functions
2608 static void hp100_start_interface( struct net_device *dev )
2610 unsigned long flags;
2611 int ioaddr = dev->base_addr;
2612 struct hp100_private *lp = (struct hp100_private *)dev->priv;
2614 #ifdef HP100_DEBUG_B
2615 hp100_outw( 0x4220, TRACE );
2616 printk("hp100: %s: hp100_start_interface\n",dev->name);
2617 #endif
2619 save_flags( flags );
2620 cli();
2622 /* Ensure the adapter does not want to request an interrupt when */
2623 /* enabling the IRQ line to be active on the bus (i.e. not tri-stated) */
2624 hp100_page( PERFORMANCE );
2625 hp100_outw( 0xfefe, IRQ_MASK ); /* mask off all ints */
2626 hp100_outw( 0xffff, IRQ_STATUS ); /* ack all IRQs */
2627 hp100_outw( HP100_FAKE_INT|HP100_INT_EN|HP100_RESET_LB, OPTION_LSW);
2628 /* Un Tri-state int. TODO: Check if shared interrupts can be realised? */
2629 hp100_outw( HP100_TRI_INT | HP100_RESET_HB, OPTION_LSW );
2631 if(lp->mode==1)
2633 /* Make sure BM bit is set... */
2634 hp100_page(HW_MAP);
2635 hp100_orb( HP100_BM_MASTER, BM );
2636 hp100_rxfill( dev );
2638 else if(lp->mode==2)
2640 /* Enable memory mapping. Note: Don't do this when busmaster. */
2641 hp100_outw( HP100_MMAP_DIS | HP100_RESET_HB, OPTION_LSW );
2644 hp100_page(PERFORMANCE);
2645 hp100_outw( 0xfefe, IRQ_MASK ); /* mask off all ints */
2646 hp100_outw( 0xffff, IRQ_STATUS ); /* ack IRQ */
2648 /* enable a few interrupts: */
2649 if(lp->mode==1) /* busmaster mode */
2651 hp100_outw( HP100_RX_PDL_FILL_COMPL |
2652 HP100_RX_PDA_ZERO |
2653 HP100_RX_ERROR |
2654 /* HP100_RX_PACKET | */
2655 /* HP100_RX_EARLY_INT | */ HP100_SET_HB |
2656 /* HP100_TX_PDA_ZERO | */
2657 HP100_TX_COMPLETE |
2658 /* HP100_MISC_ERROR | */
2659 HP100_TX_ERROR | HP100_SET_LB, IRQ_MASK );
2661 else
2663 hp100_outw( HP100_RX_PACKET |
2664 HP100_RX_ERROR | HP100_SET_HB |
2665 HP100_TX_ERROR | HP100_SET_LB , IRQ_MASK );
2668 /* Enable MAC Tx and RX, set MAC modes, ... */
2669 hp100_set_multicast_list( dev );
2671 restore_flags( flags );
2675 static void hp100_stop_interface( struct net_device *dev )
2677 struct hp100_private *lp = (struct hp100_private *)dev->priv;
2678 int ioaddr = dev->base_addr;
2679 u_int val;
2681 #ifdef HP100_DEBUG_B
2682 printk("hp100: %s: hp100_stop_interface\n",dev->name);
2683 hp100_outw( 0x4221, TRACE );
2684 #endif
2686 if (lp->mode==1)
2687 hp100_BM_shutdown( dev );
2688 else
2690 /* Note: MMAP_DIS will be reenabled by start_interface */
2691 hp100_outw( HP100_INT_EN | HP100_RESET_LB |
2692 HP100_TRI_INT | HP100_MMAP_DIS | HP100_SET_HB, OPTION_LSW );
2693 val = hp100_inw( OPTION_LSW );
2695 hp100_page( MAC_CTRL );
2696 hp100_andb( ~(HP100_RX_EN | HP100_TX_EN), MAC_CFG_1 );
2698 if ( !(val & HP100_HW_RST) ) return; /* If reset, imm. return ... */
2699 /* ... else: busy wait until idle */
2700 for ( val = 0; val < 6000; val++ )
2701 if ( ( hp100_inb( MAC_CFG_1 ) & (HP100_TX_IDLE | HP100_RX_IDLE) ) ==
2702 (HP100_TX_IDLE | HP100_RX_IDLE) )
2704 hp100_page(PERFORMANCE);
2705 return;
2707 printk( "hp100: %s: hp100_stop_interface - timeout\n", dev->name );
2708 hp100_page(PERFORMANCE);
2713 static void hp100_load_eeprom( struct net_device *dev, u_short probe_ioaddr )
2715 int i;
2716 int ioaddr = probe_ioaddr > 0 ? probe_ioaddr : dev->base_addr;
2718 #ifdef HP100_DEBUG_B
2719 hp100_outw( 0x4222, TRACE );
2720 #endif
2722 hp100_page( EEPROM_CTRL );
2723 hp100_andw( ~HP100_EEPROM_LOAD, EEPROM_CTRL );
2724 hp100_orw( HP100_EEPROM_LOAD, EEPROM_CTRL );
2725 for ( i = 0; i < 10000; i++ )
2726 if ( !( hp100_inb( OPTION_MSW ) & HP100_EE_LOAD ) ) return;
2727 printk( "hp100: %s: hp100_load_eeprom - timeout\n", dev->name );
2731 /* Sense connection status.
2732 * return values: LAN_10 - Connected to 10Mbit/s network
2733 * LAN_100 - Connected to 100Mbit/s network
2734 * LAN_ERR - not connected or 100Mbit/s Hub down
2736 static int hp100_sense_lan( struct net_device *dev )
2738 int ioaddr = dev->base_addr;
2739 u_short val_VG, val_10;
2740 struct hp100_private *lp = (struct hp100_private *)dev->priv;
2742 #ifdef HP100_DEBUG_B
2743 hp100_outw( 0x4223, TRACE );
2744 #endif
2746 hp100_page( MAC_CTRL );
2747 val_10 = hp100_inb( 10_LAN_CFG_1 );
2748 val_VG = hp100_inb( VG_LAN_CFG_1 );
2749 hp100_page( PERFORMANCE );
2750 #ifdef HP100_DEBUG
2751 printk( "hp100: %s: sense_lan: val_VG = 0x%04x, val_10 = 0x%04x\n", dev->name, val_VG, val_10 );
2752 #endif
2754 if ( val_10 & HP100_LINK_BEAT_ST ) /* 10Mb connection is active */
2755 return HP100_LAN_10;
2757 if ( val_10 & HP100_AUI_ST ) /* have we BNC or AUI onboard? */
2759 val_10 |= HP100_AUI_SEL | HP100_LOW_TH;
2760 hp100_page( MAC_CTRL );
2761 hp100_outb( val_10, 10_LAN_CFG_1 );
2762 hp100_page( PERFORMANCE );
2763 return HP100_LAN_10;
2766 if ( (lp->id->id == 0x02019F022) ||
2767 (lp->id->id == 0x01042103c) ||
2768 (lp->id->id == 0x01040103c) )
2769 return HP100_LAN_ERR; /* Those cards don't have a 100 Mbit connector */
2771 if ( val_VG & HP100_LINK_CABLE_ST ) /* Can hear the HUBs tone. */
2772 return HP100_LAN_100;
2773 return HP100_LAN_ERR;
2778 static int hp100_down_vg_link( struct net_device *dev )
2780 struct hp100_private *lp = (struct hp100_private *)dev->priv;
2781 int ioaddr = dev->base_addr;
2782 unsigned long time;
2783 long savelan, newlan;
2785 #ifdef HP100_DEBUG_B
2786 hp100_outw( 0x4224, TRACE );
2787 printk("hp100: %s: down_vg_link\n", dev->name);
2788 #endif
2790 hp100_page( MAC_CTRL );
2791 time=jiffies+(HZ/4);
2793 if ( hp100_inb( VG_LAN_CFG_1 ) & HP100_LINK_CABLE_ST ) break;
2794 } while (time_after(time, jiffies));
2796 if ( time_after_eq(jiffies, time) ) /* no signal->no logout */
2797 return 0;
2799 /* Drop the VG Link by clearing the link up cmd and load addr.*/
2801 hp100_andb( ~( HP100_LOAD_ADDR| HP100_LINK_CMD), VG_LAN_CFG_1);
2802 hp100_orb( HP100_VG_SEL, VG_LAN_CFG_1);
2804 /* Conditionally stall for >250ms on Link-Up Status (to go down) */
2805 time=jiffies+(HZ/2);
2807 if ( !(hp100_inb( VG_LAN_CFG_1) & HP100_LINK_UP_ST) ) break;
2808 } while(time_after(time, jiffies));
2810 #ifdef HP100_DEBUG
2811 if (time_after_eq(jiffies, time))
2812 printk("hp100: %s: down_vg_link: Link does not go down?\n", dev->name);
2813 #endif
2815 /* To prevent condition where Rev 1 VG MAC and old hubs do not complete */
2816 /* logout under traffic (even though all the status bits are cleared), */
2817 /* do this workaround to get the Rev 1 MAC in its idle state */
2818 if ( lp->chip==HP100_CHIPID_LASSEN )
2820 /* Reset VG MAC to insure it leaves the logoff state even if */
2821 /* the Hub is still emitting tones */
2822 hp100_andb(~HP100_VG_RESET, VG_LAN_CFG_1);
2823 udelay(1500); /* wait for >1ms */
2824 hp100_orb(HP100_VG_RESET, VG_LAN_CFG_1); /* Release Reset */
2825 udelay(1500);
2828 /* New: For lassen, switch to 10 Mbps mac briefly to clear training ACK */
2829 /* to get the VG mac to full reset. This is not req.d with later chips */
2830 /* Note: It will take the between 1 and 2 seconds for the VG mac to be */
2831 /* selected again! This will be left to the connect hub function to */
2832 /* perform if desired. */
2833 if (lp->chip==HP100_CHIPID_LASSEN)
2835 /* Have to write to 10 and 100VG control registers simultaneously */
2836 savelan=newlan=hp100_inl(10_LAN_CFG_1); /* read 10+100 LAN_CFG regs */
2837 newlan &= ~(HP100_VG_SEL<<16);
2838 newlan |= (HP100_DOT3_MAC)<<8;
2839 hp100_andb( ~HP100_AUTO_MODE, MAC_CFG_3); /* Autosel off */
2840 hp100_outl(newlan, 10_LAN_CFG_1);
2842 /* Conditionally stall for 5sec on VG selected. */
2843 time=jiffies+(HZ*5);
2845 if( !(hp100_inb(MAC_CFG_4) & HP100_MAC_SEL_ST) ) break;
2846 } while(time_after(time, jiffies));
2848 hp100_orb( HP100_AUTO_MODE, MAC_CFG_3); /* Autosel back on */
2849 hp100_outl(savelan, 10_LAN_CFG_1);
2852 time=jiffies+(3*HZ); /* Timeout 3s */
2853 do {
2854 if ( (hp100_inb( VG_LAN_CFG_1 )&HP100_LINK_CABLE_ST) == 0) break;
2855 } while (time_after(time, jiffies));
2857 if(time_before_eq(time, jiffies))
2859 #ifdef HP100_DEBUG
2860 printk( "hp100: %s: down_vg_link: timeout\n", dev->name );
2861 #endif
2862 return -EIO;
2865 time=jiffies+(2*HZ); /* This seems to take a while.... */
2866 do {} while (time_after(time, jiffies));
2868 return 0;
2872 static int hp100_login_to_vg_hub( struct net_device *dev, u_short force_relogin )
2874 int ioaddr = dev->base_addr;
2875 struct hp100_private *lp = (struct hp100_private *)dev->priv;
2876 u_short val=0;
2877 unsigned long time;
2878 int startst;
2880 #ifdef HP100_DEBUG_B
2881 hp100_outw( 0x4225, TRACE );
2882 printk("hp100: %s: login_to_vg_hub\n", dev->name);
2883 #endif
2885 /* Initiate a login sequence iff VG MAC is enabled and either Load Address
2886 * bit is zero or the force relogin flag is set (e.g. due to MAC address or
2887 * promiscuous mode change)
2889 hp100_page( MAC_CTRL );
2890 startst=hp100_inb( VG_LAN_CFG_1 );
2891 if((force_relogin==TRUE)||(hp100_inb( MAC_CFG_4 )&HP100_MAC_SEL_ST))
2893 #ifdef HP100_DEBUG_TRAINING
2894 printk("hp100: %s: Start training\n", dev->name);
2895 #endif
2897 /* Ensure VG Reset bit is 1 (i.e., do not reset)*/
2898 hp100_orb( HP100_VG_RESET , VG_LAN_CFG_1 );
2900 /* If Lassen AND auto-select-mode AND VG tones were sensed on */
2901 /* entry then temporarily put them into force 100Mbit mode */
2902 if((lp->chip==HP100_CHIPID_LASSEN)&&( startst & HP100_LINK_CABLE_ST ) )
2903 hp100_andb( ~HP100_DOT3_MAC, 10_LAN_CFG_2 );
2905 /* Drop the VG link by zeroing Link Up Command and Load Address */
2906 hp100_andb( ~(HP100_LINK_CMD/* |HP100_LOAD_ADDR */), VG_LAN_CFG_1);
2908 #ifdef HP100_DEBUG_TRAINING
2909 printk("hp100: %s: Bring down the link\n", dev->name);
2910 #endif
2912 /* Wait for link to drop */
2913 time = jiffies + (HZ/10);
2914 do {
2915 if (~(hp100_inb( VG_LAN_CFG_1 )& HP100_LINK_UP_ST) ) break;
2916 } while (time_after(time, jiffies));
2918 /* Start an addressed training and optionally request promiscuous port */
2919 if ( (dev->flags) & IFF_PROMISC )
2921 hp100_orb( HP100_PROM_MODE, VG_LAN_CFG_2);
2922 if(lp->chip==HP100_CHIPID_LASSEN)
2923 hp100_orw( HP100_MACRQ_PROMSC, TRAIN_REQUEST );
2925 else
2927 hp100_andb( ~HP100_PROM_MODE, VG_LAN_CFG_2);
2928 /* For ETR parts we need to reset the prom. bit in the training
2929 * register, otherwise promiscious mode won't be disabled.
2931 if(lp->chip==HP100_CHIPID_LASSEN)
2933 hp100_andw( ~HP100_MACRQ_PROMSC, TRAIN_REQUEST );
2937 /* With ETR parts, frame format request bits can be set. */
2938 if(lp->chip==HP100_CHIPID_LASSEN)
2939 hp100_orb( HP100_MACRQ_FRAMEFMT_EITHER, TRAIN_REQUEST);
2941 hp100_orb( HP100_LINK_CMD|HP100_LOAD_ADDR|HP100_VG_RESET, VG_LAN_CFG_1);
2943 /* Note: Next wait could be omitted for Hood and earlier chips under */
2944 /* certain circumstances */
2945 /* TODO: check if hood/earlier and skip wait. */
2947 /* Wait for either short timeout for VG tones or long for login */
2948 /* Wait for the card hardware to signalise link cable status ok... */
2949 hp100_page( MAC_CTRL );
2950 time = jiffies + ( 1*HZ ); /* 1 sec timeout for cable st */
2951 do {
2952 if ( hp100_inb( VG_LAN_CFG_1 ) & HP100_LINK_CABLE_ST ) break;
2953 } while ( time_before(jiffies, time) );
2955 if ( time_after_eq(jiffies, time) )
2957 #ifdef HP100_DEBUG_TRAINING
2958 printk( "hp100: %s: Link cable status not ok? Training aborted.\n", dev->name );
2959 #endif
2961 else
2963 #ifdef HP100_DEBUG_TRAINING
2964 printk( "hp100: %s: HUB tones detected. Trying to train.\n", dev->name);
2965 #endif
2967 time = jiffies + ( 2*HZ ); /* again a timeout */
2968 do {
2969 val = hp100_inb( VG_LAN_CFG_1 );
2970 if ( (val & ( HP100_LINK_UP_ST )) )
2972 #ifdef HP100_DEBUG_TRAINING
2973 printk( "hp100: %s: Passed training.\n", dev->name);
2974 #endif
2975 break;
2977 } while ( time_after(time, jiffies) );
2980 /* If LINK_UP_ST is set, then we are logged into the hub. */
2981 if ( time_before_eq(jiffies, time) && (val & HP100_LINK_UP_ST) )
2983 #ifdef HP100_DEBUG_TRAINING
2984 printk( "hp100: %s: Successfully logged into the HUB.\n", dev->name);
2985 if(lp->chip==HP100_CHIPID_LASSEN)
2987 val = hp100_inw(TRAIN_ALLOW);
2988 printk( "hp100: %s: Card supports 100VG MAC Version \"%s\" ",
2989 dev->name,(hp100_inw(TRAIN_REQUEST)&HP100_CARD_MACVER) ? "802.12" : "Pre");
2990 printk( "Driver will use MAC Version \"%s\"\n",
2991 ( val & HP100_HUB_MACVER) ? "802.12" : "Pre" );
2992 printk( "hp100: %s: Frame format is %s.\n",dev->name,(val&HP100_MALLOW_FRAMEFMT)?"802.5":"802.3");
2994 #endif
2996 else
2998 /* If LINK_UP_ST is not set, login was not successful */
2999 printk("hp100: %s: Problem logging into the HUB.\n",dev->name);
3000 if(lp->chip==HP100_CHIPID_LASSEN)
3002 /* Check allowed Register to find out why there is a problem. */
3003 val = hp100_inw( TRAIN_ALLOW ); /* wont work on non-ETR card */
3004 #ifdef HP100_DEBUG_TRAINING
3005 printk("hp100: %s: MAC Configuration requested: 0x%04x, HUB allowed: 0x%04x\n", dev->name, hp100_inw(TRAIN_REQUEST), val);
3006 #endif
3007 if ( val & HP100_MALLOW_ACCDENIED )
3008 printk("hp100: %s: HUB access denied.\n", dev->name);
3009 if ( val & HP100_MALLOW_CONFIGURE )
3010 printk("hp100: %s: MAC Configuration is incompatible with the Network.\n", dev->name);
3011 if ( val & HP100_MALLOW_DUPADDR )
3012 printk("hp100: %s: Duplicate MAC Address on the Network.\n", dev->name);
3016 /* If we have put the chip into forced 100 Mbit mode earlier, go back */
3017 /* to auto-select mode */
3019 if( (lp->chip==HP100_CHIPID_LASSEN)&&(startst & HP100_LINK_CABLE_ST) )
3021 hp100_page( MAC_CTRL );
3022 hp100_orb( HP100_DOT3_MAC, 10_LAN_CFG_2 );
3025 val=hp100_inb(VG_LAN_CFG_1);
3027 /* Clear the MISC_ERROR Interrupt, which might be generated when doing the relogin */
3028 hp100_page(PERFORMANCE);
3029 hp100_outw( HP100_MISC_ERROR, IRQ_STATUS);
3031 if (val&HP100_LINK_UP_ST)
3032 return(0); /* login was ok */
3033 else
3035 printk("hp100: %s: Training failed.\n", dev->name);
3036 hp100_down_vg_link( dev );
3037 return -EIO;
3040 /* no forced relogin & already link there->no training. */
3041 return -EIO;
3045 static void hp100_cascade_reset( struct net_device *dev, u_short enable )
3047 int ioaddr = dev->base_addr;
3048 struct hp100_private *lp = (struct hp100_private *)dev->priv;
3049 int i;
3051 #ifdef HP100_DEBUG_B
3052 hp100_outw( 0x4226, TRACE );
3053 printk("hp100: %s: cascade_reset\n", dev->name);
3054 #endif
3056 if (enable==TRUE)
3058 hp100_outw( HP100_HW_RST | HP100_RESET_LB, OPTION_LSW );
3059 if(lp->chip==HP100_CHIPID_LASSEN)
3061 /* Lassen requires a PCI transmit fifo reset */
3062 hp100_page( HW_MAP );
3063 hp100_andb( ~HP100_PCI_RESET, PCICTRL2 );
3064 hp100_orb( HP100_PCI_RESET, PCICTRL2 );
3065 /* Wait for min. 300 ns */
3066 /* we cant use jiffies here, because it may be */
3067 /* that we have disabled the timer... */
3068 for (i=0; i<0xffff; i++);
3069 hp100_andb( ~HP100_PCI_RESET, PCICTRL2 );
3070 hp100_page( PERFORMANCE );
3073 else
3074 { /* bring out of reset */
3075 hp100_outw(HP100_HW_RST|HP100_SET_LB, OPTION_LSW);
3076 for (i=0; i<0xffff; i++ );
3077 hp100_page(PERFORMANCE);
3081 #ifdef HP100_DEBUG
3082 void hp100_RegisterDump( struct net_device *dev )
3084 int ioaddr=dev->base_addr;
3085 int Page;
3086 int Register;
3088 /* Dump common registers */
3089 printk("hp100: %s: Cascade Register Dump\n", dev->name);
3090 printk("hardware id #1: 0x%.2x\n",hp100_inb(HW_ID));
3091 printk("hardware id #2/paging: 0x%.2x\n",hp100_inb(PAGING));
3092 printk("option #1: 0x%.4x\n",hp100_inw(OPTION_LSW));
3093 printk("option #2: 0x%.4x\n",hp100_inw(OPTION_MSW));
3095 /* Dump paged registers */
3096 for (Page = 0; Page < 8; Page++)
3098 /* Dump registers */
3099 printk("page: 0x%.2x\n",Page);
3100 outw( Page, ioaddr+0x02);
3101 for (Register = 0x8; Register < 0x22; Register += 2)
3103 /* Display Register contents except data port */
3104 if (((Register != 0x10) && (Register != 0x12)) || (Page > 0))
3106 printk("0x%.2x = 0x%.4x\n",Register,inw(ioaddr+Register));
3110 hp100_page(PERFORMANCE);
3112 #endif
3117 * module section
3120 #ifdef MODULE
3122 /* Parameters set by insmod */
3123 int hp100_port[5] = { 0, -1, -1, -1, -1 };
3124 #ifdef LINUX_2_1
3125 MODULE_PARM(hp100_port, "1-5i");
3126 #endif
3128 #ifdef LINUX_2_1
3129 char hp100_name[5][IFNAMSIZ] = { "", "", "", "", "" };
3130 MODULE_PARM(hp100_name, "1-5c" __MODULE_STRING(IFNAMSIZ));
3131 #else
3132 static char devname[5][IFNAMSIZ] = { "", "", "", "", "" };
3133 static char *hp100_name[5] = { devname[0], devname[1],
3134 devname[2], devname[3],
3135 devname[4] };
3136 #endif
3138 /* List of devices */
3139 static struct net_device *hp100_devlist[5] = { NULL, NULL, NULL, NULL, NULL };
3142 * Note: if you have more than five 100vg cards in your pc, feel free to
3143 * increase this value
3147 * Note: to register three eisa or pci devices, use:
3148 * option hp100 hp100_port=0,0,0
3149 * to register one card at io 0x280 as eth239, use:
3150 * option hp100 hp100_port=0x280 hp100_name=eth239
3153 int init_module( void )
3155 int i, cards;
3157 if (hp100_port == 0 && !EISA_bus && !pcibios_present())
3158 printk("hp100: You should not use auto-probing with insmod!\n");
3160 /* Loop on all possible base addresses */
3161 i = -1; cards = 0;
3162 while((hp100_port[++i] != -1) && (i < 5))
3164 /* Create device and set basics args */
3165 hp100_devlist[i] = kmalloc(sizeof(struct net_device), GFP_KERNEL);
3166 memset(hp100_devlist[i], 0x00, sizeof(struct net_device));
3167 hp100_devlist[i]->name = hp100_name[i];
3168 hp100_devlist[i]->base_addr = hp100_port[i];
3169 hp100_devlist[i]->init = &hp100_probe;
3171 /* Try to create the device */
3172 if(register_netdev(hp100_devlist[i]) != 0)
3174 /* DeAllocate everything */
3175 /* Note: if dev->priv is mallocated, there is no way to fail */
3176 kfree_s(hp100_devlist[i], sizeof(struct net_device));
3177 hp100_devlist[i] = (struct net_device *) NULL;
3179 else
3180 cards++;
3181 } /* Loop over all devices */
3183 return cards > 0 ? 0 : -ENODEV;
3186 void cleanup_module( void )
3188 int i;
3190 /* TODO: Check if all skb's are released/freed. */
3191 for(i = 0; i < 5; i++)
3192 if(hp100_devlist[i] != (struct net_device *) NULL)
3194 unregister_netdev( hp100_devlist[i] );
3195 release_region( hp100_devlist[i]->base_addr, HP100_REGION_SIZE );
3196 if( ((struct hp100_private *)hp100_devlist[i]->priv)->mode==1 ) /* busmaster */
3197 kfree_s( ((struct hp100_private *)hp100_devlist[i]->priv)->page_vaddr, MAX_RINGSIZE+0x0f);
3198 if ( ((struct hp100_private *)hp100_devlist[i]->priv) -> mem_ptr_virt )
3199 iounmap( ((struct hp100_private *)hp100_devlist[i]->priv) -> mem_ptr_virt );
3200 kfree_s( hp100_devlist[i]->priv, sizeof( struct hp100_private ) );
3201 hp100_devlist[i]->priv = NULL;
3202 kfree_s(hp100_devlist[i], sizeof(struct net_device));
3203 hp100_devlist[i] = (struct net_device *) NULL;
3207 #endif /* MODULE */
3212 * Local variables:
3213 * compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c hp100.c"
3214 * c-indent-level: 2
3215 * tab-width: 8
3216 * End: