hc
2024-11-01 2f529f9b558ca1c1bd74be7437a84e4711743404
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
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
/* rt2500pci.h
 *
 * Copyright (C) 2004 - 2005 rt2x00-2.0.0-b3 SourceForge Project
 *                         <http://rt2x00.serialmonkey.com>
 *               2006        rtnet adaption by Daniel Gregorek 
 *                           <dxg@gmx.de>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the
 * Free Software Foundation, Inc.,
 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
 
/*
 *    Module: rt2500pci
 * Abstract: Data structures and registers for the rt2500pci module.
 * Supported chipsets: RT2560.
 */
 
#ifndef RT2500PCI_H
#define RT2500PCI_H
 
/*
 * RT chip defines
 */
#define RT2560 0x0201
 
/*
 * RF chip defines
 */
#define RF2522 0x0200
#define RF2523 0x0201
#define RF2524 0x0202
#define RF2525 0x0203
#define RF2525E 0x0204
#define RF5222 0x0210
 
/*
 * Control/Status Registers(CSR).
 */
#define CSR0 0x0000 /* ASIC revision number. */
#define CSR1 0x0004 /* System control register. */
#define CSR2 0x0008 /* System admin status register (invalid). */
#define CSR3 0x000c /* STA MAC address register 0. */
#define CSR4 0x0010 /* STA MAC address register 1. */
#define CSR5 0x0014 /* BSSID register 0. */
#define CSR6 0x0018 /* BSSID register 1. */
#define CSR7 0x001c /* Interrupt source register. */
#define CSR8 0x0020 /* Interrupt mask register. */
#define CSR9 0x0024 /* Maximum frame length register. */
#define SECCSR0 0x0028 /* WEP control register. */
#define CSR11 0x002c /* Back-off control register. */
#define CSR12 0x0030 /* Synchronization configuration register 0. */
#define CSR13 0x0034 /* Synchronization configuration register 1. */
#define CSR14 0x0038 /* Synchronization control register. */
#define CSR15 0x003c /* Synchronization status register. */
#define CSR16 0x0040 /* TSF timer register 0. */
#define CSR17 0x0044 /* TSF timer register 1. */
#define CSR18 0x0048 /* IFS timer register 0. */
#define CSR19 0x004c /* IFS timer register 1. */
#define CSR20 0x0050 /* WakeUp register. */
#define CSR21 0x0054 /* EEPROM control register. */
#define CSR22 0x0058 /* CFP Control Register. */
 
/*
 * Transmit related CSRs.
 */
#define TXCSR0 0x0060 /* TX control register. */
#define TXCSR1 0x0064 /* TX configuration register. */
#define TXCSR2 0x0068 /* TX descriptor configuratioon register. */
#define TXCSR3 0x006c /* TX Ring Base address register. */
#define TXCSR4 0x0070 /* TX Atim Ring Base address register. */
#define TXCSR5 0x0074 /* TX Prio Ring Base address register. */
#define TXCSR6 0x0078 /* Beacon base address. */
#define TXCSR7 0x007c /* AutoResponder Control Register. */
#define TXCSR8 0x0098 /* CCK TX BBP registers. */
#define TXCSR9 0x0094 /* OFDM TX BBP registers. */
 
/*
 * Receive related CSRs.
 */
#define RXCSR0 0x0080 /* RX control register. */
#define RXCSR1 0x0084 /* RX descriptor configuration register. */
#define RXCSR2 0x0088 /* RX Ring base address register. */
#define RXCSR3 0x0090 /* BBP ID register 0 */
#define ARCSR1 0x009c /* Auto Responder PLCP config register 1. */
 
/*
 * PCI control CSRs.
 */
#define PCICSR 0x008c /* PCI control register. */
 
/*
 * Statistic Register.
 */
#define CNT0 0x00a0 /* FCS error count. */
#define TIMECSR2 0x00a8
#define CNT1 0x00ac /* PLCP error count. */
#define CNT2 0x00b0 /* long error count. */
#define TIMECSR3 0x00b4
#define CNT3 0x00b8 /* CCA false alarm count. */
#define CNT4 0x00bc /* Rx FIFO overflow count. */
#define CNT5 0x00c0 /* Tx FIFO underrun count. */
 
/*
 * Baseband Control Register.
 */
#define PWRCSR0 0x00c4 /* Power mode configuration. */
#define PSCSR0 0x00c8 /* Power state transition time. */
#define PSCSR1 0x00cc /* Power state transition time. */
#define PSCSR2 0x00d0 /* Power state transition time. */
#define PSCSR3 0x00d4 /* Power state transition time. */
#define PWRCSR1 0x00d8 /* Manual power control / status. */
#define TIMECSR 0x00dc /* Timer control. */
#define MACCSR0 0x00e0 /* MAC configuration. */
#define MACCSR1 0x00e4 /* MAC configuration. */
#define RALINKCSR 0x00e8 /* Ralink Auto-reset register. */
#define BCNCSR 0x00ec /* Beacon interval control register. */
 
/*
 * BBP / RF / IF Control Register.
 */
#define BBPCSR 0x00f0 /* BBP serial control. */
#define RFCSR 0x00f4 /* RF serial control. */
#define LEDCSR 0x00f8 /* LED control register */
 
#define SECCSR3 0x00fc /* AES control register. */
 
/*
 * ASIC pointer information.
 */
#define RXPTR 0x0100 /* Current RX ring address. */
#define TXPTR 0x0104 /* Current Tx ring address. */
#define PRIPTR 0x0108 /* Current Priority ring address. */
#define ATIMPTR 0x010c /* Current ATIM ring address. */
 
#define TXACKCSR0 0x0110 /* TX ACK timeout. */
#define ACKCNT0 0x0114 /* TX ACK timeout count. */
#define ACKCNT1 0x0118 /* RX ACK timeout count. */
 
/*
 * GPIO and others.
 */
#define GPIOCSR 0x0120 /* GPIO. */
#define FIFOCSR0 0x0128 /* TX FIFO pointer. */
#define FIFOCSR1 0x012c /* RX FIFO pointer. */
#define BCNCSR1 0x0130 /* Tx BEACON offset time, unit: 1 usec. */
#define MACCSR2 0x0134 /* TX_PE to RX_PE delay time, unit: 1 PCI clock cycle. */
#define TESTCSR 0x0138 /* TEST mode selection register. */
#define ARCSR2 0x013c /* 1 Mbps ACK/CTS PLCP. */
#define ARCSR3 0x0140 /* 2 Mbps ACK/CTS PLCP. */
#define ARCSR4 0x0144 /* 5.5 Mbps ACK/CTS PLCP. */
#define ARCSR5 0x0148 /* 11 Mbps ACK/CTS PLCP. */
#define ARTCSR0 0x014c /* ACK/CTS payload consumed time for 1/2/5.5/11 mbps. */
#define ARTCSR1                                                                \
   0x0150 /* OFDM ACK/CTS payload consumed time for 6/9/12/18 mbps. */
#define ARTCSR2                                                                \
   0x0154 /* OFDM ACK/CTS payload consumed time for 24/36/48/54 mbps. */
#define SECCSR1 0x0158 /* WEP control register. */
#define BBPCSR1 0x015c /* BBP TX configuration. */
#define DBANDCSR0 0x0160 /* Dual band configuration register 0. */
#define DBANDCSR1 0x0164 /* Dual band configuration register 1. */
#define BBPPCSR 0x0168 /* BBP Pin control register. */
#define DBGSEL0 0x016c /* MAC special debug mode selection register 0. */
#define DBGSEL1 0x0170 /* MAC special debug mode selection register 1. */
#define BISTCSR 0x0174 /* BBP BIST register. */
#define MCAST0 0x0178 /* multicast filter register 0. */
#define MCAST1 0x017c /* multicast filter register 1. */
#define UARTCSR0 0x0180 /* UART1 TX register. */
#define UARTCSR1 0x0184 /* UART1 RX register. */
#define UARTCSR3 0x0188 /* UART1 frame control register. */
#define UARTCSR4 0x018c /* UART1 buffer control register. */
#define UART2CSR0 0x0190 /* UART2 TX register. */
#define UART2CSR1 0x0194 /* UART2 RX register. */
#define UART2CSR3 0x0198 /* UART2 frame control register. */
#define UART2CSR4 0x019c /* UART2 buffer control register. */
 
/*
 * EEPROM addresses
 */
#define EEPROM_ANTENNA 0x10
#define EEPROM_GEOGRAPHY 0x12
#define EEPROM_BBP_START 0x13
#define EEPROM_BBP_END 0x22
 
#define EEPROM_BBP_SIZE 16
 
