summaryrefslogtreecommitdiff
path: root/cpu/arm920t/wmt/mac.h
blob: 04dffdb9df0029e301ae434db5b0a3d3a3bbac47 (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
/*++ 
Copyright (c) 2010 WonderMedia Technologies, Inc.

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, see http://www.gnu.org/licenses/>.

WonderMedia Technologies, Inc.
10F, 529, Chung-Cheng Road, Hsin-Tien, Taipei 231, R.O.C.
--*/


#ifndef __MAC_H__
#define __MAC_H__

#if !defined(__TTYPE_H__)
#include "ttype.h"
#endif
#if !defined(__TMACRO_H__)
#include "tmacro.h"
#endif
#if !defined(__UPC_H__)
#include "upc.h"
#endif


/*---------------------  Export Definitions -------------------------*/
//
// Registers in the MAC
//
#define MAC_REG_PAR         0x00        // physical address
#define MAC_REG_RCR         0x06        //
#define MAC_REG_TCR         0x07        //
#define MAC_REG_CR0         0x08        //
#define MAC_REG_CR1         0x09        //
#define MAC_REG_TQWK        0x0A
#define MAC_REG_ISR         0x0C        //
#define MAC_REG_IMR         0x0E        //
#define MAC_REG_MAR         0x10        //
#define MAC_REG_MCAM        0x10        //
#define MAC_REG_VCAM        0x16        //
#define MAC_REG_CUR_RD_ADDR 0x18        //
#define MAC_REG_CUR_TD_ADDR 0x1C        //
#define MAC_REG_RX_DMA_PTR  0x60        //
#define MAC_REG_MPHY        0x6C        //
#define MAC_REG_MIISR       0x6D        //
#define MAC_REG_BCR0        0x6E        //
#define MAC_REG_BCR1        0x6F        //
#define MAC_REG_MIICR       0x70        //
#define MAC_REG_MIIAD       0x71        //
#define MAC_REG_MIIDATA     0x72        //
#define MAC_REG_EECSR       0x74        //
#define MAC_REG_TEST        0x75        //
#define MAC_REG_CFGA        0x78        //
#define MAC_REG_CFGB        0x79        //
#define MAC_REG_CFGC        0x7A        //
#define MAC_REG_CFGD        0x7B        //
#define MAC_REG_CNTR_MPA    0x7C        //
#define MAC_REG_CNTR_CRC    0x7E        //

// Registers only in integrated LAN
#define MAC_REG_BISTCSR0    0x50        //
#define MAC_REG_BISTCSR1    0x51        //
#define MAC_REG_BISTCSR2    0x52        //
#define MAC_REG_BISTCSR3    0x53        //

// Registers for 3065
#define MAC_REG_GFTEST      0x54        //
#define MAC_REG_RFTCMD      0x55        //
#define MAC_REG_TFTCMD      0x56        //
#define MAC_REG_GFSTATUS    0x57        //
#define MAC_REG_BNRY        0x58        //
#define MAC_REG_CURR        0x5A        //
#define MAC_REG_FIFO_DATA   0x5C        //
#define MAC_REG_CUR_RXDMA   0x60        //
#define MAC_REG_CUR_TXDMA   0x64        //

// Registers for 3359 Ethernet MAC module
#define MAC_REG_EEADR       0x7C        //
#define MAC_REG_EECMD       0x7D        //
#define MAC_REG_EESD_CKSUM  0x7E        //
#define MAC_REG_DPMSR       0x7F        //

#define MAC_REG_MISC_CR0    0x80        //
#define MAC_REG_MISC_CR1    0x81        //
#define MAC_REG_PMCPORT     0x82        //
#define MAC_REG_STICKHW     0x83        //
#define MAC_REG_MISR        0x84        //
#define MAC_REG_MIMR        0x86        //
#define MAC_REG_CAMMSK      0x88        //
#define MAC_REG_BPMA        0x8C        //
#define MAC_REG_BPMD        0x8F        //
#define MAC_REG_BPCMD       0x90        //
#define MAC_REG_BPIN_DATA   0x91        //
#define MAC_REG_CAMC        0x92        //
#define MAC_REG_CAMADD      0x93        //
#define MAC_REG_EECHKSUM    0x93        //
#define MAC_REG_SUS_MII_AD  0x94        //
#define MAC_REG_MIBCR       0x94
#define MAC_REG_MIBDATA     0x96        //
#define MAC_REG_SUS_PHY_ID  0x96        //
#define MAC_REG_MIBPORT     0x96        //
#define MAC_REG_MIBDAT      0x97        //
#define MAC_REG_PAUSE_TIMER 0x98        //
#define MAC_REG_FLOWCR0     0x98
#define MAC_REG_SOFT_TIMER0 0x9C        //
#define MAC_REG_SOFT_TIMER1 0x9E        //
#define MAC_REG_WOLCR_SET   0xA0        //
#define MAC_REG_PWCFG_SET   0xA1        //
#define MAC_REG_TSTREG_SET  0xA2        //
#define MAC_REG_WOLCR1_SET  0xA2        //
#define MAC_REG_WOLCG_SET   0xA3        //
#define MAC_REG_WOLCR_CLR   0xA4        //
#define MAC_REG_PWCFG_CLR   0xA5        //
#define MAC_REG_TSTREG_CLR  0xA6        //
#define MAC_REG_WOLCR1_CLR  0xA6        //
#define MAC_REG_WOLCG_CLR   0xA7        //
#define MAC_REG_PWRCSR_SET  0xA8        //
#define MAC_REG_PWRCSR1_SET 0xA9        //
#define MAC_REG_PWRCSR_CLR  0xAC        //
#define MAC_REG_PWRCSR1_CLR 0xAD        //
#define MAC_REG_PATRN_CRC0  0xB0        //
#define MAC_REG_PATRN_CRC1  0xB4        //
#define MAC_REG_PATRN_CRC2  0xB8        //
#define MAC_REG_PATRN_CRC3  0xBC        //
#define MAC_REG_BYTEMSK0_0  0xC0        //
#define MAC_REG_BYTEMSK0_1  0xC4        //
#define MAC_REG_BYTEMSK0_2  0xC8        //
#define MAC_REG_BYTEMSK0_3  0xCC        //
#define MAC_REG_BYTEMSK1_0  0xD0        //
#define MAC_REG_BYTEMSK1_1  0xD4        //
#define MAC_REG_BYTEMSK1_2  0xD8        //
#define MAC_REG_BYTEMSK1_3  0xDC        //
#define MAC_REG_BYTEMSK2_0  0xE0        //
#define MAC_REG_BYTEMSK2_1  0xE4        //
#define MAC_REG_BYTEMSK2_2  0xE8        //
#define MAC_REG_BYTEMSK2_3  0xEC        //
#define MAC_REG_BYTEMSK3_0  0xF0        //
#define MAC_REG_BYTEMSK3_1  0xF4        //
#define MAC_REG_BYTEMSK3_2  0xF8        //
#define MAC_REG_BYTEMSK3_3  0xFC        //


//
// Bits in the RCR register
//
#define RCR_RRFT2           0x80        //
#define RCR_RRFT1           0x40        //
#define RCR_RRFT0           0x20        //
#define RCR_PROM            0x10        //
#define RCR_AB              0x08        //
#define RCR_AM              0x04        //
#define RCR_AR              0x02        //
#define RCR_SEP             0x01        //

//
// Bits in the TCR register
//
#define TCR_RTSF            0x80        //
#define TCR_RTFT1           0x40        //
#define TCR_RTFT0           0x20        //
#define TCR_OFSET           0x08        //
#define TCR_LB1             0x04        // loopback[1]
#define TCR_LB0             0x02        // loopback[0]
#define TCR_PQEN            0x01

//
// Bits in the CR0 register
//
#define CR0_RDMD            0x40        // rx descriptor polling demand
#define CR0_TDMD            0x20        // tx descriptor polling demand
#define CR0_TXON            0x10        //
#define CR0_RXON            0x08        //
#define CR0_STOP            0x04        // stop MAC, default = 1
#define CR0_STRT            0x02        // start MAC
#define CR0_INIT            0x01        // start init process

//
// Bits in the CR1 register
//
#define CR1_SFRST           0x80        // software reset
#define CR1_RDMD1           0x40        //
#define CR1_TDMD1           0x20        //
#define CR1_KEYPAG          0x10        //
#define CR1_DPOLL           0x08        // disable rx/tx auto polling
#define CR1_FDX             0x04        // full duplex mode
#define CR1_ETEN            0x02        // early tx mode
#define CR1_EREN            0x01        // early rx mode

//
// Bits in the IMR register
//
#define IMR_KEYM            0x8000      //
#define IMR_SRCM            0x4000      //
#define IMR_ABTM            0x2000      //
#define IMR_NORBFM          0x1000      //
#define IMR_PKTRAM          0x0800      //
#define IMR_OVFM            0x0400      //
#define IMR_ETM             0x0200      //
#define IMR_ERM             0x0100      //
#define IMR_CNTM            0x0080      //
#define IMR_BEM             0x0040      //
#define IMR_RUM             0x0020      //
#define IMR_TUM             0x0010      //
#define IMR_TXEM            0x0008      //
#define IMR_RXEM            0x0004      //
#define IMR_PTXM            0x0002      //
#define IMR_PRXM            0x0001      //

//
// Bits in the ISR (MISR) register
//
#define ISR_GENI            0x00008000UL    //  for 3065
#define ISR_SRCI            0x00004000UL    //
#define ISR_ABTI            0x00002000UL    //
#define ISR_NORBF           0x00001000UL    //
#define ISR_PKTRA           0x00000800UL    //
#define ISR_OVFI            0x00000400UL    //
#define ISR_UDFI            0x00000200UL    //  for 3065
#define ISR_ERI             0x00000100UL    //
#define ISR_CNT             0x00000080UL    //
#define ISR_BE              0x00000040UL    //
#define ISR_RU              0x00000020UL    //
#define ISR_TU              0x00000010UL    //
#define ISR_TXE             0x00000008UL    //
#define ISR_RXE             0x00000004UL    //
#define ISR_PTX             0x00000002UL    //
#define ISR_PRX             0x00000001UL    //
// Bits in MISR
#define ISR_PWEINT          0x00800000UL    // power event report in test mode
#define ISR_UDPINT_CLR      0x00400000UL    // userdefined, host driven interrupt.clear
#define ISR_UDPINT_SET      0x00200000UL    // userdefined, host driven interrupt.Set
#define ISR_SSRCI           0x00100000UL    // suspend well mii polling status change interrupt
#define ISR_TDWBRAI         0x00080000UL    // TD WB queue race
#define ISR_PHYINT          0x00040000UL    // PHY state change interrupt, active by
                                            // PHYINTEN (misc.cr[9]) in normal mode
#define ISR_TM1_INT         0x00020000UL    //
#define ISR_TM0_INT         0x00010000UL    //


//
// Bits in the MIISR register
//
#define MIISR_N_FDX         0x04
#define MIISR_LNKFL         0x02        //
#define MIISR_SPEED         0x01        //

//
// Bits in the MIICR register
//
#define MIICR_MAUTO         0x80        //
#define MIICR_RCMD          0x40        //
#define MIICR_WCMD          0x20        //
#define MIICR_MDPM          0x10        //
#define MIICR_MOUT          0x08        //
#define MIICR_MDO           0x04        //
#define MIICR_MDI           0x02        //
#define MIICR_MDC           0x01        //

//
// Bits in the MIIAD register
//
#define MIIAD_MIDLE         0x80        //
#define MIIAD_MSRCEN        0x40        //
#define MIIAD_MDONE         0x20        //
//
// Bits in the MIBCR register
//
#define MIBCR_MIBEN         0x10
#define MIBCR_MIBHALF       0x20
#define MIBCR_MIBINC        0x40
#define MIBCR_MIBRTN        0x80
//
// Bits in the EECSR register
//
#define EECSR_EEPR          0x80        // eeprom programed status, 73h means programed
#define EECSR_EMBP          0x40        // eeprom embeded programming
#define EECSR_AUTOLD        0x20        // eeprom content reload
#define EECSR_DPM           0x10        // eeprom direct programming
#define EECSR_CS            0x08        // eeprom CS pin
#define EECSR_SK            0x04        // eeprom SK pin
#define EECSR_DI            0x02        // eeprom DI pin
#define EECSR_DO            0x01        // eeprom DO pin

//
// Bits in the BCR0 register
//
#define BCR0_BOOT_MASK      ((BYTE) 0xC0)
#define BCR0_BOOT_INT19     ((BYTE) 0x00)
#define BCR0_BOOT_INT18     ((BYTE) 0x40)
#define BCR0_BOOT_LOCAL     ((BYTE) 0x80)
#define BCR0_BOOT_BEV       ((BYTE) 0xC0)

#define BCR0_MED2           0x80        //
#define BCR0_LED100M        0x40        //
#define BCR0_CRFT2          0x20        //
#define BCR0_CRFT1          0x10        //
#define BCR0_CRFT0          0x08        //
#define BCR0_DMAL2          0x04        //
#define BCR0_DMAL1          0x02        //
#define BCR0_DMAL0          0x01        //

//
// Bits in the BCR1 register
//
#define BCR1_MED1           0x80        //
#define BCR1_MED0           0x40        //
#define BCR1_CTSF           0x20        //
#define BCR1_CTFT1          0x10        //
#define BCR1_CTFT0          0x08        //
#define BCR1_POT2           0x04        //
#define BCR1_POT1           0x02        //
#define BCR1_POT0           0x01        //

//
// Bits in the CFGA register
//
#define CFGA_EELOAD         0x80        // enable eeprom embeded and direct programming
#define CFGA_MMIOEN         0x20        // memory mapped I/O enable (3043)
#define CFGA_LED0S0         0x01        //

// VT3106
#define CFGA_PMHCTG         0x20        // pattern match crc calculation TAG info inclusion

//
// Bits in the CFGB register
//
#define CFGB_QPKTDIS        0x80        //
#define CFGB_MRLDIS         0x20        //

//
// Bits in the CFGC register
//
#define CFGC_BOOT_RPL       ((BYTE) 0x80) //Boot method selection for VT3106S
#define CFGC_MEDEN          0x80        //
#define CFGC_BROPT          0x40        //
#define CFGC_DLYEN          0x20        //
#define CFGC_DTSEL          0x10        //
#define CFGC_BTSEL          0x08        //
#define CFGC_BPS2           0x04        // bootrom select[2]
#define CFGC_BPS1           0x02        // bootrom select[1]
#define CFGC_BPS0           0x01        // bootrom select[0]
//
// Bits in the CAMCR register
//
#define CAMC_CAMRD          0x08
#define CAMC_CAMWR          0x04
#define CAMC_VCAMSL         0x02
#define CAMC_CAMEN          0x01

//
// Bits in the CFGD register
//
#define CFGD_GPIOEN         0x80        //
#define CFGD_DIAG           0x40        //
#define CFGD_BOOT_RPL       ((BYTE) 0x20) //Boot method selection for VT3106J, VT3206
#define CFGD_MAGIC          0x10        //
#define CFGD_CRADOM         0x08        //
#define CFGD_CAP            0x04        //
#define CFGD_MBA            0x02        //
#define CFGD_BAKOPT         0x01        //

#define CFGD_MMIOEN         0x80        // memory mapped I/O enable (3065/3106)

// for VT3065

// Bits in STICKHW
#define STICKHW_LEGWOLEN        0x0080  // status for software reference
#define STICKHW_LEGACY_WOLSR    0x0008
#define STICKHW_LEGACY_WOLEN    0x0004
#define STICKHW_DS1_SHADOW      0x0002  // R/W by software/cfg cycle
#define STICKHW_DS0_SHADOW      0x0001  // suspend well DS write port

// Bits in MISC.CR0
#define MISC_CR0_TM0US          0x20
#define MISC_CR0_FDXTFEN        0x10    // Full-duplex flow control TX enable
#define MISC_CR0_FDXRFEN        0x08    // Full-duplex flow control RX enable
#define MISC_CR0_HDXFEN         0x04    // Half-duplex flow control enable
#define MISC_CR0_TIMER0_SUSPEND 0x02
#define MISC_CR0_TIMER0_EN      0x01

// Bits in MISC.CR1
#define MISC_CR1_FORSRST        0x40
#define MISC_CR1_VAUXJMP        0x20
#define MISC_CR1_PHYINT         0x02
#define MISC_CR1_TIMER1_EN      0x01

// Bits in BPCMD
#define BPCMD_BPDNE             0x80
#define BPCMD_EBPWR             0x02
#define BPCMD_EBPRD             0x01

// Bits in MISR
#define MISR_PWEINT             0x80    // power event report in test mode
#define MISR_UDPINT_CLR         0x40    // userdefined, host driven interrupt.clear
#define MISR_UDPINT_SET         0x20    // userdefined, host driven interrupt.Set
#define MISR_SSRCI              0x10    // suspend well mii polling status change interrupt
#define MISR_TDWBRAI            0x08    // TD WB queue race
#define MISR_PHYINT             0x04    // PHY state change interrupt, active by
                                        // PHYINTEN (misc.cr[9]) in normal mode
#define MISR_TM1_INT            0x02
#define MISR_TM0_INT            0x01

// Bits in WOLCR
#define WOLCR_LNKOFF_EN         0x80    // link off detected enable
#define WOLCR_LNKON_EN          0x40    // link on detected enable
#define WOLCR_MAGPKT_EN         0x20    // magic packet filter enable
#define WOLCR_UNICAST_EN        0x10    // unicast filter enable
#define WOLCR_MSWOLEN3          0x08    // enable pattern match filtering
#define WOLCR_MSWOLEN2          0x04
#define WOLCR_MSWOLEN1          0x02
#define WOLCR_MSWOLEN0          0x01


// Bits in PWCFG
#define PWCFG_SMIITIME          0x80    // internal MII I/F timing
#define PWCFG_PCISTICK          0x40    // PCI sticky R/W enable
#define PWCFG_WOLTYPE           0x20    // pulse(1) or button (0)
#define PWCFG_LEGCY_WOL         0x10
#define PWCFG_PMCSR_PME_SR      0x08
#define PWCFG_PMCSR_PME_EN      0x04    // control by PCISTICK
#define PWCFG_LEGACY_WOLSR      0x02    // Legacy WOL_SR shadow
#define PWCFG_LEGACY_WOLEN      0x01    // Legacy WOL_EN shadow

// Bits in TestReg
#define TSTREG_SGENWATCH        0x08
#define TSTREG_SMCSNOOP         0x04
#define TSTREG_SMACTEST         0x02
#define TSTREG_SNORMAL          0x01

// Bits in WOLCFG
#define WOLCFG_PME_OVR          0x80    // for legacy use, force PMEEN always
#define WOLCFG_SFDX             0x40    // full duplex while in WOL mode
#define WOLCFG_SAM              0x20    // accept multicast case reset, default=0
#define WOLCFG_SAB              0x10    // accept broadcast case reset, default=0
#define WOLCFG_SMIIACC          0x08    // ??
#define WOLCFG_SMIIOPT          0x04    // MIIOPT to extend clock in suspendwell
#define WOLCFG_SSRCEN           0x02    // suspend well mii status change enable
#define WOLCFG_PHYINTEN         0x01    // 0:PHYINT trigger enable, 1:use internal MII
                                        // to report status change

// Bits in DPMSR
#define DPMSR_PDPM              0x04    // Direct Programming Request

// Bits in RAMBIST CSRs
#define BISTCSR0_TSTPAT0        0x01    //
#define BISTCSR0_TSTPAT1        0x02    //
#define BISTCSR0_TSTMODE        0x04    //
#define BISTCSR0_TX0RX1         0x08    //
#define BISTCSR1_BISTGO         0x01    //
#define BISTCSR2_TSTSR          0x01    //
#define BISTCSR3_CMDPRTEN       0x02    //
#define BISTCSR3_RAMTSTEN       0x01    //


// Ethernet address filter type
#define PKT_TYPE_NONE               0x0000  // turn off receiver
#define PKT_TYPE_DIRECTED           0x0001  // obselete, directed address is always accepted
#define PKT_TYPE_MULTICAST          0x0002
#define PKT_TYPE_ALL_MULTICAST      0x0004
#define PKT_TYPE_BROADCAST          0x0008
#define PKT_TYPE_PROMISCUOUS        0x0020
#define PKT_TYPE_LONG               0x2000  // NOTE.... the definition of LONG is >2048 bytes in our chip
#define PKT_TYPE_RUNT               0x4000
#define PKT_TYPE_ERROR              0x8000  // accept error packets, e.g. CRC error


// Loopback mode
#define MAC_LB_NONE         0x00        //
#define MAC_LB_INTERNAL     0x01        //
#define MAC_LB_PHY          0x02        // MII or Internal-10BaseT loopback


// Forced media type
#define FORCED_MEDIA_NONE       0x00    //
#define FORCED_MEDIA_AUTO       0x01    //
#define FORCED_MEDIA_100M_HALF  0x02    // hub card
#define FORCED_MEDIA_100M_FULL  0x03    // fiber channel
#define FORCED_MEDIA_10M_HALF   0x04    //
#define FORCED_MEDIA_10M_FULL   0x05    //


// enabled mask value of irq
#if defined(_SIM)
#define IMR_MASK_VALUE      0x000BFFFFUL    // initial value of IMR
#else
#define IMR_MASK_VALUE      0x000BD77FUL    // initial value of IMR
                                            // ignore ABTI,PKTRACE,CNT to
                                            // reduce intr. frequency
                                            // NOTE.... do not enable NoBuf int mask at NDIS driver
                                            // when (1) NoBuf -> RxThreshold = SF
                                            //      (2) OK    -> RxThreshold = original value
#endif


// wait time within loop
#define CB_DELAY_LOOP_WAIT  10          // 10ms
#define CB_DELAY_MII_STABLE 660         //

// max time out delay time
#define W_MAX_TIMEOUT       0x0FFFU     //

/*---------------------  Export Types  ------------------------------*/

/*---------------------  Export Macros ------------------------------*/
#define MACvRegBitsOn(dwIoBase, byRegOfs, byBits)           \
{                                                           \
    BYTE byData;                                            \
    VNSvInPortB(dwIoBase + byRegOfs, &byData);              \
    VNSvOutPortB(dwIoBase + byRegOfs, byData | (BYTE)(byBits));   \
}


#define MACvRegBitsOff(dwIoBase, byRegOfs, byBits)          \
{                                                           \
    BYTE byData;                                            \
    VNSvInPortB(dwIoBase + byRegOfs, &byData);              \
    VNSvOutPortB(dwIoBase + byRegOfs, byData & (BYTE)~(byBits));  \
}


// set the chip with current rx descriptor address
#define MACvSetCurrRxDescAddr(dwIoBase, dwCurrDescAddr)     \
{                                                           \
    VNSvOutPortD(dwIoBase + MAC_REG_CUR_RD_ADDR,            \
        dwCurrDescAddr);                                    \
}

#define MACvGetCurrRxDescAddr(dwIoBase, pdwCurrDescAddr)    \
{                                                           \
    VNSvInPortD(dwIoBase + MAC_REG_CUR_RD_ADDR,             \
        (PDWORD)pdwCurrDescAddr);                           \
}


// set the chip with current tx descriptor address
#define MACvSetCurrTxDescAddr(dwIoBase, dwCurrDescAddr)     \
{                                                           \
    VNSvOutPortD(dwIoBase + MAC_REG_CUR_TD_ADDR,            \
        dwCurrDescAddr);                                    \
}

// set the chip with current tx descriptor address for 3106

#define MACvGetCurrTxDescAddr(dwIoBase, pdwCurrDescAddr)    \
{                                                           \
    VNSvInPortD(dwIoBase + MAC_REG_CUR_TD_ADDR,             \
        (PDWORD)pdwCurrDescAddr);                           \
}

#define MACvReadTallyCounter(dwIoBase, pwRegMPA,            \
                pwRegCRC)                                   \
{                                                           \
    VNSvInPortW(dwIoBase + MAC_REG_CNTR_MPA, pwRegMPA);     \
    VNSvInPortW(dwIoBase + MAC_REG_CNTR_CRC, pwRegCRC);     \
}


