1 | /** $Id: DevE1000Phy.h 28800 2010-04-27 08:22:32Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DevE1000Phy - Intel 82540EM Ethernet Controller Internal PHY Emulation, Header.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2007 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #include <VBox/types.h>
|
---|
19 |
|
---|
20 | #define PHY_EPID_M881000 0xC50
|
---|
21 | #define PHY_EPID_M881011 0xC24
|
---|
22 |
|
---|
23 | #define PCTRL_SPDSELM 0x0040
|
---|
24 | #define PCTRL_DUPMOD 0x0100
|
---|
25 | #define PCTRL_ANEG 0x1000
|
---|
26 | #define PCTRL_SPDSELL 0x2000
|
---|
27 | #define PCTRL_RESET 0x8000
|
---|
28 |
|
---|
29 | #define PSTATUS_LNKSTAT 0x0004
|
---|
30 |
|
---|
31 | /*
|
---|
32 | * Speed: 1000 Mb/s
|
---|
33 | * Duplex: full
|
---|
34 | * Page received
|
---|
35 | * Resolved
|
---|
36 | * Link up
|
---|
37 | * Receive Pause Enable
|
---|
38 | */
|
---|
39 | #define PSSTAT_LINK 0xBC08
|
---|
40 |
|
---|
41 | namespace Phy
|
---|
42 | {
|
---|
43 | /**
|
---|
44 | * Indices of memory-mapped registers in register table
|
---|
45 | */
|
---|
46 | enum enmRegIdx
|
---|
47 | {
|
---|
48 | PCTRL_IDX,
|
---|
49 | PSTATUS_IDX,
|
---|
50 | PID_IDX,
|
---|
51 | EPID_IDX,
|
---|
52 | ANA_IDX,
|
---|
53 | LPA_IDX,
|
---|
54 | ANE_IDX,
|
---|
55 | NPT_IDX,
|
---|
56 | LPN_IDX,
|
---|
57 | GCON_IDX,
|
---|
58 | GSTATUS_IDX,
|
---|
59 | EPSTATUS_IDX,
|
---|
60 | PSCON_IDX,
|
---|
61 | PSSTAT_IDX,
|
---|
62 | PINTE_IDX,
|
---|
63 | PINTS_IDX,
|
---|
64 | EPSCON1_IDX,
|
---|
65 | PREC_IDX,
|
---|
66 | EPSCON2_IDX,
|
---|
67 | R30PS_IDX,
|
---|
68 | R30AW_IDX,
|
---|
69 | NUM_OF_PHY_REGS
|
---|
70 | };
|
---|
71 | /**
|
---|
72 | * Emulation state of PHY.
|
---|
73 | */
|
---|
74 | struct Phy_st
|
---|
75 | {
|
---|
76 | /** Network controller instance this PHY is attached to. */
|
---|
77 | int iInstance;
|
---|
78 | /** Register storage. */
|
---|
79 | uint16_t au16Regs[NUM_OF_PHY_REGS];
|
---|
80 | /** Current state of serial MDIO interface. */
|
---|
81 | uint16_t u16State;
|
---|
82 | /** Current state of serial MDIO interface. */
|
---|
83 | uint16_t u16Acc;
|
---|
84 | /** Number of bits remaining to be shifted into/out of accumulator. */
|
---|
85 | uint16_t u16Cnt;
|
---|
86 | /** PHY register offset selected for MDIO operation. */
|
---|
87 | uint16_t u16RegAdr;
|
---|
88 | };
|
---|
89 | }
|
---|
90 |
|
---|
91 | #define MDIO_IDLE 0
|
---|
92 | #define MDIO_ST 1
|
---|
93 | #define MDIO_OP_ADR 2
|
---|
94 | #define MDIO_TA_RD 3
|
---|
95 | #define MDIO_TA_WR 4
|
---|
96 | #define MDIO_READ 5
|
---|
97 | #define MDIO_WRITE 6
|
---|
98 |
|
---|
99 | #define MDIO_READ_OP 2
|
---|
100 | #define MDIO_WRITE_OP 1
|
---|
101 |
|
---|
102 | typedef struct Phy::Phy_st PHY;
|
---|
103 | typedef PHY *PPHY;
|
---|
104 |
|
---|
105 | /* Interface *****************************************************************/
|
---|
106 | namespace Phy {
|
---|
107 | /** Initialize PHY. */
|
---|
108 | void init(PPHY pPhy, int iNICInstance, uint16_t u16EPid);
|
---|
109 | /** Read PHY register at specified address. */
|
---|
110 | uint16_t readRegister(PPHY pPhy, uint32_t u32Address);
|
---|
111 | /** Write to PHY register at specified address. */
|
---|
112 | void writeRegister(PPHY pPhy, uint32_t u32Address, uint16_t u16Value);
|
---|
113 | /** Read the value on MDIO pin. */
|
---|
114 | bool readMDIO(PPHY pPhy);
|
---|
115 | /** Set the value of MDIO pin. */
|
---|
116 | void writeMDIO(PPHY pPhy, bool fPin);
|
---|
117 | /** Hardware reset. */
|
---|
118 | void hardReset(PPHY pPhy);
|
---|
119 | /** Query link status. */
|
---|
120 | bool isLinkUp(PPHY pPhy);
|
---|
121 | /** Set link status. */
|
---|
122 | void setLinkStatus(PPHY pPhy, bool fLinkIsUp);
|
---|
123 | /** Save PHY state. */
|
---|
124 | int saveState(PSSMHANDLE pSSMHandle, PPHY pPhy);
|
---|
125 | /** Restore previously saved PHY state. */
|
---|
126 | int loadState(PSSMHANDLE pSSMHandle, PPHY pPhy);
|
---|
127 | }
|
---|
128 |
|
---|