/*
 * CSR Registers.
 * Some values are set in TU, whereas 1 TU == 1024 us.
 */
 
/*
 * CSR1: System control register.
 */
#define CSR1_SOFT_RESET                                                        \
   FIELD32(0, 0x00000001) /* Software reset, 1: reset, 0: normal. */
#define CSR1_BBP_RESET                                                         \
   FIELD32(1, 0x00000002) /* Hardware reset, 1: reset, 0, release. */
#define CSR1_HOST_READY                                                        \
   FIELD32(2, 0x00000004) /* Host ready after initialization. */
 
/*
 * CSR3: STA MAC address register 0.
 */
#define CSR3_BYTE0 FIELD32(0, 0x000000ff) /* MAC address byte 0. */
#define CSR3_BYTE1 FIELD32(8, 0x0000ff00) /* MAC address byte 1. */
#define CSR3_BYTE2 FIELD32(16, 0x00ff0000) /* MAC address byte 2. */
#define CSR3_BYTE3 FIELD32(24, 0xff000000) /* MAC address byte 3. */
 
/*
 * CSR4: STA MAC address register 1.
 */
#define CSR4_BYTE4 FIELD32(0, 0x000000ff) /* MAC address byte 4. */
#define CSR4_BYTE5 FIELD32(8, 0x0000ff00) /* MAC address byte 5. */
 
/*
 * CSR5: BSSID register 0.
 */
#define CSR5_BYTE0 FIELD32(0, 0x000000ff) /* BSSID address byte 0. */
#define CSR5_BYTE1 FIELD32(8, 0x0000ff00) /* BSSID address byte 1. */
#define CSR5_BYTE2 FIELD32(16, 0x00ff0000) /* BSSID address byte 2. */
#define CSR5_BYTE3 FIELD32(24, 0xff000000) /* BSSID address byte 3. */
 
/*
 * CSR6: BSSID register 1.
 */
#define CSR6_BYTE4 FIELD32(0, 0x000000ff) /* BSSID address byte 4. */
#define CSR6_BYTE5 FIELD32(8, 0x0000ff00) /* BSSID address byte 5. */
 
/*
 * CSR7: Interrupt source register.
 * Write 1 to clear.
 */
#define CSR7_TBCN_EXPIRE                                                       \
   FIELD32(0, 0x00000001) /* beacon timer expired interrupt. */
#define CSR7_TWAKE_EXPIRE                                                      \
   FIELD32(1, 0x00000002) /* wakeup timer expired interrupt. */
#define CSR7_TATIMW_EXPIRE                                                     \
   FIELD32(2, 0x00000004) /* timer of atim window expired interrupt. */
#define CSR7_TXDONE_TXRING                                                     \
   FIELD32(3, 0x00000008) /* tx ring transmit done interrupt. */
#define CSR7_TXDONE_ATIMRING                                                   \
   FIELD32(4, 0x00000010) /* atim ring transmit done interrupt. */
#define CSR7_TXDONE_PRIORING                                                   \
   FIELD32(5, 0x00000020) /* priority ring transmit done interrupt. */
#define CSR7_RXDONE FIELD32(6, 0x00000040) /* receive done interrupt. */
#define CSR7_DECRYPTION_DONE                                                   \
   FIELD32(7, 0x00000080) /* Decryption done interrupt. */
#define CSR7_ENCRYPTION_DONE                                                   \
   FIELD32(8, 0x00000100) /* Encryption done interrupt. */
#define CSR7_UART1_TX_TRESHOLD                                                 \
   FIELD32(9, 0x00000200) /* UART1 TX reaches threshold. */
#define CSR7_UART1_RX_TRESHOLD                                                 \
   FIELD32(10, 0x00000400) /* UART1 RX reaches threshold. */
#define CSR7_UART1_IDLE_TRESHOLD                                               \
   FIELD32(11, 0x00000800) /* UART1 IDLE over threshold. */
#define CSR7_UART1_TX_BUFF_ERROR                                               \
   FIELD32(12, 0x00001000) /* UART1 TX buffer error. */
#define CSR7_UART1_RX_BUFF_ERROR                                               \
   FIELD32(13, 0x00002000) /* UART1 RX buffer error. */
#define CSR7_UART2_TX_TRESHOLD                                                 \
   FIELD32(14, 0x00004000) /* UART2 TX reaches threshold. */
#define CSR7_UART2_RX_TRESHOLD                                                 \
   FIELD32(15, 0x00008000) /* UART2 RX reaches threshold. */
#define CSR7_UART2_IDLE_TRESHOLD                                               \
   FIELD32(16, 0x00010000) /* UART2 IDLE over threshold. */
#define CSR7_UART2_TX_BUFF_ERROR                                               \
   FIELD32(17, 0x00020000) /* UART2 TX buffer error. */
#define CSR7_UART2_RX_BUFF_ERROR                                               \
   FIELD32(18, 0x00040000) /* UART2 RX buffer error. */
#define CSR7_TIMER_CSR3_EXPIRE                                                 \
   FIELD32(19,                                                            \
       0x00080000) /* TIMECSR3 timer expired (802.1H quiet period). */
 
/*
 * CSR8: Interrupt mask register.
 * Write 1 to mask interrupt.
 */
#define CSR8_TBCN_EXPIRE                                                       \
   FIELD32(0, 0x00000001) /* beacon timer expired interrupt. */
#define CSR8_TWAKE_EXPIRE                                                      \
   FIELD32(1, 0x00000002) /* wakeup timer expired interrupt. */
#define CSR8_TATIMW_EXPIRE                                                     \
   FIELD32(2, 0x00000004) /* timer of atim window expired interrupt. */
#define CSR8_TXDONE_TXRING                                                     \
   FIELD32(3, 0x00000008) /* tx ring transmit done interrupt. */
#define CSR8_TXDONE_ATIMRING                                                   \
   FIELD32(4, 0x00000010) /* atim ring transmit done interrupt. */
#define CSR8_TXDONE_PRIORING                                                   \
   FIELD32(5, 0x00000020) /* priority ring transmit done interrupt. */
#define CSR8_RXDONE FIELD32(6, 0x00000040) /* receive done interrupt. */
#define CSR8_DECRYPTION_DONE                                                   \
   FIELD32(7, 0x00000080) /* Decryption done interrupt. */
#define CSR8_ENCRYPTION_DONE                                                   \
   FIELD32(8, 0x00000100) /* Encryption done interrupt. */
#define CSR8_UART1_TX_TRESHOLD                                                 \
   FIELD32(9, 0x00000200) /* UART1 TX reaches threshold. */
#define CSR8_UART1_RX_TRESHOLD                                                 \
   FIELD32(10, 0x00000400) /* UART1 RX reaches threshold. */
#define CSR8_UART1_IDLE_TRESHOLD                                               \
   FIELD32(11, 0x00000800) /* UART1 IDLE over threshold. */
#define CSR8_UART1_TX_BUFF_ERROR                                               \
   FIELD32(12, 0x00001000) /* UART1 TX buffer error. */
#define CSR8_UART1_RX_BUFF_ERROR                                               \
   FIELD32(13, 0x00002000) /* UART1 RX buffer error. */
#define CSR8_UART2_TX_TRESHOLD                                                 \
   FIELD32(14, 0x00004000) /* UART2 TX reaches threshold. */
#define CSR8_UART2_RX_TRESHOLD                                                 \
   FIELD32(15, 0x00008000) /* UART2 RX reaches threshold. */
#define CSR8_UART2_IDLE_TRESHOLD                                               \
   FIELD32(16, 0x00010000) /* UART2 IDLE over threshold. */
#define CSR8_UART2_TX_BUFF_ERROR                                               \
   FIELD32(17, 0x00020000) /* UART2 TX buffer error. */
#define CSR8_UART2_RX_BUFF_ERROR                                               \
   FIELD32(18, 0x00040000) /* UART2 RX buffer error. */
#define CSR8_TIMER_CSR3_EXPIRE                                                 \
   FIELD32(19,                                                            \
       0x00080000) /* TIMECSR3 timer expired (802.1H quiet period). */
 
/*
 * CSR9: Maximum frame length register.
 */
#define CSR9_MAX_FRAME_UNIT                                                    \
   FIELD32(7,                                                             \
       0x00000f80) /* maximum frame length in 128b unit, default: 12. */
 
/*
 * SECCSR0: WEP control register.
 */
#define SECCSR0_KICK_DECRYPT                                                   \
   FIELD32(0, 0x00000001) /* Kick decryption engine, self-clear. */
#define SECCSR0_ONE_SHOT                                                       \
   FIELD32(1, 0x00000002) /* 0: ring mode, 1: One shot only mode. */
