summaryrefslogtreecommitdiffstats
path: root/openwrt/package/linux/kernel-patches/027-drivers_net_port_based_qos
blob: bb3ad6f6dc9e9493a0f94e05c8435f45f6db1ff9 (plain)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
diff -Nur linux-mips-cvs/drivers/net/port_based_qos/Atan.c linux-broadcom/drivers/net/port_based_qos/Atan.c
--- linux-mips-cvs/drivers/net/port_based_qos/Atan.c	1970-01-01 01:00:00.000000000 +0100
+++ linux-broadcom/drivers/net/port_based_qos/Atan.c	2005-01-31 13:13:14.000000000 +0100
@@ -0,0 +1,177 @@
+#include "Atan.h"
+#include "c47xx.h"
+
+extern void conf_gpio(int x);
+
+/*----------------------------------------------------------------------------
+Write specified data to eeprom
+entry:	*src	= pointer to specified data to write
+		len		= number of short(2 bytes) to be written
+*/
+void write_eeprom( short RegNumber, unsigned short *data, int len )
+{
+    int i2;
+    unsigned short s_addr, s_data;
+    unsigned short *src;
+
+    src = data;
+    SetEEpromToSendState();
+//  the write enable(WEN) instruction must be executed before any device
+//  programming can be done
+
+    s_data = 0x04c0;
+    SendAddrToEEprom(s_data); //00000001 0011000000B
+    SetCSToLowForEEprom();
+
+    s_addr = 0x0500 | (RegNumber & 0x0ff); //00000001 01dddddddd
+    s_data = *src;
+
+    for (i2 = len; i2 > 0 ; i2 --)
+    {
+      SendAddrToEEprom(s_addr); //00000001 01dddddd
+      SendDataToEEprom(s_data); //dddddddd dddddddd
+      SetCSToLowForEEprom();
+      SetCSToLowForEEprom();
+      //WriteWait();     
+      s_addr ++;
+      src ++;
+      s_data = *src;
+    }
+//  after all data has been written to EEprom , the write disable(WDS) 
+//  instruction must be executed
+    SetCSToHighForEEprom();
+    s_data = 0x0400;
+    SendAddrToEEprom(s_data); //00000001 00000000B
+    SetCSToLowForEEprom();
+    SetCSToLowForEEprom();
+}
+
+void SetEEpromToSendState()
+{
+  conf_gpio(0x0);
+  conf_gpio(0x0);
+  conf_gpio(B_ECS);
+  conf_gpio(B_ECS);
+  
+//  ;cs     __--   ,bit 2
+//  ;sck    ____   ,bit 3
+//  ;di     ____   ,bit 5
+//  ;do     ____   ,bit 4
+//  ;
+}
+
+void ResetEEpromToSendState()
+{
+  conf_gpio(0x0);
+  conf_gpio(0x0);
+  conf_gpio(0x0);
+  conf_gpio(0x0);
+  
+//  ;cs     ____   ,bit 2  
+//  ;sck    ____   ,bit 3
+//  ;di     ____   ,bit 5
+//  ;do     ____   ,bit 4 
+//  ;
+}
+
+void SetCSToLowForEEprom()
+{
+  conf_gpio(0x0);
+  conf_gpio(B_ECK);
+  conf_gpio(B_ECK);
+  conf_gpio(0x0);
+  
+//  ;cs     ____   ,bit 2
+//  ;sck    _--_   ,bit 3
+//  ;di     ____   ,bit 5
+//  ;do     ____   ,bit 4 
+//  ;
+}
+
+void SetCSToHighForEEprom()
+{
+  conf_gpio(B_ECS);
+  conf_gpio(B_ECS|B_ECK);
+  conf_gpio(B_ECS|B_ECK);
+  conf_gpio(B_ECS);
+  
+//  ;cs     ----   ,bit 2
+//  ;sck    _--_   ,bit 3
+//  ;di     ____   ,bit 5
+//  ;do     ____   ,bit 4  
+//  ;
+}
+
+void send_1ToEEprom()
+{
+  conf_gpio(B_ECS|B_EDI);
+  conf_gpio(B_ECS|B_ECK|B_EDI);
+  conf_gpio(B_ECS|B_ECK|B_EDI);
+  conf_gpio(B_ECS|B_EDI);
+  
+//  ;cs     ----   ,bit 2
+//  ;sck    _--_   ,bit 3
+//  ;di     ----   ,bit 5
+//  ;do     ____   ,bit 4
+//  ;       
+}
+
+void send_0ToEEprom()
+{
+  conf_gpio(B_ECS);
+  conf_gpio(B_ECS|B_ECK);
+  conf_gpio(B_ECS|B_ECK);
+  conf_gpio(B_ECS);
+  
+//  ;cs     ----   ,bit 2
+//  ;sck    _--_   ,bit 3
+//  ;di     ____   ,bit 5
+//  ;do     ____   ,bit 4
+//  ;       
+}
+
+#if 0
+void WriteWait()
+{
+  unsigned int status;
+  
+  SetCSToLowForEEprom();
+  SetCSToHighForEEprom();
+  do {
+  	SetCSToHighForEEprom();
+  	//status = ReadGPIOData(EDO);
+  	status = gpio & B_EDO;	// read EDO bit
+  }
+  while (!status);   // wait for write - ready
+  SetCSToLowForEEprom();
+}
+#endif
+
+void SendDataToEEprom(short s_data) 
+{
+  int data_mask;
+  
+  for (data_mask = 0x8000; data_mask != 0; )
+  {
+    if (s_data & data_mask) 
+      send_1ToEEprom();
+    else
+      send_0ToEEprom();  
+    data_mask = data_mask >> 1;
+  }
+}
+
+void SendAddrToEEprom(short s_data) 
+{
+  int data_mask;
+  
+  for (data_mask = 0x0400 ;data_mask != 0; )
+  {
+    if (s_data & data_mask) 
+      send_1ToEEprom();
+    else
+      send_0ToEEprom();  
+    data_mask = data_mask >> 1;
+  }
+}
+
diff -Nur linux-mips-cvs/drivers/net/port_based_qos/Atan.h linux-broadcom/drivers/net/port_based_qos/Atan.h
--- linux-mips-cvs/drivers/net/port_based_qos/Atan.h	1970-01-01 01:00:00.000000000 +0100
+++ linux-broadcom/drivers/net/port_based_qos/Atan.h	2005-01-31 13:13:14.000000000 +0100
@@ -0,0 +1,18 @@
+#ifndef _ATAN_H_
+#define _ATAN_H_
+
+#define SINGLECOLOUR				0x1
+#define DUALCOLOUR					0x2
+
+void write_eeprom(short,unsigned short *,int);
+void SetEEpromToSendState(void);
+void ResetEEpromToSendState(void); 
+void SetCSToLowForEEprom(void);
+void SetCSToHighForEEprom(void);  
+void send_1ToEEprom(void);
+void send_0ToEEprom(void);
+//void WriteWait(void);
+void SendAddrToEEprom(short);
+void SendDataToEEprom(short);
+
+#endif
diff -Nur linux-mips-cvs/drivers/net/port_based_qos/Makefile linux-broadcom/drivers/net/port_based_qos/Makefile
--- linux-mips-cvs/drivers/net/port_based_qos/Makefile	1970-01-01 01:00:00.000000000 +0100
+++ linux-broadcom/drivers/net/port_based_qos/Makefile	2005-01-31 13:13:14.000000000 +0100
@@ -0,0 +1,27 @@
+#  Copyright 2001, Cybertan Corporation
+#  All Rights Reserved.
+#  
+#  This is UNPUBLISHED PROPRIETARY SOURCE CODE of Cybertan Corporation;
+#  the contents of this file may not be disclosed to third parties, copied or
+#  duplicated in any form, in whole or in part, without the prior written
+#  permission of Cybertan Corporation.
+#
+#
+# $Id$
+#
+
+O_TARGET	:= port_based_qos_mod.o 
+
+PORT_BASED_QOS_MOD_OBJS	:= port_based_qos.o Atan.o c47xx.o eeprom.o 
+
+export-objs	:= 
+obj-y		:= $(PORT_BASED_QOS_MOD_OBJS)
+obj-m		:= $(O_TARGET)
+
+SRCBASE		:= $(TOPDIR)/../..
+EXTRA_CFLAGS	+= -I$(SRCBASE)/include -Wall -I$(SRCBASE)/
+
+vpath %.c $(SRCBASE)/shared
+
+include $(TOPDIR)/Rules.make
+
diff -Nur linux-mips-cvs/drivers/net/port_based_qos/c47xx.c linux-broadcom/drivers/net/port_based_qos/c47xx.c
--- linux-mips-cvs/drivers/net/port_based_qos/c47xx.c	1970-01-01 01:00:00.000000000 +0100
+++ linux-broadcom/drivers/net/port_based_qos/c47xx.c	2005-01-31 13:13:14.000000000 +0100
@@ -0,0 +1,85 @@
+#include <typedefs.h>
+#include <sbutils.h>
+#include <bcmdevs.h>
+#include <osl.h>
+#include <bcmnvram.h>
+#include <bcmutils.h>
+
+#include <sbpci.h>
+#include <sbchipc.h>
+#include <sbconfig.h>
+#include <sbextif.h>
+#include <sbmips.h>
+#include "c47xx.h"
+extern uint32 sb_gpioouten(void *sbh, uint32 mask, uint32 val);
+extern uint32 sb_gpioout(void *sbh, uint32 mask, uint32 val);
+extern uint32 sb_gpioin(void *sbh);
+extern uint32 sb_gpiointmask(void *sbh, uint32 mask, uint32 val);
+
+#define OUTENMASK	B_RESET|B_ECS|B_ECK|B_EDI
+#define CFGMASK		B_ECS|B_ECK|B_EDI
+#define BIT(x)	(1 << (x))
+#define	ASSERT(exp)		do {} while (0)
+
+void
+conf_gpio(int x)
+{
+	ASSERT(sbh);
+
+	/* Enable all of output pins */
+	sb_gpioouten(sbh, OUTENMASK, OUTENMASK);
+
+	/* We don't want the B_RESET pin changed, unless
+	 * it tries to set the B_RESET pin.
+	 */
+	if (x & B_RESET)
+		sb_gpioout(sbh, OUTENMASK, x);
+	else
+		sb_gpioout(sbh, CFGMASK, x);
+	
+}
+	
+void
+gpio_line_set(int x, unsigned int value)
+{
+	ASSERT(sbh);
+
+	if (value == 1)
+		sb_gpioout(sbh, BIT(x), BIT(x));
+	else if (value == 0)
+		sb_gpioout(sbh, BIT(x), 0);
+}
+
+void
+gpio_line_get(int x, int *value)
+{
+	ASSERT(sbh);
+
+	*value = (sb_gpioin(sbh) >> x) & 0x1;
+}
+
+void
+gpio_line_config_in(int x)
+{
+	ASSERT(sbh);
+	
+	sb_gpioouten(sbh, BIT(x), 0);
+	sb_gpiointmask(sbh, BIT(x), BIT(x));
+}
+
+void
+gpio_line_config_out(int x)
+{
+	ASSERT(sbh);
+
+	sb_gpiointmask(sbh, BIT(x), 0);
+	sb_gpioouten(sbh, BIT(x), BIT(x));
+}
+
+void
+gpio_line_config_out_all(int x)
+{
+	ASSERT(sbh);
+
+	sb_gpioouten(sbh, OUTENMASK, OUTENMASK);
+}
diff -Nur linux-mips-cvs/drivers/net/port_based_qos/c47xx.h linux-broadcom/drivers/net/port_based_qos/c47xx.h
--- linux-mips-cvs/drivers/net/port_based_qos/c47xx.h	1970-01-01 01:00:00.000000000 +0100
+++ linux-broadcom/drivers/net/port_based_qos/c47xx.h	2005-01-31 13:13:14.000000000 +0100
@@ -0,0 +1,23 @@
+#ifndef _C47XX_H_
+#define _C47XX_H_
+
+extern void	*bcm947xx_sbh;
+#define sbh bcm947xx_sbh
+
+#define GPIO0	0
+#define GPIO1	1
+#define GPIO2	2
+#define GPIO3	3
+#define GPIO4	4
+#define GPIO5	5
+#define GPIO6	6
+#define GPIO7	7
+#define GPIO8	8
+
+#define B_RESET		1<<GPIO0
+#define B_ECS		1<<GPIO2
+#define B_ECK		1<<GPIO3
+#define B_EDO		1<<GPIO4
+#define B_EDI		1<<GPIO5
+
+#endif
diff -Nur linux-mips-cvs/drivers/net/port_based_qos/eeprom.c linux-broadcom/drivers/net/port_based_qos/eeprom.c
--- linux-mips-cvs/drivers/net/port_based_qos/eeprom.c	1970-01-01 01:00:00.000000000 +0100
+++ linux-broadcom/drivers/net/port_based_qos/eeprom.c	2005-01-31 13:13:14.000000000 +0100
@@ -0,0 +1,355 @@
+#include <linux/delay.h>
+
+#define EEDO_PIN	4
+#define EECS_PIN	2
+#define EECK_PIN	3
+#define EEDI_PIN	5
+#define RESET_PIN	0
+
+static void SetCSToLowForEEprom(void);
+//static void SetCSToHighForEEprom(void);
+static void send1ToEEprom(void);
+static void send0ToEEprom(void);
+static void InitSerialInterface(void);
+static void SerialPulse(void);
+static void WriteDataToRegister(unsigned short RegNumber, unsigned short data);
+void ReadDataFromRegister(unsigned short addr, unsigned short *hidata, unsigned short *lodata,int select_count);
+static void WriteDataToEEprom(unsigned short addr, unsigned short data);
+static void WriteCmdToEEprom(unsigned short cmd);
+extern void gpio_line_set(int x, unsigned int value);
+extern void gpio_line_get(int x, int *value);
+extern void gpio_line_config_out(int x);
+extern void gpio_line_config_in(int x);
+extern void gpio_line_config_out_all(void);
+//  ;cs     __--   ,bit 3
+//  ;sck    ____   ,bit 4
+//  ;di     ____   ,bit 5
+//  ;do     ____   ,bit 6
+//  ;
+
+static void SetEEpromToSendState(void)
+{        
+	gpio_line_set(EECS_PIN, 0); 
+        gpio_line_set(EECK_PIN, 0);       
+	gpio_line_set(EEDI_PIN, 1);	
+//	gpio_line_set(EEDO_PIN, 1);    /* high impedance */	
+	
+        mdelay(1);
+        gpio_line_set(EECS_PIN, 1);
+//	gpio_line_set(EEDO_PIN, 1);    /* high impedance */
+}
+
+#if 0
+static void EEpromInit(void)
+{
+	gpio_line_set(EECS_PIN, 0); 
+        gpio_line_set(EECK_PIN, 0);       
+	gpio_line_set(EEDI_PIN, 1);	
+	gpio_line_set(EEDO_PIN, 1);    /* high impedance */	
+	
+        mdelay(1);
+}
+   
+//  ;cs     ____   ,bit 3  
+//  ;sck    ____   ,bit 4
+//  ;di     ____   ,bit 5
+//  ;do     ____   ,bit 6 
+//  ;
+static void ResetEEpromToSendState(void)
+{
+	gpio_line_set(EECS_PIN, 0);
+	gpio_line_set(EEDI_PIN, 0);
+	//gpio_line_set(EEDO_PIN, 0);
+	gpio_line_set(EECK_PIN, 0);
+}
+#endif /* 0 */
+   
+//  ;cs     ____   ,bit 3  
+//  ;sck    _--_   ,bit 4
+//  ;di     ____   ,bit 5
+//  ;do     ____   ,bit 6 
+//  ;
+static void SetCSToLowForEEprom(void)
+{
+        /* minimum tcs is 1us */      
+	gpio_line_set(EECS_PIN, 0);        
+        gpio_line_set(EECS_PIN, 0); 	  
+
+	gpio_line_set(EECK_PIN, 0);
+	gpio_line_set(EECK_PIN, 1);
+	gpio_line_set(EECK_PIN, 1);
+	gpio_line_set(EECK_PIN, 1);
+	gpio_line_set(EECK_PIN, 1);
+	gpio_line_set(EECK_PIN, 0);
+
+	gpio_line_set(EECS_PIN, 1);     
+
+        udelay(10);
+}
+
+#if 0  
+//  ;cs     ----   ,bit 3
+//  ;sck    _--_   ,bit 4
+//  ;di     ____   ,bit 5
+//  ;do     ____   ,bit 6  
+//  ;
+static void SetCSToHighForEEprom(void)
+{
+	gpio_line_set(EECS_PIN, 1);
+	
+        /* min tskh and tskl is 1us */
+	gpio_line_set(EECK_PIN, 1);
+	udelay(2);
+	gpio_line_set(EECK_PIN, 0); 
+}
+#endif /* 0 */
+  
+//  ;cs     ----   ,bit 3
+//  ;sck    _--_   ,bit 4
+//  ;di     ----   ,bit 5
+//  ;do     ____   ,bit 6
+//  ;       
+static void send1ToEEprom(void)
+{	   
+//printf("send1ToEEprom(1)...");
+	gpio_line_set(EEDI_PIN, 1);	    	     
+	    
+	gpio_line_set(EECK_PIN, 0);
+        udelay(1);	    
+	gpio_line_set(EECK_PIN, 1);             
+	gpio_line_set(EECK_PIN, 1);	 
+	gpio_line_set(EECK_PIN, 1);   	
+        udelay(1);
+	gpio_line_set(EECK_PIN, 0);
+}
+
+//  ;cs     ----   ,bit 3
+//  ;sck    _--_   ,bit 4
+//  ;di     ____   ,bit 5
+//  ;do     ____   ,bit 6
+//  ;       
+static void send0ToEEprom(void)
+{
+//printf("send0ToEEprom(0)...");
+	gpio_line_set(EEDI_PIN, 0);	    	     
+	    
+	gpio_line_set(EECK_PIN, 0);	    
+	udelay(1);
+	gpio_line_set(EECK_PIN, 1);             
+	gpio_line_set(EECK_PIN, 1);	 
+	gpio_line_set(EECK_PIN, 1);   	
+	udelay(1);
+	gpio_line_set(EECK_PIN, 0);
+}
+
+static void WriteDataToEEprom(unsigned short addr, unsigned short data) 
+{
+  unsigned short addr_mask, data_mask;
+  
+  SetEEpromToSendState();
+  for (addr_mask = 0x400; addr_mask != 0; )
+  {
+    if (addr & addr_mask) 
+      send1ToEEprom();
+    else
+      send0ToEEprom();  
+    addr_mask = addr_mask >> 1;    
+  }
+  for (data_mask = 0x8000; data_mask != 0; )
+  {
+    if (data & data_mask) 
+      send1ToEEprom();
+    else
+      send0ToEEprom();  
+    data_mask = data_mask >> 1;    
+  }
+  SetCSToLowForEEprom();
+}
+
+static void WriteCmdToEEprom(unsigned short cmd) 
+{
+  unsigned short cmd_mask;
+  
+  SetEEpromToSendState();
+  for (cmd_mask = 0x0400 ;cmd_mask != 0; )
+  {
+    if (cmd & cmd_mask) 
+      send1ToEEprom();
+    else
+      send0ToEEprom();  
+    cmd_mask = cmd_mask >> 1;
+  }
+   SetCSToLowForEEprom();
+}
+
+/*
+ * Write data to configure registers through EEPROM interface, even we do not have
+ * an external EEPROM connectted, ADM6996 got a virtual AT39C66 inside
+ */
+static void WriteDataToRegister(unsigned short RegNumber, unsigned short data)
+{
+    unsigned short cmd, addr;   
+
+    printk("WriteDataToRegister(RegNumber=0x%x, data=0x%x)\n", RegNumber, data);
+   
+//  the write enable(WEN) instruction must be executed before any device
+//  programming can be done
+    cmd = 0x04c0;
+    WriteCmdToEEprom(cmd); //00000001 0011000000B    
+
+    addr = 0x0500 | (RegNumber & 0x0ff); //00000001 01dddddddd   
+    WriteDataToEEprom(addr, data); //00000001 01dddddd
+    
+     
+//  after all data has been written to EEprom , the write disable(WDS) 
+//  instruction must be executed   
+    cmd = 0x0400;
+    WriteCmdToEEprom(cmd); //00000001 00000000B   
+}
+
+static void SerialDelay(int count)
+{        
+     udelay(count);
+}
+
+static void InitSerialInterface(void)
+{
+        gpio_line_set(EECK_PIN, 0);  
+        gpio_line_set(EEDI_PIN, 0);  
+}
+
+static void SerialPulse(void)
+{
+	 gpio_line_set(EECK_PIN, 0);  
+	 gpio_line_set(EECK_PIN, 1);  	
+         SerialDelay(10);
+         gpio_line_set(EECK_PIN, 1);  
+         gpio_line_set(EECK_PIN, 0);  
+}
+/* 
+ * Since there is no EEPROM is our board, read from EEPROM need to obey the timing alike
+ *  MII interface, EECK = MDC, EEDI = MDIO, please refer to section 4.3 of ADM6996 datasheet
+ */
+void ReadDataFromRegister(unsigned short addr, unsigned short *hidata, unsigned short *lodata, int select_count) 
+{
+  	unsigned short addr_mask, data_mask;
+  	int value, i;
+        unsigned char StartBits, Opcode, TAbits;
+	
+	gpio_line_config_out_all();
+	mdelay(1);	
+	/* initialize serial interface */
+        gpio_line_set(EECS_PIN, 0);  
+	InitSerialInterface();        
+
+        /* Preamble, 35 bits */
+        gpio_line_set(EECK_PIN, 0); 
+        gpio_line_set(EEDI_PIN, 1);
+        for (i = 0; i < 35; i++)        
+        {    
+            gpio_line_set(EECK_PIN, 1); 	                
+            SerialDelay(10);
+            gpio_line_set(EECK_PIN, 0); 
+	    SerialDelay(10);
+        }
+ 
+        /* Start bits, 2-bit(01b) */
+        InitSerialInterface();
+        StartBits = 0x01;
+        for (i = 0; i < 2; i++)
+        {
+             value = (StartBits & 2) ? 1 : 0;
+             gpio_line_set(EEDI_PIN, value);  
+             SerialDelay(1);
+             SerialPulse();
+             StartBits <<= 1;
+         }
+          
+         /* Opcode, read = 10b */
+         InitSerialInterface();
+         Opcode = 0x02;
+         for (i = 0; i < 2; i++)
+         {
+             value = (Opcode & 0x02) ? 1 : 0;
+             gpio_line_set(EEDI_PIN, value);  
+	     SerialDelay(1);
+             SerialPulse();
+             Opcode <<= 1;
+         }         
+
+         /* 10 bits register address */
+         /* 1-bit Table Select, 2-bit Device Address, 7-bit Register Address  */         
+         InitSerialInterface();
+	 if (select_count)
+	 	addr = (addr & 0x7f) | 0x200; 
+	 else
+	 	addr = addr & 0x7f ; 
+         for (addr_mask = 0x200; addr_mask != 0; addr_mask >>= 1)
+         {
+             value = (addr & addr_mask) ? 1 : 0;
+             gpio_line_set(EEDI_PIN, value);  
+	     SerialDelay(1);
+             SerialPulse();           
+         }      	
+
+         /* TA, turnaround 2-bit */
+         InitSerialInterface();
+         TAbits = 0x02;	
+          gpio_line_config_in(EEDI_PIN);
+         for (i = 0; i < 2; i++)
+         {
+             gpio_line_set(EECK_PIN, 1);  	     
+	     SerialDelay(4);  	     
+	     gpio_line_get(EEDI_PIN, &value); 
+	     SerialDelay(4);  
+             TAbits <<= 1;            
+	     gpio_line_set(EECK_PIN, 1);
+         }
+ 
+	
+         /* Latch data from serial management EEDI pin */
+         *hidata = 0;
+         gpio_line_set(EECK_PIN, 0);  
+	 for (data_mask = 0x8000; data_mask != 0; data_mask >>= 1)       
+         {
+             SerialDelay(4);             
+             gpio_line_set(EECK_PIN, 1);  
+             gpio_line_get(EEDI_PIN, &value); 
+             if (value)
+             {
+                 *hidata |= data_mask;                 
+	     }
+             gpio_line_set(EECK_PIN, 0); 
+	     SerialDelay(4);
+         }
+	 *lodata = 0;
+         gpio_line_set(EECK_PIN, 0);  
+	 for (data_mask = 0x8000; data_mask != 0; data_mask >>= 1)       
+         {
+             SerialDelay(4);           
+             gpio_line_set(EECK_PIN, 1);  
+             gpio_line_get(EEDI_PIN, &value); 
+             if (value)
+             {
+                 *lodata |= data_mask;                 
+	     }
+             gpio_line_set(EECK_PIN, 0); 
+	     SerialDelay(4);
+         }
+  	
+         SerialDelay(2);
+
+         /* Idle, EECK must send at least one clock at idle time */
+         SerialPulse();
+         gpio_line_set(EECK_PIN, 0);  
+         SerialDelay(10);
+         gpio_line_set(EECK_PIN, 1);  
+         SerialDelay(10);
+         gpio_line_set(EECK_PIN, 0);  
+         SerialPulse();
+
+         gpio_line_config_out(EEDI_PIN);
+	 gpio_line_set(EECS_PIN, 1);
+
+   printk("ReadDataFromRegister(addr=0x%x, hidata=0x%x, lodata=0x%x)\n", addr, *hidata, *lodata);
+}
diff -Nur linux-mips-cvs/drivers/net/port_based_qos/port_based_qos.c linux-broadcom/drivers/net/port_based_qos/port_based_qos.c
--- linux-mips-cvs/drivers/net/port_based_qos/port_based_qos.c	1970-01-01 01:00:00.000000000 +0100
+++ linux-broadcom/drivers/net/port_based_qos/port_based_qos.c	2005-01-31 13:13:14.000000000 +0100
@@ -0,0 +1,460 @@
+ /*
+ * Remaining issues:
+ *   + stats support
+ *   + multicast support
+ *   + media sense
+ *   + half/full duplex
+ *   - random MAC addr.
+ */
+
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/pci.h>
+#include <linux/init.h>
+#include <linux/ioport.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/ethtool.h>
+#include <linux/mii.h>
+#include <asm/io.h>
+
+#include <linux/sysctl.h>
+#include <cy_conf.h>
+
+#define MODULE_NAME "port_based_qos_mod"
+#define DEVICE_NAME "qos"
+#define MODULE_VERSION "0.0.1"
+
+extern void ReadDataFromRegister(unsigned short addr, unsigned short *hidata, unsigned short *lodata,int select_count);
+
+#ifdef PERFORMANCE_SUPPORT
+static struct ctl_table_header *qos_sysctl_header;
+static unsigned long qos[28];
+
+static ctl_table mytable[] = {
+         { 2000, "qos", 
+	   qos, sizeof(qos), 
+	   0644, NULL, 
+	   proc_dointvec },
+         { 0 }
+};
+
+static unsigned short statis_addr_map[7][6] ={
+	{0x04, 0x06, 0x08, 0x0a, 0x0b, 0x0c},
+	{0x16, 0x18, 0x1a, 0x1c, 0x1d, 0x1e},
+	{0x0d, 0x0f, 0x11, 0x13, 0x14, 0x15},
+	{0x1f, 0x21, 0x23, 0x25, 0x26, 0x27},
+	{0x31, 0x33, 0x35, 0x37, 0x38, 0x39},
+	{0x28, 0x2a, 0x2c, 0x2e, 0x2f, 0x30},
+	{0x01, 0x01, 0x01, 0x01, 0x01, 0x01}
+};
+
+unsigned long get_statistic_from_serial(unsigned short port, unsigned short item)
+{
+    unsigned short hidata, lodata;
+	
+    ReadDataFromRegister(statis_addr_map[item][port], &hidata, &lodata, 1); 
+	return ((hidata << 16) | lodata);
+}
+#endif
+
+#ifdef HW_QOS_SUPPORT
+struct port_qos_t{
+	int addr;
+	int content_mask;
+	int *content_set; 
+};
+
+void WriteDataToRegister_(unsigned short reg_idx, unsigned short content_idx);
+extern void write_eeprom(short,short *,int);
+
+#define BANDWIDTH_1_BIT	2
+#define BANDWIDTH_2_BIT	4
+#define BANDWIDTH_3_BIT	6
+#define BANDWIDTH_4_BIT	7
+
+#define PORT_CONFIG_1	0x3
+#define PORT_CONFIG_2	0x5
+#define PORT_CONFIG_3	0x7
+#define PORT_CONFIG_4	0x8
+#define BANDWIDTH_CTL_123	0x31
+#define BANDWIDTH_CTL_4	0x32
+#define BANDWIDTH_CTL_ENABLE	0x33
+#define DISCARD_MODE	0x10
+#define TOS_PRIO_MAP	0xf
+
+#define PRIORITY_MASK	0xfc7f
+#define PRIORITY_DISABLE_MASK	0xfc7e
+#define FLOW_CTL_MASK	0xfffe
+#define RATE_LIMIT_MASK_1	0xff8f
+#define RATE_LIMIT_MASK_2	0xf8ff
+#define RATE_LIMIT_MASK_3	0x8fff
+#define RATE_LIMIT_MASK_4	0xfff8
+#define BANDWIDTH_CTL_MASK	0xff2b
+#define DISCARD_MASK	0x0fff
+
+#define BANDWIDTH_ENABLE_1	1 << BANDWIDTH_1_BIT//04 
+#define BANDWIDTH_ENABLE_2	1 << BANDWIDTH_2_BIT//10 
+#define BANDWIDTH_ENABLE_3	1 << BANDWIDTH_3_BIT//40 
+#define BANDWIDTH_ENABLE_4	1 << BANDWIDTH_4_BIT//80 
+#define BANDWIDTH_CTL_MASK_1	0xffff^BANDWIDTH_ENABLE_1//0xfffb 
+#define BANDWIDTH_CTL_MASK_2	0xffff^BANDWIDTH_ENABLE_2//0xffef 
+#define BANDWIDTH_CTL_MASK_3	0xffff^BANDWIDTH_ENABLE_3//0xffbf 
+#define BANDWIDTH_CTL_MASK_4	0xffff^BANDWIDTH_ENABLE_4//0xff7f 
+
+/*static int disable_content[] = {0x0};
+//static int enable_content[] = {0xd4, 0x0cff};//bit 7,6,4,2; Q1=11(50%),Q0=00(0%)*/
+//static int sw_content[] = {0x0,0x0c00};//bit 7,6,4,2; Q1=11(50%),Q0=00(0%)
+static int sw_content[] = {0x0,0xc000};//bit 7,6,4,2; Q1=11(50%),Q0=00(0%)
+static int port_priority_content[] = {0x080,0x380};//Q0,Q3
+//static int port_priority_content[] = {0x300,0x0};//Q1,Q0
+static int port_flow_ctl_content[] = {0x0,0x1};
+static int port_rate_limit_content_1[] = {0x0,0x00,0x10,0x20,0x30,0x40,0x50,0x60,0x70};
+static int port_rate_limit_content_2[] = {0x0,0x000,0x100,0x200,0x300,0x400,0x500,0x600,0x700};
+static int port_rate_limit_content_3[] = {0x0,0x0000,0x1000,0x2000,0x3000,0x4000,0x5000,0x6000,0x7000};
+static int port_rate_limit_content_4[] = {0x0,0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7};
+static int port_rate_limit_enable_1[] = {0x0, BANDWIDTH_ENABLE_1};
+static int port_rate_limit_enable_2[] = {0x0, BANDWIDTH_ENABLE_2};
+static int port_rate_limit_enable_3[] = {0x0, BANDWIDTH_ENABLE_3};
+static int port_rate_limit_enable_4[] = {0x0, BANDWIDTH_ENABLE_4};
+
+static struct port_qos_t port_mii_disable[] = {
+	{ BANDWIDTH_CTL_ENABLE, BANDWIDTH_CTL_MASK, sw_content},
+	//{ DISCARD_MODE, DISCARD_MASK, sw_content},
+	{ PORT_CONFIG_1, PRIORITY_MASK, sw_content},//port_priority_1
+	{ PORT_CONFIG_2, PRIORITY_MASK, sw_content},//port_priority_2
+	{ PORT_CONFIG_3, PRIORITY_MASK, sw_content},//port_priority_3
+	{ PORT_CONFIG_4, PRIORITY_MASK, sw_content},//port_priority_4
+	{ PORT_CONFIG_1, FLOW_CTL_MASK, &port_flow_ctl_content[1]},//port_flow_control_1
+	{ PORT_CONFIG_2, FLOW_CTL_MASK, &port_flow_ctl_content[1]},//port_flow_control_2
+	{ PORT_CONFIG_3, FLOW_CTL_MASK, &port_flow_ctl_content[1]},//port_flow_control_3
+	{ PORT_CONFIG_4, FLOW_CTL_MASK, &port_flow_ctl_content[1]},//port_flow_control_4
+	{ -1}
+};
+
+static struct port_qos_t port_mii_enable[] = {
+	//{ BANDWIDTH_CTL_ENABLE, BANDWIDTH_CTL_MASK, enable_content},
+	//{ DISCARD_MODE, DISCARD_MASK, sw_content},
+	{ -1}
+};
+
+struct port_qos_t *port_mii_sw_array[] = {port_mii_disable, port_mii_enable};
+
+/*static struct port_qos_t port_mii_addr[] = {
+	{ PORT_CONFIG_1, PRIORITY_MASK, port_priority_content},//port_priority_1
+	{ PORT_CONFIG_1, FLOW_CTL_MASK, port_flow_ctl_content},//port_flow_control_1
+	//{ "port_frame_type_1", 0x3},
+	{ BANDWIDTH_CTL_123, RATE_LIMIT_MASK_14, port_rate_limit_content_14},//port_rate_limit_1
+	{ PORT_CONFIG_2, PRIORITY_MASK, port_priority_content},//port_priority_2
+	{ PORT_CONFIG_2, FLOW_CTL_MASK, port_flow_ctl_content},//port_flow_control_2
+	//{ "port_frame_type_2", 0x5},
+	{ BANDWIDTH_CTL_123, RATE_LIMIT_MASK_2, port_rate_limit_content_2},//port_rate_limit_2
+	{ PORT_CONFIG_3, PRIORITY_MASK, port_priority_content},//port_priority_3
+	{ PORT_CONFIG_3, FLOW_CTL_MASK, port_flow_ctl_content},//port_flow_control_3
+	//{ "port_frame_type_3", 0x7},
+	{ BANDWIDTH_CTL_123, RATE_LIMIT_MASK_3, port_rate_limit_content_3},//port_rate_limit_3
+	//{ "port_priority_4", 0x8, 0x380},
+	{ PORT_CONFIG_4, PRIORITY_MASK, port_priority_content},//port_priority_4
+	{ PORT_CONFIG_4, FLOW_CTL_MASK, port_flow_ctl_content},//port_flow_control_4
+	//{ "port_frame_type_4", 0x8},
+	{ BANDWIDTH_CTL_4, RATE_LIMIT_MASK_14, port_rate_limit_content_14},//port_rate_limit_4
+	{ -1}
+};*/
+
+static struct port_qos_t priority_1[] = {
+	{ PORT_CONFIG_1, PRIORITY_MASK, port_priority_content},//port_priority_1
+	{ -1}
+};
+static struct port_qos_t flow_control_1[] = {
+	{ PORT_CONFIG_1, FLOW_CTL_MASK, port_flow_ctl_content},//port_flow_control_1
+	{ -1}
+};
+static struct port_qos_t rate_limit_1[] = {
+	{ BANDWIDTH_CTL_123, RATE_LIMIT_MASK_1, port_rate_limit_content_1},//port_rate_limit_1
+	{ BANDWIDTH_CTL_ENABLE, BANDWIDTH_CTL_MASK_1, port_rate_limit_enable_1},//port_rate_limit_4
+	{ -1}
+};
+static struct port_qos_t priority_2[] = {
+	{ PORT_CONFIG_2, PRIORITY_MASK, port_priority_content},//port_priority_2
+	{ -1}
+};
+static struct port_qos_t flow_control_2[] = {
+	{ PORT_CONFIG_2, FLOW_CTL_MASK, port_flow_ctl_content},//port_flow_control_2
+	{ -1}
+};
+static struct port_qos_t rate_limit_2[] = {
+	{ BANDWIDTH_CTL_123, RATE_LIMIT_MASK_2, port_rate_limit_content_2},//port_rate_limit_2
+	{ BANDWIDTH_CTL_ENABLE, BANDWIDTH_CTL_MASK_2, port_rate_limit_enable_2},//port_rate_limit_4
+	{ -1}
+};
+static struct port_qos_t priority_3[] = {
+	{ PORT_CONFIG_3, PRIORITY_MASK, port_priority_content},//port_priority_3
+	{ -1}
+};
+static struct port_qos_t flow_control_3[] = {
+	{ PORT_CONFIG_3, FLOW_CTL_MASK, port_flow_ctl_content},//port_flow_control_3
+	{ -1}
+};
+static struct port_qos_t rate_limit_3[] = {
+	{ BANDWIDTH_CTL_123, RATE_LIMIT_MASK_3, port_rate_limit_content_3},//port_rate_limit_3
+	{ BANDWIDTH_CTL_ENABLE, BANDWIDTH_CTL_MASK_3, port_rate_limit_enable_3},//port_rate_limit_4
+	{ -1}
+};
+static struct port_qos_t priority_4[] = {
+	{ PORT_CONFIG_4, PRIORITY_MASK, port_priority_content},//port_priority_4
+	{ -1}
+};
+static struct port_qos_t flow_control_4[] = {
+	{ PORT_CONFIG_4, FLOW_CTL_MASK, port_flow_ctl_content},//port_flow_control_4
+	{ -1}
+};
+static struct port_qos_t rate_limit_4[] = {
+	{ BANDWIDTH_CTL_4, RATE_LIMIT_MASK_4, port_rate_limit_content_4},//port_rate_limit_4
+	{ BANDWIDTH_CTL_ENABLE, BANDWIDTH_CTL_MASK_4, port_rate_limit_enable_4},//port_rate_limit_4
+	{ -1}
+};
+
+static struct port_qos_t *port_mii_addr[] = {
+	priority_1,
+	flow_control_1,
+	rate_limit_1,
+	priority_2,
+	flow_control_2,
+	rate_limit_2,
+	priority_3,
+	flow_control_3,
+	rate_limit_3,
+	priority_4,
+	flow_control_4,
+	rate_limit_4,
+	NULL
+};
+
+void WriteDataToRegister_(unsigned short reg_idx, unsigned short content_idx)
+{
+    short RegNumber;
+    unsigned short data, hidata=0x0, lodata=0x0;
+    int i;
+    struct port_qos_t *port_qos = port_mii_addr[reg_idx];
+    
+    //printk("\nWriteDataToRegister_:reg_idx=%d content_idx=%d\n", reg_idx, content_idx);
+    if (!port_qos)
+	 port_qos = port_mii_sw_array[content_idx];
+	
+    for (i=0; port_qos[i].addr != -1; i++)
+    {
+    	RegNumber = port_qos[i].addr;
+ 	ReadDataFromRegister(RegNumber, &hidata, &lodata, 0);
+
+        if (!(RegNumber % 2)) /* even port number use lower word */
+		hidata = lodata;
+
+        data = (hidata & port_qos[i].content_mask) | (((i > 0) && (content_idx > 1))? port_qos[i].content_set[1] : port_qos[i].content_set[content_idx]);
+	
+	write_eeprom(RegNumber, &data, 1);
+   	ReadDataFromRegister(RegNumber, &hidata, &lodata, 0);
+    }
+   	ReadDataFromRegister(0xf, &hidata, &lodata, 0);
+    	
+	/*RegNumber = port_mii_addr[reg_idx].addr;
+	if (RegNumber == -1)//Disable or Enable
+	{
+		struct port_qos_t *port_mii_sw = port_mii_sw_array[content_idx];
+	
+    		printk("\nWriteDataToRegister_:reg_idx=%d content_idx=%d\n", reg_idx, content_idx);
+		for (i=0; port_mii_sw[i].addr != -1; i++)
+		{
+    			RegNumber = port_mii_sw[i].addr;
+				
+			ReadDataFromRegister(RegNumber, &hidata, &lodata, 0);
+        		
+			if (!(RegNumber % 2)) 
+				hidata = lodata;
+			 
+		        data = (hidata & port_mii_sw[i].content_mask) | port_mii_sw[i].content_set[i];
+	
+			write_eeprom(RegNumber, &data, 1);
+    			
+   			ReadDataFromRegister(RegNumber, &hidata, &lodata, 0);
+			printk("\n============== %s===============\n", (content_idx==0)?"disable":"enable");
+		}
+	}
+	else
+	{
+    		ReadDataFromRegister(RegNumber, &hidata, &lodata, 0);
+
+        	if (!(RegNumber % 2)) 
+			hidata = lodata;
+
+	        data = (hidata & port_mii_addr[reg_idx].content_mask) | port_mii_addr[reg_idx].content_set[content_idx];
+	
+		write_eeprom(RegNumber, &data, 1);
+   		ReadDataFromRegister(RegNumber, &hidata, &lodata, 0);
+	}*/
+}
+#endif
+
+static int dev_do_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
+{
+    struct mii_ioctl_data *data = (struct mii_ioctl_data *)req->ifr_data;
+#ifdef PERFORMANCE_SUPPORT
+    int item, port; 
+    
+    unsigned long status_item;
+#endif
+    
+    switch (cmd)
+    {
+    case SIOCGMIIPHY:		/* Get address of MII PHY in use. */
+    case SIOCDEVPRIVATE:	/* for binary compat, remove in 2.5 */
+
+	/* Fall through to the SIOCGMIIREG, taken from eepro100 and rtl
+	 * drivers */
+#ifdef PERFORMANCE_SUPPORT
+    case SIOCGMIIREG:		/* Read MII PHY register. */
+	for (item=0; item<6; item++)
+		for (port=1; port<5; port++){
+			qos[(item * 4) + (port-1)] = get_statistic_from_serial(port, item);	
+		}
+	
+	status_item = get_statistic_from_serial(0, 6);
+	
+	qos[24] = (0x1 & (status_item >> 8));
+	qos[25] = (0x1 & (status_item >> 16));
+	qos[26] = (0x1 & (status_item >> 24));
+	qos[27] = (0x1 & (status_item >> 28));
+	
+	return 0;
+#endif
+
+    case SIOCDEVPRIVATE+1:	/* for binary compat, remove in 2.5 */
+#ifdef HW_QOS_SUPPORT
+    case SIOCSMIIREG:		/* Write MII PHY register. */
+	{
+	printk("\n x phy_id=%x\n", data->phy_id);
+	printk("\n x reg_num=%x\n", data->reg_num);
+	printk("\n x val_in=%x\n", data->val_in);
+	printk("\n x val_out=%x\n", data->val_out);
+		
+   	WriteDataToRegister_(data->phy_id, data->val_in); 
+	return 0;
+	}
+#endif
+    case SIOCDEVPRIVATE+2:	/* for binary compat, remove in 2.5 */
+    default:
+	return -EOPNOTSUPP;
+    }
+}
+
+static int __devinit qos_eth_probe(struct net_device *dev)
+{
+    
+    SET_MODULE_OWNER(dev);
+
+    ether_setup(dev);
+
+    strcpy(dev->name, DEVICE_NAME "0");
+
+    dev->do_ioctl = dev_do_ioctl;
+
+    return 0;
+}
+
+#ifdef HW_QOS_SUPPORT
+static char *port_option_name[] = {
+ 	"port_priority_1",
+	"port_flow_control_1",
+	//{ "port_frame_type_1",
+	"port_rate_limit_1",
+	"port_priority_2",
+	"port_flow_control_2",
+	//{ "port_frame_type_2",
+	"port_rate_limit_2",
+	"port_priority_3",
+	"port_flow_control_3",
+	//{ "port_frame_type_3",
+	"port_rate_limit_3",
+	"port_priority_4",
+	//{ "port_priority_4", PORT_CONFIG_4, PRIORITY_MASK, port_priority_content},
+	"port_flow_control_4",
+	//{ "port_frame_type_4",
+	"port_rate_limit_4",
+	"QoS",
+	NULL
+};
+
+extern char *nvram_get(const char *name);
+extern uint bcm_atoi(char *s);
+
+static int set_port_option(struct net_device *dev, unsigned short port_addr, char *option_content)
+{
+    struct ifreq ifr;
+    struct mii_ioctl_data stats;
+	
+    stats.phy_id=port_addr;
+    stats.val_in=bcm_atoi(option_content);
+
+    ifr.ifr_data = (void *)&stats;
+    
+    return dev_do_ioctl(dev, &ifr, SIOCSMIIREG);
+}
+
+
+void
+restore_default_from_NV(struct net_device *dev)
+{
+	unsigned short i;
+	char *value = NULL;
+	
+	for (i = 0; port_option_name[i]; i++)
+	{
+		if((value = nvram_get(port_option_name[i])))
+			set_port_option(dev, i, value);
+	}
+	return;
+}
+#endif
+
+static struct net_device qos_devices;
+
+/* Module initialization and cleanup */
+int init_module(void)
+{
+    int res;
+    struct net_device *dev;
+
+    printk("Initializing " MODULE_NAME " driver " MODULE_VERSION "\n");
+
+	dev = &qos_devices;
+
+	dev->init = qos_eth_probe;
+
+	if ((res = register_netdev(dev)))
+	    printk("Failed to register netdev. res = %d\n", res);
+
+#ifdef PERFORMANCE_SUPPORT
+    	qos_sysctl_header = register_sysctl_table(mytable, 0);
+#endif
+#ifdef HW_QOS_SUPPORT
+	restore_default_from_NV(dev);
+	write_eeprom(TOS_PRIO_MAP, &sw_content[0], 1);/* disable TOS priority map*/
+#endif
+    return 0;
+}
+
+void cleanup_module(void)
+{
+	struct net_device *dev = &qos_devices;
+	if (dev->priv != NULL)
+	{
+	    unregister_netdev(dev);
+	    kfree(dev->priv);
+	    dev->priv = NULL;
+	}
+    	
+#ifdef PERFORMANCE_SUPPORT
+	unregister_sysctl_table(qos_sysctl_header);
+#endif
+}
+