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_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 #ifdef MODULE
72 #include <linux/module.h>
73 #include <linux/version.h>
74 #endif
75
76 #include <linux/kernel.h>
77 #include <linux/sched.h>
78 #include <linux/string.h>
79 #include <linux/errno.h>
80 #include <linux/ioport.h>
81 #include <linux/malloc.h>
82 #include <linux/interrupt.h>
83 #include <asm/bitops.h>
84 #include <asm/io.h>
85
86 #include <linux/netdevice.h>
87 #include <linux/etherdevice.h>
88 #include <linux/skbuff.h>
89
90 #include <linux/types.h>
91
92 #include "hp100.h"
93
94
95
96
97
98 #define HP100_MAX_PACKET_SIZE (1536+4)
99 #define HP100_MIN_PACKET_SIZE 60
100
101 #ifndef HP100_RX_RATIO
102
103 #define HP100_RX_RATIO 65
104 #endif
105
106
107
108
109
110 struct hp100_eisa_id {
111 u_int id;
112 char *name;
113 };
114
115 struct hp100_private {
116 struct hp100_eisa_id *id;
117 u_short soft_model;
118 u_int memory_size;
119 u_short rx_ratio;
120 short lan_type;
121 int hub_status;
122 u_char mac1_mode;
123 u_char mac2_mode;
124 struct enet_statistics stats;
125 };
126
127 struct hp100_rx_look {
128 struct hp100_rx_header header;
129 char something[ 24 ];
130 };
131
132
133
134
135
136 static struct hp100_eisa_id hp100_eisa_ids[] = {
137 { 0x080F1F022, "HP J2577 rev A" },
138 { 0x050F1F022, "HP J2573 rev A" },
139 { 0x02019F022, "HP 27248B" },
140 { 0x04019F022, "HP J2577" },
141 { 0x05019F022, "HP J2573" }
142 };
143
144 #ifdef MODULE
145 int hp100_default_rx_ratio = HP100_RX_RATIO;
146 #endif
147
148
149
150
151
152 static int hp100_probe1( struct device *dev, int ioaddr );
153 static int hp100_open( struct device *dev );
154 static int hp100_close( struct device *dev );
155 static int hp100_start_xmit( struct sk_buff *skb, struct device *dev );
156 static void hp100_rx( struct device *dev );
157 static struct enet_statistics *hp100_get_stats( struct device *dev );
158 static void hp100_update_stats( struct device *dev );
159 #ifdef HAVE_MULTICAST
160 static void hp100_set_multicast_list( struct device *dev, int num_addrs, void *addrs );
161 #endif
162 #ifndef LINUX_1_1_52
163 static void hp100_interrupt( int irq, struct pt_regs *regs );
164 #else
165 static void hp100_interrupt( int irq );
166 #endif
167
168 static void hp100_start_interface( struct device *dev );
169 static void hp100_stop_interface( struct device *dev );
170 static void hp100_load_eeprom( struct device *dev );
171 static int hp100_sense_lan( struct device *dev );
172 static int hp100_login_to_vg_hub( struct device *dev );
173 static int hp100_down_vg_link( struct device *dev );
174
175
176
177
178
179 int hp100_probe( struct device *dev )
180 {
181 int base_addr = dev ? dev -> base_addr : 0;
182 int ioaddr;
183
184 if ( base_addr > 0xff )
185 return hp100_probe1(dev, base_addr);
186 else
187 if ( base_addr != 0 ) return -ENXIO;
188
189
190
191 for ( ioaddr = 0x1c38; EISA_bus && ioaddr < 0x10000; ioaddr += 0x400 )
192 {
193 if ( check_region( ioaddr, 0x20 ) ) continue;
194 if ( hp100_probe1( dev, ioaddr ) == 0 ) return 0;
195 }
196
197
198
199 for ( ioaddr = 0x100; ioaddr < 0x400; ioaddr += 0x20 )
200 {
201 if ( check_region( ioaddr, 0x20 ) ) continue;
202 if ( hp100_probe1( dev, ioaddr ) == 0 ) return 0;
203 }
204
205 return -ENODEV;
206 }
207
208 static int hp100_probe1( struct device *dev, int ioaddr )
209 {
210 int i;
211 u_char uc;
212 u_int eisa_id;
213 struct hp100_private *lp;
214 struct hp100_eisa_id *eid;
215
216 if ( dev == NULL )
217 {
218 #ifdef HP100_DEBUG
219 printk( "hp100_probe1: dev == NULL ?\n" );
220 #endif
221 return EIO;
222 }
223
224 if ( inb( ioaddr + 0 ) != HP100_HW_ID_0 ||
225 inb( ioaddr + 1 ) != HP100_HW_ID_1 ||
226 ( inb( ioaddr + 2 ) & 0xf0 ) != HP100_HW_ID_2_REVA ||
227 inb( ioaddr + 3 ) != HP100_HW_ID_3 )
228 return -ENODEV;
229
230 dev -> base_addr = ioaddr;
231
232 #ifdef HP100_DEBUG_PROBE1
233 printk( "hp100_probe1: card found at port 0x%x\n", ioaddr );
234 #endif
235
236 hp100_page( ID_MAC_ADDR );
237 for ( i = uc = eisa_id = 0; i < 4; i++ )
238 {
239 eisa_id >>= 8;
240 eisa_id |= ( hp100_inb( BOARD_ID + i ) ) << 24;
241 uc += eisa_id >> 24;
242 }
243 uc += hp100_inb( BOARD_ID + 4 );
244
245 #ifdef HP100_DEBUG_PROBE1
246 printk( "hp100_probe1: EISA ID = 0x%08x checksum = 0x%02x\n", eisa_id, uc );
247 #endif
248
249 if ( uc != 0xff )
250 {
251 printk( "hp100_probe: bad EISA ID checksum at base port 0x%x\n", ioaddr );
252 return -ENODEV;
253 }
254
255 for ( i = 0; i < sizeof( hp100_eisa_ids ) / sizeof( struct hp100_eisa_id ); i++ )
256 if ( ( hp100_eisa_ids[ i ].id & 0xf0ffffff ) == ( eisa_id & 0xf0ffffff ) )
257 break;
258 if ( i >= sizeof( hp100_eisa_ids ) / sizeof( struct hp100_eisa_id ) )
259 {
260 printk( "hp100_probe1: card at port 0x%x isn't known\n", ioaddr );
261 return -ENODEV;
262 }
263 eid = &hp100_eisa_ids[ i ];
264 if ( ( eid -> id & 0x0f000000 ) < ( eisa_id & 0x0f000000 ) )
265 {
266 printk( "hp100_probe1: newer version of card %s at port 0x%x - unsupported\n",
267 eid -> name, ioaddr );
268 return -ENODEV;
269 }
270
271 for ( i = uc = 0; i < 7; i++ )
272 uc += hp100_inb( LAN_ADDR + i );
273 if ( uc != 0xff )
274 {
275 printk( "hp100_probe1: bad lan address checksum (card %s at port 0x%x)\n",
276 eid -> name, ioaddr );
277 return -EIO;
278 }
279
280 hp100_page( HW_MAP );
281 if ( hp100_inw( OPTION_LSW ) & ( HP100_MEM_EN | HP100_BM_WRITE | HP100_BM_READ ) )
282 {
283 printk( "hp100_probe1: memory mapped io isn't supported (card %s at port 0x%x)\n",
284 eid -> name, ioaddr );
285 return -EIO;
286 }
287
288 if ( ( dev -> priv = kmalloc( sizeof( struct hp100_private ), GFP_KERNEL ) ) == NULL )
289 return -ENOMEM;
290 memset( dev -> priv, 0, sizeof( struct hp100_private ) );
291
292 lp = (struct hp100_private *)dev -> priv;
293 lp -> id = eid;
294 hp100_page( ID_MAC_ADDR );
295 lp -> soft_model = hp100_inb( SOFT_MODEL );
296 lp -> mac1_mode = HP100_MAC1MODE3;
297 lp -> mac2_mode = HP100_MAC2MODE3;
298
299 dev -> base_addr = ioaddr;
300 hp100_page( HW_MAP );
301 dev -> irq = hp100_inb( IRQ_CHANNEL ) & HP100_IRQ_MASK;
302 if ( dev -> irq == 2 ) dev -> irq = 9;
303 lp -> memory_size = 0x200 << ( ( hp100_inb( SRAM ) & 0xe0 ) >> 5 );
304 #ifndef MODULE
305 lp -> rx_ratio = HP100_RX_RATIO;
306 #else
307 lp -> rx_ratio = hp100_default_rx_ratio;
308 #endif
309
310 dev -> open = hp100_open;
311 dev -> stop = hp100_close;
312 dev -> hard_start_xmit = hp100_start_xmit;
313 dev -> get_stats = hp100_get_stats;
314 #ifdef HAVE_MULTICAST
315 dev -> set_multicast_list = &hp100_set_multicast_list;
316 #endif
317
318 #ifndef LINUX_1_1_52
319 request_region( dev -> base_addr, 0x20, eid -> name );
320 #endif
321
322 hp100_page( ID_MAC_ADDR );
323 for ( i = uc = 0; i < 6; i++ )
324 dev -> dev_addr[ i ] = hp100_inb( LAN_ADDR + i );
325
326 ether_setup( dev );
327
328 lp -> lan_type = hp100_sense_lan( dev );
329
330 printk( "%s: %s at 0x%x, IRQ %d, %dkB SRAM (rx/tx %d%%), ",
331 dev -> name, lp -> id -> name, ioaddr, dev -> irq,
332 lp -> memory_size >> ( 10 - 4 ), lp -> rx_ratio );
333 switch ( lp -> lan_type ) {
334 case HP100_LAN_100: printk( "100Mb/s VG TP" ); break;
335 case HP100_LAN_10: printk( "10Mb/s TP" ); break;
336 default: printk( "link down" ); break;
337 }
338 printk( ".\n" );
339
340 return 0;
341 }
342
343
344
345
346
347 static int hp100_open( struct device *dev )
348 {
349 int i;
350 int ioaddr = dev -> base_addr;
351 struct hp100_private *lp = (struct hp100_private *)dev -> priv;
352
353 if ( ( lp -> lan_type = hp100_sense_lan( dev ) ) < 0 )
354 {
355 printk( "%s: no connection found - check wire\n", dev -> name );
356 return -EIO;
357 }
358
359 if ( request_irq( dev -> irq, hp100_interrupt, SA_INTERRUPT, lp -> id -> name ) )
360 {
361 printk( "%s: unable to get IRQ %d\n", dev -> name, dev -> irq );
362 return -EAGAIN;
363 }
364 irq2dev_map[ dev -> irq ] = dev;
365
366 #ifdef MODULE
367 MOD_INC_USE_COUNT;
368 #endif
369
370 dev -> tbusy = 0;
371 dev -> trans_start = jiffies;
372 dev -> interrupt = 0;
373 dev -> start = 1;
374
375 lp -> mac1_mode = HP100_MAC1MODE3;
376 lp -> mac2_mode = HP100_MAC2MODE3;
377
378 hp100_page( MAC_CTRL );
379 hp100_orw( HP100_LINK_BEAT_DIS, LAN_CFG_10 );
380
381 hp100_stop_interface( dev );
382 hp100_reset_card();
383 hp100_load_eeprom( dev );
384
385 hp100_outw( HP100_MMAP_DIS | HP100_SET_HB |
386 HP100_IO_EN | HP100_SET_LB, OPTION_LSW );
387 hp100_outw( HP100_DEBUG_EN | HP100_RX_HDR | HP100_EE_EN | HP100_RESET_HB |
388 HP100_FAKE_INT | HP100_RESET_LB, OPTION_LSW );
389 #if 0
390 hp100_outw( HP100_PRIORITY_TX | HP100_ADV_NXT_PKT |
391 HP100_TX_CMD | HP100_RESET_LB, OPTION_MSW );
392 #else
393 hp100_outw( HP100_ADV_NXT_PKT | HP100_TX_CMD | HP100_RESET_LB, OPTION_MSW );
394 #endif
395
396 hp100_page( MAC_ADDRESS );
397 for ( i = 0; i < 6; i++ )
398 hp100_outb( dev -> dev_addr[ i ], MAC_ADDR + i );
399 for ( i = 0; i < 8; i++ )
400 hp100_outb( 0xff, HASH_BYTE0 + i );
401 hp100_page( PERFORMANCE );
402 hp100_outw( 0xfefe, IRQ_MASK );
403 hp100_outw( 0xffff, IRQ_STATUS );
404 hp100_outw( (HP100_RX_PACKET | HP100_RX_ERROR | HP100_SET_HB) |
405 (HP100_TX_ERROR | HP100_SET_LB ), IRQ_MASK );
406
407 hp100_reset_card();
408 hp100_page( MMU_CFG );
409 hp100_outw( ( lp -> memory_size * lp -> rx_ratio ) / 100, RX_MEM_STOP );
410 hp100_outw( lp -> memory_size - 1, TX_MEM_STOP );
411 hp100_unreset_card();
412
413 if ( lp -> lan_type == HP100_LAN_100 )
414 lp -> hub_status = hp100_login_to_vg_hub( dev );
415
416 hp100_start_interface( dev );
417
418 return 0;
419 }
420
421 static int hp100_close( struct device *dev )
422 {
423 int ioaddr = dev -> base_addr;
424 struct hp100_private *lp = (struct hp100_private *)dev -> priv;
425
426 hp100_page( PERFORMANCE );
427 hp100_outw( 0xfefe, IRQ_MASK );
428
429 hp100_stop_interface( dev );
430
431 if ( lp -> lan_type == HP100_LAN_100 )
432 hp100_login_to_vg_hub( dev );
433
434 dev -> tbusy = 1;
435 dev -> start = 0;
436
437 free_irq( dev -> irq );
438 irq2dev_map[ dev -> irq ] = NULL;
439 #ifdef MODULE
440 MOD_DEC_USE_COUNT;
441 #endif
442 return 0;
443 }
444
445
446
447
448
449 static int hp100_start_xmit( struct sk_buff *skb, struct device *dev )
450 {
451 int i;
452 int ioaddr = dev -> base_addr;
453 u_short val;
454 struct hp100_private *lp = (struct hp100_private *)dev -> priv;
455
456 if ( ( i = ( hp100_inl( TX_MEM_FREE ) & ~0x7fffffff ) ) < skb -> len + 16 )
457 {
458 #ifdef HP100_DEBUG
459 printk( "hp100_start_xmit: rx free mem = 0x%x\n", i );
460 #endif
461 if ( jiffies - dev -> trans_start < 2 * HZ ) return -EAGAIN;
462 if ( lp -> lan_type == HP100_LAN_100 && lp -> hub_status < 0 )
463
464 {
465 printk( "%s: login to 100Mb/s hub retry\n", dev -> name );
466 hp100_ints_off();
467 hp100_stop_interface( dev );
468 lp -> hub_status = hp100_login_to_vg_hub( dev );
469 hp100_start_interface( dev );
470 hp100_ints_on();
471 }
472 else
473 {
474 hp100_ints_off();
475 i = hp100_sense_lan( dev );
476 hp100_page( PERFORMANCE );
477 hp100_ints_on();
478 if ( i == HP100_LAN_ERR )
479 printk( "%s: link down detected\n", dev -> name );
480 else
481 if ( lp -> lan_type != i )
482 {
483
484 printk( "%s: cable change 10Mb/s <-> 100Mb/s detected\n", dev -> name );
485 lp -> lan_type = i;
486 hp100_ints_off();
487 hp100_stop_interface( dev );
488 if ( lp -> lan_type == HP100_LAN_100 )
489 lp -> hub_status = hp100_login_to_vg_hub( dev );
490 hp100_start_interface( dev );
491 hp100_ints_on();
492 }
493 else
494 {
495 printk( "%s: interface reset\n", dev -> name );
496 hp100_ints_off();
497 hp100_stop_interface( dev );
498 hp100_start_interface( dev );
499 hp100_ints_on();
500 }
501 }
502 dev -> trans_start = jiffies;
503 return -EAGAIN;
504 }
505
506 if ( skb == NULL )
507 {
508 dev_tint( dev );
509 return 0;
510 }
511
512 if ( skb -> len <= 0 ) return 0;
513
514 for ( i = 0; i < 6000 && ( hp100_inw( OPTION_MSW ) & HP100_TX_CMD ); i++ )
515 {
516 #ifdef HP100_DEBUG_TX
517 printk( "hp100_start_xmit: busy\n" );
518 #endif
519 }
520
521 hp100_ints_off();
522 val = hp100_inw( IRQ_STATUS );
523 hp100_outw( val & HP100_TX_COMPLETE, IRQ_STATUS );
524 #ifdef HP100_DEBUG_TX
525 printk( "hp100_start_xmit: irq_status = 0x%x, len = %d\n", val, (int)skb -> len );
526 #endif
527 if ( skb -> len >= HP100_MIN_PACKET_SIZE )
528 {
529 hp100_outw( skb -> len, DATA32 );
530 hp100_outw( skb -> len, FRAGMENT_LEN );
531 outsl( ioaddr + HP100_REG_DATA32, skb -> data, ( skb -> len + 3 ) >> 2 );
532 hp100_outw( HP100_TX_CMD | HP100_SET_LB, OPTION_MSW );
533 }
534 else
535 {
536 hp100_outw( HP100_MIN_PACKET_SIZE, DATA32 );
537 hp100_outw( HP100_MIN_PACKET_SIZE, FRAGMENT_LEN );
538 i = skb -> len + 3;
539 outsl( ioaddr + HP100_REG_DATA32, skb -> data, i >> 2 );
540 for ( i &= ~3; i < HP100_MIN_PACKET_SIZE; i += 4 )
541 hp100_outl( 0, DATA32 );
542 hp100_outw( HP100_TX_CMD | HP100_SET_LB, OPTION_MSW );
543 }
544 lp -> stats.tx_packets++;
545 dev -> trans_start = jiffies;
546 hp100_ints_on();
547
548 dev_kfree_skb( skb, FREE_WRITE );
549
550 #ifdef HP100_DEBUG_TX
551 printk( "hp100_start_xmit: end\n" );
552 #endif
553
554 return 0;
555 }
556
557
558
559
560
561 static void hp100_rx( struct device *dev )
562 {
563 int packets, pkt_len;
564 int ioaddr = dev -> base_addr;
565 struct hp100_private *lp = (struct hp100_private *)dev -> priv;
566 u_int header;
567 struct sk_buff *skb;
568
569 packets = hp100_inb( RX_PKT_CNT );
570 #ifdef HP100_DEBUG
571 if ( packets > 1 )
572 printk( "hp100_rx: waiting packets = %d\n", packets );
573 #endif
574 while ( packets-- > 0 )
575 {
576 for ( pkt_len = 0; pkt_len < 6000 && ( hp100_inw( OPTION_MSW ) & HP100_ADV_NXT_PKT ); pkt_len++ )
577 {
578 #ifdef HP100_DEBUG_TX
579 printk( "hp100_rx: busy, remaining packets = %d\n", packets );
580 #endif
581 }
582 header = hp100_inl( DATA32 );
583 pkt_len = header & HP100_PKT_LEN_MASK;
584 #ifdef HP100_DEBUG_RX
585 printk( "hp100_rx: new packet - length = %d, errors = 0x%x, dest = 0x%x\n",
586 header & HP100_PKT_LEN_MASK, ( header >> 16 ) & 0xfff8, ( header >> 16 ) & 7 );
587 #endif
588 skb = alloc_skb( ( pkt_len + 3 ) & ~3, GFP_ATOMIC );
589 if ( skb == NULL )
590 {
591 #ifdef HP100_DEBUG
592 printk( "hp100_rx: couldn't allocate a sk_buff of size %d\n", pkt_len );
593 #endif
594 lp -> stats.rx_dropped++;
595 }
596 else
597 {
598 skb -> len = pkt_len;
599 skb -> dev = dev;
600 insl( ioaddr + HP100_REG_DATA32, skb -> data, ( pkt_len + 3 ) >> 2 );
601 skb->protocol=eth_type_trans(skb,dev);
602 netif_rx( skb );
603 lp -> stats.rx_packets++;
604 }
605 hp100_outw( HP100_ADV_NXT_PKT | HP100_SET_LB, OPTION_MSW );
606 switch ( header & 0x00070000 ) {
607 case (HP100_MULTI_ADDR_HASH<<16):
608 case (HP100_MULTI_ADDR_NO_HASH<<16):
609 lp -> stats.multicast++; break;
610 }
611 }
612 #ifdef HP100_DEBUG_RX
613 printk( "hp100_rx: end\n" );
614 #endif
615 }
616
617
618
619
620
621 static struct enet_statistics *hp100_get_stats( struct device *dev )
622 {
623 int ioaddr = dev -> base_addr;
624
625 hp100_ints_off();
626 hp100_update_stats( dev );
627 hp100_ints_on();
628 return &((struct hp100_private *)dev -> priv) -> stats;
629 }
630
631 static void hp100_update_stats( struct device *dev )
632 {
633 int ioaddr = dev -> base_addr;
634 u_short val;
635 struct hp100_private *lp = (struct hp100_private *)dev -> priv;
636
637 hp100_page( MAC_CTRL );
638 val = hp100_inw( DROPPED ) & 0x0fff;
639 lp -> stats.rx_errors += val;
640 lp -> stats.rx_over_errors += val;
641 val = hp100_inb( CRC );
642 lp -> stats.rx_errors += val;
643 lp -> stats.rx_crc_errors += val;
644 val = hp100_inb( ABORT );
645 lp -> stats.tx_errors += val;
646 lp -> stats.tx_aborted_errors += val;
647 hp100_page( PERFORMANCE );
648 }
649
650
651
652
653
654 #ifdef HAVE_MULTICAST
655
656
657
658
659
660
661
662
663
664
665 static void hp100_set_multicast_list( struct device *dev, int num_addrs, void *addrs )
666 {
667 int ioaddr = dev -> base_addr;
668 struct hp100_private *lp = (struct hp100_private *)dev -> priv;
669
670 #ifdef HP100_DEBUG_MULTI
671 printk( "hp100_set_multicast_list: num_addrs = %d\n", num_addrs );
672 #endif
673 hp100_ints_off();
674 cli();
675 hp100_page( MAC_CTRL );
676 hp100_andb( ~(HP100_RX_EN | HP100_TX_EN), MAC_CFG_1 );
677
678 if ( num_addrs < 0 )
679 {
680 lp -> mac2_mode = HP100_MAC2MODE6;
681 lp -> mac1_mode = HP100_MAC1MODE6;
682 }
683 else
684 if ( num_addrs > 0 )
685 {
686 lp -> mac2_mode = HP100_MAC2MODE5;
687 lp -> mac1_mode = HP100_MAC1MODE5;
688 }
689 else
690 {
691 lp -> mac2_mode = HP100_MAC2MODE3;
692 lp -> mac1_mode = HP100_MAC1MODE3;
693 }
694
695 hp100_outb( lp -> mac2_mode, MAC_CFG_2 );
696 hp100_andb( HP100_MAC1MODEMASK, MAC_CFG_1 );
697 hp100_orb( lp -> mac1_mode, MAC_CFG_1 );
698
699 hp100_orb( HP100_RX_EN | HP100_RX_IDLE, MAC_CFG_1 );
700 hp100_orb( HP100_TX_EN | HP100_TX_IDLE, MAC_CFG_1 );
701 hp100_page( PERFORMANCE );
702 sti();
703 hp100_ints_on();
704 }
705
706 #endif
707
708
709
710
711
712 #ifndef LINUX_1_1_52
713 static void hp100_interrupt( int irq, struct pt_regs *regs )
714 #else
715 static void hp100_interrupt( int irq )
716 #endif
717 {
718 struct device *dev = (struct device *)irq2dev_map[ irq ];
719 struct hp100_private *lp;
720 int ioaddr;
721 u_short val;
722
723 if ( dev == NULL ) return;
724 ioaddr = dev -> base_addr;
725 if ( dev -> interrupt )
726 printk( "%s: re-entering the interrupt handler\n", dev -> name );
727 hp100_ints_off();
728 dev -> interrupt = 1;
729 val = hp100_inw( IRQ_STATUS );
730 #ifdef HP100_DEBUG_IRQ
731 printk( "hp100_interrupt: irq_status = 0x%x\n", val );
732 #endif
733 if ( val & HP100_RX_PACKET )
734 {
735 hp100_rx( dev );
736 hp100_outw( HP100_RX_PACKET, IRQ_STATUS );
737 }
738 if ( val & (HP100_TX_SPACE_AVAIL | HP100_TX_COMPLETE) )
739 {
740 hp100_outw( val & (HP100_TX_SPACE_AVAIL | HP100_TX_COMPLETE), IRQ_STATUS );
741 }
742 if ( val & ( HP100_TX_ERROR | HP100_RX_ERROR ) )
743 {
744 lp = (struct hp100_private *)dev -> priv;
745 hp100_update_stats( dev );
746 hp100_outw( val & (HP100_TX_ERROR | HP100_RX_ERROR), IRQ_STATUS );
747 }
748 #ifdef HP100_DEBUG_IRQ
749 printk( "hp100_interrupt: end\n" );
750 #endif
751 dev -> interrupt = 0;
752 hp100_ints_on();
753 }
754
755
756
757
758
759 static void hp100_start_interface( struct device *dev )
760 {
761 int ioaddr = dev -> base_addr;
762 struct hp100_private *lp = (struct hp100_private *)dev -> priv;
763
764 hp100_unreset_card();
765 cli();
766 hp100_page( MAC_CTRL );
767 hp100_outb( lp -> mac2_mode, MAC_CFG_2 );
768 hp100_andb( HP100_MAC1MODEMASK, MAC_CFG_1 );
769 hp100_orb( lp -> mac1_mode, MAC_CFG_1 );
770 hp100_orb( HP100_RX_EN | HP100_RX_IDLE, MAC_CFG_1 );
771 hp100_orb( HP100_TX_EN | HP100_TX_IDLE, MAC_CFG_1 );
772 hp100_page( PERFORMANCE );
773 hp100_outw( HP100_INT_EN | HP100_SET_LB, OPTION_LSW );
774 hp100_outw( HP100_TRI_INT | HP100_RESET_HB, OPTION_LSW );
775 sti();
776 }
777
778 static void hp100_stop_interface( struct device *dev )
779 {
780 int ioaddr = dev -> base_addr;
781 u_short val;
782
783 hp100_outw( HP100_INT_EN | HP100_RESET_LB |
784 HP100_TRI_INT | HP100_SET_HB, OPTION_LSW );
785 val = hp100_inw( OPTION_LSW );
786 hp100_page( HW_MAP );
787 hp100_andb( HP100_BM_SLAVE, BM );
788 hp100_page( MAC_CTRL );
789 hp100_andb( ~(HP100_RX_EN | HP100_TX_EN), MAC_CFG_1 );
790 if ( !(val & HP100_HW_RST) ) return;
791 for ( val = 0; val < 6000; val++ )
792 if ( ( hp100_inb( MAC_CFG_1 ) & (HP100_TX_IDLE | HP100_RX_IDLE) ) ==
793 (HP100_TX_IDLE | HP100_RX_IDLE) )
794 return;
795 printk( "%s: hp100_stop_interface - timeout\n", dev -> name );
796 }
797
798 static void hp100_load_eeprom( struct device *dev )
799 {
800 int i;
801 int ioaddr = dev -> base_addr;
802
803 hp100_page( EEPROM_CTRL );
804 hp100_andw( ~HP100_EEPROM_LOAD, EEPROM_CTRL );
805 hp100_orw( HP100_EEPROM_LOAD, EEPROM_CTRL );
806 for ( i = 0; i < 6000; i++ )
807 if ( !( hp100_inw( OPTION_MSW ) & HP100_EE_LOAD ) ) return;
808 printk( "%s: hp100_load_eeprom - timeout\n", dev -> name );
809 }
810
811
812
813 static int hp100_sense_lan( struct device *dev )
814 {
815 int i;
816 int ioaddr = dev -> base_addr;
817 u_short val_VG, val_10;
818 struct hp100_private *lp = (struct hp100_private *)dev -> priv;
819
820 hp100_page( MAC_CTRL );
821 hp100_orw( HP100_VG_RESET, LAN_CFG_VG );
822 val_10 = hp100_inw( LAN_CFG_10 );
823 val_VG = hp100_inw( LAN_CFG_VG );
824 #ifdef HP100_DEBUG_SENSE
825 printk( "hp100_sense_lan: val_VG = 0x%04x, val_10 = 0x%04x\n", val_VG, val_10 );
826 #endif
827 if ( val_10 & HP100_LINK_BEAT_ST ) return HP100_LAN_10;
828 if ( lp -> id -> id == 0x02019F022 )
829 return HP100_LAN_ERR;
830 for ( i = 0; i < 2500; i++ )
831 {
832 val_VG = hp100_inw( LAN_CFG_VG );
833 if ( val_VG & HP100_LINK_CABLE_ST ) return HP100_LAN_100;
834 }
835 return HP100_LAN_ERR;
836 }
837
838 static int hp100_down_vg_link( struct device *dev )
839 {
840 int ioaddr = dev -> base_addr;
841 unsigned long time;
842 int i;
843
844 hp100_page( MAC_CTRL );
845 for ( i = 2500; i > 0; i-- )
846 if ( hp100_inw( LAN_CFG_VG ) & HP100_LINK_CABLE_ST ) break;
847 if ( i <= 0 )
848 return 0;
849 hp100_andw( ~HP100_LINK_CMD, LAN_CFG_VG );
850 time = jiffies + 10;
851 while ( time > jiffies )
852 if ( !( hp100_inw( LAN_CFG_VG ) & ( HP100_LINK_UP_ST |
853 HP100_LINK_CABLE_ST |
854 HP100_LINK_GOOD_ST ) ) )
855 return 0;
856 #ifdef HP100_DEBUG
857 printk( "hp100_down_vg_link: timeout\n" );
858 #endif
859 return -EIO;
860 }
861
862 static int hp100_login_to_vg_hub( struct device *dev )
863 {
864 int i;
865 int ioaddr = dev -> base_addr;
866 u_short val;
867 unsigned long time;
868
869 hp100_page( MAC_CTRL );
870 hp100_orw( HP100_VG_RESET, LAN_CFG_VG );
871 time = jiffies + ( HZ / 2 );
872 do {
873 if ( hp100_inw( LAN_CFG_VG ) & HP100_LINK_CABLE_ST ) break;
874 } while ( time > jiffies );
875 if ( time <= jiffies )
876 {
877 #ifdef HP100_DEBUG
878 printk( "hp100_login_to_vg_hub: timeout for link\n" );
879 #endif
880 return -EIO;
881 }
882
883 if ( hp100_down_vg_link( dev ) < 0 )
884 {
885 hp100_andw( ~HP100_VG_RESET, LAN_CFG_VG );
886 hp100_orw( HP100_VG_RESET, LAN_CFG_VG );
887 }
888
889 hp100_orw( HP100_LOAD_ADDR | HP100_LINK_CMD, LAN_CFG_VG );
890 for ( i = 2500; i > 0; i-- )
891 if ( hp100_inw( LAN_CFG_VG ) & HP100_LINK_CABLE_ST ) break;
892 if ( i <= 0 )
893 {
894 #ifdef HP100_DEBUG
895 printk( "hp100_login_to_vg_hub: timeout for link (bring up)\n" );
896 #endif
897 goto down_link;
898 }
899
900 time = jiffies + ( HZ / 2 );
901 do {
902 val = hp100_inw( LAN_CFG_VG );
903 if ( ( val & ( HP100_LINK_UP_ST | HP100_LINK_GOOD_ST ) ) ==
904 ( HP100_LINK_UP_ST | HP100_LINK_GOOD_ST ) )
905 return 0;
906 } while ( time > jiffies );
907 if ( val & HP100_LINK_GOOD_ST )
908 printk( "%s: 100Mb cable training failed, check cable.\n", dev -> name );
909 else
910 printk( "%s: 100Mb node not accepted by hub, check frame type or security.\n", dev -> name );
911
912 down_link:
913 hp100_down_vg_link( dev );
914 hp100_page( MAC_CTRL );
915 hp100_andw( ~( HP100_LOAD_ADDR | HP100_PROM_MODE ), LAN_CFG_VG );
916 hp100_orw( HP100_LINK_CMD, LAN_CFG_VG );
917 return -EIO;
918 }
919
920
921
922
923
924 #ifdef MODULE
925
926 char kernel_version[] = UTS_RELEASE;
927
928 static int hp100_port = -1;
929
930 static struct device dev_hp100 = {
931 " ", 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, hp100_probe
932 };
933
934 int init_module( void )
935 {
936 if ( hp100_port > 0 ) dev_hp100.base_addr = hp100_port;
937 if ( register_netdev( &dev_hp100 ) != 0 ) return -EIO;
938 return 0;
939 }
940
941 void cleanup_module( void )
942 {
943 unregister_netdev( &dev_hp100 );
944 release_region( dev_hp100.base_addr, 0x20 );
945 kfree_s( dev_hp100.priv, sizeof( struct hp100_private ) );
946 dev_hp100.priv = NULL;
947 }
948
949 #endif