#define MACvStart(dwIoBase)                 \
{                                           \
    VNSvOutPortB(dwIoBase + MAC_REG_CR0,    \
        CR0_TXON | CR0_RXON | CR0_STRT);    \
}


#define MACvRxOn(dwIoBase)                              \
{                                                       \
    BYTE byOrgValue;                                    \
    VNSvInPortB(dwIoBase + MAC_REG_CR0, &byOrgValue);   \
    byOrgValue = (BYTE)((byOrgValue & ~CR0_STOP) | CR0_RXON | CR0_STRT);  \
    VNSvOutPortB(dwIoBase + MAC_REG_CR0, byOrgValue);   \
}


#define MACvTxOn(dwIoBase)                              \
{                                                       \
    BYTE byOrgValue;                                    \
    VNSvInPortB(dwIoBase + MAC_REG_CR0, &byOrgValue);   \
    byOrgValue = (BYTE)((byOrgValue & ~CR0_STOP) | CR0_TXON | CR0_STRT); \
    VNSvOutPortB(dwIoBase + MAC_REG_CR0, byOrgValue);   \
}


#define MACvTransmit(dwIoBase)                          \
{                                                       \
    BYTE byOrgValue;                                    \
    VNSvInPortB(dwIoBase + MAC_REG_CR1, &byOrgValue);   \
    byOrgValue = (BYTE)(byOrgValue | CR1_TDMD1);        \
    VNSvOutPortB(dwIoBase + MAC_REG_CR1, byOrgValue);   \
}