#define SECCSR0_DESC_ADDRESS                                                   \
   FIELD32(2, 0xfffffffc) /* Descriptor physical address of frame. */
 
/*
 * CSR11: Back-off control register.
 */
#define CSR11_CWMIN                                                            \
   FIELD32(0, 0x0000000f) /* CWmin. Default cwmin is 31 (2^5 - 1). */
#define CSR11_CWMAX                                                            \
   FIELD32(4, 0x000000f0) /* CWmax. Default cwmax is 1023 (2^10 - 1). */
#define CSR11_SLOT_TIME                                                        \
   FIELD32(8, 0x00001f00) /* slot time, default is 20us for 802.11b */
#define CSR11_CW_SELECT                                                        \
   FIELD32(13,                                                            \
       0x00002000) /* CWmin/CWmax selection, 1: Register, 0: TXD. */
#define CSR11_LONG_RETRY FIELD32(16, 0x00ff0000) /* long retry count. */
#define CSR11_SHORT_RETRY FIELD32(24, 0xff000000) /* short retry count. */
 
/*
 * CSR12: Synchronization configuration register 0.
 * All units in 1/16 TU.
 */
#define CSR12_BEACON_INTERVAL                                                  \
   FIELD32(0, 0x0000ffff) /* beacon interval, default is 100 TU. */
#define CSR12_CFPMAX_DURATION                                                  \
   FIELD32(16, 0xffff0000) /* cfp maximum duration, default is 100 TU. */
 
/*
 * CSR13: Synchronization configuration register 1.
 * All units in 1/16 TU.
 */
#define CSR13_ATIMW_DURATION FIELD32(0, 0x0000ffff) /* atim window duration. */
#define CSR13_CFP_PERIOD                                                       \
   FIELD32(16, 0x00ff0000) /* cfp period, default is 0 TU. */
 
/*
 * CSR14: Synchronization control register.
 */
#define CSR14_TSF_COUNT FIELD32(0, 0x00000001) /* enable tsf auto counting. */
#define CSR14_TSF_SYNC                                                         \
   FIELD32(1,                                                             \
       0x00000006) /* tsf sync, 0: disable, 1: infra, 2: ad-hoc mode. */
#define CSR14_TBCN FIELD32(3, 0x00000008) /* enable tbcn with reload value. */
#define CSR14_TCFP                                                             \
   FIELD32(4, 0x00000010) /* enable tcfp & cfp / cp switching. */
#define CSR14_TATIMW                                                           \
   FIELD32(5, 0x00000020) /* enable tatimw & atim window switching. */
#define CSR14_BEACON_GEN FIELD32(6, 0x00000040) /* enable beacon generator. */
#define CSR14_CFP_COUNT_PRELOAD                                                \
   FIELD32(8, 0x0000ff00) /* cfp count preload value. */
#define CSR14_TBCM_PRELOAD                                                     \
   FIELD32(16, 0xffff0000) /* tbcn preload value in units of 64us. */
 
/*
 * CSR15: Synchronization status register.
 */
#define CSR15_CFP                                                              \
   FIELD32(0, 0x00000001) /* ASIC is in contention-free period. */
#define CSR15_ATIMW FIELD32(1, 0x00000002) /* ASIC is in ATIM window. */
#define CSR15_BEACON_SENT FIELD32(2, 0x00000004) /* Beacon is send. */
 
/*
 * CSR16: TSF timer register 0.
 */
#define CSR16_LOW_TSFTIMER FIELD32(0, 0xffffffff)
 
/*
 * CSR17: TSF timer register 1.
 */
#define CSR17_HIGH_TSFTIMER FIELD32(0, 0xffffffff)
 
/*
 * CSR18: IFS timer register 0.
 */
#define CSR18_SIFS FIELD32(0, 0x000001ff) /* sifs, default is 10 us. */
#define CSR18_PIFS FIELD32(16, 0x01f00000) /* pifs, default is 30 us. */
 
/*
 * CSR19: IFS timer register 1.
 */
#define CSR19_DIFS FIELD32(0, 0x0000ffff) /* difs, default is 50 us. */
#define CSR19_EIFS FIELD32(16, 0xffff0000) /* eifs, default is 364 us. */
 
/*
 * CSR20: Wakeup timer register.
 */
#define CSR20_DELAY_AFTER_TBCN                                                 \
   FIELD32(0,                                                             \
       0x0000ffff) /* delay after tbcn expired in units of 1/16 TU. */
#define CSR20_TBCN_BEFORE_WAKEUP                                               \
   FIELD32(16, 0x00ff0000) /* number of beacon before wakeup. */
#define CSR20_AUTOWAKE                                                         \
   FIELD32(24, 0x01000000) /* enable auto wakeup / sleep mechanism. */
 
/*
 * CSR21: EEPROM control register.
 */
#define CSR21_RELOAD                                                           \
   FIELD32(0, 0x00000001) /* Write 1 to reload eeprom content. */
#define CSR21_EEPROM_DATA_CLOCK FIELD32(1, 0x00000002)
#define CSR21_EEPROM_CHIP_SELECT FIELD32(2, 0x00000004)
#define CSR21_EEPROM_DATA_IN FIELD32(3, 0x00000008)
#define CSR21_EEPROM_DATA_OUT FIELD32(4, 0x00000010)
#define CSR21_TYPE_93C46 FIELD32(5, 0x00000020) /* 1: 93c46, 0:93c66. */
 
/*
 * CSR22: CFP control register.
 */
#define CSR22_CFP_DURATION_REMAIN                                              \
   FIELD32(0, 0x0000ffff) /* cfp duration remain, in units of TU. */
#define CSR22_RELOAD_CFP_DURATION                                              \
   FIELD32(16, 0x00010000) /* Write 1 to reload cfp duration remain. */
 
/*
 * TX / RX Registers.
 * Some values are set in TU, whereas 1 TU == 1024 us.
 */
 
/*
 * TXCSR0: TX Control Register.
 */
#define TXCSR0_KICK_TX FIELD32(0, 0x00000001) /* kick tx ring. */
#define TXCSR0_KICK_ATIM FIELD32(1, 0x00000002) /* kick atim ring. */
#define TXCSR0_KICK_PRIO FIELD32(2, 0x00000004) /* kick priority ring. */
#define TXCSR0_ABORT                                                           \
   FIELD32(3, 0x00000008) /* abort all transmit related ring operation. */
 
/*
 * TXCSR1: TX Configuration Register.
 */
#define TXCSR1_ACK_TIMEOUT                                                     \
   FIELD32(0,                                                             \
       0x000001ff) /* ack timeout, default = sifs + 2*slottime + acktime @ 1mbps. */
#define TXCSR1_ACK_CONSUME_TIME                                                \
   FIELD32(9,                                                             \
       0x0003fe00) /* ack consume time, default = sifs + acktime @ 1mbps. */
#define TXCSR1_TSF_OFFSET FIELD32(18, 0x00fc0000) /* insert tsf offset. */
#define TXCSR1_AUTORESPONDER                                                   \
   FIELD32(24,                                                            \
       0x01000000) /* enable auto responder which include ack & cts. */
 
/*
 * TXCSR2: Tx descriptor configuration register.
 */
#define TXCSR2_TXD_SIZE                                                        \
   FIELD32(0, 0x000000ff) /* tx descriptor size, default is 48. */
#define TXCSR2_NUM_TXD FIELD32(8, 0x0000ff00) /* number of txd in ring. */
#define TXCSR2_NUM_ATIM FIELD32(16, 0x00ff0000) /* number of atim in ring. */
#define TXCSR2_NUM_PRIO                                                        \
   FIELD32(24, 0xff000000) /* number of priority in ring. */
 
/*
 * TXCSR3: TX Ring Base address register.
 */
#define TXCSR3_TX_RING_REGISTER FIELD32(0, 0xffffffff)
 
/*
 * TXCSR4: TX Atim Ring Base address register.
 */
#define TXCSR4_ATIM_RING_REGISTER FIELD32(0, 0xffffffff)
 
/*
 * TXCSR5: TX Prio Ring Base address register.
 */
#define TXCSR5_PRIO_RING_REGISTER FIELD32(0, 0xffffffff)
 
/*
 * TXCSR6: Beacon Base address register.
 */
#define TXCSR6_BEACON_REGISTER FIELD32(0, 0xffffffff)
 
/*
 * TXCSR7: Auto responder control register.
 */
#define TXCSR7_AR_POWERMANAGEMENT                                              \
   FIELD32(0, 0x00000001) /* auto responder power management bit. */
 
/*
 * TXCSR8: CCK Tx BBP register.
 */
#define TXCSR8_CCK_SIGNAL                                                      \
   FIELD32(0, 0x000000ff) /* BBP rate field address for CCK. */
