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#include <common.h>
51#include <command.h>
52#include <config.h>
53#include <malloc.h>
54#include "smc91111.h"
55#include <net.h>
56
57
58#define POWER_DOWN 0
59
60#define NO_AUTOPROBE
61
62#define SMC_DEBUG 0
63
64#if SMC_DEBUG > 1
65static const char version[] =
66 "smc91111.c:v1.0 04/25/01 by Daris A Nevil (dnevil@snmc.com)\n";
67#endif
68
69
70#ifndef CONFIG_SMC_AUTONEG_TIMEOUT
71#define CONFIG_SMC_AUTONEG_TIMEOUT 10
72#endif
73
74
75
76
77
78
79
80
81
82
83
84
85#define MEMORY_WAIT_TIME 16
86
87
88#if (SMC_DEBUG > 2 )
89#define PRINTK3(args...) printf(args)
90#else
91#define PRINTK3(args...)
92#endif
93
94#if SMC_DEBUG > 1
95#define PRINTK2(args...) printf(args)
96#else
97#define PRINTK2(args...)
98#endif
99
100#ifdef SMC_DEBUG
101#define PRINTK(args...) printf(args)
102#else
103#define PRINTK(args...)
104#endif
105
106
107
108
109
110
111
112
113
114
115
116#define LAN91C111_MEMORY_MULTIPLIER (1024*2)
117
118#ifndef CONFIG_SMC91111_BASE
119#error "SMC91111 Base address must be passed to initialization funciton"
120
121#endif
122
123#define SMC_DEV_NAME "SMC91111"
124#define SMC_PHY_ADDR 0x0000
125#define SMC_ALLOC_MAX_TRY 5
126#define SMC_TX_TIMEOUT 30
127
128#define SMC_PHY_CLOCK_DELAY 1000
129
130#define ETH_ZLEN 60
131
132#ifdef CONFIG_SMC_USE_32_BIT
133#define USE_32_BIT 1
134#else
135#undef USE_32_BIT
136#endif
137
138#ifdef SHARED_RESOURCES
139extern void swap_to(int device_id);
140#else
141# define swap_to(x)
142#endif
143
144#ifndef CONFIG_SMC91111_EXT_PHY
145static void smc_phy_configure(struct eth_device *dev);
146#endif
147
148
149
150
151
152
153
154
155
156#ifdef CONFIG_SMC_USE_IOFUNCS
157
158
159
160
161
162
163
164
165
166
167
168
169static inline word SMC_inw(struct eth_device *dev, dword offset)
170{
171 word v;
172 v = *((volatile word*)(dev->iobase + offset));
173 barrier(); *(volatile u32*)(0xc0000000);
174 return v;
175}
176
177static inline void SMC_outw(struct eth_device *dev, word value, dword offset)
178{
179 *((volatile word*)(dev->iobase + offset)) = value;
180 barrier(); *(volatile u32*)(0xc0000000);
181}
182
183static inline byte SMC_inb(struct eth_device *dev, dword offset)
184{
185 word _w;
186
187 _w = SMC_inw(dev, offset & ~((dword)1));
188 return (offset & 1) ? (byte)(_w >> 8) : (byte)(_w);
189}
190
191static inline void SMC_outb(struct eth_device *dev, byte value, dword offset)
192{
193 word _w;
194
195 _w = SMC_inw(dev, offset & ~((dword)1));
196 if (offset & 1)
197 *((volatile word*)(dev->iobase + (offset & ~((dword)1)))) =
198 (value<<8) | (_w & 0x00ff);
199 else
200 *((volatile word*)(dev->iobase + offset)) =
201 value | (_w & 0xff00);
202}
203
204static inline void SMC_insw(struct eth_device *dev, dword offset,
205 volatile uchar* buf, dword len)
206{
207 volatile word *p = (volatile word *)buf;
208
209 while (len-- > 0) {
210 *p++ = SMC_inw(dev, offset);
211 barrier();
212 *((volatile u32*)(0xc0000000));
213 }
214}
215
216static inline void SMC_outsw(struct eth_device *dev, dword offset,
217 uchar* buf, dword len)
218{
219 volatile word *p = (volatile word *)buf;
220
221 while (len-- > 0) {
222 SMC_outw(dev, *p++, offset);
223 barrier();
224 *(volatile u32*)(0xc0000000);
225 }
226}
227#endif
228
229
230
231
232#if SMC_DEBUG > 2
233static void print_packet( byte *, int );
234#endif
235
236#define tx_done(dev) 1
237
238static int poll4int (struct eth_device *dev, byte mask, int timeout)
239{
240 int tmo = get_timer (0) + timeout * CONFIG_SYS_HZ;
241 int is_timeout = 0;
242 word old_bank = SMC_inw (dev, BSR_REG);
243
244 PRINTK2 ("Polling...\n");
245 SMC_SELECT_BANK (dev, 2);
246 while ((SMC_inw (dev, SMC91111_INT_REG) & mask) == 0) {
247 if (get_timer (0) >= tmo) {
248 is_timeout = 1;
249 break;
250 }
251 }
252
253
254 SMC_SELECT_BANK (dev, old_bank);
255
256 if (is_timeout)
257 return 1;
258 else
259 return 0;
260}
261
262
263static inline void smc_wait_mmu_release_complete (struct eth_device *dev)
264{
265 int count = 0;
266
267
268 while (SMC_inw (dev, MMU_CMD_REG) & MC_BUSY) {
269 udelay (1);
270 if (++count > 200)
271 break;
272 }
273}
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292static void smc_reset (struct eth_device *dev)
293{
294 PRINTK2 ("%s: smc_reset\n", SMC_DEV_NAME);
295
296
297
298 SMC_SELECT_BANK (dev, 0);
299 SMC_outw (dev, RCR_SOFTRST, RCR_REG);
300
301
302
303
304
305 SMC_SELECT_BANK (dev, 1);
306#if defined(CONFIG_SMC91111_EXT_PHY)
307 SMC_outw (dev, CONFIG_DEFAULT | CONFIG_EXT_PHY, CONFIG_REG);
308#else
309 SMC_outw (dev, CONFIG_DEFAULT, CONFIG_REG);
310#endif
311
312
313
314
315 SMC_outw (dev, SMC_inw (dev, CONFIG_REG) | CONFIG_EPH_POWER_EN,
316 CONFIG_REG);
317
318 SMC_SELECT_BANK (dev, 0);
319
320
321 udelay (10);
322
323
324 SMC_outw (dev, RCR_CLEAR, RCR_REG);
325 SMC_outw (dev, TCR_CLEAR, TCR_REG);
326
327
328 SMC_SELECT_BANK (dev, 1);
329 SMC_outw (dev, CTL_DEFAULT, CTL_REG);
330
331
332 SMC_SELECT_BANK (dev, 2);
333 smc_wait_mmu_release_complete (dev);
334 SMC_outw (dev, MC_RESET, MMU_CMD_REG);
335 while (SMC_inw (dev, MMU_CMD_REG) & MC_BUSY)
336 udelay (1);
337
338
339
340
341
342
343 SMC_outb (dev, 0, IM_REG);
344}
345
346
347
348
349
350
351
352
353
354static void smc_enable(struct eth_device *dev)
355{
356 PRINTK2("%s: smc_enable\n", SMC_DEV_NAME);
357 SMC_SELECT_BANK( dev, 0 );
358
359 SMC_outw( dev, TCR_DEFAULT, TCR_REG );
360 SMC_outw( dev, RCR_DEFAULT, RCR_REG );
361
362
363
364}
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380static void smc_halt(struct eth_device *dev)
381{
382 PRINTK2("%s: smc_halt\n", SMC_DEV_NAME);
383
384
385 SMC_SELECT_BANK( dev, 2 );
386 SMC_outb( dev, 0, IM_REG );
387
388
389 SMC_SELECT_BANK( dev, 0 );
390 SMC_outb( dev, RCR_CLEAR, RCR_REG );
391 SMC_outb( dev, TCR_CLEAR, TCR_REG );
392
393 swap_to(FLASH);
394}
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415static int smc_send(struct eth_device *dev, void *packet, int packet_length)
416{
417 byte packet_no;
418 byte *buf;
419 int length;
420 int numPages;
421 int try = 0;
422 int time_out;
423 byte status;
424 byte saved_pnr;
425 word saved_ptr;
426
427
428 SMC_SELECT_BANK (dev, 2);
429 saved_pnr = SMC_inb( dev, PN_REG );
430 saved_ptr = SMC_inw( dev, PTR_REG );
431
432 PRINTK3 ("%s: smc_hardware_send_packet\n", SMC_DEV_NAME);
433
434 length = ETH_ZLEN < packet_length ? packet_length : ETH_ZLEN;
435
436
437
438
439
440
441
442
443
444
445
446
447
448 numPages = ((length & 0xfffe) + 6);
449 numPages >>= 8;
450
451 if (numPages > 7) {
452 printf ("%s: Far too big packet error. \n", SMC_DEV_NAME);
453 return 0;
454 }
455
456
457 SMC_SELECT_BANK (dev, 2);
458 SMC_outw (dev, MC_ALLOC | numPages, MMU_CMD_REG);
459
460
461
462
463
464
465
466
467again:
468 try++;
469 time_out = MEMORY_WAIT_TIME;
470 do {
471 status = SMC_inb (dev, SMC91111_INT_REG);
472 if (status & IM_ALLOC_INT) {
473
474 SMC_outb (dev, IM_ALLOC_INT, SMC91111_INT_REG);
475 break;
476 }
477 } while (--time_out);
478
479 if (!time_out) {
480 PRINTK2 ("%s: memory allocation, try %d failed ...\n",
481 SMC_DEV_NAME, try);
482 if (try < SMC_ALLOC_MAX_TRY)
483 goto again;
484 else
485 return 0;
486 }
487
488 PRINTK2 ("%s: memory allocation, try %d succeeded ...\n",
489 SMC_DEV_NAME, try);
490
491 buf = (byte *) packet;
492
493
494 packet_no = SMC_inb (dev, AR_REG);
495 if (packet_no & AR_FAILED) {
496
497 printf ("%s: Memory allocation failed. \n", SMC_DEV_NAME);
498 return 0;
499 }
500
501
502 SMC_outb (dev, packet_no, PN_REG);
503
504
505 while ( saved_ptr & PTR_NOTEMPTY )
506 printf ("Write data fifo not empty!\n");
507
508
509 SMC_outw (dev, PTR_AUTOINC, PTR_REG);
510
511 PRINTK3 ("%s: Trying to xmit packet of length %x\n",
512 SMC_DEV_NAME, length);
513
514#if SMC_DEBUG > 2
515 printf ("Transmitting Packet\n");
516 print_packet (buf, length);
517#endif
518
519
520
521#ifdef USE_32_BIT
522 SMC_outl (dev, (length + 6) << 16, SMC91111_DATA_REG);
523#else
524 SMC_outw (dev, 0, SMC91111_DATA_REG);
525
526 SMC_outw (dev, (length + 6), SMC91111_DATA_REG);
527#endif
528
529
530
531
532
533
534
535
536#ifdef USE_32_BIT
537 SMC_outsl (dev, SMC91111_DATA_REG, buf, length >> 2);
538 if (length & 0x2)
539 SMC_outw (dev, *((word *) (buf + (length & 0xFFFFFFFC))),
540 SMC91111_DATA_REG);
541#else
542 SMC_outsw (dev, SMC91111_DATA_REG, buf, (length) >> 1);
543#endif
544
545
546 if ((length & 1) == 0) {
547 SMC_outw (dev, 0, SMC91111_DATA_REG);
548 } else {
549 SMC_outw (dev, buf[length - 1] | 0x2000, SMC91111_DATA_REG);
550 }
551
552
553 SMC_outw (dev, MC_ENQUEUE, MMU_CMD_REG);
554
555
556
557
558 if (poll4int(dev, IM_TX_EMPTY_INT, SMC_TX_TIMEOUT)) {
559
560 PRINTK2 ("%s: TX timeout, sending failed...\n", SMC_DEV_NAME);
561
562
563
564
565
566 while (SMC_inw (dev, MMU_CMD_REG) & MC_BUSY) {
567 udelay (10);
568 }
569
570 PRINTK2 ("MMU ready\n");
571
572
573 return 0;
574 } else {
575
576 SMC_outb (dev, IM_TX_EMPTY_INT, SMC91111_INT_REG);
577
578 PRINTK2 ("%s: Sent packet of length %d \n", SMC_DEV_NAME,
579 length);
580
581
582
583
584
585 while (SMC_inw (dev, MMU_CMD_REG) & MC_BUSY) {
586 udelay (10);
587 }
588
589 PRINTK2 ("MMU ready\n");
590
591
592 }
593
594
595 SMC_outb( dev, saved_pnr, PN_REG );
596 SMC_outw( dev, saved_ptr, PTR_REG );
597
598 return length;
599}
600
601static int smc_write_hwaddr(struct eth_device *dev)
602{
603 int i;
604
605 swap_to(ETHERNET);
606 SMC_SELECT_BANK (dev, 1);
607#ifdef USE_32_BIT
608 for (i = 0; i < 6; i += 2) {
609 word address;
610
611 address = dev->enetaddr[i + 1] << 8;
612 address |= dev->enetaddr[i];
613 SMC_outw(dev, address, (ADDR0_REG + i));
614 }
615#else
616 for (i = 0; i < 6; i++)
617 SMC_outb(dev, dev->enetaddr[i], (ADDR0_REG + i));
618#endif
619 swap_to(FLASH);
620 return 0;
621}
622
623
624
625
626
627
628
629static int smc_init(struct eth_device *dev, bd_t *bd)
630{
631 swap_to(ETHERNET);
632
633 PRINTK2 ("%s: smc_init\n", SMC_DEV_NAME);
634
635
636 smc_reset (dev);
637 smc_enable (dev);
638
639
640#ifndef CONFIG_SMC91111_EXT_PHY
641 smc_phy_configure (dev);
642#endif
643
644
645
646
647
648 printf(SMC_DEV_NAME ": MAC %pM\n", dev->enetaddr);
649
650 return 0;
651}
652
653
654
655
656
657
658
659
660
661
662
663
664
665static int smc_rcv(struct eth_device *dev)
666{
667 int packet_number;
668 word status;
669 word packet_length;
670 int is_error = 0;
671#ifdef USE_32_BIT
672 dword stat_len;
673#endif
674 byte saved_pnr;
675 word saved_ptr;
676
677 SMC_SELECT_BANK(dev, 2);
678
679 saved_pnr = SMC_inb( dev, PN_REG );
680 saved_ptr = SMC_inw( dev, PTR_REG );
681
682 packet_number = SMC_inw( dev, RXFIFO_REG );
683
684 if ( packet_number & RXFIFO_REMPTY ) {
685
686 return 0;
687 }
688
689 PRINTK3("%s: smc_rcv\n", SMC_DEV_NAME);
690
691 SMC_outw( dev, PTR_READ | PTR_RCV | PTR_AUTOINC, PTR_REG );
692
693
694#ifdef USE_32_BIT
695 stat_len = SMC_inl(dev, SMC91111_DATA_REG);
696 status = stat_len & 0xffff;
697 packet_length = stat_len >> 16;
698#else
699 status = SMC_inw( dev, SMC91111_DATA_REG );
700 packet_length = SMC_inw( dev, SMC91111_DATA_REG );
701#endif
702
703 packet_length &= 0x07ff;
704
705 PRINTK2("RCV: STATUS %4x LENGTH %4x\n", status, packet_length );
706
707 if ( !(status & RS_ERRORS ) ){
708
709 packet_length -= 4;
710
711
712
713
714
715
716
717#ifdef USE_32_BIT
718 PRINTK3(" Reading %d dwords (and %d bytes)\n",
719 packet_length >> 2, packet_length & 3 );
720
721
722
723
724 SMC_insl(dev, SMC91111_DATA_REG, net_rx_packets[0],
725 packet_length >> 2);
726
727 if (packet_length & 3) {
728 int i;
729
730 byte *tail = (byte *)(net_rx_packets[0] +
731 (packet_length & ~3));
732 dword leftover = SMC_inl(dev, SMC91111_DATA_REG);
733 for (i=0; i<(packet_length & 3); i++)
734 *tail++ = (byte) (leftover >> (8*i)) & 0xff;
735 }
736#else
737 PRINTK3(" Reading %d words and %d byte(s)\n",
738 (packet_length >> 1 ), packet_length & 1 );
739 SMC_insw(dev, SMC91111_DATA_REG , net_rx_packets[0],
740 packet_length >> 1);
741
742#endif
743
744#if SMC_DEBUG > 2
745 printf("Receiving Packet\n");
746 print_packet(net_rx_packets[0], packet_length);
747#endif
748 } else {
749
750
751 is_error = 1;
752 }
753
754 while ( SMC_inw( dev, MMU_CMD_REG ) & MC_BUSY )
755 udelay(1);
756
757
758 SMC_outw( dev, MC_RELEASE, MMU_CMD_REG );
759
760 while ( SMC_inw( dev, MMU_CMD_REG ) & MC_BUSY )
761 udelay(1);
762
763
764 SMC_outb( dev, saved_pnr, PN_REG );
765 SMC_outw( dev, saved_ptr, PTR_REG );
766
767 if (!is_error) {
768
769 net_process_received_packet(net_rx_packets[0], packet_length);
770 return packet_length;
771 } else {
772 return 0;
773 }
774
775}
776
777
778#if 0
779
780
781
782static word smc_modify_regbit(struct eth_device *dev, int bank, int ioaddr, int reg,
783 unsigned int bit, int val)
784{
785 word regval;
786
787 SMC_SELECT_BANK( dev, bank );
788
789 regval = SMC_inw( dev, reg );
790 if (val)
791 regval |= bit;
792 else
793 regval &= ~bit;
794
795 SMC_outw( dev, regval, 0 );
796 return(regval);
797}
798
799
800
801
802
803static int smc_get_regbit(struct eth_device *dev, int bank, int ioaddr, int reg, unsigned int bit)
804{
805 SMC_SELECT_BANK( dev, bank );
806 if ( SMC_inw( dev, reg ) & bit)
807 return(1);
808 else
809 return(0);
810}
811
812
813
814
815
816static void smc_modify_reg(struct eth_device *dev, int bank, int ioaddr, int reg, word val)
817{
818 SMC_SELECT_BANK( dev, bank );
819 SMC_outw( dev, val, reg );
820}
821
822
823
824
825
826static int smc_get_reg(struct eth_device *dev, int bank, int ioaddr, int reg)
827{
828 SMC_SELECT_BANK( dev, bank );
829 return(SMC_inw( dev, reg ));
830}
831
832#endif
833
834
835
836#if (SMC_DEBUG > 2 )
837
838
839
840
841static void smc_dump_mii_stream (byte * bits, int size)
842{
843 int i;
844
845 printf ("BIT#:");
846 for (i = 0; i < size; ++i) {
847 printf ("%d", i % 10);
848 }
849
850 printf ("\nMDOE:");
851 for (i = 0; i < size; ++i) {
852 if (bits[i] & MII_MDOE)
853 printf ("1");
854 else
855 printf ("0");
856 }
857
858 printf ("\nMDO :");
859 for (i = 0; i < size; ++i) {
860 if (bits[i] & MII_MDO)
861 printf ("1");
862 else
863 printf ("0");
864 }
865
866 printf ("\nMDI :");
867 for (i = 0; i < size; ++i) {
868 if (bits[i] & MII_MDI)
869 printf ("1");
870 else
871 printf ("0");
872 }
873
874 printf ("\n");
875}
876#endif
877
878
879
880
881#ifndef CONFIG_SMC91111_EXT_PHY
882static word smc_read_phy_register (struct eth_device *dev, byte phyreg)
883{
884 int oldBank;
885 int i;
886 byte mask;
887 word mii_reg;
888 byte bits[64];
889 int clk_idx = 0;
890 int input_idx;
891 word phydata;
892 byte phyaddr = SMC_PHY_ADDR;
893
894
895 for (i = 0; i < 32; ++i)
896 bits[clk_idx++] = MII_MDOE | MII_MDO;
897
898
899 bits[clk_idx++] = MII_MDOE;
900 bits[clk_idx++] = MII_MDOE | MII_MDO;
901
902
903 bits[clk_idx++] = MII_MDOE | MII_MDO;
904 bits[clk_idx++] = MII_MDOE;
905
906
907 mask = (byte) 0x10;
908 for (i = 0; i < 5; ++i) {
909 if (phyaddr & mask)
910 bits[clk_idx++] = MII_MDOE | MII_MDO;
911 else
912 bits[clk_idx++] = MII_MDOE;
913
914
915 mask >>= 1;
916 }
917
918
919 mask = (byte) 0x10;
920 for (i = 0; i < 5; ++i) {
921 if (phyreg & mask)
922 bits[clk_idx++] = MII_MDOE | MII_MDO;
923 else
924 bits[clk_idx++] = MII_MDOE;
925
926
927 mask >>= 1;
928 }
929
930
931 bits[clk_idx++] = 0;
932
933
934
935 input_idx = clk_idx;
936
937
938 for (i = 0; i < 16; ++i)
939 bits[clk_idx++] = 0;
940
941
942 bits[clk_idx++] = 0;
943
944
945 oldBank = SMC_inw (dev, BANK_SELECT);
946
947
948 SMC_SELECT_BANK (dev, 3);
949
950
951 mii_reg = SMC_inw (dev, MII_REG);
952
953
954 mii_reg &= ~(MII_MDOE | MII_MCLK | MII_MDI | MII_MDO);
955
956
957 for (i = 0; i < sizeof bits; ++i) {
958
959 SMC_outw (dev, mii_reg | bits[i], MII_REG);
960 udelay (SMC_PHY_CLOCK_DELAY);
961
962
963
964 SMC_outw (dev, mii_reg | bits[i] | MII_MCLK, MII_REG);
965 udelay (SMC_PHY_CLOCK_DELAY);
966 bits[i] |= SMC_inw (dev, MII_REG) & MII_MDI;
967 }
968
969
970
971 SMC_outw (dev, mii_reg, MII_REG);
972 udelay (SMC_PHY_CLOCK_DELAY);
973
974
975 SMC_SELECT_BANK (dev, oldBank);
976
977
978 phydata = 0;
979 for (i = 0; i < 16; ++i) {
980 phydata <<= 1;
981
982 if (bits[input_idx++] & MII_MDI)
983 phydata |= 0x0001;
984 }
985
986#if (SMC_DEBUG > 2 )
987 printf ("smc_read_phy_register(): phyaddr=%x,phyreg=%x,phydata=%x\n",
988 phyaddr, phyreg, phydata);
989 smc_dump_mii_stream (bits, sizeof bits);
990#endif
991
992 return (phydata);
993}
994
995
996
997
998
999static void smc_write_phy_register (struct eth_device *dev, byte phyreg,
1000 word phydata)
1001{
1002 int oldBank;
1003 int i;
1004 word mask;
1005 word mii_reg;
1006 byte bits[65];
1007 int clk_idx = 0;
1008 byte phyaddr = SMC_PHY_ADDR;
1009
1010
1011 for (i = 0; i < 32; ++i)
1012 bits[clk_idx++] = MII_MDOE | MII_MDO;
1013
1014
1015 bits[clk_idx++] = MII_MDOE;
1016 bits[clk_idx++] = MII_MDOE | MII_MDO;
1017
1018
1019 bits[clk_idx++] = MII_MDOE;
1020 bits[clk_idx++] = MII_MDOE | MII_MDO;
1021
1022
1023 mask = (byte) 0x10;
1024 for (i = 0; i < 5; ++i) {
1025 if (phyaddr & mask)
1026 bits[clk_idx++] = MII_MDOE | MII_MDO;
1027 else
1028 bits[clk_idx++] = MII_MDOE;
1029
1030
1031 mask >>= 1;
1032 }
1033
1034
1035 mask = (byte) 0x10;
1036 for (i = 0; i < 5; ++i) {
1037 if (phyreg & mask)
1038 bits[clk_idx++] = MII_MDOE | MII_MDO;
1039 else
1040 bits[clk_idx++] = MII_MDOE;
1041
1042
1043 mask >>= 1;
1044 }
1045
1046
1047 bits[clk_idx++] = 0;
1048 bits[clk_idx++] = 0;
1049
1050
1051 mask = 0x8000;
1052 for (i = 0; i < 16; ++i) {
1053 if (phydata & mask)
1054 bits[clk_idx++] = MII_MDOE | MII_MDO;
1055 else
1056 bits[clk_idx++] = MII_MDOE;
1057
1058
1059 mask >>= 1;
1060 }
1061
1062
1063 bits[clk_idx++] = 0;
1064
1065
1066 oldBank = SMC_inw (dev, BANK_SELECT);
1067
1068
1069 SMC_SELECT_BANK (dev, 3);
1070
1071
1072 mii_reg = SMC_inw (dev, MII_REG);
1073
1074
1075 mii_reg &= ~(MII_MDOE | MII_MCLK | MII_MDI | MII_MDO);
1076
1077
1078 for (i = 0; i < sizeof bits; ++i) {
1079
1080 SMC_outw (dev, mii_reg | bits[i], MII_REG);
1081 udelay (SMC_PHY_CLOCK_DELAY);
1082
1083
1084
1085 SMC_outw (dev, mii_reg | bits[i] | MII_MCLK, MII_REG);
1086 udelay (SMC_PHY_CLOCK_DELAY);
1087 bits[i] |= SMC_inw (dev, MII_REG) & MII_MDI;
1088 }
1089
1090
1091
1092 SMC_outw (dev, mii_reg, MII_REG);
1093 udelay (SMC_PHY_CLOCK_DELAY);
1094
1095
1096 SMC_SELECT_BANK (dev, oldBank);
1097
1098#if (SMC_DEBUG > 2 )
1099 printf ("smc_write_phy_register(): phyaddr=%x,phyreg=%x,phydata=%x\n",
1100 phyaddr, phyreg, phydata);
1101 smc_dump_mii_stream (bits, sizeof bits);
1102#endif
1103}
1104#endif
1105
1106
1107
1108
1109
1110
1111#ifndef CONFIG_SMC91111_EXT_PHY
1112static void smc_phy_configure (struct eth_device *dev)
1113{
1114 int timeout;
1115 word my_phy_caps;
1116 word my_ad_caps;
1117 word status = 0;
1118
1119 PRINTK3 ("%s: smc_program_phy()\n", SMC_DEV_NAME);
1120
1121
1122 smc_write_phy_register (dev, PHY_CNTL_REG, PHY_CNTL_RST);
1123
1124
1125 timeout = 6;
1126 while (timeout--) {
1127 if (!(smc_read_phy_register (dev, PHY_CNTL_REG)
1128 & PHY_CNTL_RST)) {
1129
1130 break;
1131 }
1132
1133 mdelay(500);
1134 }
1135
1136 if (timeout < 1) {
1137 printf ("%s:PHY reset timed out\n", SMC_DEV_NAME);
1138 goto smc_phy_configure_exit;
1139 }
1140
1141
1142
1143
1144
1145
1146 smc_write_phy_register (dev, PHY_MASK_REG, 0xffff);
1147
1148
1149 SMC_SELECT_BANK (dev, 0);
1150 SMC_outw (dev, RPC_DEFAULT, RPC_REG);
1151
1152
1153 my_phy_caps = smc_read_phy_register (dev, PHY_STAT_REG);
1154 my_ad_caps = PHY_AD_CSMA;
1155
1156 if (my_phy_caps & PHY_STAT_CAP_T4)
1157 my_ad_caps |= PHY_AD_T4;
1158
1159 if (my_phy_caps & PHY_STAT_CAP_TXF)
1160 my_ad_caps |= PHY_AD_TX_FDX;
1161
1162 if (my_phy_caps & PHY_STAT_CAP_TXH)
1163 my_ad_caps |= PHY_AD_TX_HDX;
1164
1165 if (my_phy_caps & PHY_STAT_CAP_TF)
1166 my_ad_caps |= PHY_AD_10_FDX;
1167
1168 if (my_phy_caps & PHY_STAT_CAP_TH)
1169 my_ad_caps |= PHY_AD_10_HDX;
1170
1171
1172 smc_write_phy_register (dev, PHY_AD_REG, my_ad_caps);
1173
1174
1175
1176
1177 smc_read_phy_register(dev, PHY_AD_REG);
1178
1179 PRINTK2 ("%s: phy caps=%x\n", SMC_DEV_NAME, my_phy_caps);
1180 PRINTK2 ("%s: phy advertised caps=%x\n", SMC_DEV_NAME, my_ad_caps);
1181
1182
1183 smc_write_phy_register (dev, PHY_CNTL_REG,
1184 PHY_CNTL_ANEG_EN | PHY_CNTL_ANEG_RST);
1185
1186
1187
1188
1189 timeout = CONFIG_SMC_AUTONEG_TIMEOUT * 2;
1190 while (timeout--) {
1191
1192 status = smc_read_phy_register (dev, PHY_STAT_REG);
1193 if (status & PHY_STAT_ANEG_ACK) {
1194
1195 break;
1196 }
1197
1198 mdelay(500);
1199
1200
1201 if (status & PHY_STAT_REM_FLT) {
1202 printf ("%s: PHY remote fault detected\n",
1203 SMC_DEV_NAME);
1204
1205
1206 printf ("%s: PHY restarting auto-negotiation\n",
1207 SMC_DEV_NAME);
1208 smc_write_phy_register (dev, PHY_CNTL_REG,
1209 PHY_CNTL_ANEG_EN |
1210 PHY_CNTL_ANEG_RST |
1211 PHY_CNTL_SPEED |
1212 PHY_CNTL_DPLX);
1213 }
1214 }
1215
1216 if (timeout < 1) {
1217 printf ("%s: PHY auto-negotiate timed out\n", SMC_DEV_NAME);
1218 }
1219
1220
1221 if (status & PHY_STAT_REM_FLT) {
1222 printf ("%s: PHY remote fault detected\n", SMC_DEV_NAME);
1223 }
1224
1225
1226 SMC_outw (dev, RPC_DEFAULT, RPC_REG);
1227
1228smc_phy_configure_exit: ;
1229
1230}
1231#endif
1232
1233
1234#if SMC_DEBUG > 2
1235static void print_packet( byte * buf, int length )
1236{
1237 int i;
1238 int remainder;
1239 int lines;
1240
1241 printf("Packet of length %d \n", length );
1242
1243#if SMC_DEBUG > 3
1244 lines = length / 16;
1245 remainder = length % 16;
1246
1247 for ( i = 0; i < lines ; i ++ ) {
1248 int cur;
1249
1250 for ( cur = 0; cur < 8; cur ++ ) {
1251 byte a, b;
1252
1253 a = *(buf ++ );
1254 b = *(buf ++ );
1255 printf("%02x%02x ", a, b );
1256 }
1257 printf("\n");
1258 }
1259 for ( i = 0; i < remainder/2 ; i++ ) {
1260 byte a, b;
1261
1262 a = *(buf ++ );
1263 b = *(buf ++ );
1264 printf("%02x%02x ", a, b );
1265 }
1266 printf("\n");
1267#endif
1268}
1269#endif
1270
1271int smc91111_initialize(u8 dev_num, int base_addr)
1272{
1273 struct smc91111_priv *priv;
1274 struct eth_device *dev;
1275 int i;
1276
1277 priv = malloc(sizeof(*priv));
1278 if (!priv)
1279 return 0;
1280 dev = malloc(sizeof(*dev));
1281 if (!dev) {
1282 free(priv);
1283 return 0;
1284 }
1285
1286 memset(dev, 0, sizeof(*dev));
1287 priv->dev_num = dev_num;
1288 dev->priv = priv;
1289 dev->iobase = base_addr;
1290
1291 swap_to(ETHERNET);
1292 SMC_SELECT_BANK(dev, 1);
1293 for (i = 0; i < 6; ++i)
1294 dev->enetaddr[i] = SMC_inb(dev, (ADDR0_REG + i));
1295 swap_to(FLASH);
1296
1297 dev->init = smc_init;
1298 dev->halt = smc_halt;
1299 dev->send = smc_send;
1300 dev->recv = smc_rcv;
1301 dev->write_hwaddr = smc_write_hwaddr;
1302 sprintf(dev->name, "%s-%hu", SMC_DEV_NAME, dev_num);
1303
1304 eth_register(dev);
1305 return 0;
1306}
1307