This source file includes following definitions.
- hp100_probe
- hp100_probe1
- hp100_open
- hp100_close
- hp100_start_xmit
- hp100_rx
- hp100_get_stats
- hp100_update_stats
- hp100_clear_stats
- hp100_set_multicast_list
- hp100_interrupt
- hp100_start_interface
- hp100_stop_interface
- hp100_load_eeprom
- hp100_sense_lan
- hp100_down_vg_link
- hp100_login_to_vg_hub
- init_module
- cleanup_module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85 #include <linux/module.h>
86
87 #include <linux/kernel.h>
88 #include <linux/sched.h>
89 #include <linux/string.h>
90 #include <linux/errno.h>
91 #include <linux/ioport.h>
92 #include <linux/malloc.h>
93 #include <linux/interrupt.h>
94 #include <linux/pci.h>
95 #include <linux/bios32.h>
96 #include <asm/bitops.h>
97 #include <asm/io.h>
98
99 #include <linux/netdevice.h>
100 #include <linux/etherdevice.h>
101 #include <linux/skbuff.h>
102
103 #include <linux/types.h>
104 #include <linux/config.h>
105
106 #include "hp100.h"
107
108
109
110
111
112 #define HP100_BUS_ISA 0
113 #define HP100_BUS_EISA 1
114 #define HP100_BUS_PCI 2
115
116 #define HP100_REGION_SIZE 0x20
117
118 #define HP100_MAX_PACKET_SIZE (1536+4)
119 #define HP100_MIN_PACKET_SIZE 60
120
121 #ifndef HP100_DEFAULT_RX_RATIO
122
123 #define HP100_DEFAULT_RX_RATIO 65
124 #endif
125
126 #ifndef HP100_DEFAULT_PRIORITY_TX
127
128 #define HP100_DEFAULT_PRIORITY_TX 0
129 #endif
130
131
132
133
134
135 struct hp100_eisa_id {
136 u_int id;
137 const char *name;
138 u_char bus;
139 };
140
141 struct hp100_private {
142 struct hp100_eisa_id *id;
143 u_short soft_model;
144 u_int memory_size;
145 u_short rx_ratio;
146 u_short priority_tx;
147 short mem_mapped;
148 u_char *mem_ptr_virt;
149 u_char *mem_ptr_phys;
150 short lan_type;
151 int hub_status;
152 u_char mac1_mode;
153 u_char mac2_mode;
154 struct enet_statistics stats;
155 };
156
157
158
159
160
161 static struct hp100_eisa_id hp100_eisa_ids[] = {
162
163
164 { 0x080F1F022, "HP J2577 rev A", HP100_BUS_EISA },
165
166
167 { 0x050F1F022, "HP J2573 rev A", HP100_BUS_ISA },
168
169
170 { 0x02019F022, "HP 27248B", HP100_BUS_EISA },
171
172
173 { 0x04019F022, "HP J2577", HP100_BUS_EISA },
174
175
176 { 0x05019F022, "HP J2573", HP100_BUS_ISA },
177
178
179
180 { 0x01030103c, "HP J2585", HP100_BUS_PCI },
181 };
182
183 int hp100_rx_ratio = HP100_DEFAULT_RX_RATIO;
184 int hp100_priority_tx = HP100_DEFAULT_PRIORITY_TX;
185
186
187
188
189
190 static int hp100_probe1( struct device *dev, int ioaddr, int bus );
191 static int hp100_open( struct device *dev );
192 static int hp100_close( struct device *dev );
193 static int hp100_start_xmit( struct sk_buff *skb, struct device *dev );
194 static void hp100_rx( struct device *dev );
195 static struct enet_statistics *hp100_get_stats( struct device *dev );
196 static void hp100_update_stats( struct device *dev );
197 static void hp100_clear_stats( int ioaddr );
198 #ifdef HAVE_MULTICAST
199 static void hp100_set_multicast_list( struct device *dev, int num_addrs, void *addrs );
200 #endif
201 static void hp100_interrupt( int irq, struct pt_regs *regs );
202
203 static void hp100_start_interface( struct device *dev );
204 static void hp100_stop_interface( struct device *dev );
205 static void hp100_load_eeprom( struct device *dev );
206 static int hp100_sense_lan( struct device *dev );
207 static int hp100_login_to_vg_hub( struct device *dev );
208 static int hp100_down_vg_link( struct device *dev );
209
210
211
212
213
214 int hp100_probe( struct device *dev )
215 {
216 int base_addr = dev ? dev -> base_addr : 0;
217 int ioaddr;
218 #ifdef CONFIG_PCI
219 int pci_start_index = 0;
220 #endif
221
222 if ( base_addr > 0xff )
223 {
224 if ( check_region( base_addr, HP100_REGION_SIZE ) ) return -EINVAL;
225 if ( base_addr < 0x400 )
226 return hp100_probe1( dev, base_addr, HP100_BUS_ISA );
227 else
228 return hp100_probe1( dev, base_addr, HP100_BUS_EISA );
229 }
230 else
231 #ifdef CONFIG_PCI
232 if ( base_addr > 0 && base_addr < 8 + 1 )
233 pci_start_index = 0x100 | ( base_addr - 1 );
234 else
235 #endif
236 if ( base_addr != 0 ) return -ENXIO;
237
238
239
240 #ifdef CONFIG_PCI
241 if ( pcibios_present() )
242 {
243 int pci_index;
244
245 #ifdef HP100_DEBUG_PCI
246 printk( "hp100: PCI BIOS is present, checking for devices..\n" );
247 #endif
248 for ( pci_index = pci_start_index & 7; pci_index < 8; pci_index++ )
249 {
250 u_char pci_bus, pci_device_fn;
251 u_short pci_command;
252
253 if ( pcibios_find_device( PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_J2585A,
254 pci_index, &pci_bus,
255 &pci_device_fn ) != 0 ) break;
256 pcibios_read_config_dword( pci_bus, pci_device_fn,
257 PCI_BASE_ADDRESS_0, &ioaddr );
258
259 ioaddr &= ~3;
260
261 if ( check_region( ioaddr, HP100_REGION_SIZE ) ) continue;
262
263 pcibios_read_config_word( pci_bus, pci_device_fn,
264 PCI_COMMAND, &pci_command );
265 if ( !( pci_command & PCI_COMMAND_MASTER ) )
266 {
267 #ifdef HP100_DEBUG_PCI
268 printk( "hp100: PCI Master Bit has not been set. Setting...\n" );
269 #endif
270 pci_command |= PCI_COMMAND_MASTER;
271 pcibios_write_config_word( pci_bus, pci_device_fn,
272 PCI_COMMAND, pci_command );
273 }
274 #ifdef HP100_DEBUG_PCI
275 printk( "hp100: PCI adapter found at 0x%x\n", ioaddr );
276 #endif
277 if ( hp100_probe1( dev, ioaddr, HP100_BUS_PCI ) == 0 ) return 0;
278 }
279 }
280 if ( pci_start_index > 0 ) return -ENODEV;
281 #endif
282
283
284
285 for ( ioaddr = 0x1c38; EISA_bus && ioaddr < 0x10000; ioaddr += 0x400 )
286 {
287 if ( check_region( ioaddr, HP100_REGION_SIZE ) ) continue;
288 if ( hp100_probe1( dev, ioaddr, HP100_BUS_EISA ) == 0 ) return 0;
289 }
290
291
292
293 for ( ioaddr = 0x100; ioaddr < 0x400; ioaddr += 0x20 )
294 {
295 if ( check_region( ioaddr, HP100_REGION_SIZE ) ) continue;
296 if ( hp100_probe1( dev, ioaddr, HP100_BUS_ISA ) == 0 ) return 0;
297 }
298
299 return -ENODEV;
300 }
301
302 static int hp100_probe1( struct device *dev, int ioaddr, int bus )
303 {
304 int i;
305 u_char uc, uc_1;
306 u_int eisa_id;
307 short mem_mapped;
308 u_char *mem_ptr_phys, *mem_ptr_virt;
309 struct hp100_private *lp;
310 struct hp100_eisa_id *eid;
311
312 if ( dev == NULL )
313 {
314 #ifdef HP100_DEBUG
315 printk( "hp100_probe1: dev == NULL ?\n" );
316 #endif
317 return EIO;
318 }
319
320 if ( bus != HP100_BUS_PCI )
321 if ( inb( ioaddr + 0 ) != HP100_HW_ID_0 ||
322 inb( ioaddr + 1 ) != HP100_HW_ID_1 ||
323 ( inb( ioaddr + 2 ) & 0xf0 ) != HP100_HW_ID_2_REVA ||
324 inb( ioaddr + 3 ) != HP100_HW_ID_3 )
325 return -ENODEV;
326
327 dev -> base_addr = ioaddr;
328
329 #ifdef HP100_DEBUG_PROBE1
330 printk( "hp100_probe1: card found at port 0x%x\n", ioaddr );
331 #endif
332
333 hp100_page( ID_MAC_ADDR );
334 for ( i = uc = eisa_id = 0; i < 4; i++ )
335 {
336 eisa_id >>= 8;
337 uc_1 = hp100_inb( BOARD_ID + i );
338 eisa_id |= uc_1 << 24;
339 uc += uc_1;
340 }
341 uc += hp100_inb( BOARD_ID + 4 );
342
343 #ifdef HP100_DEBUG_PROBE1
344 printk( "hp100_probe1: EISA ID = 0x%08x checksum = 0x%02x\n", eisa_id, uc );
345 #endif
346
347 if ( uc != 0xff )
348 {
349 printk( "hp100_probe: bad EISA ID checksum at base port 0x%x\n", ioaddr );
350 return -ENODEV;
351 }
352
353 for ( i = 0; i < sizeof( hp100_eisa_ids ) / sizeof( struct hp100_eisa_id ); i++ )
354 if ( ( hp100_eisa_ids[ i ].id & 0xf0ffffff ) == ( eisa_id & 0xf0ffffff ) )
355 break;
356 if ( i >= sizeof( hp100_eisa_ids ) / sizeof( struct hp100_eisa_id ) )
357 {
358 printk( "hp100_probe1: card at port 0x%x isn't known (id = 0x%x)\n", ioaddr, eisa_id );
359 return -ENODEV;
360 }
361 eid = &hp100_eisa_ids[ i ];
362 if ( ( eid -> id & 0x0f000000 ) < ( eisa_id & 0x0f000000 ) )
363 {
364 printk( "hp100_probe1: newer version of card %s at port 0x%x - unsupported\n",
365 eid -> name, ioaddr );
366 return -ENODEV;
367 }
368
369 for ( i = uc = 0; i < 7; i++ )
370 uc += hp100_inb( LAN_ADDR + i );
371 if ( uc != 0xff )
372 {
373 printk( "hp100_probe1: bad lan address checksum (card %s at port 0x%x)\n",
374 eid -> name, ioaddr );
375 return -EIO;
376 }
377
378 #ifndef HP100_IO_MAPPED
379 hp100_page( HW_MAP );
380 mem_mapped = ( hp100_inw( OPTION_LSW ) &
381 ( HP100_MEM_EN | HP100_BM_WRITE | HP100_BM_READ ) ) != 0;
382 mem_ptr_phys = mem_ptr_virt = NULL;
383 if ( mem_mapped )
384 {
385 mem_ptr_phys = (u_char *)( hp100_inw( MEM_MAP_LSW ) |
386 ( hp100_inw( MEM_MAP_MSW ) << 16 ) );
387 (u_int)mem_ptr_phys &= ~0x1fff;
388 if ( bus == HP100_BUS_ISA && ( (u_long)mem_ptr_phys & ~0xfffff ) != 0 )
389 {
390 mem_ptr_phys = NULL;
391 mem_mapped = 0;
392 }
393 if ( mem_mapped && bus == HP100_BUS_PCI )
394 {
395 if ( ( mem_ptr_virt = vremap( (u_long)mem_ptr_phys, 0x2000 ) ) == NULL )
396 {
397 printk( "hp100: vremap for high PCI memory at 0x%lx failed\n", (u_long)mem_ptr_phys );
398 mem_ptr_phys = NULL;
399 mem_mapped = 0;
400 }
401 }
402 }
403 #else
404 mem_mapped = 0;
405 mem_ptr_phys = mem_ptr_virt = NULL;
406 #endif
407
408 if ( ( dev -> priv = kmalloc( sizeof( struct hp100_private ), GFP_KERNEL ) ) == NULL )
409 return -ENOMEM;
410 memset( dev -> priv, 0, sizeof( struct hp100_private ) );
411
412 lp = (struct hp100_private *)dev -> priv;
413 lp -> id = eid;
414 lp -> mem_mapped = mem_mapped;
415 lp -> mem_ptr_phys = mem_ptr_phys;
416 lp -> mem_ptr_virt = mem_ptr_virt;
417 hp100_page( ID_MAC_ADDR );
418 lp -> soft_model = hp100_inb( SOFT_MODEL );
419 lp -> mac1_mode = HP100_MAC1MODE3;
420 lp -> mac2_mode = HP100_MAC2MODE3;
421
422 dev -> base_addr = ioaddr;
423 hp100_page( HW_MAP );
424 dev -> irq = hp100_inb( IRQ_CHANNEL ) & HP100_IRQ_MASK;
425 if ( dev -> irq == 2 ) dev -> irq = 9;
426 lp -> memory_size = 0x200 << ( ( hp100_inb( SRAM ) & 0xe0 ) >> 5 );
427 lp -> rx_ratio = hp100_rx_ratio;
428
429 dev -> open = hp100_open;
430 dev -> stop = hp100_close;
431 dev -> hard_start_xmit = hp100_start_xmit;
432 dev -> get_stats = hp100_get_stats;
433 #ifdef HAVE_MULTICAST
434 dev -> set_multicast_list = &hp100_set_multicast_list;
435 #endif
436
437 request_region( dev -> base_addr, HP100_REGION_SIZE, eid -> name );
438
439 hp100_page( ID_MAC_ADDR );
440 for ( i = uc = 0; i < 6; i++ )
441 dev -> dev_addr[ i ] = hp100_inb( LAN_ADDR + i );
442
443 hp100_clear_stats( ioaddr );
444
445 ether_setup( dev );
446
447 lp -> lan_type = hp100_sense_lan( dev );
448
449 printk( "%s: %s at 0x%x, IRQ %d, ",
450 dev -> name, lp -> id -> name, ioaddr, dev -> irq );
451 switch ( bus ) {
452 case HP100_BUS_EISA: printk( "EISA" ); break;
453 case HP100_BUS_PCI: printk( "PCI" ); break;
454 default: printk( "ISA" ); break;
455 }
456 printk( " bus, %dk SRAM (rx/tx %d%%).\n",
457 lp -> memory_size >> ( 10 - 4 ), lp -> rx_ratio );
458 if ( mem_mapped )
459 {
460 printk( "%s: Memory area at 0x%lx-0x%lx",
461 dev -> name, (u_long)mem_ptr_phys, (u_long)mem_ptr_phys + 0x1fff );
462 if ( mem_ptr_virt )
463 printk( " (virtual base 0x%lx)", (u_long)mem_ptr_virt );
464 printk( ".\n" );
465 }
466 printk( "%s: ", dev -> name );
467 if ( lp -> lan_type != HP100_LAN_ERR )
468 printk( "Adapter is attached to " );
469 switch ( lp -> lan_type ) {
470 case HP100_LAN_100:
471 printk( "100Mb/s Voice Grade AnyLAN network.\n" );
472 break;
473 case HP100_LAN_10:
474 printk( "10Mb/s network.\n" );
475 break;
476 default:
477 printk( "Warning! Link down.\n" );
478 }
479
480 hp100_stop_interface( dev );
481
482 return 0;
483 }
484
485
486
487
488
489 static int hp100_open( struct device *dev )
490 {
491 int i;
492 int ioaddr = dev -> base_addr;
493 struct hp100_private *lp = (struct hp100_private *)dev -> priv;
494
495 if ( request_irq( dev -> irq, hp100_interrupt, SA_INTERRUPT, lp -> id -> name ) )
496 {
497 printk( "%s: unable to get IRQ %d\n", dev -> name, dev -> irq );
498 return -EAGAIN;
499 }
500 irq2dev_map[ dev -> irq ] = dev;
501
502 MOD_INC_USE_COUNT;
503
504 dev -> tbusy = 0;
505 dev -> trans_start = jiffies;
506 dev -> interrupt = 0;
507 dev -> start = 1;
508
509 lp -> lan_type = hp100_sense_lan( dev );
510 lp -> mac1_mode = HP100_MAC1MODE3;
511 lp -> mac2_mode = HP100_MAC2MODE3;
512
513 hp100_page( MAC_CTRL );
514 hp100_orw( HP100_LINK_BEAT_DIS | HP100_RESET_LB, LAN_CFG_10 );
515
516 hp100_stop_interface( dev );
517 hp100_load_eeprom( dev );
518
519 hp100_outw( HP100_MMAP_DIS | HP100_SET_HB |
520 HP100_IO_EN | HP100_SET_LB, OPTION_LSW );
521 hp100_outw( HP100_DEBUG_EN | HP100_RX_HDR | HP100_EE_EN | HP100_RESET_HB |
522 HP100_FAKE_INT | HP100_RESET_LB, OPTION_LSW );
523 hp100_outw( HP100_ADV_NXT_PKT | HP100_TX_CMD | HP100_RESET_LB |
524 HP100_PRIORITY_TX | ( hp100_priority_tx ? HP100_SET_HB : HP100_RESET_HB ),
525 OPTION_MSW );
526
527 hp100_page( MAC_ADDRESS );
528 for ( i = 0; i < 6; i++ )
529 hp100_outb( dev -> dev_addr[ i ], MAC_ADDR + i );
530 for ( i = 0; i < 8; i++ )
531 hp100_outb( 0xff, HASH_BYTE0 + i );
532 hp100_page( PERFORMANCE );
533 hp100_outw( 0xfefe, IRQ_MASK );
534 hp100_outw( 0xffff, IRQ_STATUS );
535 hp100_outw( (HP100_RX_PACKET | HP100_RX_ERROR | HP100_SET_HB) |
536 (HP100_TX_ERROR | HP100_SET_LB ), IRQ_MASK );
537
538 hp100_reset_card();
539 hp100_page( MMU_CFG );
540 hp100_outw( ( lp -> memory_size * lp -> rx_ratio ) / 100, RX_MEM_STOP );
541 hp100_outw( lp -> memory_size - 1, TX_MEM_STOP );
542 hp100_unreset_card();
543
544 if ( lp -> lan_type == HP100_LAN_100 )
545 lp -> hub_status = hp100_login_to_vg_hub( dev );
546
547 hp100_start_interface( dev );
548
549 return 0;
550 }
551
552 static int hp100_close( struct device *dev )
553 {
554 int ioaddr = dev -> base_addr;
555 struct hp100_private *lp = (struct hp100_private *)dev -> priv;
556
557 hp100_page( PERFORMANCE );
558 hp100_outw( 0xfefe, IRQ_MASK );
559
560 hp100_stop_interface( dev );
561
562 if ( lp -> lan_type == HP100_LAN_100 )
563 hp100_login_to_vg_hub( dev );
564
565 dev -> tbusy = 1;
566 dev -> start = 0;
567
568 free_irq( dev -> irq );
569 irq2dev_map[ dev -> irq ] = NULL;
570 MOD_DEC_USE_COUNT;
571 return 0;
572 }
573
574
575
576
577
578 static int hp100_start_xmit( struct sk_buff *skb, struct device *dev )
579 {
580 int i, ok_flag;
581 int ioaddr = dev -> base_addr;
582 u_short val;
583 struct hp100_private *lp = (struct hp100_private *)dev -> priv;
584
585 if ( lp -> lan_type < 0 )
586 {
587 hp100_stop_interface( dev );
588 if ( ( lp -> lan_type = hp100_sense_lan( dev ) ) < 0 )
589 {
590 printk( "%s: no connection found - check wire\n", dev -> name );
591 hp100_start_interface( dev );
592 return -EIO;
593 }
594 if ( lp -> lan_type == HP100_LAN_100 )
595 lp -> hub_status = hp100_login_to_vg_hub( dev );
596 hp100_start_interface( dev );
597 }
598
599 if ( ( i = ( hp100_inl( TX_MEM_FREE ) & ~0x7fffffff ) ) < skb -> len + 16 )
600 {
601 #ifdef HP100_DEBUG
602 printk( "hp100_start_xmit: rx free mem = 0x%x\n", i );
603 #endif
604 if ( jiffies - dev -> trans_start < 2 * HZ ) return -EAGAIN;
605 if ( lp -> lan_type == HP100_LAN_100 && lp -> hub_status < 0 )
606
607 {
608 printk( "%s: login to 100Mb/s hub retry\n", dev -> name );
609 hp100_stop_interface( dev );
610 lp -> hub_status = hp100_login_to_vg_hub( dev );
611 hp100_start_interface( dev );
612 }
613 else
614 {
615 hp100_ints_off();
616 i = hp100_sense_lan( dev );
617 hp100_page( PERFORMANCE );
618 hp100_ints_on();
619 if ( i == HP100_LAN_ERR )
620 printk( "%s: link down detected\n", dev -> name );
621 else
622 if ( lp -> lan_type != i )
623 {
624
625 printk( "%s: cable change 10Mb/s <-> 100Mb/s detected\n", dev -> name );
626 lp -> lan_type = i;
627 hp100_stop_interface( dev );
628 if ( lp -> lan_type == HP100_LAN_100 )
629 lp -> hub_status = hp100_login_to_vg_hub( dev );
630 hp100_start_interface( dev );
631 }
632 else
633 {
634 printk( "%s: interface reset\n", dev -> name );
635 hp100_stop_interface( dev );
636 hp100_start_interface( dev );
637 }
638 }
639 dev -> trans_start = jiffies;
640 return -EAGAIN;
641 }
642
643 if ( skb == NULL )
644 {
645 dev_tint( dev );
646 return 0;
647 }
648
649 if ( skb -> len <= 0 ) return 0;
650
651 for ( i = 0; i < 6000 && ( hp100_inw( OPTION_MSW ) & HP100_TX_CMD ); i++ )
652 {
653 #ifdef HP100_DEBUG_TX
654 printk( "hp100_start_xmit: busy\n" );
655 #endif
656 }
657
658 hp100_ints_off();
659 val = hp100_inw( IRQ_STATUS );
660 hp100_outw( val & HP100_TX_COMPLETE, IRQ_STATUS );
661 #ifdef HP100_DEBUG_TX
662 printk( "hp100_start_xmit: irq_status = 0x%x, len = %d\n", val, (int)skb -> len );
663 #endif
664 ok_flag = skb -> len >= HP100_MIN_PACKET_SIZE;
665 i = ok_flag ? skb -> len : HP100_MIN_PACKET_SIZE;
666 hp100_outw( i, DATA32 );
667 hp100_outw( i, FRAGMENT_LEN );
668 if ( lp -> mem_mapped )
669 {
670 if ( lp -> mem_ptr_virt )
671 {
672 memcpy( lp -> mem_ptr_virt, skb -> data, skb -> len );
673 if ( !ok_flag )
674 memset( lp -> mem_ptr_virt, 0, HP100_MIN_PACKET_SIZE - skb -> len );
675 }
676 else
677 {
678 memcpy_toio( lp -> mem_ptr_phys, skb -> data, skb -> len );
679 if ( !ok_flag )
680 memset_io( lp -> mem_ptr_phys, 0, HP100_MIN_PACKET_SIZE - skb -> len );
681 }
682 }
683 else
684 {
685 outsl( ioaddr + HP100_REG_DATA32, skb -> data, ( skb -> len + 3 ) >> 2 );
686 if ( !ok_flag )
687 for ( i = ( skb -> len + 3 ) & ~3; i < HP100_MIN_PACKET_SIZE; i += 4 )
688 hp100_outl( 0, DATA32 );
689 }
690 hp100_outw( HP100_TX_CMD | HP100_SET_LB, OPTION_MSW );
691 lp -> stats.tx_packets++;
692 dev -> trans_start = jiffies;
693 hp100_ints_on();
694
695 dev_kfree_skb( skb, FREE_WRITE );
696
697 #ifdef HP100_DEBUG_TX
698 printk( "hp100_start_xmit: end\n" );
699 #endif
700
701 return 0;
702 }
703
704
705
706
707
708 static void hp100_rx( struct device *dev )
709 {
710 int packets, pkt_len;
711 int ioaddr = dev -> base_addr;
712 struct hp100_private *lp = (struct hp100_private *)dev -> priv;
713 u_int header;
714 struct sk_buff *skb;
715
716 #if 0
717 if ( lp -> lan_type < 0 )
718 {
719 if ( ( lp -> lan_type = hp100_sense_lan( dev ) ) == HP100_LAN_100 )
720 lp -> hub_status = hp100_login_to_vg_hub( dev );
721 hp100_page( PERFORMANCE );
722 }
723 #endif
724
725 packets = hp100_inb( RX_PKT_CNT );
726 #ifdef HP100_DEBUG
727 if ( packets > 1 )
728 printk( "hp100_rx: waiting packets = %d\n", packets );
729 #endif
730 while ( packets-- > 0 )
731 {
732 for ( pkt_len = 0; pkt_len < 6000 && ( hp100_inw( OPTION_MSW ) & HP100_ADV_NXT_PKT ); pkt_len++ )
733 {
734 #ifdef HP100_DEBUG_TX
735 printk( "hp100_rx: busy, remaining packets = %d\n", packets );
736 #endif
737 }
738 if ( lp -> mem_mapped )
739 {
740 if ( lp -> mem_ptr_virt )
741 header = *(__u32 *)lp -> mem_ptr_virt;
742 else
743 header = readl( lp -> mem_ptr_phys );
744 }
745 else
746 header = hp100_inl( DATA32 );
747 pkt_len = header & HP100_PKT_LEN_MASK;
748 #ifdef HP100_DEBUG_RX
749 printk( "hp100_rx: new packet - length = %d, errors = 0x%x, dest = 0x%x\n",
750 header & HP100_PKT_LEN_MASK, ( header >> 16 ) & 0xfff8, ( header >> 16 ) & 7 );
751 #endif
752
753
754
755
756
757 skb = dev_alloc_skb( pkt_len );
758 if ( skb == NULL )
759 {
760 #ifdef HP100_DEBUG
761 printk( "hp100_rx: couldn't allocate a sk_buff of size %d\n", pkt_len );
762 #endif
763 lp -> stats.rx_dropped++;
764 }
765 else
766 {
767 u_char *ptr;
768
769 skb -> dev = dev;
770 ptr = (u_char *)skb_put( skb, pkt_len );
771 if ( lp -> mem_mapped )
772 {
773 if ( lp -> mem_ptr_virt )
774 memcpy( ptr, lp -> mem_ptr_virt, ( pkt_len + 3 ) & ~3 );
775 else
776 memcpy_fromio( ptr, lp -> mem_ptr_phys, ( pkt_len + 3 ) & ~3 );
777 }
778 else
779 insl( ioaddr + HP100_REG_DATA32, ptr, ( pkt_len + 3 ) >> 2 );
780 skb -> protocol = eth_type_trans( skb, dev );
781 netif_rx( skb );
782 lp -> stats.rx_packets++;
783 #ifdef HP100_DEBUG_RX
784 printk( "rx: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
785 ptr[ 0 ], ptr[ 1 ], ptr[ 2 ], ptr[ 3 ], ptr[ 4 ], ptr[ 5 ],
786 ptr[ 6 ], ptr[ 7 ], ptr[ 8 ], ptr[ 9 ], ptr[ 10 ], ptr[ 11 ] );
787 #endif
788 }
789 hp100_outw( HP100_ADV_NXT_PKT | HP100_SET_LB, OPTION_MSW );
790 switch ( header & 0x00070000 ) {
791 case (HP100_MULTI_ADDR_HASH<<16):
792 case (HP100_MULTI_ADDR_NO_HASH<<16):
793 lp -> stats.multicast++; break;
794 }
795 }
796 #ifdef HP100_DEBUG_RX
797 printk( "hp100_rx: end\n" );
798 #endif
799 }
800
801
802
803
804
805 static struct enet_statistics *hp100_get_stats( struct device *dev )
806 {
807 int ioaddr = dev -> base_addr;
808
809 hp100_ints_off();
810 hp100_update_stats( dev );
811 hp100_ints_on();
812 return &((struct hp100_private *)dev -> priv) -> stats;
813 }
814
815 static void hp100_update_stats( struct device *dev )
816 {
817 int ioaddr = dev -> base_addr;
818 u_short val;
819 struct hp100_private *lp = (struct hp100_private *)dev -> priv;
820
821 hp100_page( MAC_CTRL );
822 val = hp100_inw( DROPPED ) & 0x0fff;
823 lp -> stats.rx_errors += val;
824 lp -> stats.rx_over_errors += val;
825 val = hp100_inb( CRC );
826 lp -> stats.rx_errors += val;
827 lp -> stats.rx_crc_errors += val;
828 val = hp100_inb( ABORT );
829 lp -> stats.tx_errors += val;
830 lp -> stats.tx_aborted_errors += val;
831 hp100_page( PERFORMANCE );
832 }
833
834 static void hp100_clear_stats( int ioaddr )
835 {
836 cli();
837 hp100_page( MAC_CTRL );
838 hp100_inw( DROPPED );
839 hp100_inb( CRC );
840 hp100_inb( ABORT );
841 hp100_page( PERFORMANCE );
842 sti();
843 }
844
845
846
847
848
849 #ifdef HAVE_MULTICAST
850
851
852
853
854
855
856
857
858
859
860 static void hp100_set_multicast_list( struct device *dev, int num_addrs, void *addrs )
861 {
862 int ioaddr = dev -> base_addr;
863 struct hp100_private *lp = (struct hp100_private *)dev -> priv;
864
865 #ifdef HP100_DEBUG_MULTI
866 printk( "hp100_set_multicast_list: num_addrs = %d\n", num_addrs );
867 #endif
868 cli();
869 hp100_ints_off();
870 hp100_page( MAC_CTRL );
871 hp100_andb( ~(HP100_RX_EN | HP100_TX_EN), MAC_CFG_1 );
872
873 if ( num_addrs == -1 )
874 {
875 lp -> mac2_mode = HP100_MAC2MODE6;
876 lp -> mac1_mode = HP100_MAC1MODE6;
877 }
878 else
879 if ( num_addrs != 0 )
880 {
881 lp -> mac2_mode = HP100_MAC2MODE5;
882 lp -> mac1_mode = HP100_MAC1MODE5;
883 }
884 else
885 {
886 lp -> mac2_mode = HP100_MAC2MODE3;
887 lp -> mac1_mode = HP100_MAC1MODE3;
888 }
889
890 hp100_outb( lp -> mac2_mode, MAC_CFG_2 );
891 hp100_andb( HP100_MAC1MODEMASK, MAC_CFG_1 );
892 hp100_orb( lp -> mac1_mode |
893 HP100_RX_EN | HP100_RX_IDLE |
894 HP100_TX_EN | HP100_TX_IDLE, MAC_CFG_1 );
895 hp100_page( PERFORMANCE );
896 hp100_ints_on();
897 sti();
898 }
899
900 #endif
901
902
903
904
905
906 static void hp100_interrupt( int irq, struct pt_regs *regs )
907 {
908 struct device *dev = (struct device *)irq2dev_map[ irq ];
909 struct hp100_private *lp;
910 int ioaddr;
911 u_short val;
912
913 if ( dev == NULL ) return;
914 ioaddr = dev -> base_addr;
915 if ( dev -> interrupt )
916 printk( "%s: re-entering the interrupt handler\n", dev -> name );
917 hp100_ints_off();
918 dev -> interrupt = 1;
919 hp100_page( PERFORMANCE );
920 val = hp100_inw( IRQ_STATUS );
921 #ifdef HP100_DEBUG_IRQ
922 printk( "hp100_interrupt: irq_status = 0x%x\n", val );
923 #endif
924 if ( val & HP100_RX_PACKET )
925 {
926 hp100_rx( dev );
927 hp100_outw( HP100_RX_PACKET, IRQ_STATUS );
928 }
929 if ( val & (HP100_TX_SPACE_AVAIL | HP100_TX_COMPLETE) )
930 {
931 hp100_outw( val & (HP100_TX_SPACE_AVAIL | HP100_TX_COMPLETE), IRQ_STATUS );
932 }
933 if ( val & ( HP100_TX_ERROR | HP100_RX_ERROR ) )
934 {
935 lp = (struct hp100_private *)dev -> priv;
936 hp100_update_stats( dev );
937 hp100_outw( val & (HP100_TX_ERROR | HP100_RX_ERROR), IRQ_STATUS );
938 }
939 #ifdef HP100_DEBUG_IRQ
940 printk( "hp100_interrupt: end\n" );
941 #endif
942 dev -> interrupt = 0;
943 hp100_ints_on();
944 }
945
946
947
948
949
950 static void hp100_start_interface( struct device *dev )
951 {
952 int ioaddr = dev -> base_addr;
953 struct hp100_private *lp = (struct hp100_private *)dev -> priv;
954
955 cli();
956 hp100_unreset_card();
957 hp100_page( MAC_CTRL );
958 hp100_outb( lp -> mac2_mode, MAC_CFG_2 );
959 hp100_andb( HP100_MAC1MODEMASK, MAC_CFG_1 );
960 hp100_orb( lp -> mac1_mode |
961 HP100_RX_EN | HP100_RX_IDLE |
962 HP100_TX_EN | HP100_TX_IDLE, MAC_CFG_1 );
963 hp100_page( PERFORMANCE );
964 hp100_outw( HP100_INT_EN | HP100_SET_LB, OPTION_LSW );
965 hp100_outw( HP100_TRI_INT | HP100_RESET_HB, OPTION_LSW );
966 if ( lp -> mem_mapped )
967 {
968
969 hp100_outw( HP100_MMAP_DIS | HP100_RESET_HB, OPTION_LSW );
970 }
971 sti();
972 }
973
974 static void hp100_stop_interface( struct device *dev )
975 {
976 int ioaddr = dev -> base_addr;
977 u_short val;
978
979 hp100_outw( HP100_INT_EN | HP100_RESET_LB |
980 HP100_TRI_INT | HP100_MMAP_DIS | HP100_SET_HB, OPTION_LSW );
981 val = hp100_inw( OPTION_LSW );
982 hp100_page( HW_MAP );
983 hp100_andb( HP100_BM_SLAVE, BM );
984 hp100_page( MAC_CTRL );
985 hp100_andb( ~(HP100_RX_EN | HP100_TX_EN), MAC_CFG_1 );
986 if ( !(val & HP100_HW_RST) ) return;
987 for ( val = 0; val < 6000; val++ )
988 if ( ( hp100_inb( MAC_CFG_1 ) & (HP100_TX_IDLE | HP100_RX_IDLE) ) ==
989 (HP100_TX_IDLE | HP100_RX_IDLE) )
990 return;
991 printk( "%s: hp100_stop_interface - timeout\n", dev -> name );
992 }
993
994 static void hp100_load_eeprom( struct device *dev )
995 {
996 int i;
997 int ioaddr = dev -> base_addr;
998
999 hp100_page( EEPROM_CTRL );
1000 hp100_andw( ~HP100_EEPROM_LOAD, EEPROM_CTRL );
1001 hp100_orw( HP100_EEPROM_LOAD, EEPROM_CTRL );
1002 for ( i = 0; i < 6000; i++ )
1003 if ( !( hp100_inw( OPTION_MSW ) & HP100_EE_LOAD ) ) return;
1004 printk( "%s: hp100_load_eeprom - timeout\n", dev -> name );
1005 }
1006
1007
1008
1009 static int hp100_sense_lan( struct device *dev )
1010 {
1011 int i;
1012 int ioaddr = dev -> base_addr;
1013 u_short val_VG, val_10;
1014 struct hp100_private *lp = (struct hp100_private *)dev -> priv;
1015
1016 hp100_page( MAC_CTRL );
1017 hp100_orw( HP100_VG_RESET, LAN_CFG_VG );
1018 val_10 = hp100_inw( LAN_CFG_10 );
1019 val_VG = hp100_inw( LAN_CFG_VG );
1020 #ifdef HP100_DEBUG_SENSE
1021 printk( "hp100_sense_lan: val_VG = 0x%04x, val_10 = 0x%04x\n", val_VG, val_10 );
1022 #endif
1023 if ( val_10 & HP100_LINK_BEAT_ST ) return HP100_LAN_10;
1024 if ( lp -> id -> id == 0x02019F022 )
1025 return HP100_LAN_ERR;
1026 for ( i = 0; i < 2500; i++ )
1027 {
1028 val_VG = hp100_inw( LAN_CFG_VG );
1029 if ( val_VG & HP100_LINK_CABLE_ST ) return HP100_LAN_100;
1030 }
1031 return HP100_LAN_ERR;
1032 }
1033
1034 static int hp100_down_vg_link( struct device *dev )
1035 {
1036 int ioaddr = dev -> base_addr;
1037 unsigned long time;
1038 int i;
1039
1040 hp100_page( MAC_CTRL );
1041 for ( i = 2500; i > 0; i-- )
1042 if ( hp100_inw( LAN_CFG_VG ) & HP100_LINK_CABLE_ST ) break;
1043 if ( i <= 0 )
1044 return 0;
1045 hp100_andw( ~HP100_LINK_CMD, LAN_CFG_VG );
1046 time = jiffies + 10;
1047 while ( time > jiffies )
1048 if ( !( hp100_inw( LAN_CFG_VG ) & ( HP100_LINK_UP_ST |
1049 HP100_LINK_CABLE_ST |
1050 HP100_LINK_GOOD_ST ) ) )
1051 return 0;
1052 #ifdef HP100_DEBUG
1053 printk( "hp100_down_vg_link: timeout\n" );
1054 #endif
1055 return -EIO;
1056 }
1057
1058 static int hp100_login_to_vg_hub( struct device *dev )
1059 {
1060 int i;
1061 int ioaddr = dev -> base_addr;
1062 u_short val;
1063 unsigned long time;
1064
1065 hp100_page( MAC_CTRL );
1066 hp100_orw( HP100_VG_RESET, LAN_CFG_VG );
1067 time = jiffies + ( HZ / 2 );
1068 do {
1069 if ( hp100_inw( LAN_CFG_VG ) & HP100_LINK_CABLE_ST ) break;
1070 } while ( time > jiffies );
1071 if ( time <= jiffies )
1072 {
1073 #ifdef HP100_DEBUG
1074 printk( "hp100_login_to_vg_hub: timeout for link\n" );
1075 #endif
1076 return -EIO;
1077 }
1078
1079 if ( hp100_down_vg_link( dev ) < 0 )
1080 {
1081 hp100_andw( ~HP100_VG_RESET, LAN_CFG_VG );
1082 hp100_orw( HP100_VG_RESET, LAN_CFG_VG );
1083 }
1084
1085 hp100_orw( HP100_LOAD_ADDR | HP100_LINK_CMD, LAN_CFG_VG );
1086 for ( i = 2500; i > 0; i-- )
1087 if ( hp100_inw( LAN_CFG_VG ) & HP100_LINK_CABLE_ST ) break;
1088 if ( i <= 0 )
1089 {
1090 #ifdef HP100_DEBUG
1091 printk( "hp100_login_to_vg_hub: timeout for link (bring up)\n" );
1092 #endif
1093 goto down_link;
1094 }
1095
1096 time = jiffies + ( HZ / 2 );
1097 do {
1098 val = hp100_inw( LAN_CFG_VG );
1099 if ( ( val & ( HP100_LINK_UP_ST | HP100_LINK_GOOD_ST ) ) ==
1100 ( HP100_LINK_UP_ST | HP100_LINK_GOOD_ST ) )
1101 return 0;
1102 } while ( time > jiffies );
1103 if ( val & HP100_LINK_GOOD_ST )
1104 printk( "%s: 100Mb cable training failed, check cable.\n", dev -> name );
1105 else
1106 printk( "%s: 100Mb node not accepted by hub, check frame type or security.\n", dev -> name );
1107
1108 down_link:
1109 hp100_down_vg_link( dev );
1110 hp100_page( MAC_CTRL );
1111 hp100_andw( ~( HP100_LOAD_ADDR | HP100_PROM_MODE ), LAN_CFG_VG );
1112 hp100_orw( HP100_LINK_CMD, LAN_CFG_VG );
1113 return -EIO;
1114 }
1115
1116
1117
1118
1119
1120 #ifdef MODULE
1121
1122 static int hp100_port = -1;
1123
1124 static char devicename[9] = { 0, };
1125 static struct device dev_hp100 = {
1126 devicename,
1127 0, 0, 0, 0,
1128 0, 0,
1129 0, 0, 0, NULL, hp100_probe
1130 };
1131
1132 int init_module( void )
1133 {
1134 if (hp100_port == 0 && !EISA_bus)
1135 printk("HP100: You should not use auto-probing with insmod!\n");
1136 if ( hp100_port > 0 )
1137 dev_hp100.base_addr = hp100_port;
1138 if ( register_netdev( &dev_hp100 ) != 0 )
1139 return -EIO;
1140 return 0;
1141 }
1142
1143 void cleanup_module( void )
1144 {
1145 unregister_netdev( &dev_hp100 );
1146 release_region( dev_hp100.base_addr, HP100_REGION_SIZE );
1147 if ( ((struct hp100_private *)dev_hp100.priv) -> mem_ptr_virt )
1148 vfree( ((struct hp100_private *)dev_hp100.priv) -> mem_ptr_virt );
1149 kfree_s( dev_hp100.priv, sizeof( struct hp100_private ) );
1150 dev_hp100.priv = NULL;
1151 }
1152
1153 #endif