#define TXCSR8_CCK_SERVICE                                                     \
   FIELD32(8, 0x0000ff00) /* BBP service field address for CCK. */
#define TXCSR8_CCK_LENGTH_LOW                                                  \
   FIELD32(16, 0x00ff0000) /* BBP length low byte address for CCK. */
#define TXCSR8_CCK_LENGTH_HIGH                                                 \
   FIELD32(24, 0xff000000) /* BBP length high byte address for CCK. */
 
/* 
 * TXCSR9: OFDM TX BBP registers
 */
#define TXCSR9_OFDM_RATE                                                       \
   FIELD32(0, 0x000000ff) /* BBP rate field address for OFDM. */
#define TXCSR9_OFDM_SERVICE                                                    \
   FIELD32(8, 0x0000ff00) /* BBP service field address for OFDM. */
#define TXCSR9_OFDM_LENGTH_LOW                                                 \
   FIELD32(16, 0x00ff0000) /* BBP length low byte address for OFDM. */
#define TXCSR9_OFDM_LENGTH_HIGH                                                \
   FIELD32(24, 0xff000000) /* BBP length high byte address for OFDM. */
 
/*
 * RXCSR0: RX Control Register.
 */
#define RXCSR0_DISABLE_RX FIELD32(0, 0x00000001) /* disable rx engine. */
#define RXCSR0_DROP_CRC FIELD32(1, 0x00000002) /* drop crc error. */
#define RXCSR0_DROP_PHYSICAL FIELD32(2, 0x00000004) /* drop physical error. */
#define RXCSR0_DROP_CONTROL FIELD32(3, 0x00000008) /* drop control frame. */
#define RXCSR0_DROP_NOT_TO_ME                                                  \
   FIELD32(4, 0x00000010) /* drop not to me unicast frame. */
#define RXCSR0_DROP_TODS                                                       \
   FIELD32(5, 0x00000020) /* drop frame tods bit is true. */
#define RXCSR0_DROP_VERSION_ERROR                                              \
   FIELD32(6, 0x00000040) /* drop version error frame. */
#define RXCSR0_PASS_CRC                                                        \
   FIELD32(7, 0x00000080) /* pass all packets with crc attached. */
#define RXCSR0_PASS_PLCP                                                       \
   FIELD32(8,                                                             \
       0x00000100) /* Pass all packets with 4 bytes PLCP attached. */
#define RXCSR0_DROP_MCAST FIELD32(9, 0x00000200) /* Drop multicast frames. */
#define RXCSR0_DROP_BCAST FIELD32(10, 0x00000400) /* Drop broadcast frames. */
#define RXCSR0_ENABLE_QOS                                                      \
   FIELD32(11, 0x00000800) /* Accept QOS data frame and parse QOS field. */
 
/*
 * RXCSR1: RX descriptor configuration register.
 */
#define RXCSR1_RXD_SIZE                                                        \
   FIELD32(0, 0x000000ff) /* rx descriptor size, default is 32b. */
#define RXCSR1_NUM_RXD FIELD32(8, 0x0000ff00) /* number of rxd in ring. */
 
/*
 * RXCSR2: RX Ring base address register.
 */
#define RXCSR2_RX_RING_REGISTER FIELD32(0, 0xffffffff)
 
/*
 * RXCSR3: BBP ID register for Rx operation.
 */
#define RXCSR3_BBP_ID0 FIELD32(0, 0x0000007f) /* bbp register 0 id. */
#define RXCSR3_BBP_ID0_VALID                                                   \
   FIELD32(7, 0x00000080) /* bbp register 0 id is valid or not. */
#define RXCSR3_BBP_ID1 FIELD32(8, 0x00007f00) /* bbp register 1 id. */
#define RXCSR3_BBP_ID1_VALID                                                   \
   FIELD32(15, 0x00008000) /* bbp register 1 id is valid or not. */
#define RXCSR3_BBP_ID2 FIELD32(16, 0x007f0000) /* bbp register 2 id. */
#define RXCSR3_BBP_ID2_VALID                                                   \
   FIELD32(23, 0x00800000) /* bbp register 2 id is valid or not. */
#define RXCSR3_BBP_ID3 FIELD32(24, 0x7f000000) /* bbp register 3 id. */
#define RXCSR3_BBP_ID3_VALID                                                   \
   FIELD32(31, 0x80000000) /* bbp register 3 id is valid or not. */
 
/*
 * ARCSR1: Auto Responder PLCP config register 1.
 */
#define ARCSR1_AR_BBP_DATA2                                                    \
   FIELD32(0, 0x000000ff) /* Auto responder BBP register 2 data. */
#define ARCSR1_AR_BBP_ID2                                                      \
   FIELD32(8, 0x0000ff00) /* Auto responder BBP register 2 Id. */
#define ARCSR1_AR_BBP_DATA3                                                    \
   FIELD32(16, 0x00ff0000) /* Auto responder BBP register 3 data. */
#define ARCSR1_AR_BBP_ID3                                                      \
   FIELD32(24, 0xff000000) /* Auto responder BBP register 3 Id. */
 
/*
 * Miscellaneous Registers.
 * Some values are set in TU, whereas 1 TU == 1024 us.
 */
 
/*
 * PCISR: PCI control register.
 */
#define PCICSR_BIG_ENDIAN                                                      \
   FIELD32(0, 0x00000001) /* 1: big endian, 0: little endian. */
#define PCICSR_RX_TRESHOLD                                                     \
   FIELD32(1, 0x00000006) /* rx threshold in dw to start pci access */
/* 0: 16dw (default), 1: 8dw, 2: 4dw, 3: 32dw. */
#define PCICSR_TX_TRESHOLD                                                     \
   FIELD32(3, 0x00000018) /* tx threshold in dw to start pci access */
/* 0: 0dw (default), 1: 1dw, 2: 4dw, 3: forward. */
#define PCICSR_BURST_LENTH FIELD32(5, 0x00000060) /* pci burst length */
/* 0: 4dw (default, 1: 8dw, 2: 16dw, 3:32dw. */
#define PCICSR_ENABLE_CLK FIELD32(7, 0x00000080) /* enable clk_run, */
/* pci clock can't going down to non-operational. */
#define PCICSR_READ_MULTIPLE                                                   \
   FIELD32(8, 0x00000100) /* Enable memory read multiple. */
#define PCICSR_WRITE_INVALID                                                   \
   FIELD32(9, 0x00000200) /* Enable memory write & invalid. */
 
/*
 * PWRCSR1: Manual power control / status register.
 * state: 0 deep_sleep, 1: sleep, 2: standby, 3: awake.
 */
#define PWRCSR1_SET_STATE                                                      \
   FIELD32(0,                                                             \
       0x00000001) /* set state. Write 1 to trigger, self cleared. */
#define PWRCSR1_BBP_DESIRE_STATE FIELD32(1, 0x00000006) /* BBP desired state. */
#define PWRCSR1_RF_DESIRE_STATE FIELD32(3, 0x00000018) /* RF desired state. */
#define PWRCSR1_BBP_CURR_STATE FIELD32(5, 0x00000060) /* BBP current state. */
#define PWRCSR1_RF_CURR_STATE FIELD32(7, 0x00000180) /* RF current state. */
#define PWRCSR1_PUT_TO_SLEEP                                                   \
   FIELD32(9,                                                             \
       0x00000200) /* put to sleep. Write 1 to trigger, self cleared. */
 
/*
 * TIMECSR: Timer control register.
 */
#define TIMECSR_US_COUNT                                                       \
   FIELD32(0, 0x000000ff) /* 1 us timer count in units of clock cycles. */
#define TIMECSR_US_64_COUNT                                                    \
   FIELD32(8, 0x0000ff00) /* 64 us timer count in units of 1 us timer. */
#define TIMECSR_BEACON_EXPECT                                                  \
   FIELD32(16, 0x00070000) /* Beacon expect window. */
 
/*
 * MACCSR1: MAC configuration register 1.
 */
#define MACCSR1_KICK_RX                                                        \
   FIELD32(0, 0x00000001) /* kick one-shot rx in one-shot rx mode. */
#define MACCSR1_ONESHOT_RXMODE                                                 \
   FIELD32(1, 0x00000002) /* enable one-shot rx mode for debugging. */
#define MACCSR1_BBPRX_RESET_MODE                                               \
   FIELD32(2, 0x00000004) /* ralink bbp rx reset mode. */
#define MACCSR1_AUTO_TXBBP                                                     \
   FIELD32(3, 0x00000008) /* auto tx logic access bbp control register. */