#define MACvClearStckDS(dwIoBase)                           \
{                                                           \
    BYTE byOrgValue;                                        \
    VNSvInPortB(dwIoBase + MAC_REG_STICKHW, &byOrgValue);   \
    byOrgValue = byOrgValue & (BYTE)0xFC;                   \
    VNSvOutPortB(dwIoBase + MAC_REG_STICKHW, byOrgValue);   \
}


#define MACvPwrEvntDisable(dwIoBase)                    \
{                                                       \
    VNSvOutPortB(dwIoBase + MAC_REG_WOLCR_CLR, 0xFF);   \
    VNSvOutPortB(dwIoBase + MAC_REG_WOLCR1_CLR, 0x03);  \
}

/*---------------------  Export Classes  ----------------------------*/

/*---------------------  Export Variables  --------------------------*/

/*---------------------  Export Functions  --------------------------*/
#ifdef __cplusplus
extern "C" {                            /* Assume C declarations for C++ */
#endif /* __cplusplus */

BOOL
MACbIsCableLinkOk(
    DWORD   dwIoBase
    );

BOOL
MACbIsIn100MMode(
    DWORD   dwIoBase,
    BYTE    byRevId
    );

VOID
MACvIsInFullDuplexMode(
    PBOOL   pbFullDup,
    DWORD   dwIoBase
    );

BOOL
MACbIsRegBitsOff(
    DWORD   dwIoBase,
    BYTE    byRegOfs,
    BYTE    byTestBits
    );

BOOL
MACbIsRegBitsOn(
    DWORD   dwIoBase,
    BYTE    byRegOfs,
    BYTE    byTestBits
    );

BOOL
MACbSafeSoftwareReset(
    DWORD   dwIoBase,
    BYTE    byRevId
    );

BOOL
MACbStop(
    DWORD   dwIoBase
    );

BOOL
MACbSafeStop(
    DWORD   dwIoBase,
    BYTE    byRevId
    );

BOOL
MACbSafeRxOff(
    DWORD   dwIoBase,
    BYTE    byRevId
    );

BOOL
MACbSafeTxOff(
    DWORD   dwIoBase,
    BYTE    byRevId
    );

BOOL
MACbSoftwareReset(
    DWORD   dwIoBase,
    BYTE    byRevId
    );

BYTE
MACbyReadEECSR(
    DWORD   dwIoBase
    );

BYTE
MACbyReadMIICR(
    DWORD   dwIoBase
    );

BYTE
MACbyReadMultiAddr(
    DWORD   dwIoBase,
    UINT    uByteIdx
    );

VOID
MACvWriteMultiAddr(
    DWORD   dwIoBase,
    UINT    uByteIdx,
    BYTE    byData
    );

VOID
MACvEnableMiiAutoPoll(
    DWORD   dwIoBase
    );

VOID
MACvInitialize(
    DWORD   dwIoBase,
    BYTE    byRevId
    );

VOID
MACvIntDisable(
    DWORD   dwIoBase,
    BYTE    byRevId
    );

VOID
MACvIntEnable(
    DWORD   dwIoBase,
    BYTE    byRevId,
    DWORD   dwMask
    );

VOID
MACvSafeDisableMiiAutoPoll(
    DWORD   dwIoBase,
    BYTE    byRevId
    );

VOID
MACvRestoreContext(
    DWORD   dwIoBase,
    BYTE    byRevId,
    PBYTE   pbyCxtBuf
    );

VOID
MACvReadISR(
    DWORD   dwIoBase,
    BYTE    byRevId,
    PDWORD  pdwValue
    );

VOID
MACvWriteISR(
    DWORD   dwIoBase,
    BYTE    byRevId,
    DWORD   dwValue
    );

VOID
MACvSaveContext(
    DWORD   dwIoBase,
    BYTE    byRevId,
    PBYTE   pbyCxtBuf
    );

VOID
MACvSetDmaLength(
    DWORD   dwIoBase,
    BYTE    byDmaLength
    );

VOID
MACvSetDuplexMode(
    DWORD   dwIoBase,
    BYTE    byRevId,
    BOOL    bFullDuplexOn
    );

VOID
MACvSetLoopbackMode(
    DWORD   dwIoBase,
    BYTE    byLoopbackMode
    );

VOID
MACvSetPacketFilter(
    DWORD   dwIoBase,
    WORD    wFilterType
    );

VOID
MACvSetRxThreshold(
    DWORD   dwIoBase,
    BYTE    byThreshold
    );

VOID
MACvGetTxThreshold(
    DWORD   dwIoBase,
    PBYTE   pbyThreshold
    );

VOID
MACvSetTxThreshold(
    DWORD   dwIoBase,
    BYTE    byThreshold
    );

VOID
MACvTimer0MicroSDelay(
    DWORD   dwIoBase,
    BYTE    byRevId,
    UINT    udelay
    );

VOID
MACvTimer0MiniSDelay(
    DWORD   dwIoBase,
    BYTE    byRevId,
    UINT    udelay
    );

VOID
MACvWriteEECSR(
    DWORD   dwIoBase,
    BYTE    byValue,
    BYTE    byRevId
    );

BYTE
MACbyGetPhyId(
    DWORD   dwIoBase
    );

#ifdef __cplusplus
}                                       /* End of extern "C" { */
#endif /* __cplusplus */

#endif // __MAC_H__