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 #ifdef MODULE
503 MOD_INC_USE_COUNT;
504 #endif
505
506 dev -> tbusy = 0;
507 dev -> trans_start = jiffies;
508 dev -> interrupt = 0;
509 dev -> start = 1;
510
511 lp -> lan_type = hp100_sense_lan( dev );
512 lp -> mac1_mode = HP100_MAC1MODE3;
513 lp -> mac2_mode = HP100_MAC2MODE3;
514
515 hp100_page( MAC_CTRL );
516 hp100_orw( HP100_LINK_BEAT_DIS | HP100_RESET_LB, LAN_CFG_10 );
517
518 hp100_stop_interface( dev );
519 hp100_load_eeprom( dev );
520
521 hp100_outw( HP100_MMAP_DIS | HP100_SET_HB |
522 HP100_IO_EN | HP100_SET_LB, OPTION_LSW );
523 hp100_outw( HP100_DEBUG_EN | HP100_RX_HDR | HP100_EE_EN | HP100_RESET_HB |
524 HP100_FAKE_INT | HP100_RESET_LB, OPTION_LSW );
525 hp100_outw( HP100_ADV_NXT_PKT | HP100_TX_CMD | HP100_RESET_LB |
526 HP100_PRIORITY_TX | ( hp100_priority_tx ? HP100_SET_HB : HP100_RESET_HB ),
527 OPTION_MSW );
528
529 hp100_page( MAC_ADDRESS );
530 for ( i = 0; i < 6; i++ )
531 hp100_outb( dev -> dev_addr[ i ], MAC_ADDR + i );
532 for ( i = 0; i < 8; i++ )
533 hp100_outb( 0xff, HASH_BYTE0 + i );
534 hp100_page( PERFORMANCE );
535 hp100_outw( 0xfefe, IRQ_MASK );
536 hp100_outw( 0xffff, IRQ_STATUS );
537 hp100_outw( (HP100_RX_PACKET | HP100_RX_ERROR | HP100_SET_HB) |
538 (HP100_TX_ERROR | HP100_SET_LB ), IRQ_MASK );
539
540 hp100_reset_card();
541 hp100_page( MMU_CFG );
542 hp100_outw( ( lp -> memory_size * lp -> rx_ratio ) / 100, RX_MEM_STOP );
543 hp100_outw( lp -> memory_size - 1, TX_MEM_STOP );
544 hp100_unreset_card();
545
546 if ( lp -> lan_type == HP100_LAN_100 )
547 lp -> hub_status = hp100_login_to_vg_hub( dev );
548
549 hp100_start_interface( dev );
550
551 return 0;
552 }
553
554 static int hp100_close( struct device *dev )
555 {
556 int ioaddr = dev -> base_addr;
557 struct hp100_private *lp = (struct hp100_private *)dev -> priv;
558
559 hp100_page( PERFORMANCE );
560 hp100_outw( 0xfefe, IRQ_MASK );
561
562 hp100_stop_interface( dev );
563
564 if ( lp -> lan_type == HP100_LAN_100 )
565 hp100_login_to_vg_hub( dev );
566
567 dev -> tbusy = 1;
568 dev -> start = 0;
569
570 free_irq( dev -> irq );
571 irq2dev_map[ dev -> irq ] = NULL;
572 #ifdef MODULE
573 MOD_DEC_USE_COUNT;
574 #endif
575 return 0;
576 }
577
578
579
580
581
582 static int hp100_start_xmit( struct sk_buff *skb, struct device *dev )
583 {
584 int i, ok_flag;
585 int ioaddr = dev -> base_addr;
586 u_short val;
587 struct hp100_private *lp = (struct hp100_private *)dev -> priv;
588
589 if ( lp -> lan_type < 0 )
590 {
591 hp100_stop_interface( dev );
592 if ( ( lp -> lan_type = hp100_sense_lan( dev ) ) < 0 )
593 {
594 printk( "%s: no connection found - check wire\n", dev -> name );
595 hp100_start_interface( dev );
596 return -EIO;
597 }
598 if ( lp -> lan_type == HP100_LAN_100 )
599 lp -> hub_status = hp100_login_to_vg_hub( dev );
600 hp100_start_interface( dev );
601 }
602
603 if ( ( i = ( hp100_inl( TX_MEM_FREE ) & ~0x7fffffff ) ) < skb -> len + 16 )
604 {
605 #ifdef HP100_DEBUG
606 printk( "hp100_start_xmit: rx free mem = 0x%x\n", i );
607 #endif
608 if ( jiffies - dev -> trans_start < 2 * HZ ) return -EAGAIN;
609 if ( lp -> lan_type == HP100_LAN_100 && lp -> hub_status < 0 )
610
611 {
612 printk( "%s: login to 100Mb/s hub retry\n", dev -> name );
613 hp100_stop_interface( dev );
614 lp -> hub_status = hp100_login_to_vg_hub( dev );
615 hp100_start_interface( dev );
616 }
617 else
618 {
619 hp100_ints_off();
620 i = hp100_sense_lan( dev );
621 hp100_page( PERFORMANCE );
622 hp100_ints_on();
623 if ( i == HP100_LAN_ERR )
624 printk( "%s: link down detected\n", dev -> name );
625 else
626 if ( lp -> lan_type != i )
627 {
628
629 printk( "%s: cable change 10Mb/s <-> 100Mb/s detected\n", dev -> name );
630 lp -> lan_type = i;
631 hp100_stop_interface( dev );
632 if ( lp -> lan_type == HP100_LAN_100 )
633 lp -> hub_status = hp100_login_to_vg_hub( dev );
634 hp100_start_interface( dev );
635 }
636 else
637 {
638 printk( "%s: interface reset\n", dev -> name );
639 hp100_stop_interface( dev );
640 hp100_start_interface( dev );
641 }
642 }
643 dev -> trans_start = jiffies;
644 return -EAGAIN;
645 }
646
647 if ( skb == NULL )
648 {
649 dev_tint( dev );
650 return 0;
651 }
652
653 if ( skb -> len <= 0 ) return 0;
654
655 for ( i = 0; i < 6000 && ( hp100_inw( OPTION_MSW ) & HP100_TX_CMD ); i++ )
656 {
657 #ifdef HP100_DEBUG_TX
658 printk( "hp100_start_xmit: busy\n" );
659 #endif
660 }
661
662 hp100_ints_off();
663 val = hp100_inw( IRQ_STATUS );
664 hp100_outw( val & HP100_TX_COMPLETE, IRQ_STATUS );
665 #ifdef HP100_DEBUG_TX
666 printk( "hp100_start_xmit: irq_status = 0x%x, len = %d\n", val, (int)skb -> len );
667 #endif
668 ok_flag = skb -> len >= HP100_MIN_PACKET_SIZE;
669 i = ok_flag ? skb -> len : HP100_MIN_PACKET_SIZE;
670 hp100_outw( i, DATA32 );
671 hp100_outw( i, FRAGMENT_LEN );
672 if ( lp -> mem_mapped )
673 {
674 if ( lp -> mem_ptr_virt )
675 {
676 memcpy( lp -> mem_ptr_virt, skb -> data, skb -> len );
677 if ( !ok_flag )
678 memset( lp -> mem_ptr_virt, 0, HP100_MIN_PACKET_SIZE - skb -> len );
679 }
680 else
681 {
682 memcpy_toio( lp -> mem_ptr_phys, skb -> data, skb -> len );
683 if ( !ok_flag )
684 memset_io( lp -> mem_ptr_phys, 0, HP100_MIN_PACKET_SIZE - skb -> len );
685 }
686 }
687 else
688 {
689 outsl( ioaddr + HP100_REG_DATA32, skb -> data, ( skb -> len + 3 ) >> 2 );
690 if ( !ok_flag )
691 for ( i = ( skb -> len + 3 ) & ~3; i < HP100_MIN_PACKET_SIZE; i += 4 )
692 hp100_outl( 0, DATA32 );
693 }
694 hp100_outw( HP100_TX_CMD | HP100_SET_LB, OPTION_MSW );
695 lp -> stats.tx_packets++;
696 dev -> trans_start = jiffies;
697 hp100_ints_on();
698
699 dev_kfree_skb( skb, FREE_WRITE );
700
701 #ifdef HP100_DEBUG_TX
702 printk( "hp100_start_xmit: end\n" );
703 #endif
704
705 return 0;
706 }
707
708
709
710
711
712 static void hp100_rx( struct device *dev )
713 {
714 int packets, pkt_len;
715 int ioaddr = dev -> base_addr;
716 struct hp100_private *lp = (struct hp100_private *)dev -> priv;
717 u_int header;
718 struct sk_buff *skb;
719
720 #if 0
721 if ( lp -> lan_type < 0 )
722 {
723 if ( ( lp -> lan_type = hp100_sense_lan( dev ) ) == HP100_LAN_100 )
724 lp -> hub_status = hp100_login_to_vg_hub( dev );
725 hp100_page( PERFORMANCE );
726 }
727 #endif
728
729 packets = hp100_inb( RX_PKT_CNT );
730 #ifdef HP100_DEBUG
731 if ( packets > 1 )
732 printk( "hp100_rx: waiting packets = %d\n", packets );
733 #endif
734 while ( packets-- > 0 )
735 {
736 for ( pkt_len = 0; pkt_len < 6000 && ( hp100_inw( OPTION_MSW ) & HP100_ADV_NXT_PKT ); pkt_len++ )
737 {
738 #ifdef HP100_DEBUG_TX
739 printk( "hp100_rx: busy, remaining packets = %d\n", packets );
740 #endif
741 }
742 if ( lp -> mem_mapped )
743 {
744 if ( lp -> mem_ptr_virt )
745 header = *(__u32 *)lp -> mem_ptr_virt;
746 else
747 header = readl( lp -> mem_ptr_phys );
748 }
749 else
750 header = hp100_inl( DATA32 );
751 pkt_len = header & HP100_PKT_LEN_MASK;
752 #ifdef HP100_DEBUG_RX
753 printk( "hp100_rx: new packet - length = %d, errors = 0x%x, dest = 0x%x\n",
754 header & HP100_PKT_LEN_MASK, ( header >> 16 ) & 0xfff8, ( header >> 16 ) & 7 );
755 #endif
756
757
758
759
760
761 skb = dev_alloc_skb( pkt_len );
762 if ( skb == NULL )
763 {
764 #ifdef HP100_DEBUG
765 printk( "hp100_rx: couldn't allocate a sk_buff of size %d\n", pkt_len );
766 #endif
767 lp -> stats.rx_dropped++;
768 }
769 else
770 {
771 u_char *ptr;
772
773 skb -> dev = dev;
774 ptr = (u_char *)skb_put( skb, pkt_len );
775 if ( lp -> mem_mapped )
776 {
777 if ( lp -> mem_ptr_virt )
778 memcpy( ptr, lp -> mem_ptr_virt, ( pkt_len + 3 ) & ~3 );
779 else
780 memcpy_fromio( ptr, lp -> mem_ptr_phys, ( pkt_len + 3 ) & ~3 );
781 }
782 else
783 insl( ioaddr + HP100_REG_DATA32, ptr, ( pkt_len + 3 ) >> 2 );
784 skb -> protocol = eth_type_trans( skb, dev );
785 netif_rx( skb );
786 lp -> stats.rx_packets++;
787 #ifdef HP100_DEBUG_RX
788 printk( "rx: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
789 ptr[ 0 ], ptr[ 1 ], ptr[ 2 ], ptr[ 3 ], ptr[ 4 ], ptr[ 5 ],
790 ptr[ 6 ], ptr[ 7 ], ptr[ 8 ], ptr[ 9 ], ptr[ 10 ], ptr[ 11 ] );
791 #endif
792 }
793 hp100_outw( HP100_ADV_NXT_PKT | HP100_SET_LB, OPTION_MSW );
794 switch ( header & 0x00070000 ) {
795 case (HP100_MULTI_ADDR_HASH<<16):
796 case (HP100_MULTI_ADDR_NO_HASH<<16):
797 lp -> stats.multicast++; break;
798 }
799 }
800 #ifdef HP100_DEBUG_RX
801 printk( "hp100_rx: end\n" );
802 #endif
803 }
804
805
806
807
808
809 static struct enet_statistics *hp100_get_stats( struct device *dev )
810 {
811 int ioaddr = dev -> base_addr;
812
813 hp100_ints_off();
814 hp100_update_stats( dev );
815 hp100_ints_on();
816 return &((struct hp100_private *)dev -> priv) -> stats;
817 }
818
819 static void hp100_update_stats( struct device *dev )
820 {
821 int ioaddr = dev -> base_addr;
822 u_short val;
823 struct hp100_private *lp = (struct hp100_private *)dev -> priv;
824
825 hp100_page( MAC_CTRL );
826 val = hp100_inw( DROPPED ) & 0x0fff;
827 lp -> stats.rx_errors += val;
828 lp -> stats.rx_over_errors += val;
829 val = hp100_inb( CRC );
830 lp -> stats.rx_errors += val;
831 lp -> stats.rx_crc_errors += val;
832 val = hp100_inb( ABORT );
833 lp -> stats.tx_errors += val;
834 lp -> stats.tx_aborted_errors += val;
835 hp100_page( PERFORMANCE );
836 }
837
838 static void hp100_clear_stats( int ioaddr )
839 {
840 cli();
841 hp100_page( MAC_CTRL );
842 hp100_inw( DROPPED );
843 hp100_inb( CRC );
844 hp100_inb( ABORT );
845 hp100_page( PERFORMANCE );
846 sti();
847 }
848
849
850
851
852
853 #ifdef HAVE_MULTICAST
854
855
856
857
858
859
860
861
862
863
864 static void hp100_set_multicast_list( struct device *dev, int num_addrs, void *addrs )
865 {
866 int ioaddr = dev -> base_addr;
867 struct hp100_private *lp = (struct hp100_private *)dev -> priv;
868
869 #ifdef HP100_DEBUG_MULTI
870 printk( "hp100_set_multicast_list: num_addrs = %d\n", num_addrs );
871 #endif
872 cli();
873 hp100_ints_off();
874 hp100_page( MAC_CTRL );
875 hp100_andb( ~(HP100_RX_EN | HP100_TX_EN), MAC_CFG_1 );
876
877 if ( num_addrs == -1 )
878 {
879 lp -> mac2_mode = HP100_MAC2MODE6;
880 lp -> mac1_mode = HP100_MAC1MODE6;
881 }
882 else
883 if ( num_addrs != 0 )
884 {
885 lp -> mac2_mode = HP100_MAC2MODE5;
886 lp -> mac1_mode = HP100_MAC1MODE5;
887 }
888 else
889 {
890 lp -> mac2_mode = HP100_MAC2MODE3;
891 lp -> mac1_mode = HP100_MAC1MODE3;
892 }
893
894 hp100_outb( lp -> mac2_mode, MAC_CFG_2 );
895 hp100_andb( HP100_MAC1MODEMASK, MAC_CFG_1 );
896 hp100_orb( lp -> mac1_mode |
897 HP100_RX_EN | HP100_RX_IDLE |
898 HP100_TX_EN | HP100_TX_IDLE, MAC_CFG_1 );
899 hp100_page( PERFORMANCE );
900 hp100_ints_on();
901 sti();
902 }
903
904 #endif
905
906
907
908
909
910 static void hp100_interrupt( int irq, struct pt_regs *regs )
911 {
912 struct device *dev = (struct device *)irq2dev_map[ irq ];
913 struct hp100_private *lp;
914 int ioaddr;
915 u_short val;
916
917 if ( dev == NULL ) return;
918 ioaddr = dev -> base_addr;
919 if ( dev -> interrupt )
920 printk( "%s: re-entering the interrupt handler\n", dev -> name );
921 hp100_ints_off();
922 dev -> interrupt = 1;
923 hp100_page( PERFORMANCE );
924 val = hp100_inw( IRQ_STATUS );
925 #ifdef HP100_DEBUG_IRQ
926 printk( "hp100_interrupt: irq_status = 0x%x\n", val );
927 #endif
928 if ( val & HP100_RX_PACKET )
929 {
930 hp100_rx( dev );
931 hp100_outw( HP100_RX_PACKET, IRQ_STATUS );
932 }
933 if ( val & (HP100_TX_SPACE_AVAIL | HP100_TX_COMPLETE) )
934 {
935 hp100_outw( val & (HP100_TX_SPACE_AVAIL | HP100_TX_COMPLETE), IRQ_STATUS );
936 }
937 if ( val & ( HP100_TX_ERROR | HP100_RX_ERROR ) )
938 {
939 lp = (struct hp100_private *)dev -> priv;
940 hp100_update_stats( dev );
941 hp100_outw( val & (HP100_TX_ERROR | HP100_RX_ERROR), IRQ_STATUS );
942 }
943 #ifdef HP100_DEBUG_IRQ
944 printk( "hp100_interrupt: end\n" );
945 #endif
946 dev -> interrupt = 0;
947 hp100_ints_on();
948 }
949
950
951
952
953
954 static void hp100_start_interface( struct device *dev )
955 {
956 int ioaddr = dev -> base_addr;
957 struct hp100_private *lp = (struct hp100_private *)dev -> priv;
958
959 cli();
960 hp100_unreset_card();
961 hp100_page( MAC_CTRL );
962 hp100_outb( lp -> mac2_mode, MAC_CFG_2 );
963 hp100_andb( HP100_MAC1MODEMASK, MAC_CFG_1 );
964 hp100_orb( lp -> mac1_mode |
965 HP100_RX_EN | HP100_RX_IDLE |
966 HP100_TX_EN | HP100_TX_IDLE, MAC_CFG_1 );
967 hp100_page( PERFORMANCE );
968 hp100_outw( HP100_INT_EN | HP100_SET_LB, OPTION_LSW );
969 hp100_outw( HP100_TRI_INT | HP100_RESET_HB, OPTION_LSW );
970 if ( lp -> mem_mapped )
971 {
972
973 hp100_outw( HP100_MMAP_DIS | HP100_RESET_HB, OPTION_LSW );
974 }
975 sti();
976 }
977
978 static void hp100_stop_interface( struct device *dev )
979 {
980 int ioaddr = dev -> base_addr;
981 u_short val;
982
983 hp100_outw( HP100_INT_EN | HP100_RESET_LB |
984 HP100_TRI_INT | HP100_MMAP_DIS | HP100_SET_HB, OPTION_LSW );
985 val = hp100_inw( OPTION_LSW );
986 hp100_page( HW_MAP );
987 hp100_andb( HP100_BM_SLAVE, BM );
988 hp100_page( MAC_CTRL );
989 hp100_andb( ~(HP100_RX_EN | HP100_TX_EN), MAC_CFG_1 );
990 if ( !(val & HP100_HW_RST) ) return;
991 for ( val = 0; val < 6000; val++ )
992 if ( ( hp100_inb( MAC_CFG_1 ) & (HP100_TX_IDLE | HP100_RX_IDLE) ) ==
993 (HP100_TX_IDLE | HP100_RX_IDLE) )
994 return;
995 printk( "%s: hp100_stop_interface - timeout\n", dev -> name );
996 }
997
998 static void hp100_load_eeprom( struct device *dev )
999 {
1000 int i;
1001 int ioaddr = dev -> base_addr;
1002
1003 hp100_page( EEPROM_CTRL );
1004 hp100_andw( ~HP100_EEPROM_LOAD, EEPROM_CTRL );
1005 hp100_orw( HP100_EEPROM_LOAD, EEPROM_CTRL );
1006 for ( i = 0; i < 6000; i++ )
1007 if ( !( hp100_inw( OPTION_MSW ) & HP100_EE_LOAD ) ) return;
1008 printk( "%s: hp100_load_eeprom - timeout\n", dev -> name );
1009 }
1010
1011
1012
1013 static int hp100_sense_lan( struct device *dev )
1014 {
1015 int i;
1016 int ioaddr = dev -> base_addr;
1017 u_short val_VG, val_10;
1018 struct hp100_private *lp = (struct hp100_private *)dev -> priv;
1019
1020 hp100_page( MAC_CTRL );
1021 hp100_orw( HP100_VG_RESET, LAN_CFG_VG );
1022 val_10 = hp100_inw( LAN_CFG_10 );
1023 val_VG = hp100_inw( LAN_CFG_VG );
1024 #ifdef HP100_DEBUG_SENSE
1025 printk( "hp100_sense_lan: val_VG = 0x%04x, val_10 = 0x%04x\n", val_VG, val_10 );
1026 #endif
1027 if ( val_10 & HP100_LINK_BEAT_ST ) return HP100_LAN_10;
1028 if ( lp -> id -> id == 0x02019F022 )
1029 return HP100_LAN_ERR;
1030 for ( i = 0; i < 2500; i++ )
1031 {
1032 val_VG = hp100_inw( LAN_CFG_VG );
1033 if ( val_VG & HP100_LINK_CABLE_ST ) return HP100_LAN_100;
1034 }
1035 return HP100_LAN_ERR;
1036 }
1037
1038 static int hp100_down_vg_link( struct device *dev )
1039 {
1040 int ioaddr = dev -> base_addr;
1041 unsigned long time;
1042 int i;
1043
1044 hp100_page( MAC_CTRL );
1045 for ( i = 2500; i > 0; i-- )
1046 if ( hp100_inw( LAN_CFG_VG ) & HP100_LINK_CABLE_ST ) break;
1047 if ( i <= 0 )
1048 return 0;
1049 hp100_andw( ~HP100_LINK_CMD, LAN_CFG_VG );
1050 time = jiffies + 10;
1051 while ( time > jiffies )
1052 if ( !( hp100_inw( LAN_CFG_VG ) & ( HP100_LINK_UP_ST |
1053 HP100_LINK_CABLE_ST |
1054 HP100_LINK_GOOD_ST ) ) )
1055 return 0;
1056 #ifdef HP100_DEBUG
1057 printk( "hp100_down_vg_link: timeout\n" );
1058 #endif
1059 return -EIO;
1060 }
1061
1062 static int hp100_login_to_vg_hub( struct device *dev )
1063 {
1064 int i;
1065 int ioaddr = dev -> base_addr;
1066 u_short val;
1067 unsigned long time;
1068
1069 hp100_page( MAC_CTRL );
1070 hp100_orw( HP100_VG_RESET, LAN_CFG_VG );
1071 time = jiffies + ( HZ / 2 );
1072 do {
1073 if ( hp100_inw( LAN_CFG_VG ) & HP100_LINK_CABLE_ST ) break;
1074 } while ( time > jiffies );
1075 if ( time <= jiffies )
1076 {
1077 #ifdef HP100_DEBUG
1078 printk( "hp100_login_to_vg_hub: timeout for link\n" );
1079 #endif
1080 return -EIO;
1081 }
1082
1083 if ( hp100_down_vg_link( dev ) < 0 )
1084 {
1085 hp100_andw( ~HP100_VG_RESET, LAN_CFG_VG );
1086 hp100_orw( HP100_VG_RESET, LAN_CFG_VG );
1087 }
1088
1089 hp100_orw( HP100_LOAD_ADDR | HP100_LINK_CMD, LAN_CFG_VG );
1090 for ( i = 2500; i > 0; i-- )
1091 if ( hp100_inw( LAN_CFG_VG ) & HP100_LINK_CABLE_ST ) break;
1092 if ( i <= 0 )
1093 {
1094 #ifdef HP100_DEBUG
1095 printk( "hp100_login_to_vg_hub: timeout for link (bring up)\n" );
1096 #endif
1097 goto down_link;
1098 }
1099
1100 time = jiffies + ( HZ / 2 );
1101 do {
1102 val = hp100_inw( LAN_CFG_VG );
1103 if ( ( val & ( HP100_LINK_UP_ST | HP100_LINK_GOOD_ST ) ) ==
1104 ( HP100_LINK_UP_ST | HP100_LINK_GOOD_ST ) )
1105 return 0;
1106 } while ( time > jiffies );
1107 if ( val & HP100_LINK_GOOD_ST )
1108 printk( "%s: 100Mb cable training failed, check cable.\n", dev -> name );
1109 else
1110 printk( "%s: 100Mb node not accepted by hub, check frame type or security.\n", dev -> name );
1111
1112 down_link:
1113 hp100_down_vg_link( dev );
1114 hp100_page( MAC_CTRL );
1115 hp100_andw( ~( HP100_LOAD_ADDR | HP100_PROM_MODE ), LAN_CFG_VG );
1116 hp100_orw( HP100_LINK_CMD, LAN_CFG_VG );
1117 return -EIO;
1118 }
1119
1120
1121
1122
1123
1124 #ifdef MODULE
1125
1126 static int hp100_port = -1;
1127
1128 static char devicename[9] = { 0, };
1129 static struct device dev_hp100 = {
1130 devicename,
1131 0, 0, 0, 0,
1132 0, 0,
1133 0, 0, 0, NULL, hp100_probe
1134 };
1135
1136 int init_module( void )
1137 {
1138 if (hp100_port == 0 && !EISA_bus)
1139 printk("HP100: You should not use auto-probing with insmod!\n");
1140 if ( hp100_port > 0 )
1141 dev_hp100.base_addr = hp100_port;
1142 if ( register_netdev( &dev_hp100 ) != 0 )
1143 return -EIO;
1144 return 0;
1145 }
1146
1147 void cleanup_module( void )
1148 {
1149 unregister_netdev( &dev_hp100 );
1150 release_region( dev_hp100.base_addr, HP100_REGION_SIZE );
1151 if ( ((struct hp100_private *)dev_hp100.priv) -> mem_ptr_virt )
1152 vfree( ((struct hp100_private *)dev_hp100.priv) -> mem_ptr_virt );
1153 kfree_s( dev_hp100.priv, sizeof( struct hp100_private ) );
1154 dev_hp100.priv = NULL;
1155 }
1156
1157 #endif