#define MACCSR1_AUTO_RXBBP                                                     \
   FIELD32(4, 0x00000010) /* auto rx logic access bbp control register. */
#define MACCSR1_LOOPBACK FIELD32(5, 0x00000060) /* loopback mode. */
/* 0: normal, 1: internal, 2: external, 3:rsvd. */
#define MACCSR1_INTERSIL_IF                                                    \
   FIELD32(7, 0x00000080) /* intersil if calibration pin. */
 
/*
 * RALINKCSR: Ralink Rx auto-reset BBCR.
 */
#define RALINKCSR_AR_BBP_DATA0                                                 \
   FIELD32(0, 0x000000ff) /* auto reset bbp register 0 data. */
#define RALINKCSR_AR_BBP_ID0                                                   \
   FIELD32(8, 0x00007f00) /* auto reset bbp register 0 id. */
#define RALINKCSR_AR_BBP_VALID0                                                \
   FIELD32(15, 0x00008000) /* auto reset bbp register 0 valid. */
#define RALINKCSR_AR_BBP_DATA1                                                 \
   FIELD32(16, 0x00ff0000) /* auto reset bbp register 1 data. */
#define RALINKCSR_AR_BBP_ID1                                                   \
   FIELD32(24, 0x7f000000) /* auto reset bbp register 1 id. */
#define RALINKCSR_AR_BBP_VALID1                                                \
   FIELD32(31, 0x80000000) /* auto reset bbp register 1 valid. */
 
/*
 * BCNCSR: Beacon interval control register.
 */
#define BCNCSR_CHANGE                                                          \
   FIELD32(0, 0x00000001) /* write one to change beacon interval. */
#define BCNCSR_DELTATIME FIELD32(1, 0x0000001e) /* the delta time value. */
#define BCNCSR_NUM_BEACON                                                      \
   FIELD32(5, 0x00001fe0) /* number of beacon according to mode. */
#define BCNCSR_MODE FIELD32(13, 0x00006000) /* please refer to asic specs. */
#define BCNCSR_PLUS                                                            \
   FIELD32(15, 0x00008000) /* plus or minus delta time value. */
 
/*
 * BBPCSR: BBP serial control register.
 */
#define BBPCSR_VALUE                                                           \
   FIELD32(0, 0x000000ff) /* register value to program into bbp. */
#define BBPCSR_REGNUM FIELD32(8, 0x00007f00) /* selected bbp register. */
#define BBPCSR_BUSY                                                            \
   FIELD32(15, 0x00008000) /* 1: asic is busy execute bbp programming. */
#define BBPCSR_WRITE_CONTROL                                                   \
   FIELD32(16, 0x00010000) /* 1: write bbp, 0: read bbp. */
 
/*
 * RFCSR: RF serial control register.
 */
#define RFCSR_VALUE                                                            \
   FIELD32(0, 0x00ffffff) /* register value + id to program into rf/if. */
#define RFCSR_NUMBER_OF_BITS                                                   \
   FIELD32(24,                                                            \
       0x1f000000) /* number of bits used in value (i:20, rfmd:22). */
#define RFCSR_IF_SELECT                                                        \
   FIELD32(29, 0x20000000) /* chip to program: 0: rf, 1: if. */
#define RFCSR_PLL_LD FIELD32(30, 0x40000000) /* rf pll_ld status. */
#define RFCSR_BUSY                                                             \
   FIELD32(31, 0x80000000) /* 1: asic is busy execute rf programming. */
 
/*
 * LEDCSR: LED control register.
 */
#define LEDCSR_ON_PERIOD FIELD32(0, 0x000000ff) /* on period, default 70ms. */
#define LEDCSR_OFF_PERIOD FIELD32(8, 0x0000ff00) /* off period, default 30ms. */
#define LEDCSR_LINK FIELD32(16, 0x00010000) /* 0: linkoff, 1: linkup. */
#define LEDCSR_ACTIVITY FIELD32(17, 0x00020000) /* 0: idle, 1: active. */
#define LEDCSR_LINK_POLARITY                                                   \
   FIELD32(18, 0x00040000) /* 0: active low, 1: active high. */
#define LEDCSR_ACTIVITY_POLARITY                                               \
   FIELD32(19, 0x00080000) /* 0: active low, 1: active high. */
#define LEDCSR_LED_DEFAULT                                                     \
   FIELD32(20, 0x00100000) /* LED state for "enable" 0: ON, 1: OFF. */
 
/*
 * GPIOCSR: GPIO control register.
 */
#define GPIOCSR_BIT0 FIELD32(0, 0x00000001)
#define GPIOCSR_BIT1 FIELD32(1, 0x00000002)
#define GPIOCSR_BIT2 FIELD32(2, 0x00000004)
#define GPIOCSR_BIT3 FIELD32(3, 0x00000008)
#define GPIOCSR_BIT4 FIELD32(4, 0x00000010)
#define GPIOCSR_BIT5 FIELD32(5, 0x00000020)
#define GPIOCSR_BIT6 FIELD32(6, 0x00000040)
#define GPIOCSR_BIT7 FIELD32(7, 0x00000080)
#define GPIOCSR_DIR0 FIELD32(8, 0x00000100)
#define GPIOCSR_DIR1 FIELD32(9, 0x00000200)
#define GPIOCSR_DIR2 FIELD32(10, 0x00000400)
#define GPIOCSR_DIR3 FIELD32(11, 0x00000800)
#define GPIOCSR_DIR4 FIELD32(12, 0x00001000)
#define GPIOCSR_DIR5 FIELD32(13, 0x00002000)
#define GPIOCSR_DIR6 FIELD32(14, 0x00004000)
#define GPIOCSR_DIR7 FIELD32(15, 0x00008000)
 
/*
 * BCNCSR1: Tx BEACON offset time control register.
 */
#define BCNCSR1_PRELOAD                                                        \
   FIELD32(0, 0x0000ffff) /* beacon timer offset in units of usec. */
#define BCNCSR1_BEACON_CWMIN FIELD32(16, 0x000f0000) /* 2^CwMin. */
 
/*
 * MACCSR2: TX_PE to RX_PE turn-around time control register
 */
#define MACCSR2_DELAY                                                          \
   FIELD32(0,                                                             \
       0x000000ff) /* RX_PE low width, in units of pci clock cycle. */
 
/*
 * SECCSR1_RT2509: WEP control register 
 */
#define SECCSR1_KICK_ENCRYPT                                                   \
   FIELD32(0, 0x00000001) /* Kick encryption engine, self-clear. */
#define SECCSR1_ONE_SHOT                                                       \
   FIELD32(1, 0x00000002) /* 0: ring mode, 1: One shot only mode. */
#define SECCSR1_DESC_ADDRESS                                                   \
   FIELD32(2, 0xfffffffc) /* Descriptor physical address of frame. */
 
/*
 * RF registers
 */
#define RF1_TUNER FIELD32(17, 0x00020000)
#define RF3_TUNER FIELD32(8, 0x00000100)
#define RF3_TXPOWER FIELD32(9, 0x00003e00)
 
/*
 * EEPROM content format.
 * The wordsize of the EEPROM is 16 bits.
 */
 
/*
 * EEPROM operation defines.
 */
#define EEPROM_WIDTH_93c46 6
#define EEPROM_WIDTH_93c66 8
#define EEPROM_WRITE_OPCODE 0x05
#define EEPROM_READ_OPCODE 0x06
 
/*
 * EEPROM antenna.
 */
#define EEPROM_ANTENNA_NUM FIELD16(0, 0x0003) /* Number of antenna's. */
#define EEPROM_ANTENNA_TX_DEFAULT                                              \
   FIELD16(2, 0x000c) /* Default antenna 0: diversity, 1: A, 2: B. */
#define EEPROM_ANTENNA_RX_DEFAULT                                              \
   FIELD16(4, 0x0030) /* Default antenna 0: diversity, 1: A, 2: B. */
#define EEPROM_ANTENNA_LED_MODE                                                \
   FIELD16(6, 0x01c0) /* 0: default, 1: TX/RX activity, */
/* 2: Single LED (ignore link), 3: reserved. */
#define EEPROM_ANTENNA_DYN_TXAGC                                               \
   FIELD16(9, 0x0200) /* Dynamic TX AGC control. */
#define EEPROM_ANTENNA_HARDWARE_RADIO                                          \
   FIELD16(10, 0x0400) /* 1: Hardware controlled radio. Read GPIO0. */
#define EEPROM_ANTENNA_RF_TYPE                                                 \
   FIELD16(11, 0xf800) /* rf_type of this adapter. */
 
/*
 * EEPROM geography.
 */
#define EEPROM_GEOGRAPHY_GEO                                                   \
   FIELD16(8, 0x0f00) /* Default geography setting for device. */
 
