3 ** HP CASCADE Architecture Driver for 100VG-AnyLan Network Adapters
5 ** $Id: hp100.c,v 1.57 1998/04/10 16:27:23 perex Exp perex $
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>
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
22 ** but it should also work with the other CASCADE based adapters.
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.
50 ** - updates for new PCI interface for 2.1 kernels
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
57 ** - included fix for Compex FreedomLine PCI adapter
60 ** - fixed bad initialization in init_module
61 ** - added Compex FreedomLine adapter
62 ** - some fixes in card initialization
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
72 ** - fixed bug in multicast support
76 #define HP100_DEFAULT_PRIORITY_TX 0
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 */
84 #undef HP100_DEBUG_IRQ
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>
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
113 typedef struct net_device_stats hp100_stats_t
;
116 #include <linux/bios32.h>
117 #define ioremap vremap
118 #define iounmap vfree
119 typedef struct enet_statistics hp100_stats_t
;
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
135 #ifndef PCI_VENDOR_ID_COMPEX
136 #define PCI_VENDOR_ID_COMPEX 0x11f6
138 #ifndef PCI_DEVICE_ID_COMPEX_ENET100VG4
139 #define PCI_DEVICE_ID_COMPEX_ENET100VG4 0x0112
141 #ifndef PCI_VENDOR_ID_COMPEX2
142 #define PCI_VENDOR_ID_COMPEX2 0x101a
144 #ifndef PCI_DEVICE_ID_COMPEX2_100VG
145 #define PCI_DEVICE_ID_COMPEX2_100VG 0x0005
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
158 #ifndef HP100_DEFAULT_PRIORITY_TX
159 /* default - don't enable transmit outgoing packets as priority */
160 #define HP100_DEFAULT_PRIORITY_TX 0
167 struct hp100_eisa_id
{
173 struct hp100_pci_id
{
178 struct hp100_private
{
179 struct hp100_eisa_id
*id
;
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 */
190 u_char pci_device_fn
;
192 struct pci_dev
*pci_dev
;
194 short mem_mapped
; /* memory mapped access */
195 u32
*mem_ptr_virt
; /* virtual memory mapped area, maybe NULL */
196 unsigned long 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? */
201 u_char hash_bytes
[ 8 ];
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 */
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;
289 MODULE_PARM( hp100_rx_ratio
, "1i" );
290 MODULE_PARM( hp100_priority_tx
, "1i" );
291 MODULE_PARM( hp100_mode
, "1i" );
299 static int hp100_probe1( struct net_device
*dev
, int ioaddr
, u_char bus
, struct pci_dev
*pci_dev
);
301 static int hp100_probe1( struct net_device
*dev
, int ioaddr
, u_char bus
, u_char pci_bus
, u_char pci_device_fn
);
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
);
330 static void hp100_RegisterDump( struct net_device
*dev
);
333 /* TODO: This function should not really be needed in a good design... */
334 static void wait( void )
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;
350 int pci_start_index
= 0;
354 hp100_outw( 0x4200, TRACE
);
355 printk( "hp100: %s: probe\n", dev
->name
);
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 )
363 return hp100_probe1( dev
, base_addr
, HP100_BUS_ISA
, NULL
);
365 return hp100_probe1( dev
, base_addr
, HP100_BUS_ISA
, 0, 0 );
367 if ( EISA_bus
&& base_addr
>= 0x1c38 && ( (base_addr
- 0x1c38) & 0x3ff ) == 0 )
369 return hp100_probe1( dev
, base_addr
, HP100_BUS_EISA
, NULL
);
371 return hp100_probe1( dev
, base_addr
, HP100_BUS_EISA
, 0, 0 );
375 printk( "hp100: %s: You must specify card # in i/o address parameter for PCI bus...", dev
->name
);
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 );
386 if ( base_addr
> 0 && base_addr
< 8 + 1 )
387 pci_start_index
= 0x100 | ( base_addr
- 1 );
390 if ( base_addr
!= 0 ) return -ENXIO
;
392 /* at first - scan PCI bus(es) */
395 if ( pcibios_present() )
399 struct pci_dev
*pci_dev
= NULL
;
404 #ifdef HP100_DEBUG_PCI
405 printk( "hp100: %s: PCI BIOS is present, checking for devices..\n", dev
->name
);
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) ) {
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
) ) {
423 printk( "hp100: %s: PCI I/O Bit has not been set. Setting...\n", dev
->name
);
425 pci_command
|= PCI_COMMAND_IO
;
426 pci_write_config_word( pci_dev
, PCI_COMMAND
, pci_command
);
428 if ( !( pci_command
& PCI_COMMAND_MASTER
) ) {
430 printk( "hp100: %s: PCI Master Bit has not been set. Setting...\n", dev
->name
);
432 pci_command
|= PCI_COMMAND_MASTER
;
433 pci_write_config_word( pci_dev
, PCI_COMMAND
, pci_command
);
436 printk( "hp100: %s: PCI adapter found at 0x%x\n", dev
->name
, ioaddr
);
438 if ( hp100_probe1( dev
, ioaddr
, HP100_BUS_PCI
, pci_dev
) == 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
;
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
,
453 &pci_device_fn
) == 0 ) goto __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
) )
469 printk( "hp100: %s: PCI I/O Bit has not been set. Setting...\n", dev
->name
);
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
) )
478 printk( "hp100: %s: PCI Master Bit has not been set. Setting...\n", dev
->name
);
480 pci_command
|= PCI_COMMAND_MASTER
;
481 pcibios_write_config_word( pci_bus
, pci_device_fn
,
482 PCI_COMMAND
, pci_command
);
485 printk( "hp100: %s: PCI adapter found at 0x%x\n", dev
->name
, ioaddr
);
487 if ( hp100_probe1( dev
, ioaddr
, HP100_BUS_PCI
, pci_bus
, pci_device_fn
) == 0 )
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;
500 if ( hp100_probe1( dev
, ioaddr
, HP100_BUS_EISA
, NULL
) == 0 ) return 0;
502 if ( hp100_probe1( dev
, ioaddr
, HP100_BUS_EISA
, 0, 0 ) == 0 ) return 0;
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;
511 if ( hp100_probe1( dev
, ioaddr
, HP100_BUS_ISA
, NULL
) == 0 ) return 0;
513 if ( hp100_probe1( dev
, ioaddr
, HP100_BUS_ISA
, 0, 0 ) == 0 ) return 0;
522 static int __init
hp100_probe1( struct net_device
*dev
, int ioaddr
, u_char bus
, struct pci_dev
*pci_dev
)
524 static int __init
hp100_probe1( struct net_device
*dev
, int ioaddr
, u_char bus
, u_char pci_bus
, u_char pci_device_fn
)
532 u_int memory_size
= 0, virt_memory_size
= 0;
533 u_short local_mode
, lsw
;
535 unsigned long mem_ptr_phys
;
537 struct hp100_private
*lp
;
538 struct hp100_eisa_id
*eid
;
541 hp100_outw( 0x4201, TRACE
);
542 printk("hp100: %s: probe1\n",dev
->name
);
548 printk( "hp100_probe1: %s: dev == NULL ?\n", dev
->name
);
553 if ( hp100_inw( HW_ID
) != HP100_HW_ID_CASCADE
)
559 chip
= hp100_inw( PAGING
) & HP100_CHIPID_MASK
;
561 if ( chip
== HP100_CHIPID_SHASTA
)
562 printk("hp100: %s: Shasta Chip detected. (This is a pre 802.12 chip)\n", dev
->name
);
563 else if ( chip
== HP100_CHIPID_RAINIER
)
564 printk("hp100: %s: Rainier Chip detected. (This is a pre 802.12 chip)\n", dev
->name
);
565 else if ( chip
== HP100_CHIPID_LASSEN
)
566 printk("hp100: %s: Lassen Chip detected.\n", dev
->name
);
568 printk("hp100: %s: Warning: Unknown CASCADE chip (id=0x%.4x).\n",dev
->name
,chip
);
572 dev
->base_addr
= ioaddr
;
574 hp100_page( ID_MAC_ADDR
);
575 for ( i
= uc
= eisa_id
= 0; i
< 4; i
++ )
578 uc_1
= hp100_inb( BOARD_ID
+ i
);
579 eisa_id
|= uc_1
<< 24;
582 uc
+= hp100_inb( BOARD_ID
+ 4 );
584 if ( uc
!= 0xff ) /* bad checksum? */
586 printk("hp100_probe: %s: bad EISA ID checksum at base port 0x%x\n", dev
->name
, ioaddr
);
590 for ( i
=0; i
< HP100_EISA_IDS_SIZE
; i
++)
591 if ( hp100_eisa_ids
[ i
].id
== eisa_id
)
593 if ( i
>= HP100_EISA_IDS_SIZE
) {
594 for ( i
= 0; i
< HP100_EISA_IDS_SIZE
; i
++)
595 if ( ( hp100_eisa_ids
[ i
].id
& 0xf0ffffff ) == ( eisa_id
& 0xf0ffffff ) )
597 if ( i
>= HP100_EISA_IDS_SIZE
) {
598 printk( "hp100_probe: %s: card at port 0x%x isn't known (id = 0x%x)\n", dev
-> name
, ioaddr
, eisa_id
);
602 eid
= &hp100_eisa_ids
[ i
];
603 if ( ( eid
->id
& 0x0f000000 ) < ( eisa_id
& 0x0f000000 ) )
605 printk( "hp100_probe: %s: newer version of card %s at port 0x%x - unsupported\n",
606 dev
->name
, eid
->name
, ioaddr
);
610 for ( i
= uc
= 0; i
< 7; i
++ )
611 uc
+= hp100_inb( LAN_ADDR
+ i
);
614 printk("hp100_probe: %s: bad lan address checksum (card %s at port 0x%x)\n",
615 dev
->name
, eid
->name
, ioaddr
);
619 /* Make sure, that all registers are correctly updated... */
621 hp100_load_eeprom( dev
, ioaddr
);
625 * Determine driver operation mode
627 * Use the variable "hp100_mode" upon insmod or as kernel parameter to
628 * force driver modes:
629 * hp100_mode=1 -> default, use busmaster mode if configured.
630 * hp100_mode=2 -> enable shared memory mode
631 * hp100_mode=3 -> force use of i/o mapped mode.
632 * hp100_mode=4 -> same as 1, but re-set the enable bit on the card.
637 * 0x2278 -> J2585B, PnP shared memory mode
638 * 0x2270 -> J2585B, shared memory mode, 0xdc000
639 * 0xa23c -> J2585B, I/O mapped mode
640 * 0x2240 -> EISA COMPEX, BusMaster (Shasta Chip)
641 * 0x2220 -> EISA HP, I/O (Shasta Chip)
642 * 0x2260 -> EISA HP, BusMaster (Shasta Chip)
647 hp100_outw(0xfefe,OPTION_LSW
);
648 hp100_outw(local_mode
|HP100_SET_LB
|HP100_SET_HB
,OPTION_LSW
);
651 /* hp100_mode value maybe used in future by another card */
652 local_mode
=hp100_mode
;
653 if ( local_mode
< 1 || local_mode
> 4 )
654 local_mode
= 1; /* default */
656 printk( "hp100: %s: original LSW = 0x%x\n", dev
->name
, hp100_inw(OPTION_LSW
) );
661 hp100_outw(HP100_MEM_EN
|HP100_RESET_LB
, OPTION_LSW
);
662 hp100_outw(HP100_IO_EN
|HP100_SET_LB
, OPTION_LSW
);
663 hp100_outw(HP100_BM_WRITE
|HP100_BM_READ
|HP100_RESET_HB
, OPTION_LSW
);
664 printk("hp100: %s: IO mapped mode forced.\n", dev
->name
);
666 else if(local_mode
==2)
668 hp100_outw(HP100_MEM_EN
|HP100_SET_LB
, OPTION_LSW
);
669 hp100_outw(HP100_IO_EN
|HP100_SET_LB
, OPTION_LSW
);
670 hp100_outw(HP100_BM_WRITE
|HP100_BM_READ
|HP100_RESET_HB
, OPTION_LSW
);
671 printk("hp100: %s: Shared memory mode requested.\n", dev
->name
);
673 else if(local_mode
==4)
675 if(chip
==HP100_CHIPID_LASSEN
)
677 hp100_outw(HP100_BM_WRITE
|
678 HP100_BM_READ
| HP100_SET_HB
, OPTION_LSW
);
679 hp100_outw(HP100_IO_EN
|
680 HP100_MEM_EN
| HP100_RESET_LB
, OPTION_LSW
);
681 printk("hp100: %s: Busmaster mode requested.\n",dev
->name
);
686 if(local_mode
==1) /* default behaviour */
688 lsw
= hp100_inw(OPTION_LSW
);
690 if ( (lsw
& HP100_IO_EN
) &&
691 (~lsw
& HP100_MEM_EN
) &&
692 (~lsw
& (HP100_BM_WRITE
|HP100_BM_READ
)) )
695 printk("hp100: %s: IO_EN bit is set on card.\n",dev
->name
);
699 else if ( chip
== HP100_CHIPID_LASSEN
&&
700 ( lsw
& (HP100_BM_WRITE
|HP100_BM_READ
) ) ==
701 (HP100_BM_WRITE
|HP100_BM_READ
) )
703 printk("hp100: %s: Busmaster mode enabled.\n",dev
->name
);
704 hp100_outw(HP100_MEM_EN
|HP100_IO_EN
|HP100_RESET_LB
, OPTION_LSW
);
709 printk("hp100: %s: Card not configured for BM or BM not supported with this card.\n", dev
->name
);
710 printk("hp100: %s: Trying shared memory mode.\n", dev
->name
);
712 /* In this case, try shared memory mode */
714 hp100_outw(HP100_MEM_EN
|HP100_SET_LB
, OPTION_LSW
);
715 /* hp100_outw(HP100_IO_EN|HP100_RESET_LB, OPTION_LSW); */
720 printk( "hp100: %s: new LSW = 0x%x\n", dev
->name
, hp100_inw(OPTION_LSW
) );
723 /* Check for shared memory on the card, eventually remap it */
724 hp100_page( HW_MAP
);
725 mem_mapped
= (( hp100_inw( OPTION_LSW
) & ( HP100_MEM_EN
) ) != 0);
728 memory_size
= (8192<<( (hp100_inb(SRAM
)>>5)&0x07));
729 virt_memory_size
= 0;
731 /* For memory mapped or busmaster mode, we want the memory address */
732 if ( mem_mapped
|| (local_mode
==1))
734 mem_ptr_phys
= ( hp100_inw( MEM_MAP_LSW
) |
735 ( hp100_inw( MEM_MAP_MSW
) << 16 ) );
736 mem_ptr_phys
&= ~0x1fff; /* 8k alignment */
738 if ( bus
== HP100_BUS_ISA
&& (mem_ptr_phys
& ~0xfffff ) != 0 )
740 printk("hp100: %s: Can only use programmed i/o mode.\n", dev
->name
);
743 local_mode
=3; /* Use programmed i/o */
746 /* We do not need access to shared memory in busmaster mode */
747 /* However in slave mode we need to remap high (>1GB) card memory */
748 if(local_mode
!=1) /* = not busmaster */
750 if ( bus
== HP100_BUS_PCI
&& mem_ptr_phys
>= 0x100000 )
752 /* We try with smaller memory sizes, if ioremap fails */
753 for(virt_memory_size
= memory_size
; virt_memory_size
>16383; virt_memory_size
>>=1)
755 if((mem_ptr_virt
=ioremap((u_long
)mem_ptr_phys
,virt_memory_size
))==NULL
)
758 printk( "hp100: %s: ioremap for 0x%x bytes high PCI memory at 0x%lx failed\n", dev
->name
, virt_memory_size
, mem_ptr_phys
);
764 printk( "hp100: %s: remapped 0x%x bytes high PCI memory at 0x%lx to 0x%lx.\n", dev
->name
, virt_memory_size
, mem_ptr_phys
, (u_long
)mem_ptr_virt
);
770 if(mem_ptr_virt
==NULL
) /* all ioremap tries failed */
772 printk("hp100: %s: Failed to ioremap the PCI card memory. Will have to use i/o mapped mode.\n", dev
->name
);
774 virt_memory_size
= 0;
781 if(local_mode
==3) /* io mapped forced */
786 printk("hp100: %s: Using (slow) programmed i/o mode.\n", dev
->name
);
789 /* Initialise the "private" data structure for this card. */
790 if ( (dev
->priv
=kmalloc(sizeof(struct hp100_private
), GFP_KERNEL
)) == NULL
)
793 lp
= (struct hp100_private
*)dev
->priv
;
794 memset( lp
, 0, sizeof( struct hp100_private
) );
797 lp
->mode
= local_mode
;
800 lp
->pci_dev
= pci_dev
;
802 lp
->pci_bus
= pci_bus
;
803 lp
->pci_device_fn
= pci_device_fn
;
805 lp
->priority_tx
= hp100_priority_tx
;
806 lp
->rx_ratio
= hp100_rx_ratio
;
807 lp
->mem_ptr_phys
= mem_ptr_phys
;
808 lp
->mem_ptr_virt
= mem_ptr_virt
;
809 hp100_page( ID_MAC_ADDR
);
810 lp
->soft_model
= hp100_inb( SOFT_MODEL
);
811 lp
->mac1_mode
= HP100_MAC1MODE3
;
812 lp
->mac2_mode
= HP100_MAC2MODE3
;
813 memset( &lp
->hash_bytes
, 0x00, 8 );
815 dev
->base_addr
= ioaddr
;
817 lp
->memory_size
= memory_size
;
818 lp
->virt_memory_size
= virt_memory_size
;
819 lp
->rx_ratio
= hp100_rx_ratio
; /* can be conf'd with insmod */
821 /* memory region for programmed i/o */
822 request_region( dev
->base_addr
, HP100_REGION_SIZE
, eid
->name
);
824 dev
->open
= hp100_open
;
825 dev
->stop
= hp100_close
;
827 if (lp
->mode
==1) /* busmaster */
828 dev
->hard_start_xmit
= hp100_start_xmit_bm
;
830 dev
->hard_start_xmit
= hp100_start_xmit
;
832 dev
->get_stats
= hp100_get_stats
;
833 dev
->set_multicast_list
= &hp100_set_multicast_list
;
835 /* Ask the card for which IRQ line it is configured */
837 if ( bus
== HP100_BUS_PCI
) {
838 dev
->irq
= pci_dev
->irq
;
841 hp100_page( HW_MAP
);
842 dev
->irq
= hp100_inb( IRQ_CHANNEL
) & HP100_IRQMASK
;
849 if(lp
->mode
==1) /* busmaster */
852 /* Ask the card for its MAC address and store it for later use. */
853 hp100_page( ID_MAC_ADDR
);
854 for ( i
= uc
= 0; i
< 6; i
++ )
855 dev
->dev_addr
[ i
] = hp100_inb( LAN_ADDR
+ i
);
857 /* Reset statistics (counters) */
858 hp100_clear_stats( ioaddr
);
862 /* If busmaster mode is wanted, a dma-capable memory area is needed for
864 * PCI cards can access the whole PC memory. Therefore GFP_DMA is not
865 * needed for the allocation of the memory area.
868 /* TODO: We do not need this with old cards, where PDLs are stored
869 * in the cards shared memory area. But currently, busmaster has been
870 * implemented/tested only with the lassen chip anyway... */
871 if(lp
->mode
==1) /* busmaster */
873 /* Get physically continous memory for TX & RX PDLs */
874 if ( (lp
->page_vaddr
=kmalloc(MAX_RINGSIZE
+0x0f,GFP_KERNEL
) ) == NULL
)
876 lp
->page_vaddr_algn
=((u_int
*) ( ((u_int
)(lp
->page_vaddr
)+0x0f) &~0x0f));
877 memset(lp
->page_vaddr
, 0, MAX_RINGSIZE
+0x0f);
879 #ifdef HP100_DEBUG_BM
880 printk("hp100: %s: Reserved DMA memory from 0x%x to 0x%x\n",
882 (u_int
)lp
->page_vaddr_algn
,
883 (u_int
)lp
->page_vaddr_algn
+MAX_RINGSIZE
);
885 lp
->rxrcommit
= lp
->txrcommit
= 0;
886 lp
->rxrhead
= lp
->rxrtail
= &(lp
->rxring
[0]);
887 lp
->txrhead
= lp
->txrtail
= &(lp
->txring
[0]);
890 /* Initialise the card. */
891 /* (I'm not really sure if it's a good idea to do this during probing, but
892 * like this it's assured that the lan connection type can be sensed
897 /* Try to find out which kind of LAN the card is connected to. */
898 lp
->lan_type
= hp100_sense_lan( dev
);
900 /* Print out a message what about what we think we have probed. */
901 printk( "hp100: %s: %s at 0x%x, IRQ %d, ",
902 dev
->name
, lp
->id
->name
, ioaddr
, dev
->irq
);
904 case HP100_BUS_EISA
: printk( "EISA" ); break;
905 case HP100_BUS_PCI
: printk( "PCI" ); break;
906 default: printk( "ISA" ); break;
908 printk( " bus, %dk SRAM (rx/tx %d%%).\n",
909 lp
->memory_size
>> 10, lp
->rx_ratio
);
911 if ( lp
->mode
==2 ) /* memory mapped */
913 printk( "hp100: %s: Memory area at 0x%lx-0x%lx",
914 dev
->name
,mem_ptr_phys
,
915 (mem_ptr_phys
+(mem_ptr_phys
>0x100000?(u_long
)lp
->memory_size
:16*1024))-1 );
917 printk( " (virtual base 0x%lx)", (u_long
)mem_ptr_virt
);
920 /* Set for info when doing ifconfig */
921 dev
->mem_start
= mem_ptr_phys
;
922 dev
->mem_end
= mem_ptr_phys
+lp
->memory_size
;
924 printk( "hp100: %s: ", dev
->name
);
925 if ( lp
->lan_type
!= HP100_LAN_ERR
)
926 printk( "Adapter is attached to " );
927 switch ( lp
->lan_type
) {
929 printk( "100Mb/s Voice Grade AnyLAN network.\n" );
932 printk( "10Mb/s network.\n" );
935 printk( "Warning! Link down.\n" );
942 /* This procedure puts the card into a stable init state */
943 static void hp100_hwinit( struct net_device
*dev
)
945 int ioaddr
= dev
->base_addr
;
946 struct hp100_private
*lp
= (struct hp100_private
*)dev
->priv
;
949 hp100_outw( 0x4202, TRACE
);
950 printk("hp100: %s: hwinit\n", dev
->name
);
953 /* Initialise the card. -------------------------------------------- */
955 /* Clear all pending Ints and disable Ints */
956 hp100_page( PERFORMANCE
);
957 hp100_outw( 0xfefe, IRQ_MASK
); /* mask off all ints */
958 hp100_outw( 0xffff, IRQ_STATUS
); /* clear all pending ints */
960 hp100_outw( HP100_INT_EN
| HP100_RESET_LB
, OPTION_LSW
);
961 hp100_outw( HP100_TRI_INT
| HP100_SET_HB
, OPTION_LSW
);
965 hp100_BM_shutdown( dev
); /* disables BM, puts cascade in reset */
970 hp100_outw( HP100_INT_EN
| HP100_RESET_LB
, OPTION_LSW
);
971 hp100_cascade_reset( dev
, TRUE
);
972 hp100_page( MAC_CTRL
);
973 hp100_andb( ~(HP100_RX_EN
|HP100_TX_EN
), MAC_CFG_1
);
976 /* Initiate EEPROM reload */
977 hp100_load_eeprom( dev
, 0 );
981 /* Go into reset again. */
982 hp100_cascade_reset( dev
, TRUE
);
984 /* Set Option Registers to a safe state */
985 hp100_outw( HP100_DEBUG_EN
|
989 HP100_BM_READ
| HP100_RESET_HB
|
993 HP100_IO_EN
| HP100_RESET_LB
, OPTION_LSW
);
995 hp100_outw( HP100_TRI_INT
|
996 HP100_MMAP_DIS
| HP100_SET_HB
, OPTION_LSW
);
998 hp100_outb( HP100_PRIORITY_TX
|
1000 HP100_TX_CMD
| HP100_RESET_LB
, OPTION_MSW
);
1002 /* TODO: Configure MMU for Ram Test. */
1003 /* TODO: Ram Test. */
1005 /* Re-check if adapter is still at same i/o location */
1006 /* (If the base i/o in eeprom has been changed but the */
1007 /* registers had not been changed, a reload of the eeprom */
1008 /* would move the adapter to the address stored in eeprom */
1010 /* TODO: Code to implement. */
1012 /* Until here it was code from HWdiscover procedure. */
1013 /* Next comes code from mmuinit procedure of SCO BM driver which is
1014 * called from HWconfigure in the SCO driver. */
1016 /* Initialise MMU, eventually switch on Busmaster Mode, initialise
1017 * multicast filter...
1019 hp100_mmuinit( dev
);
1021 /* We don't turn the interrupts on here - this is done by start_interface. */
1022 wait(); /* TODO: Do we really need this? */
1024 /* Enable Hardware (e.g. unreset) */
1025 hp100_cascade_reset( dev
, FALSE
);
1027 /* ------- initialisation complete ----------- */
1029 /* Finally try to log in the Hub if there may be a VG connection. */
1030 if( lp
->lan_type
!= HP100_LAN_10
)
1031 hp100_login_to_vg_hub( dev
, FALSE
); /* relogin */
1036 * mmuinit - Reinitialise Cascade MMU and MAC settings.
1037 * Note: Must already be in reset and leaves card in reset.
1039 static void hp100_mmuinit( struct net_device
*dev
)
1041 int ioaddr
= dev
->base_addr
;
1042 struct hp100_private
*lp
= (struct hp100_private
*)dev
->priv
;
1045 #ifdef HP100_DEBUG_B
1046 hp100_outw( 0x4203, TRACE
);
1047 printk("hp100: %s: mmuinit\n",dev
->name
);
1051 if( 0!=(hp100_inw(OPTION_LSW
)&HP100_HW_RST
) )
1053 printk("hp100: %s: Not in reset when entering mmuinit. Fix me.\n",dev
->name
);
1058 /* Make sure IRQs are masked off and ack'ed. */
1059 hp100_page( PERFORMANCE
);
1060 hp100_outw( 0xfefe, IRQ_MASK
); /* mask off all ints */
1061 hp100_outw( 0xffff, IRQ_STATUS
); /* ack IRQ */
1065 * - Clear Debug En, Rx Hdr Pipe, EE En, I/O En, Fake Int and Intr En
1066 * - Set Tri-State Int, Bus Master Rd/Wr, and Mem Map Disable
1067 * - Clear Priority, Advance Pkt and Xmit Cmd
1070 hp100_outw( HP100_DEBUG_EN
|
1072 HP100_EE_EN
| HP100_RESET_HB
|
1075 HP100_INT_EN
| HP100_RESET_LB
, OPTION_LSW
);
1077 hp100_outw( HP100_TRI_INT
| HP100_SET_HB
, OPTION_LSW
);
1079 if(lp
->mode
==1) /* busmaster */
1081 hp100_outw( HP100_BM_WRITE
|
1083 HP100_MMAP_DIS
| HP100_SET_HB
, OPTION_LSW
);
1085 else if(lp
->mode
==2) /* memory mapped */
1087 hp100_outw( HP100_BM_WRITE
|
1088 HP100_BM_READ
| HP100_RESET_HB
, OPTION_LSW
);
1089 hp100_outw( HP100_MMAP_DIS
| HP100_RESET_HB
, OPTION_LSW
);
1090 hp100_outw( HP100_MEM_EN
| HP100_SET_LB
, OPTION_LSW
);
1091 hp100_outw( HP100_IO_EN
| HP100_SET_LB
, OPTION_LSW
);
1093 else if( lp
->mode
==3 ) /* i/o mapped mode */
1095 hp100_outw( HP100_MMAP_DIS
| HP100_SET_HB
|
1096 HP100_IO_EN
| HP100_SET_LB
, OPTION_LSW
);
1099 hp100_page( HW_MAP
);
1100 hp100_outb( 0, EARLYRXCFG
);
1101 hp100_outw( 0, EARLYTXCFG
);
1104 * Enable Bus Master mode
1106 if(lp
->mode
==1) /* busmaster */
1108 /* Experimental: Set some PCI configuration bits */
1109 hp100_page( HW_MAP
);
1110 hp100_andb( ~HP100_PDL_USE3
, MODECTRL1
); /* BM engine read maximum */
1111 hp100_andb( ~HP100_TX_DUALQ
, MODECTRL1
); /* No Queue for Priority TX */
1113 /* PCI Bus failures should result in a Misc. Interrupt */
1114 hp100_orb( HP100_EN_BUS_FAIL
, MODECTRL2
);
1116 hp100_outw( HP100_BM_READ
| HP100_BM_WRITE
| HP100_SET_HB
, OPTION_LSW
);
1117 hp100_page( HW_MAP
);
1118 /* Use Burst Mode and switch on PAGE_CK */
1119 hp100_orb( HP100_BM_BURST_RD
|
1120 HP100_BM_BURST_WR
, BM
);
1121 if((lp
->chip
==HP100_CHIPID_RAINIER
)||(lp
->chip
==HP100_CHIPID_SHASTA
))
1122 hp100_orb( HP100_BM_PAGE_CK
, BM
);
1123 hp100_orb( HP100_BM_MASTER
, BM
);
1125 else /* not busmaster */
1128 hp100_andb(~HP100_BM_MASTER
, BM
);
1132 * Divide card memory into regions for Rx, Tx and, if non-ETR chip, PDLs
1134 hp100_page( MMU_CFG
);
1135 if(lp
->mode
==1) /* only needed for Busmaster */
1137 int xmit_stop
, recv_stop
;
1139 if((lp
->chip
==HP100_CHIPID_RAINIER
)||(lp
->chip
==HP100_CHIPID_SHASTA
))
1144 * Each pdl is 508 bytes long. (63 frags * 4 bytes for address and
1145 * 4 bytes for header). We will leave NUM_RXPDLS * 508 (rounded
1146 * to the next higher 1k boundary) bytes for the rx-pdl's
1147 * Note: For non-etr chips the transmit stop register must be
1148 * programmed on a 1k boundary, i.e. bits 9:0 must be zero.
1150 pdl_stop
= lp
->memory_size
;
1151 xmit_stop
= ( pdl_stop
-508*(MAX_RX_PDL
)-16 )& ~(0x03ff);
1152 recv_stop
= ( xmit_stop
* (lp
->rx_ratio
)/100 ) &~(0x03ff);
1153 hp100_outw( (pdl_stop
>>4)-1, PDL_MEM_STOP
);
1154 #ifdef HP100_DEBUG_BM
1155 printk("hp100: %s: PDL_STOP = 0x%x\n", dev
->name
, pdl_stop
);
1158 else /* ETR chip (Lassen) in busmaster mode */
1160 xmit_stop
= ( lp
->memory_size
) - 1;
1161 recv_stop
= ( ( lp
->memory_size
* lp
->rx_ratio
) / 100 ) & ~(0x03ff);
1164 hp100_outw( xmit_stop
>>4 , TX_MEM_STOP
);
1165 hp100_outw( recv_stop
>>4 , RX_MEM_STOP
);
1166 #ifdef HP100_DEBUG_BM
1167 printk("hp100: %s: TX_STOP = 0x%x\n",dev
->name
,xmit_stop
>>4);
1168 printk("hp100: %s: RX_STOP = 0x%x\n",dev
->name
,recv_stop
>>4);
1171 else /* Slave modes (memory mapped and programmed io) */
1173 hp100_outw( (((lp
->memory_size
*lp
->rx_ratio
)/100)>>4), RX_MEM_STOP
);
1174 hp100_outw( ((lp
->memory_size
- 1 )>>4), TX_MEM_STOP
);
1176 printk("hp100: %s: TX_MEM_STOP: 0x%x\n", dev
->name
,hp100_inw(TX_MEM_STOP
));
1177 printk("hp100: %s: RX_MEM_STOP: 0x%x\n", dev
->name
,hp100_inw(RX_MEM_STOP
));
1181 /* Write MAC address into page 1 */
1182 hp100_page( MAC_ADDRESS
);
1183 for ( i
= 0; i
< 6; i
++ )
1184 hp100_outb( dev
->dev_addr
[ i
], MAC_ADDR
+ i
);
1186 /* Zero the multicast hash registers */
1187 for ( i
= 0; i
< 8; i
++ )
1188 hp100_outb( 0x0, HASH_BYTE0
+ i
);
1190 /* Set up MAC defaults */
1191 hp100_page( MAC_CTRL
);
1193 /* Go to LAN Page and zero all filter bits */
1194 /* Zero accept error, accept multicast, accept broadcast and accept */
1195 /* all directed packet bits */
1196 hp100_andb( ~(HP100_RX_EN
|
1201 HP100_ACC_PHY
), MAC_CFG_1
);
1203 hp100_outb( 0x00, MAC_CFG_2
);
1205 /* Zero the frame format bit. This works around a training bug in the */
1207 hp100_outb( 0x00, VG_LAN_CFG_2
); /* (use 802.3) */
1210 hp100_outb( HP100_PRIORITY_TX
| HP100_SET_LB
, OPTION_MSW
);
1212 hp100_outb( HP100_PRIORITY_TX
| HP100_RESET_LB
, OPTION_MSW
);
1214 hp100_outb( HP100_ADV_NXT_PKT
|
1215 HP100_TX_CMD
| HP100_RESET_LB
, OPTION_MSW
);
1217 /* If busmaster, initialize the PDLs */
1219 hp100_init_pdls( dev
);
1221 /* Go to performance page and initalize isr and imr registers */
1222 hp100_page( PERFORMANCE
);
1223 hp100_outw( 0xfefe, IRQ_MASK
); /* mask off all ints */
1224 hp100_outw( 0xffff, IRQ_STATUS
); /* ack IRQ */
1229 * open/close functions
1232 static int hp100_open( struct net_device
*dev
)
1234 struct hp100_private
*lp
= (struct hp100_private
*)dev
->priv
;
1235 #ifdef HP100_DEBUG_B
1236 int ioaddr
=dev
->base_addr
;
1239 #ifdef HP100_DEBUG_B
1240 hp100_outw( 0x4204, TRACE
);
1241 printk("hp100: %s: open\n",dev
->name
);
1244 /* New: if bus is PCI or EISA, interrupts might be shared interrupts */
1245 if ( request_irq(dev
->irq
, hp100_interrupt
,
1246 lp
->bus
==HP100_BUS_PCI
||lp
->bus
==HP100_BUS_EISA
?SA_SHIRQ
:SA_INTERRUPT
,
1249 printk( "hp100: %s: unable to get IRQ %d\n", dev
->name
, dev
->irq
);
1256 dev
->trans_start
= jiffies
;
1260 lp
->lan_type
= hp100_sense_lan( dev
);
1261 lp
->mac1_mode
= HP100_MAC1MODE3
;
1262 lp
->mac2_mode
= HP100_MAC2MODE3
;
1263 memset( &lp
->hash_bytes
, 0x00, 8 );
1265 hp100_stop_interface( dev
);
1267 hp100_hwinit( dev
);
1269 hp100_start_interface( dev
); /* sets mac modes, enables interrupts */
1275 /* The close function is called when the interface is to be brought down */
1276 static int hp100_close( struct net_device
*dev
)
1278 int ioaddr
= dev
->base_addr
;
1279 struct hp100_private
*lp
= (struct hp100_private
*)dev
->priv
;
1281 #ifdef HP100_DEBUG_B
1282 hp100_outw( 0x4205, TRACE
);
1283 printk("hp100: %s: close\n", dev
->name
);
1286 hp100_page( PERFORMANCE
);
1287 hp100_outw( 0xfefe, IRQ_MASK
); /* mask off all IRQs */
1289 hp100_stop_interface( dev
);
1291 if ( lp
->lan_type
== HP100_LAN_100
)
1292 lp
->hub_status
=hp100_login_to_vg_hub( dev
, FALSE
);
1297 free_irq( dev
->irq
, dev
);
1300 printk( "hp100: %s: close LSW = 0x%x\n", dev
->name
, hp100_inw(OPTION_LSW
) );
1309 * Configure the PDL Rx rings and LAN
1311 static void hp100_init_pdls( struct net_device
*dev
)
1313 struct hp100_private
*lp
= (struct hp100_private
*)dev
->priv
;
1314 hp100_ring_t
*ringptr
;
1318 #ifdef HP100_DEBUG_B
1319 int ioaddr
= dev
->base_addr
;
1322 #ifdef HP100_DEBUG_B
1323 hp100_outw( 0x4206, TRACE
);
1324 printk("hp100: %s: init pdls\n", dev
->name
);
1327 if(0==lp
->page_vaddr_algn
)
1328 printk("hp100: %s: Warning: lp->page_vaddr_algn not initialised!\n",dev
->name
);
1331 /* pageptr shall point into the DMA accessible memory region */
1332 /* we use this pointer to status the upper limit of allocated */
1333 /* memory in the allocated page. */
1334 /* note: align the pointers to the pci cache line size */
1335 memset(lp
->page_vaddr_algn
, 0, MAX_RINGSIZE
); /* Zero Rx/Tx ring page */
1336 pageptr
=lp
->page_vaddr_algn
;
1339 ringptr
= lp
->rxrhead
= lp
-> rxrtail
= &(lp
->rxring
[0]);
1341 /* Initialise Rx Ring */
1342 for (i
=MAX_RX_PDL
-1; i
>=0; i
--)
1344 lp
->rxring
[i
].next
= ringptr
;
1345 ringptr
=&(lp
->rxring
[i
]);
1346 pageptr
+=hp100_init_rxpdl(dev
, ringptr
, pageptr
);
1349 /* Initialise Tx Ring */
1351 ringptr
= lp
->txrhead
= lp
->txrtail
= &(lp
->txring
[0]);
1352 for (i
=MAX_TX_PDL
-1; i
>=0; i
--)
1354 lp
->txring
[i
].next
= ringptr
;
1355 ringptr
=&(lp
->txring
[i
]);
1356 pageptr
+=hp100_init_txpdl(dev
, ringptr
, pageptr
);
1362 /* These functions "format" the entries in the pdl structure */
1363 /* They return how much memory the fragments need. */
1364 static int hp100_init_rxpdl( struct net_device
*dev
, register hp100_ring_t
*ringptr
, register u32
*pdlptr
)
1366 /* pdlptr is starting address for this pdl */
1368 if( 0!=( ((unsigned)pdlptr
) & 0xf) )
1369 printk("hp100: %s: Init rxpdl: Unaligned pdlptr 0x%x.\n",dev
->name
,(unsigned)pdlptr
);
1371 ringptr
->pdl
= pdlptr
+1;
1372 ringptr
->pdl_paddr
= virt_to_bus(pdlptr
+1);
1373 ringptr
->skb
= (void *) NULL
;
1376 * Write address and length of first PDL Fragment (which is used for
1377 * storing the RX-Header
1378 * We use the 4 bytes _before_ the PDH in the pdl memory area to
1379 * store this information. (PDH is at offset 0x04)
1381 /* Note that pdlptr+1 and not pdlptr is the pointer to the PDH */
1383 *(pdlptr
+2) =(u_int
) virt_to_bus(pdlptr
); /* Address Frag 1 */
1384 *(pdlptr
+3) = 4; /* Length Frag 1 */
1386 return( ( ((MAX_RX_FRAG
*2+2)+3) /4)*4 );
1390 static int hp100_init_txpdl( struct net_device
*dev
, register hp100_ring_t
*ringptr
, register u32
*pdlptr
)
1392 if( 0!=( ((unsigned)pdlptr
) & 0xf) )
1393 printk("hp100: %s: Init txpdl: Unaligned pdlptr 0x%x.\n",dev
->name
,(unsigned) pdlptr
);
1395 ringptr
->pdl
= pdlptr
; /* +1; */
1396 ringptr
->pdl_paddr
= virt_to_bus(pdlptr
); /* +1 */
1397 ringptr
->skb
= (void *) NULL
;
1399 return((((MAX_TX_FRAG
*2+2)+3)/4)*4);
1404 * hp100_build_rx_pdl allocates an skb_buff of maximum size plus two bytes
1405 * for possible odd word alignment rounding up to next dword and set PDL
1406 * address for fragment#2
1407 * Returns: 0 if unable to allocate skb_buff
1410 int hp100_build_rx_pdl( hp100_ring_t
*ringptr
, struct net_device
*dev
)
1412 #ifdef HP100_DEBUG_B
1413 int ioaddr
= dev
->base_addr
;
1415 #ifdef HP100_DEBUG_BM
1419 #ifdef HP100_DEBUG_B
1420 hp100_outw( 0x4207, TRACE
);
1421 printk("hp100: %s: build rx pdl\n", dev
->name
);
1424 /* Allocate skb buffer of maximum size */
1425 /* Note: This depends on the alloc_skb functions allocating more
1426 * space than requested, i.e. aligning to 16bytes */
1428 ringptr
->skb
= dev_alloc_skb( ((MAX_ETHER_SIZE
+2+3)/4)*4 );
1430 if(NULL
!=ringptr
->skb
)
1433 * Reserve 2 bytes at the head of the buffer to land the IP header
1434 * on a long word boundary (According to the Network Driver section
1435 * in the Linux KHG, this should help to increase performance.)
1437 skb_reserve(ringptr
->skb
, 2);
1439 ringptr
->skb
->dev
=dev
;
1440 ringptr
->skb
->data
=(u_char
*)skb_put(ringptr
->skb
, MAX_ETHER_SIZE
);
1442 /* ringptr->pdl points to the beginning of the PDL, i.e. the PDH */
1443 /* Note: 1st Fragment is used for the 4 byte packet status
1444 * (receive header). Its PDL entries are set up by init_rxpdl. So
1445 * here we only have to set up the PDL fragment entries for the data
1446 * part. Those 4 bytes will be stored in the DMA memory region
1447 * directly before the PDL.
1449 #ifdef HP100_DEBUG_BM
1450 printk("hp100: %s: build_rx_pdl: PDH@0x%x, skb->data (len %d) at 0x%x\n",
1452 (u_int
) ringptr
->pdl
,
1453 ((MAX_ETHER_SIZE
+2+3)/4)*4,
1454 (unsigned int) ringptr
->skb
->data
);
1457 ringptr
->pdl
[0] = 0x00020000; /* Write PDH */
1458 ringptr
->pdl
[3] = ((u_int
)virt_to_bus(ringptr
->skb
->data
));
1459 ringptr
->pdl
[4] = MAX_ETHER_SIZE
; /* Length of Data */
1461 #ifdef HP100_DEBUG_BM
1462 for(p
=(ringptr
->pdl
); p
<(ringptr
->pdl
+5); p
++)
1463 printk("hp100: %s: Adr 0x%.8x = 0x%.8x\n",dev
->name
,(u_int
) p
,(u_int
) *p
);
1468 /* alloc_skb failed (no memory) -> still can receive the header
1469 * fragment into PDL memory. make PDL safe by clearing msgptr and
1470 * making the PDL only 1 fragment (i.e. the 4 byte packet status)
1472 #ifdef HP100_DEBUG_BM
1473 printk("hp100: %s: build_rx_pdl: PDH@0x%x, No space for skb.\n",
1475 (u_int
) ringptr
->pdl
);
1478 ringptr
->pdl
[0]=0x00010000; /* PDH: Count=1 Fragment */
1485 * hp100_rxfill - attempt to fill the Rx Ring will empty skb's
1487 * Makes assumption that skb's are always contiguous memory areas and
1488 * therefore PDLs contain only 2 physical fragments.
1489 * - While the number of Rx PDLs with buffers is less than maximum
1490 * a. Get a maximum packet size skb
1491 * b. Put the physical address of the buffer into the PDL.
1492 * c. Output physical address of PDL to adapter.
1494 static void hp100_rxfill( struct net_device
*dev
)
1496 int ioaddr
=dev
->base_addr
;
1498 struct hp100_private
*lp
= (struct hp100_private
*)dev
->priv
;
1499 hp100_ring_t
*ringptr
;
1501 #ifdef HP100_DEBUG_B
1502 hp100_outw( 0x4208, TRACE
);
1503 printk("hp100: %s: rxfill\n",dev
->name
);
1506 hp100_page( PERFORMANCE
);
1508 while (lp
->rxrcommit
< MAX_RX_PDL
)
1511 ** Attempt to get a buffer and build a Rx PDL.
1513 ringptr
= lp
->rxrtail
;
1514 if (0 == hp100_build_rx_pdl( ringptr
, dev
))
1516 return; /* None available, return */
1519 /* Hand this PDL over to the card */
1520 /* Note: This needs performance page selected! */
1521 #ifdef HP100_DEBUG_BM
1522 printk("hp100: %s: rxfill: Hand to card: pdl #%d @0x%x phys:0x%x, buffer: 0x%x\n",
1525 (u_int
)ringptr
->pdl
,
1526 (u_int
)ringptr
->pdl_paddr
,
1527 (u_int
)ringptr
->pdl
[3]);
1530 hp100_outl( (u32
)ringptr
->pdl_paddr
, RX_PDA
);
1533 lp
->rxrtail
= ringptr
->next
;
1539 * BM_shutdown - shutdown bus mastering and leave chip in reset state
1542 static void hp100_BM_shutdown( struct net_device
*dev
)
1544 int ioaddr
= dev
->base_addr
;
1545 struct hp100_private
*lp
= (struct hp100_private
*)dev
->priv
;
1548 #ifdef HP100_DEBUG_B
1549 hp100_outw( 0x4209, TRACE
);
1550 printk("hp100: %s: bm shutdown\n",dev
->name
);
1553 hp100_page( PERFORMANCE
);
1554 hp100_outw( 0xfefe, IRQ_MASK
); /* mask off all ints */
1555 hp100_outw( 0xffff, IRQ_STATUS
); /* Ack all ints */
1557 /* Ensure Interrupts are off */
1558 hp100_outw( HP100_INT_EN
| HP100_RESET_LB
, OPTION_LSW
);
1560 /* Disable all MAC activity */
1561 hp100_page( MAC_CTRL
);
1562 hp100_andb( ~(HP100_RX_EN
| HP100_TX_EN
), MAC_CFG_1
); /* stop rx/tx */
1564 /* If cascade MMU is not already in reset */
1565 if (0 != (hp100_inw(OPTION_LSW
)&HP100_HW_RST
) )
1567 /* Wait 1.3ms (10Mb max packet time) to ensure MAC is idle so
1568 * MMU pointers will not be reset out from underneath
1570 hp100_page( MAC_CTRL
);
1571 for(time
=0; time
<5000; time
++)
1573 if( (hp100_inb(MAC_CFG_1
)&(HP100_TX_IDLE
|HP100_RX_IDLE
))==
1574 (HP100_TX_IDLE
|HP100_RX_IDLE
) ) break;
1577 /* Shutdown algorithm depends on the generation of Cascade */
1578 if( lp
->chip
==HP100_CHIPID_LASSEN
)
1579 { /* ETR shutdown/reset */
1580 /* Disable Busmaster mode and wait for bit to go to zero. */
1582 hp100_andb( ~HP100_BM_MASTER
, BM
);
1583 /* 100 ms timeout */
1584 for(time
=0; time
<32000; time
++)
1586 if ( 0 == (hp100_inb( BM
) & HP100_BM_MASTER
) ) break;
1590 { /* Shasta or Rainier Shutdown/Reset */
1591 /* To ensure all bus master inloading activity has ceased,
1592 * wait for no Rx PDAs or no Rx packets on card.
1594 hp100_page( PERFORMANCE
);
1595 /* 100 ms timeout */
1596 for(time
=0; time
<10000; time
++)
1598 /* RX_PDL: PDLs not executed. */
1599 /* RX_PKT_CNT: RX'd packets on card. */
1600 if ( (hp100_inb( RX_PDL
) == 0) &&
1601 (hp100_inb( RX_PKT_CNT
) == 0) ) break;
1605 printk("hp100: %s: BM shutdown error.\n", dev
->name
);
1607 /* To ensure all bus master outloading activity has ceased,
1608 * wait until the Tx PDA count goes to zero or no more Tx space
1609 * available in the Tx region of the card.
1611 /* 100 ms timeout */
1612 for(time
=0; time
<10000; time
++) {
1613 if ( (0 == hp100_inb( TX_PKT_CNT
)) &&
1614 (0 != (hp100_inb( TX_MEM_FREE
)&HP100_AUTO_COMPARE
))) break;
1617 /* Disable Busmaster mode */
1619 hp100_andb( ~HP100_BM_MASTER
, BM
);
1620 } /* end of shutdown procedure for non-etr parts */
1622 hp100_cascade_reset( dev
, TRUE
);
1624 hp100_page( PERFORMANCE
);
1625 /* hp100_outw( HP100_BM_READ | HP100_BM_WRITE | HP100_RESET_HB, OPTION_LSW ); */
1626 /* Busmaster mode should be shut down now. */
1632 * transmit functions
1635 /* tx function for busmaster mode */
1636 static int hp100_start_xmit_bm( struct sk_buff
*skb
, struct net_device
*dev
)
1638 unsigned long flags
;
1640 int ioaddr
= dev
->base_addr
;
1641 struct hp100_private
*lp
= (struct hp100_private
*)dev
->priv
;
1642 hp100_ring_t
*ringptr
;
1644 #ifdef HP100_DEBUG_B
1645 hp100_outw( 0x4210, TRACE
);
1646 printk("hp100: %s: start_xmit_bm\n",dev
->name
);
1657 if ( skb
->len
<= 0 ) return 0;
1659 /* Get Tx ring tail pointer */
1660 if( lp
->txrtail
->next
==lp
->txrhead
)
1664 printk("hp100: %s: start_xmit_bm: No TX PDL available.\n", dev
->name
);
1666 /* not waited long enough since last tx? */
1667 if ( jiffies
- dev
->trans_start
< HZ
) return -EAGAIN
;
1669 if ( lp
->lan_type
< 0 ) /* no LAN type detected yet? */
1671 hp100_stop_interface( dev
);
1672 if ( ( lp
->lan_type
= hp100_sense_lan( dev
) ) < 0 )
1674 printk( "hp100: %s: no connection found - check wire\n", dev
->name
);
1675 hp100_start_interface( dev
); /* 10Mb/s RX pkts maybe handled */
1678 if ( lp
->lan_type
== HP100_LAN_100
)
1679 lp
->hub_status
= hp100_login_to_vg_hub( dev
, FALSE
); /* relogin */
1680 hp100_start_interface( dev
);
1683 if ( lp
->lan_type
== HP100_LAN_100
&& lp
->hub_status
< 0 )
1684 /* we have a 100Mb/s adapter but it isn't connected to hub */
1686 printk( "hp100: %s: login to 100Mb/s hub retry\n", dev
->name
);
1687 hp100_stop_interface( dev
);
1688 lp
->hub_status
= hp100_login_to_vg_hub( dev
, FALSE
);
1689 hp100_start_interface( dev
);
1694 i
= hp100_sense_lan( dev
);
1696 if ( i
== HP100_LAN_ERR
)
1697 printk( "hp100: %s: link down detected\n", dev
->name
);
1699 if ( lp
->lan_type
!= i
) /* cable change! */
1701 /* it's very hard - all network setting must be changed!!! */
1702 printk( "hp100: %s: cable change 10Mb/s <-> 100Mb/s detected\n", dev
->name
);
1704 hp100_stop_interface( dev
);
1705 if ( lp
->lan_type
== HP100_LAN_100
)
1706 lp
->hub_status
= hp100_login_to_vg_hub( dev
, FALSE
);
1707 hp100_start_interface( dev
);
1711 printk( "hp100: %s: interface reset\n", dev
->name
);
1712 hp100_stop_interface( dev
);
1713 if ( lp
->lan_type
== HP100_LAN_100
)
1714 lp
->hub_status
= hp100_login_to_vg_hub( dev
, FALSE
);
1715 hp100_start_interface( dev
);
1719 dev
->trans_start
= jiffies
;
1724 * we have to turn int's off before modifying this, otherwise
1725 * a tx_pdl_cleanup could occur at the same time
1727 save_flags( flags
);
1729 ringptr
=lp
->txrtail
;
1730 lp
->txrtail
=ringptr
->next
;
1732 /* Check whether packet has minimal packet size */
1733 ok_flag
= skb
->len
>= HP100_MIN_PACKET_SIZE
;
1734 i
= ok_flag
? skb
->len
: HP100_MIN_PACKET_SIZE
;
1737 ringptr
->pdl
[0]=((1<<16) | i
); /* PDH: 1 Fragment & length */
1738 ringptr
->pdl
[1]=(u32
)virt_to_bus(skb
->data
); /* 1st Frag: Adr. of data */
1739 if(lp
->chip
==HP100_CHIPID_SHASTA
)
1741 /* TODO:Could someone who has the EISA card please check if this works? */
1746 /* In the PDL, don't use the padded size but the real packet size: */
1747 ringptr
->pdl
[2]=skb
->len
; /* 1st Frag: Length of frag */
1750 /* Hand this PDL to the card. */
1751 hp100_outl( ringptr
->pdl_paddr
, TX_PDA_L
); /* Low Prio. Queue */
1754 restore_flags( flags
);
1756 /* Update statistics */
1757 lp
->stats
.tx_packets
++;
1759 lp
->stats
.tx_bytes
+= skb
->len
;
1761 dev
->trans_start
= jiffies
;
1767 /* clean_txring checks if packets have been sent by the card by reading
1768 * the TX_PDL register from the performance page and comparing it to the
1769 * number of commited packets. It then frees the skb's of the packets that
1770 * obviously have been sent to the network.
1772 * Needs the PERFORMANCE page selected.
1774 static void hp100_clean_txring( struct net_device
*dev
)
1776 struct hp100_private
*lp
= (struct hp100_private
*)dev
->priv
;
1777 int ioaddr
= dev
->base_addr
;
1780 #ifdef HP100_DEBUG_B
1781 hp100_outw( 0x4211, TRACE
);
1782 printk("hp100: %s: clean txring\n", dev
->name
);
1785 /* How many PDLs have been transmitted? */
1786 donecount
=(lp
->txrcommit
)-hp100_inb(TX_PDL
);
1789 if(donecount
>MAX_TX_PDL
)
1790 printk("hp100: %s: Warning: More PDLs transmitted than commited to card???\n",dev
->name
);
1793 for( ; 0!=donecount
; donecount
-- )
1795 #ifdef HP100_DEBUG_BM
1796 printk("hp100: %s: Free skb: data @0x%.8x txrcommit=0x%x TXPDL=0x%x, done=0x%x\n",
1798 (u_int
) lp
->txrhead
->skb
->data
,
1804 dev_kfree_skb( lp
->txrhead
->skb
);
1806 dev_kfree_skb( lp
->txrhead
->skb
, FREE_WRITE
);
1808 lp
->txrhead
->skb
=(void *)NULL
;
1809 lp
->txrhead
=lp
->txrhead
->next
;
1815 /* tx function for slave modes */
1816 static int hp100_start_xmit( struct sk_buff
*skb
, struct net_device
*dev
)
1819 int ioaddr
= dev
->base_addr
;
1821 struct hp100_private
*lp
= (struct hp100_private
*)dev
->priv
;
1823 #ifdef HP100_DEBUG_B
1824 hp100_outw( 0x4212, TRACE
);
1825 printk("hp100: %s: start_xmit\n", dev
->name
);
1836 if ( skb
->len
<= 0 ) return 0;
1838 if ( lp
->lan_type
< 0 ) /* no LAN type detected yet? */
1840 hp100_stop_interface( dev
);
1841 if ( ( lp
->lan_type
= hp100_sense_lan( dev
) ) < 0 )
1843 printk( "hp100: %s: no connection found - check wire\n", dev
->name
);
1844 hp100_start_interface( dev
); /* 10Mb/s RX packets maybe handled */
1847 if ( lp
->lan_type
== HP100_LAN_100
)
1848 lp
->hub_status
= hp100_login_to_vg_hub( dev
, FALSE
); /* relogin */
1849 hp100_start_interface( dev
);
1852 /* If there is not enough free memory on the card... */
1853 i
=hp100_inl(TX_MEM_FREE
)&0x7fffffff;
1854 if ( !(((i
/2)-539)>(skb
->len
+16) && (hp100_inb(TX_PKT_CNT
)<255)) )
1857 printk( "hp100: %s: start_xmit: tx free mem = 0x%x\n", dev
->name
, i
);
1859 /* not waited long enough since last failed tx try? */
1860 if ( jiffies
- dev
->trans_start
< HZ
)
1863 printk("hp100: %s: trans_start timing problem\n", dev
->name
);
1867 if ( lp
->lan_type
== HP100_LAN_100
&& lp
->hub_status
< 0 )
1868 /* we have a 100Mb/s adapter but it isn't connected to hub */
1870 printk( "hp100: %s: login to 100Mb/s hub retry\n", dev
->name
);
1871 hp100_stop_interface( dev
);
1872 lp
->hub_status
= hp100_login_to_vg_hub( dev
, FALSE
);
1873 hp100_start_interface( dev
);
1878 i
= hp100_sense_lan( dev
);
1880 if ( i
== HP100_LAN_ERR
)
1881 printk( "hp100: %s: link down detected\n", dev
->name
);
1883 if ( lp
->lan_type
!= i
) /* cable change! */
1885 /* it's very hard - all network setting must be changed!!! */
1886 printk( "hp100: %s: cable change 10Mb/s <-> 100Mb/s detected\n", dev
->name
);
1888 hp100_stop_interface( dev
);
1889 if ( lp
->lan_type
== HP100_LAN_100
)
1890 lp
->hub_status
= hp100_login_to_vg_hub( dev
, FALSE
);
1891 hp100_start_interface( dev
);
1895 printk( "hp100: %s: interface reset\n", dev
->name
);
1896 hp100_stop_interface( dev
);
1897 if ( lp
->lan_type
== HP100_LAN_100
)
1898 lp
->hub_status
= hp100_login_to_vg_hub( dev
, FALSE
);
1899 hp100_start_interface( dev
);
1903 dev
->trans_start
= jiffies
;
1907 for ( i
=0; i
<6000 && ( hp100_inb( OPTION_MSW
) & HP100_TX_CMD
); i
++ )
1909 #ifdef HP100_DEBUG_TX
1910 printk( "hp100: %s: start_xmit: busy\n", dev
->name
);
1915 val
= hp100_inw( IRQ_STATUS
);
1916 /* Ack / clear the interrupt TX_COMPLETE interrupt - this interrupt is set
1917 * when the current packet being transmitted on the wire is completed. */
1918 hp100_outw( HP100_TX_COMPLETE
, IRQ_STATUS
);
1919 #ifdef HP100_DEBUG_TX
1920 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
);
1923 ok_flag
= skb
->len
>= HP100_MIN_PACKET_SIZE
;
1924 i
= ok_flag
? skb
->len
: HP100_MIN_PACKET_SIZE
;
1926 hp100_outw( i
, DATA32
); /* tell card the total packet length */
1927 hp100_outw( i
, FRAGMENT_LEN
); /* and first/only fragment length */
1929 if ( lp
->mode
==2 ) /* memory mapped */
1931 if ( lp
->mem_ptr_virt
) /* high pci memory was remapped */
1933 /* Note: The J2585B needs alignment to 32bits here! */
1934 memcpy( lp
->mem_ptr_virt
, skb
->data
, ( skb
->len
+ 3 ) & ~3 );
1936 memset( lp
->mem_ptr_virt
, 0, HP100_MIN_PACKET_SIZE
- skb
->len
);
1940 /* Note: The J2585B needs alignment to 32bits here! */
1941 isa_memcpy_toio( lp
->mem_ptr_phys
, skb
->data
, (skb
->len
+ 3) & ~3 );
1943 isa_memset_io( lp
->mem_ptr_phys
, 0, HP100_MIN_PACKET_SIZE
- skb
->len
);
1946 else /* programmed i/o */
1948 outsl( ioaddr
+ HP100_REG_DATA32
, skb
->data
, ( skb
->len
+ 3 ) >> 2 );
1950 for ( i
= ( skb
->len
+ 3 ) & ~3; i
< HP100_MIN_PACKET_SIZE
; i
+= 4 )
1951 hp100_outl( 0, DATA32
);
1954 hp100_outb( HP100_TX_CMD
| HP100_SET_LB
, OPTION_MSW
); /* send packet */
1956 lp
->stats
.tx_packets
++;
1958 lp
->stats
.tx_bytes
+= skb
->len
;
1960 dev
->trans_start
=jiffies
;
1964 dev_kfree_skb( skb
);
1966 dev_kfree_skb( skb
, FREE_WRITE
);
1969 #ifdef HP100_DEBUG_TX
1970 printk( "hp100: %s: start_xmit: end\n", dev
->name
);
1978 * Receive Function (Non-Busmaster mode)
1979 * Called when an "Receive Packet" interrupt occurs, i.e. the receive
1980 * packet counter is non-zero.
1981 * For non-busmaster, this function does the whole work of transfering
1982 * the packet to the host memory and then up to higher layers via skb
1986 static void hp100_rx( struct net_device
*dev
)
1988 int packets
, pkt_len
;
1989 int ioaddr
= dev
->base_addr
;
1990 struct hp100_private
*lp
= (struct hp100_private
*)dev
->priv
;
1992 struct sk_buff
*skb
;
1995 hp100_outw( 0x4213, TRACE
);
1996 printk("hp100: %s: rx\n", dev
->name
);
1999 /* First get indication of received lan packet */
2000 /* RX_PKT_CND indicates the number of packets which have been fully */
2001 /* received onto the card but have not been fully transfered of the card */
2002 packets
= hp100_inb( RX_PKT_CNT
);
2003 #ifdef HP100_DEBUG_RX
2005 printk( "hp100: %s: rx: waiting packets = %d\n", dev
->name
,packets
);
2008 while ( packets
-- > 0 )
2010 /* If ADV_NXT_PKT is still set, we have to wait until the card has */
2011 /* really advanced to the next packet. */
2012 for (pkt_len
=0; pkt_len
<6000 &&(hp100_inb(OPTION_MSW
)&HP100_ADV_NXT_PKT
);
2015 #ifdef HP100_DEBUG_RX
2016 printk( "hp100: %s: rx: busy, remaining packets = %d\n", dev
->name
, packets
);
2020 /* First we get the header, which contains information about the */
2021 /* actual length of the received packet. */
2022 if( lp
->mode
==2 ) /* memory mapped mode */
2024 if ( lp
->mem_ptr_virt
) /* if memory was remapped */
2025 header
= readl(lp
->mem_ptr_virt
);
2027 header
= isa_readl( lp
->mem_ptr_phys
);
2029 else /* programmed i/o */
2030 header
= hp100_inl( DATA32
);
2032 pkt_len
= ((header
& HP100_PKT_LEN_MASK
) + 3) & ~3;
2034 #ifdef HP100_DEBUG_RX
2035 printk( "hp100: %s: rx: new packet - length=%d, errors=0x%x, dest=0x%x\n",
2037 header
& HP100_PKT_LEN_MASK
, (header
>>16)&0xfff8,
2041 /* Now we allocate the skb and transfer the data into it. */
2042 skb
= dev_alloc_skb( pkt_len
);
2043 if ( skb
== NULL
) /* Not enough memory->drop packet */
2046 printk( "hp100: %s: rx: couldn't allocate a sk_buff of size %d\n", dev
->name
, pkt_len
);
2048 lp
->stats
.rx_dropped
++;
2050 else /* skb successfully allocated */
2056 /* ptr to start of the sk_buff data area */
2057 ptr
= (u_char
*)skb_put( skb
, pkt_len
);
2059 /* Now transfer the data from the card into that area */
2062 if ( lp
->mem_ptr_virt
)
2063 memcpy( ptr
, lp
->mem_ptr_virt
, pkt_len
);
2064 /* Note alignment to 32bit transfers */
2066 isa_memcpy_fromio( ptr
, lp
->mem_ptr_phys
, pkt_len
);
2068 else /* io mapped */
2069 insl( ioaddr
+ HP100_REG_DATA32
, ptr
, pkt_len
>> 2 );
2071 skb
->protocol
= eth_type_trans( skb
, dev
);
2074 lp
->stats
.rx_packets
++;
2076 lp
->stats
.rx_bytes
+= skb
->len
;
2079 #ifdef HP100_DEBUG_RX
2080 printk( "hp100: %s: rx: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
2082 ptr
[ 0 ], ptr
[ 1 ], ptr
[ 2 ], ptr
[ 3 ], ptr
[ 4 ], ptr
[ 5 ],
2083 ptr
[ 6 ], ptr
[ 7 ], ptr
[ 8 ], ptr
[ 9 ], ptr
[ 10 ], ptr
[ 11 ] );
2087 /* Indicate the card that we have got the packet */
2088 hp100_outb( HP100_ADV_NXT_PKT
| HP100_SET_LB
, OPTION_MSW
);
2090 switch ( header
& 0x00070000 ) {
2091 case (HP100_MULTI_ADDR_HASH
<<16):
2092 case (HP100_MULTI_ADDR_NO_HASH
<<16):
2093 lp
->stats
.multicast
++; break;
2095 } /* end of while(there are packets) loop */
2096 #ifdef HP100_DEBUG_RX
2097 printk( "hp100_rx: %s: end\n", dev
->name
);
2103 * Receive Function for Busmaster Mode
2105 static void hp100_rx_bm( struct net_device
*dev
)
2107 int ioaddr
= dev
->base_addr
;
2108 struct hp100_private
*lp
= (struct hp100_private
*)dev
->priv
;
2113 #ifdef HP100_DEBUG_B
2114 hp100_outw( 0x4214, TRACE
);
2115 printk("hp100: %s: rx_bm\n", dev
->name
);
2119 if(0==lp
->rxrcommit
)
2121 printk("hp100: %s: rx_bm called although no PDLs were committed to adapter?\n", dev
->name
);
2126 /* RX_PKT_CNT states how many PDLs are currently formatted and available to
2127 * the cards BM engine */
2128 if( (hp100_inw(RX_PKT_CNT
)&0x00ff) >= lp
->rxrcommit
)
2130 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
);
2135 while( (lp
->rxrcommit
> hp100_inb(RX_PDL
)) )
2138 * The packet was received into the pdl pointed to by lp->rxrhead (
2139 * the oldest pdl in the ring
2142 /* First we get the header, which contains information about the */
2143 /* actual length of the received packet. */
2147 header
= *(ptr
->pdl
-1);
2148 pkt_len
= (header
& HP100_PKT_LEN_MASK
);
2150 #ifdef HP100_DEBUG_BM
2151 printk( "hp100: %s: rx_bm: header@0x%x=0x%x length=%d, errors=0x%x, dest=0x%x\n",
2153 (u_int
) (ptr
->pdl
-1),(u_int
) header
,
2155 (header
>>16)&0xfff8,
2157 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",
2159 hp100_inb( RX_PDL
),
2160 hp100_inb( TX_PDL
),
2161 hp100_inb( RX_PKT_CNT
),
2162 (u_int
) *(ptr
->pdl
),
2163 (u_int
) *(ptr
->pdl
+3),
2164 (u_int
) *(ptr
->pdl
+4));
2167 if( (pkt_len
>=MIN_ETHER_SIZE
) &&
2168 (pkt_len
<=MAX_ETHER_SIZE
) )
2172 printk("hp100: %s: rx_bm: skb null\n", dev
->name
);
2173 /* can happen if we only allocated room for the pdh due to memory shortage. */
2174 lp
->stats
.rx_dropped
++;
2178 skb_trim( ptr
->skb
, pkt_len
); /* Shorten it */
2179 ptr
->skb
->protocol
= eth_type_trans( ptr
->skb
, dev
);
2181 netif_rx( ptr
->skb
); /* Up and away... */
2183 lp
->stats
.rx_packets
++;
2185 lp
->stats
.rx_bytes
+= ptr
->skb
->len
;
2189 switch ( header
& 0x00070000 ) {
2190 case (HP100_MULTI_ADDR_HASH
<<16):
2191 case (HP100_MULTI_ADDR_NO_HASH
<<16):
2192 lp
->stats
.multicast
++; break;
2198 printk("hp100: %s: rx_bm: Received bad packet (length=%d)\n",dev
->name
,pkt_len
);
2202 dev_kfree_skb( ptr
->skb
);
2204 dev_kfree_skb( ptr
->skb
, FREE_READ
);
2206 lp
->stats
.rx_errors
++;
2209 lp
->rxrhead
=lp
->rxrhead
->next
;
2211 /* Allocate a new rx PDL (so lp->rxrcommit stays the same) */
2212 if (0 == hp100_build_rx_pdl( lp
->rxrtail
, dev
))
2214 /* No space for skb, header can still be received. */
2216 printk("hp100: %s: rx_bm: No space for new PDL.\n", dev
->name
);
2221 { /* successfully allocated new PDL - put it in ringlist at tail. */
2222 hp100_outl((u32
)lp
->rxrtail
->pdl_paddr
, RX_PDA
);
2223 lp
->rxrtail
=lp
->rxrtail
->next
;
2234 static hp100_stats_t
*hp100_get_stats( struct net_device
*dev
)
2236 int ioaddr
= dev
->base_addr
;
2238 #ifdef HP100_DEBUG_B
2239 hp100_outw( 0x4215, TRACE
);
2243 hp100_update_stats( dev
);
2245 return &((struct hp100_private
*)dev
->priv
)->stats
;
2248 static void hp100_update_stats( struct net_device
*dev
)
2250 int ioaddr
= dev
->base_addr
;
2252 struct hp100_private
*lp
= (struct hp100_private
*)dev
->priv
;
2254 #ifdef HP100_DEBUG_B
2255 hp100_outw( 0x4216, TRACE
);
2256 printk("hp100: %s: update-stats\n", dev
->name
);
2259 /* Note: Statistics counters clear when read. */
2260 hp100_page( MAC_CTRL
);
2261 val
= hp100_inw( DROPPED
) & 0x0fff;
2262 lp
->stats
.rx_errors
+= val
;
2263 lp
->stats
.rx_over_errors
+= val
;
2264 val
= hp100_inb( CRC
);
2265 lp
->stats
.rx_errors
+= val
;
2266 lp
->stats
.rx_crc_errors
+= val
;
2267 val
= hp100_inb( ABORT
);
2268 lp
->stats
.tx_errors
+= val
;
2269 lp
->stats
.tx_aborted_errors
+= val
;
2270 hp100_page( PERFORMANCE
);
2273 static void hp100_misc_interrupt( struct net_device
*dev
)
2275 struct hp100_private
*lp
= (struct hp100_private
*)dev
->priv
;
2277 #ifdef HP100_DEBUG_B
2278 hp100_outw( 0x4216, TRACE
);
2279 printk("hp100: %s: misc_interrupt\n", dev
->name
);
2282 /* Note: Statistics counters clear when read. */
2283 lp
->stats
.rx_errors
++;
2284 lp
->stats
.tx_errors
++;
2287 static void hp100_clear_stats( int ioaddr
)
2289 unsigned long flags
;
2291 #ifdef HP100_DEBUG_B
2292 hp100_outw( 0x4217, TRACE
);
2293 printk("hp100: %s: clear_stats\n", dev
->name
);
2296 save_flags( flags
);
2298 hp100_page( MAC_CTRL
); /* get all statistics bytes */
2299 hp100_inw( DROPPED
);
2302 hp100_page( PERFORMANCE
);
2303 restore_flags( flags
);
2312 * Set or clear the multicast filter for this adapter.
2315 static void hp100_set_multicast_list( struct net_device
*dev
)
2317 unsigned long flags
;
2318 int ioaddr
= dev
->base_addr
;
2319 struct hp100_private
*lp
= (struct hp100_private
*)dev
->priv
;
2321 #ifdef HP100_DEBUG_B
2322 hp100_outw( 0x4218, TRACE
);
2323 printk("hp100: %s: set_mc_list\n", dev
->name
);
2326 save_flags( flags
);
2329 hp100_page( MAC_CTRL
);
2330 hp100_andb( ~(HP100_RX_EN
| HP100_TX_EN
), MAC_CFG_1
); /* stop rx/tx */
2332 if ( dev
->flags
& IFF_PROMISC
)
2334 lp
->mac2_mode
= HP100_MAC2MODE6
; /* promiscuous mode = get all good */
2335 lp
->mac1_mode
= HP100_MAC1MODE6
; /* packets on the net */
2336 memset( &lp
->hash_bytes
, 0xff, 8 );
2338 else if ( dev
->mc_count
|| (dev
->flags
&IFF_ALLMULTI
) )
2340 lp
->mac2_mode
= HP100_MAC2MODE5
; /* multicast mode = get packets for */
2341 lp
->mac1_mode
= HP100_MAC1MODE5
; /* me, broadcasts and all multicasts */
2342 #ifdef HP100_MULTICAST_FILTER /* doesn't work!!! */
2343 if ( dev
-> flags
& IFF_ALLMULTI
)
2345 /* set hash filter to receive all multicast packets */
2346 memset( &lp
->hash_bytes
, 0xff, 8 );
2352 struct dev_mc_list
*dmi
;
2354 memset( &lp
->hash_bytes
, 0x00, 8 );
2356 printk("hp100: %s: computing hash filter - mc_count = %i\n", dev
-> name
, dev
-> mc_count
);
2358 for ( i
= 0, dmi
= dev
-> mc_list
; i
< dev
-> mc_count
; i
++, dmi
= dmi
-> next
)
2360 addrs
= dmi
-> dmi_addr
;
2361 if ( ( *addrs
& 0x01 ) == 0x01 ) /* multicast address? */
2364 printk("hp100: %s: multicast = %02x:%02x:%02x:%02x:%02x:%02x, ",
2366 addrs
[ 0 ], addrs
[ 1 ], addrs
[ 2 ],
2367 addrs
[ 3 ], addrs
[ 4 ], addrs
[ 5 ] );
2369 for ( j
= idx
= 0; j
< 6; j
++ )
2371 idx
^= *addrs
++ & 0x3f;
2372 printk( ":%02x:", idx
);
2375 printk("idx = %i\n", idx
);
2377 lp
->hash_bytes
[ idx
>> 3 ] |= ( 1 << ( idx
& 7 ) );
2382 memset( &lp
->hash_bytes
, 0xff, 8 );
2387 lp
->mac2_mode
= HP100_MAC2MODE3
; /* normal mode = get packets for me */
2388 lp
->mac1_mode
= HP100_MAC1MODE3
; /* and broadcasts */
2389 memset( &lp
->hash_bytes
, 0x00, 8 );
2392 if ( ( (hp100_inb(MAC_CFG_1
) & 0x0f)!=lp
->mac1_mode
) ||
2393 ( hp100_inb(MAC_CFG_2
)!=lp
->mac2_mode
) )
2397 hp100_outb( lp
->mac2_mode
, MAC_CFG_2
);
2398 hp100_andb( HP100_MAC1MODEMASK
, MAC_CFG_1
); /* clear mac1 mode bits */
2399 hp100_orb( lp
->mac1_mode
, MAC_CFG_1
); /* and set the new mode */
2401 hp100_page( MAC_ADDRESS
);
2402 for ( i
= 0; i
< 8; i
++ )
2403 hp100_outb( lp
->hash_bytes
[ i
], HASH_BYTE0
+ i
);
2405 printk("hp100: %s: mac1 = 0x%x, mac2 = 0x%x, multicast hash = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
2406 dev
->name
, lp
->mac1_mode
, lp
->mac2_mode
,
2407 lp
->hash_bytes
[ 0 ], lp
->hash_bytes
[ 1 ],
2408 lp
->hash_bytes
[ 2 ], lp
->hash_bytes
[ 3 ],
2409 lp
->hash_bytes
[ 4 ], lp
->hash_bytes
[ 5 ],
2410 lp
->hash_bytes
[ 6 ], lp
->hash_bytes
[ 7 ]
2414 if(lp
->lan_type
==HP100_LAN_100
)
2417 printk("hp100: %s: 100VG MAC settings have changed - relogin.\n", dev
->name
);
2419 lp
->hub_status
=hp100_login_to_vg_hub( dev
, TRUE
); /* force a relogin to the hub */
2425 u_char old_hash_bytes
[ 8 ];
2427 hp100_page( MAC_ADDRESS
);
2428 for ( i
= 0; i
< 8; i
++ )
2429 old_hash_bytes
[ i
] = hp100_inb( HASH_BYTE0
+ i
);
2430 if ( memcmp( old_hash_bytes
, &lp
->hash_bytes
, 8 ) )
2432 for ( i
= 0; i
< 8; i
++ )
2433 hp100_outb( lp
->hash_bytes
[ i
], HASH_BYTE0
+ i
);
2435 printk("hp100: %s: multicast hash = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
2437 lp
->hash_bytes
[ 0 ], lp
->hash_bytes
[ 1 ],
2438 lp
->hash_bytes
[ 2 ], lp
->hash_bytes
[ 3 ],
2439 lp
->hash_bytes
[ 4 ], lp
->hash_bytes
[ 5 ],
2440 lp
->hash_bytes
[ 6 ], lp
->hash_bytes
[ 7 ]
2444 if(lp
->lan_type
==HP100_LAN_100
)
2447 printk("hp100: %s: 100VG MAC settings have changed - relogin.\n", dev
->name
);
2449 lp
->hub_status
=hp100_login_to_vg_hub( dev
, TRUE
); /* force a relogin to the hub */
2454 hp100_page( MAC_CTRL
);
2455 hp100_orb( HP100_RX_EN
| HP100_RX_IDLE
| /* enable rx */
2456 HP100_TX_EN
| HP100_TX_IDLE
, MAC_CFG_1
); /* enable tx */
2458 hp100_page( PERFORMANCE
);
2460 restore_flags( flags
);
2465 * hardware interrupt handling
2468 static void hp100_interrupt( int irq
, void *dev_id
, struct pt_regs
*regs
)
2470 struct net_device
*dev
= (struct net_device
*)dev_id
;
2471 struct hp100_private
*lp
= (struct hp100_private
*)dev
->priv
;
2476 if ( dev
== NULL
) return;
2477 ioaddr
= dev
->base_addr
;
2479 if ( dev
->interrupt
)
2480 printk( "hp100: %s: re-entering the interrupt handler\n", dev
->name
);
2482 dev
->interrupt
= 1; /* mark that we are inside the handler */
2484 #ifdef HP100_DEBUG_B
2485 hp100_outw( 0x4219, TRACE
);
2488 /* hp100_page( PERFORMANCE ); */
2489 val
= hp100_inw( IRQ_STATUS
);
2490 #ifdef HP100_DEBUG_IRQ
2491 printk( "hp100: %s: mode=%x,IRQ_STAT=0x%.4x,RXPKTCNT=0x%.2x RXPDL=0x%.2x TXPKTCNT=0x%.2x TXPDL=0x%.2x\n",
2495 hp100_inb( RX_PKT_CNT
),
2496 hp100_inb( RX_PDL
),
2497 hp100_inb( TX_PKT_CNT
),
2502 if(val
==0) /* might be a shared interrupt */
2508 /* We're only interested in those interrupts we really enabled. */
2509 /* val &= hp100_inw( IRQ_MASK ); */
2512 * RX_PDL_FILL_COMPL is set whenever a RX_PDL has been executed. A RX_PDL
2513 * is considered executed whenever the RX_PDL data structure is no longer
2516 if ( val
& HP100_RX_PDL_FILL_COMPL
)
2522 printk("hp100: %s: rx_pdl_fill_compl interrupt although not busmaster?\n", dev
->name
);
2527 * The RX_PACKET interrupt is set, when the receive packet counter is
2528 * non zero. We use this interrupt for receiving in slave mode. In
2529 * busmaster mode, we use it to make sure we did not miss any rx_pdl_fill
2530 * interrupts. If rx_pdl_fill_compl is not set and rx_packet is set, then
2531 * we somehow have missed a rx_pdl_fill_compl interrupt.
2534 if ( val
& HP100_RX_PACKET
) /* Receive Packet Counter is non zero */
2536 if(lp
->mode
!=1) /* non busmaster */
2538 else if ( !(val
& HP100_RX_PDL_FILL_COMPL
))
2540 /* Shouldnt happen - maybe we missed a RX_PDL_FILL Interrupt? */
2546 * Ack. that we have noticed the interrupt and thereby allow next one.
2547 * Note that this is now done after the slave rx function, since first
2548 * acknowledging and then setting ADV_NXT_PKT caused an extra interrupt
2551 hp100_outw( val
, IRQ_STATUS
);
2554 * RX_ERROR is set when a packet is dropped due to no memory resources on
2555 * the card or when a RCV_ERR occurs.
2556 * TX_ERROR is set when a TX_ABORT condition occurs in the MAC->exists
2557 * only in the 802.3 MAC and happens when 16 collisions occur during a TX
2559 if ( val
& ( HP100_TX_ERROR
| HP100_RX_ERROR
) )
2561 #ifdef HP100_DEBUG_IRQ
2562 printk("hp100: %s: TX/RX Error IRQ\n", dev
->name
);
2564 hp100_update_stats( dev
);
2567 hp100_rxfill( dev
);
2568 hp100_clean_txring( dev
);
2573 * RX_PDA_ZERO is set when the PDA count goes from non-zero to zero.
2575 if ( (lp
->mode
==1)&&(val
&(HP100_RX_PDA_ZERO
)) )
2576 hp100_rxfill( dev
);
2579 * HP100_TX_COMPLETE interrupt occurs when packet transmitted on wire
2582 if ( (lp
->mode
==1) && ( val
& ( HP100_TX_COMPLETE
)) )
2583 hp100_clean_txring( dev
);
2586 * MISC_ERROR is set when either the LAN link goes down or a detected
2589 if ( val
& HP100_MISC_ERROR
) /* New for J2585B */
2591 #ifdef HP100_DEBUG_IRQ
2592 printk("hp100: %s: Misc. Error Interrupt - Check cabling.\n", dev
->name
);
2596 hp100_clean_txring( dev
);
2597 hp100_rxfill( dev
);
2599 hp100_misc_interrupt( dev
);
2608 * some misc functions
2611 static void hp100_start_interface( struct net_device
*dev
)
2613 unsigned long flags
;
2614 int ioaddr
= dev
->base_addr
;
2615 struct hp100_private
*lp
= (struct hp100_private
*)dev
->priv
;
2617 #ifdef HP100_DEBUG_B
2618 hp100_outw( 0x4220, TRACE
);
2619 printk("hp100: %s: hp100_start_interface\n",dev
->name
);
2622 save_flags( flags
);
2625 /* Ensure the adapter does not want to request an interrupt when */
2626 /* enabling the IRQ line to be active on the bus (i.e. not tri-stated) */
2627 hp100_page( PERFORMANCE
);
2628 hp100_outw( 0xfefe, IRQ_MASK
); /* mask off all ints */
2629 hp100_outw( 0xffff, IRQ_STATUS
); /* ack all IRQs */
2630 hp100_outw( HP100_FAKE_INT
|HP100_INT_EN
|HP100_RESET_LB
, OPTION_LSW
);
2631 /* Un Tri-state int. TODO: Check if shared interrupts can be realised? */
2632 hp100_outw( HP100_TRI_INT
| HP100_RESET_HB
, OPTION_LSW
);
2636 /* Make sure BM bit is set... */
2638 hp100_orb( HP100_BM_MASTER
, BM
);
2639 hp100_rxfill( dev
);
2641 else if(lp
->mode
==2)
2643 /* Enable memory mapping. Note: Don't do this when busmaster. */
2644 hp100_outw( HP100_MMAP_DIS
| HP100_RESET_HB
, OPTION_LSW
);
2647 hp100_page(PERFORMANCE
);
2648 hp100_outw( 0xfefe, IRQ_MASK
); /* mask off all ints */
2649 hp100_outw( 0xffff, IRQ_STATUS
); /* ack IRQ */
2651 /* enable a few interrupts: */
2652 if(lp
->mode
==1) /* busmaster mode */
2654 hp100_outw( HP100_RX_PDL_FILL_COMPL
|
2657 /* HP100_RX_PACKET | */
2658 /* HP100_RX_EARLY_INT | */ HP100_SET_HB
|
2659 /* HP100_TX_PDA_ZERO | */
2661 /* HP100_MISC_ERROR | */
2662 HP100_TX_ERROR
| HP100_SET_LB
, IRQ_MASK
);
2666 hp100_outw( HP100_RX_PACKET
|
2667 HP100_RX_ERROR
| HP100_SET_HB
|
2668 HP100_TX_ERROR
| HP100_SET_LB
, IRQ_MASK
);
2671 /* Enable MAC Tx and RX, set MAC modes, ... */
2672 hp100_set_multicast_list( dev
);
2674 restore_flags( flags
);
2678 static void hp100_stop_interface( struct net_device
*dev
)
2680 struct hp100_private
*lp
= (struct hp100_private
*)dev
->priv
;
2681 int ioaddr
= dev
->base_addr
;
2684 #ifdef HP100_DEBUG_B
2685 printk("hp100: %s: hp100_stop_interface\n",dev
->name
);
2686 hp100_outw( 0x4221, TRACE
);
2690 hp100_BM_shutdown( dev
);
2693 /* Note: MMAP_DIS will be reenabled by start_interface */
2694 hp100_outw( HP100_INT_EN
| HP100_RESET_LB
|
2695 HP100_TRI_INT
| HP100_MMAP_DIS
| HP100_SET_HB
, OPTION_LSW
);
2696 val
= hp100_inw( OPTION_LSW
);
2698 hp100_page( MAC_CTRL
);
2699 hp100_andb( ~(HP100_RX_EN
| HP100_TX_EN
), MAC_CFG_1
);
2701 if ( !(val
& HP100_HW_RST
) ) return; /* If reset, imm. return ... */
2702 /* ... else: busy wait until idle */
2703 for ( val
= 0; val
< 6000; val
++ )
2704 if ( ( hp100_inb( MAC_CFG_1
) & (HP100_TX_IDLE
| HP100_RX_IDLE
) ) ==
2705 (HP100_TX_IDLE
| HP100_RX_IDLE
) )
2707 hp100_page(PERFORMANCE
);
2710 printk( "hp100: %s: hp100_stop_interface - timeout\n", dev
->name
);
2711 hp100_page(PERFORMANCE
);
2716 static void hp100_load_eeprom( struct net_device
*dev
, u_short probe_ioaddr
)
2719 int ioaddr
= probe_ioaddr
> 0 ? probe_ioaddr
: dev
->base_addr
;
2721 #ifdef HP100_DEBUG_B
2722 hp100_outw( 0x4222, TRACE
);
2725 hp100_page( EEPROM_CTRL
);
2726 hp100_andw( ~HP100_EEPROM_LOAD
, EEPROM_CTRL
);
2727 hp100_orw( HP100_EEPROM_LOAD
, EEPROM_CTRL
);
2728 for ( i
= 0; i
< 10000; i
++ )
2729 if ( !( hp100_inb( OPTION_MSW
) & HP100_EE_LOAD
) ) return;
2730 printk( "hp100: %s: hp100_load_eeprom - timeout\n", dev
->name
);
2734 /* Sense connection status.
2735 * return values: LAN_10 - Connected to 10Mbit/s network
2736 * LAN_100 - Connected to 100Mbit/s network
2737 * LAN_ERR - not connected or 100Mbit/s Hub down
2739 static int hp100_sense_lan( struct net_device
*dev
)
2741 int ioaddr
= dev
->base_addr
;
2742 u_short val_VG
, val_10
;
2743 struct hp100_private
*lp
= (struct hp100_private
*)dev
->priv
;
2745 #ifdef HP100_DEBUG_B
2746 hp100_outw( 0x4223, TRACE
);
2749 hp100_page( MAC_CTRL
);
2750 val_10
= hp100_inb( 10_LAN_CFG_1
);
2751 val_VG
= hp100_inb( VG_LAN_CFG_1
);
2752 hp100_page( PERFORMANCE
);
2754 printk( "hp100: %s: sense_lan: val_VG = 0x%04x, val_10 = 0x%04x\n", dev
->name
, val_VG
, val_10
);
2757 if ( val_10
& HP100_LINK_BEAT_ST
) /* 10Mb connection is active */
2758 return HP100_LAN_10
;
2760 if ( val_10
& HP100_AUI_ST
) /* have we BNC or AUI onboard? */
2762 val_10
|= HP100_AUI_SEL
| HP100_LOW_TH
;
2763 hp100_page( MAC_CTRL
);
2764 hp100_outb( val_10
, 10_LAN_CFG_1
);
2765 hp100_page( PERFORMANCE
);
2766 return HP100_LAN_10
;
2769 if ( (lp
->id
->id
== 0x02019F022) ||
2770 (lp
->id
->id
== 0x01042103c) ||
2771 (lp
->id
->id
== 0x01040103c) )
2772 return HP100_LAN_ERR
; /* Those cards don't have a 100 Mbit connector */
2774 if ( val_VG
& HP100_LINK_CABLE_ST
) /* Can hear the HUBs tone. */
2775 return HP100_LAN_100
;
2776 return HP100_LAN_ERR
;
2781 static int hp100_down_vg_link( struct net_device
*dev
)
2783 struct hp100_private
*lp
= (struct hp100_private
*)dev
->priv
;
2784 int ioaddr
= dev
->base_addr
;
2786 long savelan
, newlan
;
2788 #ifdef HP100_DEBUG_B
2789 hp100_outw( 0x4224, TRACE
);
2790 printk("hp100: %s: down_vg_link\n", dev
->name
);
2793 hp100_page( MAC_CTRL
);
2794 time
=jiffies
+(HZ
/4);
2796 if ( hp100_inb( VG_LAN_CFG_1
) & HP100_LINK_CABLE_ST
) break;
2797 } while (time_after(time
, jiffies
));
2799 if ( time_after_eq(jiffies
, time
) ) /* no signal->no logout */
2802 /* Drop the VG Link by clearing the link up cmd and load addr.*/
2804 hp100_andb( ~( HP100_LOAD_ADDR
| HP100_LINK_CMD
), VG_LAN_CFG_1
);
2805 hp100_orb( HP100_VG_SEL
, VG_LAN_CFG_1
);
2807 /* Conditionally stall for >250ms on Link-Up Status (to go down) */
2808 time
=jiffies
+(HZ
/2);
2810 if ( !(hp100_inb( VG_LAN_CFG_1
) & HP100_LINK_UP_ST
) ) break;
2811 } while(time_after(time
, jiffies
));
2814 if (time_after_eq(jiffies
, time
))
2815 printk("hp100: %s: down_vg_link: Link does not go down?\n", dev
->name
);
2818 /* To prevent condition where Rev 1 VG MAC and old hubs do not complete */
2819 /* logout under traffic (even though all the status bits are cleared), */
2820 /* do this workaround to get the Rev 1 MAC in its idle state */
2821 if ( lp
->chip
==HP100_CHIPID_LASSEN
)
2823 /* Reset VG MAC to insure it leaves the logoff state even if */
2824 /* the Hub is still emitting tones */
2825 hp100_andb(~HP100_VG_RESET
, VG_LAN_CFG_1
);
2826 udelay(1500); /* wait for >1ms */
2827 hp100_orb(HP100_VG_RESET
, VG_LAN_CFG_1
); /* Release Reset */
2831 /* New: For lassen, switch to 10 Mbps mac briefly to clear training ACK */
2832 /* to get the VG mac to full reset. This is not req.d with later chips */
2833 /* Note: It will take the between 1 and 2 seconds for the VG mac to be */
2834 /* selected again! This will be left to the connect hub function to */
2835 /* perform if desired. */
2836 if (lp
->chip
==HP100_CHIPID_LASSEN
)
2838 /* Have to write to 10 and 100VG control registers simultaneously */
2839 savelan
=newlan
=hp100_inl(10_LAN_CFG_1
); /* read 10+100 LAN_CFG regs */
2840 newlan
&= ~(HP100_VG_SEL
<<16);
2841 newlan
|= (HP100_DOT3_MAC
)<<8;
2842 hp100_andb( ~HP100_AUTO_MODE
, MAC_CFG_3
); /* Autosel off */
2843 hp100_outl(newlan
, 10_LAN_CFG_1
);
2845 /* Conditionally stall for 5sec on VG selected. */
2846 time
=jiffies
+(HZ
*5);
2848 if( !(hp100_inb(MAC_CFG_4
) & HP100_MAC_SEL_ST
) ) break;
2849 } while(time_after(time
, jiffies
));
2851 hp100_orb( HP100_AUTO_MODE
, MAC_CFG_3
); /* Autosel back on */
2852 hp100_outl(savelan
, 10_LAN_CFG_1
);
2855 time
=jiffies
+(3*HZ
); /* Timeout 3s */
2857 if ( (hp100_inb( VG_LAN_CFG_1
)&HP100_LINK_CABLE_ST
) == 0) break;
2858 } while (time_after(time
, jiffies
));
2860 if(time_before_eq(time
, jiffies
))
2863 printk( "hp100: %s: down_vg_link: timeout\n", dev
->name
);
2868 time
=jiffies
+(2*HZ
); /* This seems to take a while.... */
2869 do {} while (time_after(time
, jiffies
));
2875 static int hp100_login_to_vg_hub( struct net_device
*dev
, u_short force_relogin
)
2877 int ioaddr
= dev
->base_addr
;
2878 struct hp100_private
*lp
= (struct hp100_private
*)dev
->priv
;
2883 #ifdef HP100_DEBUG_B
2884 hp100_outw( 0x4225, TRACE
);
2885 printk("hp100: %s: login_to_vg_hub\n", dev
->name
);
2888 /* Initiate a login sequence iff VG MAC is enabled and either Load Address
2889 * bit is zero or the force relogin flag is set (e.g. due to MAC address or
2890 * promiscuous mode change)
2892 hp100_page( MAC_CTRL
);
2893 startst
=hp100_inb( VG_LAN_CFG_1
);
2894 if((force_relogin
==TRUE
)||(hp100_inb( MAC_CFG_4
)&HP100_MAC_SEL_ST
))
2896 #ifdef HP100_DEBUG_TRAINING
2897 printk("hp100: %s: Start training\n", dev
->name
);
2900 /* Ensure VG Reset bit is 1 (i.e., do not reset)*/
2901 hp100_orb( HP100_VG_RESET
, VG_LAN_CFG_1
);
2903 /* If Lassen AND auto-select-mode AND VG tones were sensed on */
2904 /* entry then temporarily put them into force 100Mbit mode */
2905 if((lp
->chip
==HP100_CHIPID_LASSEN
)&&( startst
& HP100_LINK_CABLE_ST
) )
2906 hp100_andb( ~HP100_DOT3_MAC
, 10_LAN_CFG_2
);
2908 /* Drop the VG link by zeroing Link Up Command and Load Address */
2909 hp100_andb( ~(HP100_LINK_CMD
/* |HP100_LOAD_ADDR */), VG_LAN_CFG_1
);
2911 #ifdef HP100_DEBUG_TRAINING
2912 printk("hp100: %s: Bring down the link\n", dev
->name
);
2915 /* Wait for link to drop */
2916 time
= jiffies
+ (HZ
/10);
2918 if (~(hp100_inb( VG_LAN_CFG_1
)& HP100_LINK_UP_ST
) ) break;
2919 } while (time_after(time
, jiffies
));
2921 /* Start an addressed training and optionally request promiscuous port */
2922 if ( (dev
->flags
) & IFF_PROMISC
)
2924 hp100_orb( HP100_PROM_MODE
, VG_LAN_CFG_2
);
2925 if(lp
->chip
==HP100_CHIPID_LASSEN
)
2926 hp100_orw( HP100_MACRQ_PROMSC
, TRAIN_REQUEST
);
2930 hp100_andb( ~HP100_PROM_MODE
, VG_LAN_CFG_2
);
2931 /* For ETR parts we need to reset the prom. bit in the training
2932 * register, otherwise promiscious mode won't be disabled.
2934 if(lp
->chip
==HP100_CHIPID_LASSEN
)
2936 hp100_andw( ~HP100_MACRQ_PROMSC
, TRAIN_REQUEST
);
2940 /* With ETR parts, frame format request bits can be set. */
2941 if(lp
->chip
==HP100_CHIPID_LASSEN
)
2942 hp100_orb( HP100_MACRQ_FRAMEFMT_EITHER
, TRAIN_REQUEST
);
2944 hp100_orb( HP100_LINK_CMD
|HP100_LOAD_ADDR
|HP100_VG_RESET
, VG_LAN_CFG_1
);
2946 /* Note: Next wait could be omitted for Hood and earlier chips under */
2947 /* certain circumstances */
2948 /* TODO: check if hood/earlier and skip wait. */
2950 /* Wait for either short timeout for VG tones or long for login */
2951 /* Wait for the card hardware to signalise link cable status ok... */
2952 hp100_page( MAC_CTRL
);
2953 time
= jiffies
+ ( 1*HZ
); /* 1 sec timeout for cable st */
2955 if ( hp100_inb( VG_LAN_CFG_1
) & HP100_LINK_CABLE_ST
) break;
2956 } while ( time_before(jiffies
, time
) );
2958 if ( time_after_eq(jiffies
, time
) )
2960 #ifdef HP100_DEBUG_TRAINING
2961 printk( "hp100: %s: Link cable status not ok? Training aborted.\n", dev
->name
);
2966 #ifdef HP100_DEBUG_TRAINING
2967 printk( "hp100: %s: HUB tones detected. Trying to train.\n", dev
->name
);
2970 time
= jiffies
+ ( 2*HZ
); /* again a timeout */
2972 val
= hp100_inb( VG_LAN_CFG_1
);
2973 if ( (val
& ( HP100_LINK_UP_ST
)) )
2975 #ifdef HP100_DEBUG_TRAINING
2976 printk( "hp100: %s: Passed training.\n", dev
->name
);
2980 } while ( time_after(time
, jiffies
) );
2983 /* If LINK_UP_ST is set, then we are logged into the hub. */
2984 if ( time_before_eq(jiffies
, time
) && (val
& HP100_LINK_UP_ST
) )
2986 #ifdef HP100_DEBUG_TRAINING
2987 printk( "hp100: %s: Successfully logged into the HUB.\n", dev
->name
);
2988 if(lp
->chip
==HP100_CHIPID_LASSEN
)
2990 val
= hp100_inw(TRAIN_ALLOW
);
2991 printk( "hp100: %s: Card supports 100VG MAC Version \"%s\" ",
2992 dev
->name
,(hp100_inw(TRAIN_REQUEST
)&HP100_CARD_MACVER
) ? "802.12" : "Pre");
2993 printk( "Driver will use MAC Version \"%s\"\n",
2994 ( val
& HP100_HUB_MACVER
) ? "802.12" : "Pre" );
2995 printk( "hp100: %s: Frame format is %s.\n",dev
->name
,(val
&HP100_MALLOW_FRAMEFMT
)?"802.5":"802.3");
3001 /* If LINK_UP_ST is not set, login was not successful */
3002 printk("hp100: %s: Problem logging into the HUB.\n",dev
->name
);
3003 if(lp
->chip
==HP100_CHIPID_LASSEN
)
3005 /* Check allowed Register to find out why there is a problem. */
3006 val
= hp100_inw( TRAIN_ALLOW
); /* wont work on non-ETR card */
3007 #ifdef HP100_DEBUG_TRAINING
3008 printk("hp100: %s: MAC Configuration requested: 0x%04x, HUB allowed: 0x%04x\n", dev
->name
, hp100_inw(TRAIN_REQUEST
), val
);
3010 if ( val
& HP100_MALLOW_ACCDENIED
)
3011 printk("hp100: %s: HUB access denied.\n", dev
->name
);
3012 if ( val
& HP100_MALLOW_CONFIGURE
)
3013 printk("hp100: %s: MAC Configuration is incompatible with the Network.\n", dev
->name
);
3014 if ( val
& HP100_MALLOW_DUPADDR
)
3015 printk("hp100: %s: Duplicate MAC Address on the Network.\n", dev
->name
);
3019 /* If we have put the chip into forced 100 Mbit mode earlier, go back */
3020 /* to auto-select mode */
3022 if( (lp
->chip
==HP100_CHIPID_LASSEN
)&&(startst
& HP100_LINK_CABLE_ST
) )
3024 hp100_page( MAC_CTRL
);
3025 hp100_orb( HP100_DOT3_MAC
, 10_LAN_CFG_2
);
3028 val
=hp100_inb(VG_LAN_CFG_1
);
3030 /* Clear the MISC_ERROR Interrupt, which might be generated when doing the relogin */
3031 hp100_page(PERFORMANCE
);
3032 hp100_outw( HP100_MISC_ERROR
, IRQ_STATUS
);
3034 if (val
&HP100_LINK_UP_ST
)
3035 return(0); /* login was ok */
3038 printk("hp100: %s: Training failed.\n", dev
->name
);
3039 hp100_down_vg_link( dev
);
3043 /* no forced relogin & already link there->no training. */
3048 static void hp100_cascade_reset( struct net_device
*dev
, u_short enable
)
3050 int ioaddr
= dev
->base_addr
;
3051 struct hp100_private
*lp
= (struct hp100_private
*)dev
->priv
;
3054 #ifdef HP100_DEBUG_B
3055 hp100_outw( 0x4226, TRACE
);
3056 printk("hp100: %s: cascade_reset\n", dev
->name
);
3061 hp100_outw( HP100_HW_RST
| HP100_RESET_LB
, OPTION_LSW
);
3062 if(lp
->chip
==HP100_CHIPID_LASSEN
)
3064 /* Lassen requires a PCI transmit fifo reset */
3065 hp100_page( HW_MAP
);
3066 hp100_andb( ~HP100_PCI_RESET
, PCICTRL2
);
3067 hp100_orb( HP100_PCI_RESET
, PCICTRL2
);
3068 /* Wait for min. 300 ns */
3069 /* we cant use jiffies here, because it may be */
3070 /* that we have disabled the timer... */
3071 for (i
=0; i
<0xffff; i
++);
3072 hp100_andb( ~HP100_PCI_RESET
, PCICTRL2
);
3073 hp100_page( PERFORMANCE
);
3077 { /* bring out of reset */
3078 hp100_outw(HP100_HW_RST
|HP100_SET_LB
, OPTION_LSW
);
3079 for (i
=0; i
<0xffff; i
++ );
3080 hp100_page(PERFORMANCE
);
3085 void hp100_RegisterDump( struct net_device
*dev
)
3087 int ioaddr
=dev
->base_addr
;
3091 /* Dump common registers */
3092 printk("hp100: %s: Cascade Register Dump\n", dev
->name
);
3093 printk("hardware id #1: 0x%.2x\n",hp100_inb(HW_ID
));
3094 printk("hardware id #2/paging: 0x%.2x\n",hp100_inb(PAGING
));
3095 printk("option #1: 0x%.4x\n",hp100_inw(OPTION_LSW
));
3096 printk("option #2: 0x%.4x\n",hp100_inw(OPTION_MSW
));
3098 /* Dump paged registers */
3099 for (Page
= 0; Page
< 8; Page
++)
3101 /* Dump registers */
3102 printk("page: 0x%.2x\n",Page
);
3103 outw( Page
, ioaddr
+0x02);
3104 for (Register
= 0x8; Register
< 0x22; Register
+= 2)
3106 /* Display Register contents except data port */
3107 if (((Register
!= 0x10) && (Register
!= 0x12)) || (Page
> 0))
3109 printk("0x%.2x = 0x%.4x\n",Register
,inw(ioaddr
+Register
));
3113 hp100_page(PERFORMANCE
);
3125 /* Parameters set by insmod */
3126 int hp100_port
[5] = { 0, -1, -1, -1, -1 };
3128 MODULE_PARM(hp100_port
, "1-5i");
3132 char hp100_name
[5][IFNAMSIZ
] = { "", "", "", "", "" };
3133 MODULE_PARM(hp100_name
, "1-5c" __MODULE_STRING(IFNAMSIZ
));
3135 static char devname
[5][IFNAMSIZ
] = { "", "", "", "", "" };
3136 static char *hp100_name
[5] = { devname
[0], devname
[1],
3137 devname
[2], devname
[3],
3141 /* List of devices */
3142 static struct net_device
*hp100_devlist
[5] = { NULL
, NULL
, NULL
, NULL
, NULL
};
3145 * Note: if you have more than five 100vg cards in your pc, feel free to
3146 * increase this value
3150 * Note: to register three eisa or pci devices, use:
3151 * option hp100 hp100_port=0,0,0
3152 * to register one card at io 0x280 as eth239, use:
3153 * option hp100 hp100_port=0x280 hp100_name=eth239
3156 int init_module( void )
3160 if (hp100_port
== 0 && !EISA_bus
&& !pcibios_present())
3161 printk("hp100: You should not use auto-probing with insmod!\n");
3163 /* Loop on all possible base addresses */
3165 while((hp100_port
[++i
] != -1) && (i
< 5))
3167 /* Create device and set basics args */
3168 hp100_devlist
[i
] = kmalloc(sizeof(struct net_device
), GFP_KERNEL
);
3169 memset(hp100_devlist
[i
], 0x00, sizeof(struct net_device
));
3170 hp100_devlist
[i
]->name
= hp100_name
[i
];
3171 hp100_devlist
[i
]->base_addr
= hp100_port
[i
];
3172 hp100_devlist
[i
]->init
= &hp100_probe
;
3174 /* Try to create the device */
3175 if(register_netdev(hp100_devlist
[i
]) != 0)
3177 /* DeAllocate everything */
3178 /* Note: if dev->priv is mallocated, there is no way to fail */
3179 kfree_s(hp100_devlist
[i
], sizeof(struct net_device
));
3180 hp100_devlist
[i
] = (struct net_device
*) NULL
;
3184 } /* Loop over all devices */
3186 return cards
> 0 ? 0 : -ENODEV
;
3189 void cleanup_module( void )
3193 /* TODO: Check if all skb's are released/freed. */
3194 for(i
= 0; i
< 5; i
++)
3195 if(hp100_devlist
[i
] != (struct net_device
*) NULL
)
3197 unregister_netdev( hp100_devlist
[i
] );
3198 release_region( hp100_devlist
[i
]->base_addr
, HP100_REGION_SIZE
);
3199 if( ((struct hp100_private
*)hp100_devlist
[i
]->priv
)->mode
==1 ) /* busmaster */
3200 kfree_s( ((struct hp100_private
*)hp100_devlist
[i
]->priv
)->page_vaddr
, MAX_RINGSIZE
+0x0f);
3201 if ( ((struct hp100_private
*)hp100_devlist
[i
]->priv
) -> mem_ptr_virt
)
3202 iounmap( ((struct hp100_private
*)hp100_devlist
[i
]->priv
) -> mem_ptr_virt
);
3203 kfree_s( hp100_devlist
[i
]->priv
, sizeof( struct hp100_private
) );
3204 hp100_devlist
[i
]->priv
= NULL
;
3205 kfree_s(hp100_devlist
[i
], sizeof(struct net_device
));
3206 hp100_devlist
[i
] = (struct net_device
*) NULL
;
3216 * compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c hp100.c"