/*
 * EEPROM NIC config.
 */
#define EEPROM_NIC_CARDBUS_ACCEL FIELD16(0, 0x0001) /* 0: enable, 1: disable. */
#define EEPROM_NIC_DYN_BBP_TUNE FIELD16(1, 0x0002) /* 0: enable, 1: disable. */
#define EEPROM_NIC_CCK_TX_POWER                                                \
   FIELD16(2, 0x000c) /* CCK TX power compensation. */
 
/*
 * EEPROM TX power.
 */
#define EEPROM_TX_POWER1 FIELD16(0, 0x00ff)
#define EEPROM_TX_POWER2 FIELD16(8, 0xff00)
 
/*
 * EEPROM BBP.
 */
#define EEPROM_BBP_VALUE FIELD16(0, 0x00ff)
#define EEPROM_BBP_REG_ID FIELD16(8, 0xff00)
 
/*
 * EEPROM VERSION.
 */
#define EEPROM_VERSION_FAE FIELD16(0, 0x00ff) /* FAE release number. */
#define EEPROM_VERSION FIELD16(8, 0xff00)
 
/*
 * DMA ring defines and data structures.
 */
 
/*
 * Size of a single descriptor.
 */
#define SIZE_DESCRIPTOR 48
 
/*
 * TX descriptor format for TX, PRIO, ATIM and Beacon Ring.
 */
struct _txd {
   u32 word0;
#define TXD_W0_OWNER_NIC FIELD32(0, 0x00000001)
#define TXD_W0_VALID FIELD32(1, 0x00000002)
#define TXD_W0_RESULT FIELD32(2, 0x0000001c) /* Set by device. */
#define TXD_W0_RETRY_COUNT FIELD32(5, 0x000000e0) /* Set by device. */
#define TXD_W0_MORE_FRAG FIELD32(8, 0x00000100) /* Set by device. */
#define TXD_W0_ACK FIELD32(9, 0x00000200)
#define TXD_W0_TIMESTAMP FIELD32(10, 0x00000400)
#define TXD_W0_OFDM FIELD32(11, 0x00000800)
#define TXD_W0_CIPHER_OWNER FIELD32(12, 0x00001000)
#define TXD_W0_IFS FIELD32(13, 0x00006000)
#define TXD_W0_RETRY_MODE FIELD32(15, 0x00008000)
#define TXD_W0_DATABYTE_COUNT FIELD32(16, 0x0fff0000)
#define TXD_W0_CIPHER_ALG FIELD32(29, 0xe0000000)
 
   u32 word1;
#define TXD_W1_BUFFER_ADDRESS FIELD32(0, 0xffffffff)
 
   u32 word2;
#define TXD_W2_IV_OFFSET FIELD32(0, 0x0000003f)
#define TXD_W2_AIFS FIELD32(6, 0x000000c0)
#define TXD_W2_CWMIN FIELD32(8, 0x00000f00)
#define TXD_W2_CWMAX FIELD32(12, 0x0000f000)
 
   u32 word3;
#define TXD_W3_PLCP_SIGNAL FIELD32(0, 0x000000ff)
#define TXD_W3_PLCP_SERVICE FIELD32(8, 0x0000ff00)
#define TXD_W3_PLCP_LENGTH_LOW FIELD32(16, 0x00ff0000)
#define TXD_W3_PLCP_LENGTH_HIGH FIELD32(24, 0xff000000)
 
   u32 word4;
#define TXD_W4_IV FIELD32(0, 0xffffffff)
 
   u32 word5;
#define TXD_W5_EIV FIELD32(0, 0xffffffff)
 
   u32 word6;
#define TXD_W6_KEY FIELD32(0, 0xffffffff)
 
   u32 word7;
#define TXD_W7_KEY FIELD32(0, 0xffffffff)
 
   u32 word8;
#define TXD_W8_KEY FIELD32(0, 0xffffffff)
 
   u32 word9;
#define TXD_W9_KEY FIELD32(0, 0xffffffff)
 
   u32 word10;
#define TXD_W10_RTS FIELD32(0, 0x00000001)
#define TXD_W10_TX_RATE FIELD32(0, 0x000000fe) /* For module only. */
} __attribute__((packed));
 
/*
 * RX descriptor format for RX Ring.
 */
struct _rxd {
   u32 word0;
#define RXD_W0_OWNER_NIC FIELD32(0, 0x00000001)
#define RXD_W0_UNICAST_TO_ME FIELD32(1, 0x00000002)
#define RXD_W0_MULTICAST FIELD32(2, 0x00000004)
#define RXD_W0_BROADCAST FIELD32(3, 0x00000008)
#define RXD_W0_MY_BSS FIELD32(4, 0x00000010)
#define RXD_W0_CRC FIELD32(5, 0x00000020)
#define RXD_W0_OFDM FIELD32(6, 0x00000040)
#define RXD_W0_PHYSICAL_ERROR FIELD32(7, 0x00000080)
#define RXD_W0_CIPHER_OWNER FIELD32(8, 0x00000100)
#define RXD_W0_ICV_ERROR FIELD32(9, 0x00000200)
#define RXD_W0_IV_OFFSET FIELD32(10, 0x0000fc00)
#define RXD_W0_DATABYTE_COUNT FIELD32(16, 0x0fff0000)
#define RXD_W0_CIPHER_ALG FIELD32(29, 0xe0000000)
 
   u32 word1;
#define RXD_W1_BUFFER_ADDRESS FIELD32(0, 0xffffffff)
 
   u32 word2;
#define RXD_W2_BBR0 FIELD32(0, 0x000000ff)
#define RXD_W2_RSSI FIELD32(8, 0x0000ff00)
#define RXD_W2_TA FIELD32(16, 0xffff0000)
 
   u32 word3;
#define RXD_W3_TA FIELD32(0, 0xffffffff)
 
   u32 word4;
#define RXD_W4_IV FIELD32(0, 0xffffffff)
 
   u32 word5;
#define RXD_W5_EIV FIELD32(0, 0xffffffff)
 
   u32 word6;
#define RXD_W6_KEY FIELD32(0, 0xffffffff)
 
   u32 word7;
#define RXD_W7_KEY FIELD32(0, 0xffffffff)
 
   u32 word8;
#define RXD_W8_KEY FIELD32(0, 0xffffffff)
 
   u32 word9;
#define RXD_W9_KEY FIELD32(0, 0xffffffff)
 
   u32 word10;
#define RXD_W10_DROP FIELD32(0, 0x00000001)
} __attribute__((packed));
 
/*
 * _rt2x00_pci
 * This is the main structure which contains all variables required to communicate with the PCI device.
 */
struct _rt2x00_pci {
   /*
     * PCI device structure.
     */
   struct pci_dev *pci_dev;
 
   /*
     * Chipset identification.
     */
   struct _rt2x00_chip chip;
 
   /*
     * csr_addr
     * Base address of device registers, all exact register addresses are calculated from this address.
     */
   void __iomem *csr_addr;
 
   /*
     * RF register values for current channel.
     */
   struct _rf_channel channel;
 
   /*
     * EEPROM bus width.
     */
   u8 eeprom_width;
 
   u8 __pad; /* For alignment only. */
 
   /*
     * EEPROM BBP data.
     */
   u16 eeprom[EEPROM_BBP_SIZE];
 
   /*
     * DMA packet ring.
     */
   struct _data_ring rx;
   struct _data_ring tx;
 
   rtdm_irq_t irq_handle;
   rtdm_lock_t lock;
 
} __attribute__((packed));
 
static int rt2x00_get_rf_value(const struct _rt2x00_chip *chip,
                  const u8 channel, struct _rf_channel *rf_reg)
{
   int index = 0x00;
 
   index = rt2x00_get_channel_index(channel);
   if (index < 0)
       return -EINVAL;
 
   memset(rf_reg, 0x00, sizeof(*rf_reg));
 
   if (rt2x00_rf(chip, RF2522)) {
       rf_reg->rf1 = 0x00002050;
       rf_reg->rf3 = 0x00000101;
       goto update_rf2_1;
   }
   if (rt2x00_rf(chip, RF2523)) {
       rf_reg->rf1 = 0x00022010;
       rf_reg->rf3 = 0x000e0111;
       rf_reg->rf4 = 0x00000a1b;
       goto update_rf2_2;
   }
   if (rt2x00_rf(chip, RF2524)) {
       rf_reg->rf1 = 0x00032020;
       rf_reg->rf3 = 0x00000101;
       rf_reg->rf4 = 0x00000a1b;
       goto update_rf2_2;
   }
   if (rt2x00_rf(chip, RF2525)) {
       rf_reg->rf1 = 0x00022020;
       rf_reg->rf2 = 0x00080000;
       rf_reg->rf3 = 0x00060111;
       rf_reg->rf4 = 0x00000a1b;
       goto update_rf2_2;
   }
   if (rt2x00_rf(chip, RF2525E)) {
       rf_reg->rf2 = 0x00080000;
       rf_reg->rf3 = 0x00060111;
       goto update_rf2_3;
   }
   if (rt2x00_rf(chip, RF5222)) {
       rf_reg->rf3 = 0x00000101;
       goto update_rf2_3;
   }
 
   return -EINVAL;
 
update_rf2_1: /* RF2522. */
   rf_reg->rf2 = 0x000c1fda + (index * 0x14);
   if (channel == 14)
       rf_reg->rf2 += 0x0000001c;
   goto exit;
 
update_rf2_2: /* RF2523, RF2524, RF2525. */
   rf_reg->rf2 |= 0x00000c9e + (index * 0x04);
   if (rf_reg->rf2 & 0x00000040)
       rf_reg->rf2 += 0x00000040;
   if (channel == 14) {
       rf_reg->rf2 += 0x08;
       rf_reg->rf4 &= ~0x00000018;
   }
   goto exit;
 
update_rf2_3: /* RF2525E, RF5222. */
   if (OFDM_CHANNEL(channel)) {
       rf_reg->rf1 = 0x00022020;
       rf_reg->rf2 |= 0x00001136 + (index * 0x04);
       if (rf_reg->rf2 & 0x00000040)
           rf_reg->rf2 += 0x00000040;
       if (channel == 14) {
           rf_reg->rf2 += 0x04;
           rf_reg->rf4 = 0x00000a1b;
       } else {
           rf_reg->rf4 = 0x00000a0b;
       }
   } else if (UNII_LOW_CHANNEL(channel)) {
       rf_reg->rf1 = 0x00022010;
       rf_reg->rf2 = 0x00018896 + (index * 0x04);
       rf_reg->rf4 = 0x00000a1f;
   } else if (HIPERLAN2_CHANNEL(channel)) {
       rf_reg->rf1 = 0x00022010;
       rf_reg->rf2 = 0x00008802 + (index * 0x04);
       rf_reg->rf4 = 0x00000a0f;
   } else if (UNII_HIGH_CHANNEL(channel)) {
       rf_reg->rf1 = 0x00022020;
       rf_reg->rf2 = 0x000090a6 + (index * 0x08);
       rf_reg->rf4 = 0x00000a07;
   }
 
exit:
   rf_reg->rf1 = cpu_to_le32(rf_reg->rf1);
   rf_reg->rf2 = cpu_to_le32(rf_reg->rf2);
   rf_reg->rf3 = cpu_to_le32(rf_reg->rf3);
   rf_reg->rf4 = cpu_to_le32(rf_reg->rf4);
 
   return 0;
}
 
/*
 * Get txpower value in dBm mathing the requested percentage.
 */
static inline u8 rt2x00_get_txpower(const struct _rt2x00_chip *chip,
                   const u8 tx_power)
{
   return tx_power / 100 * 31;
 
   /*
      if(tx_power <= 3)
      return 19;
      else if(tx_power <= 12)
      return 22;
      else if(tx_power <= 25)
      return 25;
      else if(tx_power <= 50)
      return 28;
      else if(tx_power <= 75)
      return 30;
      else if(tx_power <= 100)
      return 31;
    
      ERROR("Invalid tx_power.\n");
      return 31;
    */
}
 
/*
 * Ring handlers.
 */
static inline int
rt2x00_pci_alloc_ring(struct _rt2x00_core *core, struct _data_ring *ring,
             const u8 ring_type, const u16 max_entries,
             const u16 entry_size, const u16 desc_size)
{
   struct _rt2x00_pci *rt2x00pci = rt2x00_priv(core);
 
   rt2x00_init_ring(core, ring, ring_type, max_entries, entry_size,
            desc_size);
 
   ring->data_addr =
       dma_alloc_coherent(&rt2x00pci->pci_dev->dev, ring->mem_size,
                  &ring->data_dma, GFP_KERNEL);
   if (!ring->data_addr)
       return -ENOMEM;
 
   memset(ring->data_addr, 0x00, ring->mem_size);
 
   return 0;
}
 
static int rt2x00_pci_alloc_rings(struct _rt2x00_core *core)
{
   struct _rt2x00_pci *rt2x00pci = rt2x00_priv(core);
 
   if (rt2x00_pci_alloc_ring(core, &rt2x00pci->rx, RING_RX, RX_ENTRIES,
                 DATA_FRAME_SIZE, SIZE_DESCRIPTOR) ||
       rt2x00_pci_alloc_ring(core, &rt2x00pci->tx, RING_TX, TX_ENTRIES,
                 DATA_FRAME_SIZE, SIZE_DESCRIPTOR)) {
       ERROR("DMA allocation failed.\n");
       return -ENOMEM;
   }
 
   return 0;
}
 
static inline void rt2x00_pci_free_ring(struct _data_ring *ring)
{
   struct _rt2x00_pci *rt2x00pci = rt2x00_priv(ring->core);
 
   if (ring->data_addr)
       dma_free_coherent(&rt2x00pci->pci_dev->dev, ring->mem_size,
                 ring->data_addr, ring->data_dma);
   ring->data_addr = NULL;
 
   rt2x00_deinit_ring(ring);
}
 
static void rt2x00_pci_free_rings(struct _rt2x00_core *core)
{
   struct _rt2x00_pci *rt2x00pci = rt2x00_priv(core);
 
   rt2x00_pci_free_ring(&rt2x00pci->rx);
   rt2x00_pci_free_ring(&rt2x00pci->tx);
}
 
/*
 * Macro's for calculating exact position in data ring.
 */
#define DESC_BASE(__ring) ((void *)((__ring)->data_addr))
#define DATA_BASE(__ring)                                                      \
   ((void *)(DESC_BASE(__ring) +                                          \
         ((__ring)->max_entries * (__ring)->desc_size)))
 
#define __DESC_ADDR(__ring, __index)                                           \
   ((void *)(DESC_BASE(__ring) + ((__index) * (__ring)->desc_size)))
#define __DATA_ADDR(__ring, __index)                                           \
   ((void *)(DATA_BASE(__ring) + ((__index) * (__ring)->entry_size)))
 
#define DESC_ADDR(__ring) (__DESC_ADDR(__ring, (__ring)->index))
#define DESC_ADDR_DONE(__ring) (__DESC_ADDR(__ring, (__ring)->index_done))
 
#define DATA_ADDR(__ring) (__DATA_ADDR(__ring, (__ring)->index))
#define DATA_ADDR_DONE(__ring) (__DATA_ADDR(__ring, (__ring)->index_done))
 
/*
 * Register access.
 * All access to the registers will go through rt2x00_register_read and rt2x00_register_write.
 * BBP and RF register require indirect register access through the register BBPCSR and RFCSR.
 * The indirect register access work with busy bits, and a read or write function call can fail.
 * Specific fields within a register can be accessed using the set and get field routines,
 * these function will handle the requirement of little_endian and big_endian conversions.
 */
#define REGISTER_BUSY_COUNT                                                    \
   10 /* Number of retries before failing access BBP & RF indirect register */
#define REGISTER_BUSY_DELAY                                                    \
   100 /* Delay between each register access retry. (us) */
 
static void rt2x00_register_read(const struct _rt2x00_pci *rt2x00pci,
                const unsigned long offset, u32 *value)
{
   *value = readl((void *)(rt2x00pci->csr_addr + offset));
}
 
static void rt2x00_register_multiread(const struct _rt2x00_pci *rt2x00pci,
                     const unsigned long offset, u32 *value,
                     const u16 length)
{
   memcpy_fromio((void *)value, (void *)(rt2x00pci->csr_addr + offset),
             length);
}
 
static void rt2x00_register_write(const struct _rt2x00_pci *rt2x00pci,
                 const unsigned long offset, const u32 value)
{
   writel(value, (void *)(rt2x00pci->csr_addr + offset));
}
 
static void rt2x00_register_multiwrite(const struct _rt2x00_pci *rt2x00pci,
                      const unsigned long offset, u32 *value,
                      const u16 length)
{
   memcpy_toio((void *)(rt2x00pci->csr_addr + offset), (void *)value,
           length);
}
 
static void rt2x00_bbp_regwrite(const struct _rt2x00_pci *rt2x00pci,
               const u8 reg_id, const u8 value)
{
   u32 reg = 0x00000000;
   u8 counter = 0x00;
 
   for (counter = 0x00; counter < REGISTER_BUSY_COUNT; counter++) {
       rt2x00_register_read(rt2x00pci, BBPCSR, &reg);
       if (!rt2x00_get_field32(reg, BBPCSR_BUSY))
           goto bbp_write;
       udelay(REGISTER_BUSY_DELAY);
   }
 
   ERROR("BBPCSR register busy. Write failed\n");
   return;
 
bbp_write:
   reg = 0x00000000;
   rt2x00_set_field32(&reg, BBPCSR_VALUE, value);
   rt2x00_set_field32(&reg, BBPCSR_REGNUM, reg_id);
   rt2x00_set_field32(&reg, BBPCSR_BUSY, 1);
   rt2x00_set_field32(&reg, BBPCSR_WRITE_CONTROL, 1);
 
   rt2x00_register_write(rt2x00pci, BBPCSR, reg);
}
 
static void rt2x00_bbp_regread(const struct _rt2x00_pci *rt2x00pci,
                  const u8 reg_id, u8 *value)
{
   u32 reg = 0x00000000;
   u8 counter = 0x00;
 
   /*
     * We first have to acquire the requested BBP register,
     * so we write the register id into the BBP register first.
     */
   rt2x00_set_field32(&reg, BBPCSR_REGNUM, reg_id);
   rt2x00_set_field32(&reg, BBPCSR_BUSY, 1);
   rt2x00_set_field32(&reg, BBPCSR_WRITE_CONTROL, 0);
 
   rt2x00_register_write(rt2x00pci, BBPCSR, reg);
 
   for (counter = 0x00; counter < REGISTER_BUSY_COUNT; counter++) {
       rt2x00_register_read(rt2x00pci, BBPCSR, &reg);
       if (!rt2x00_get_field32(reg, BBPCSR_BUSY)) {
           *value = rt2x00_get_field32(reg, BBPCSR_VALUE);
           return;
       }
       udelay(REGISTER_BUSY_DELAY);
   }
 
   ERROR("BBPCSR register busy. Read failed\n");
   *value = 0xff;
}
 
static void rt2x00_rf_regwrite(const struct _rt2x00_pci *rt2x00pci,
                  const u32 value)
{
   u32 reg = 0x00000000;
   u8 counter = 0x00;
 
   for (counter = 0x00; counter < REGISTER_BUSY_COUNT; counter++) {
       rt2x00_register_read(rt2x00pci, RFCSR, &reg);
       if (!rt2x00_get_field32(reg, RFCSR_BUSY))
           goto rf_write;
       udelay(REGISTER_BUSY_DELAY);
   }
 
   ERROR("RFCSR register busy. Write failed\n");
   return;
 
rf_write:
   reg = value;
   rt2x00_set_field32(&reg, RFCSR_NUMBER_OF_BITS, 20);
   rt2x00_set_field32(&reg, RFCSR_IF_SELECT, 0);
   rt2x00_set_field32(&reg, RFCSR_BUSY, 1);
 
   //  printk(KERN_INFO "DEBUG: %s:%d: reg=%x\n", __FILE__, __LINE__, reg);
 
   rt2x00_register_write(rt2x00pci, RFCSR, reg);
}
 
/*
 * EEPROM access.
 * The EEPROM is being accessed by word index.
 * rt2x00_eeprom_read_word is the main access function that can be called by
 * the rest of the module. It will take the index number of the eeprom word
 * and the bus width.
 */
static inline void rt2x00_eeprom_pulse_high(const struct _rt2x00_pci *rt2x00pci,
                       u32 *flags)
{
   rt2x00_set_field32(flags, CSR21_EEPROM_DATA_CLOCK, 1);
   rt2x00_register_write(rt2x00pci, CSR21, *flags);
   udelay(1);
}
 
static inline void rt2x00_eeprom_pulse_low(const struct _rt2x00_pci *rt2x00pci,
                      u32 *flags)
{
   rt2x00_set_field32(flags, CSR21_EEPROM_DATA_CLOCK, 0);
   rt2x00_register_write(rt2x00pci, CSR21, *flags);
   udelay(1);
}
 
static void rt2x00_eeprom_shift_out_bits(const struct _rt2x00_pci *rt2x00pci,
                    const u16 data, const u16 count)
{
   u32 flags = 0x00000000;
   u32 mask = 0x0001 << (count - 1);
 
   rt2x00_register_read(rt2x00pci, CSR21, &flags);
 
   /*
     * Clear data flags.
     */
   rt2x00_set_field32(&flags, CSR21_EEPROM_DATA_IN, 0);
   rt2x00_set_field32(&flags, CSR21_EEPROM_DATA_OUT, 0);
 
   /*
     * Start writing all bits. 
     */
   do {
       /*
         * Only set the data_in flag when we are at the correct bit.
         */
       rt2x00_set_field32(&flags, CSR21_EEPROM_DATA_IN,
                  (data & mask) ? 1 : 0);
 
       rt2x00_register_write(rt2x00pci, CSR21, flags);
 
       rt2x00_eeprom_pulse_high(rt2x00pci, &flags);
       rt2x00_eeprom_pulse_low(rt2x00pci, &flags);
 
       /*
         * Shift to next bit.
         */
       mask >>= 1;
   } while (mask);
 
   rt2x00_set_field32(&flags, CSR21_EEPROM_DATA_IN, 0);
   rt2x00_register_write(rt2x00pci, CSR21, flags);
}
 
static void rt2x00_eeprom_shift_in_bits(const struct _rt2x00_pci *rt2x00pci,
                   u16 *data)
{
   u32 flags = 0x00000000;
   u8 counter = 0x00;
 
   rt2x00_register_read(rt2x00pci, CSR21, &flags);
 
   /*
     * Clear data flags.
     */
   rt2x00_set_field32(&flags, CSR21_EEPROM_DATA_IN, 0);
   rt2x00_set_field32(&flags, CSR21_EEPROM_DATA_OUT, 0);
 
   /*
     * Start reading all 16 bits.
     */
   for (counter = 0; counter < 16; counter++) {
       /*
         * Shift to the next bit.
         */
       *data <<= 1;
 
       rt2x00_eeprom_pulse_high(rt2x00pci, &flags);
 
       rt2x00_register_read(rt2x00pci, CSR21, &flags);
 
       /*
         * Clear data_in flag and set the data bit to 1 when the data_out flag is set.
         */
       rt2x00_set_field32(&flags, CSR21_EEPROM_DATA_IN, 0);
       if (rt2x00_get_field32(flags, CSR21_EEPROM_DATA_OUT))
           *data |= 1;
 
       rt2x00_eeprom_pulse_low(rt2x00pci, &flags);
   }
}
 
static u16 rt2x00_eeprom_read_word(const struct _rt2x00_pci *rt2x00pci,
                  const u8 word)
{
   u32 flags = 0x00000000;
   u16 data = 0x0000;
 
   /*
     * Clear all flags, and enable chip select.
     */
   rt2x00_register_read(rt2x00pci, CSR21, &flags);
   rt2x00_set_field32(&flags, CSR21_EEPROM_DATA_IN, 0);
   rt2x00_set_field32(&flags, CSR21_EEPROM_DATA_OUT, 0);
   rt2x00_set_field32(&flags, CSR21_EEPROM_DATA_CLOCK, 0);
   rt2x00_set_field32(&flags, CSR21_EEPROM_CHIP_SELECT, 1);
   rt2x00_register_write(rt2x00pci, CSR21, flags);
 
   /*
     * kick a pulse.
     */
   rt2x00_eeprom_pulse_high(rt2x00pci, &flags);
   rt2x00_eeprom_pulse_low(rt2x00pci, &flags);
 
   /*
     * Select the read opcode and bus_width.
     */
   rt2x00_eeprom_shift_out_bits(rt2x00pci, EEPROM_READ_OPCODE, 3);
   rt2x00_eeprom_shift_out_bits(rt2x00pci, word, rt2x00pci->eeprom_width);
 
   rt2x00_eeprom_shift_in_bits(rt2x00pci, &data);
 
   /*
     * Clear chip_select and data_in flags.
     */
   rt2x00_register_read(rt2x00pci, CSR21, &flags);
   rt2x00_set_field32(&flags, CSR21_EEPROM_DATA_IN, 0);
   rt2x00_set_field32(&flags, CSR21_EEPROM_CHIP_SELECT, 0);
   rt2x00_register_write(rt2x00pci, CSR21, flags);
 
   /*
     * kick a pulse.
     */
   rt2x00_eeprom_pulse_high(rt2x00pci, &flags);
   rt2x00_eeprom_pulse_low(rt2x00pci, &flags);
 
   return data;
}
 
#endif /* RT2500PCI_H */