1 | /** $Id: DevE1000Phy.h 76520 2018-12-30 05:39:55Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DevE1000Phy - Intel 82540EM Ethernet Controller Internal PHY Emulation, Header.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2007-2017 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 | #ifndef VBOX_INCLUDED_Network_DevE1000_h
|
---|
19 | #define VBOX_INCLUDED_Network_DevE1000_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | #include <VBox/types.h>
|
---|
25 |
|
---|
26 | #define PHY_EPID_M881000 0xC50
|
---|
27 | #define PHY_EPID_M881011 0xC24
|
---|
28 |
|
---|
29 | #define PCTRL_SPDSELM 0x0040
|
---|
30 | #define PCTRL_DUPMOD 0x0100
|
---|
31 | #define PCTRL_ANEG 0x1000
|
---|
32 | #define PCTRL_SPDSELL 0x2000
|
---|
33 | #define PCTRL_RESET 0x8000
|
---|
34 |
|
---|
35 | #define PSTATUS_LNKSTAT 0x0004
|
---|
36 | #define PSTATUS_NEGCOMP 0x0020
|
---|
37 |
|
---|
38 | /*
|
---|
39 | * Speed: 1000 Mb/s
|
---|
40 | * Duplex: full
|
---|
41 | * Page received
|
---|
42 | * Resolved
|
---|
43 | * Link up
|
---|
44 | * Receive Pause Enable
|
---|
45 | */
|
---|
46 | #define PSSTAT_LINK_ALL 0xBC08
|
---|
47 | #define PSSTAT_LINK 0x0400
|
---|
48 |
|
---|
49 | namespace Phy
|
---|
50 | {
|
---|
51 | /**
|
---|
52 | * Indices of memory-mapped registers in register table
|
---|
53 | */
|
---|
54 | enum enmRegIdx
|
---|
55 | {
|
---|
56 | PCTRL_IDX,
|
---|
57 | PSTATUS_IDX,
|
---|
58 | PID_IDX,
|
---|
59 | EPID_IDX,
|
---|
60 | ANA_IDX,
|
---|
61 | LPA_IDX,
|
---|
62 | ANE_IDX,
|
---|
63 | NPT_IDX,
|
---|
64 | LPN_IDX,
|
---|
65 | GCON_IDX,
|
---|
66 | GSTATUS_IDX,
|
---|
67 | EPSTATUS_IDX,
|
---|
68 | PSCON_IDX,
|
---|
69 | PSSTAT_IDX,
|
---|
70 | PINTE_IDX,
|
---|
71 | PINTS_IDX,
|
---|
72 | EPSCON1_IDX,
|
---|
73 | PREC_IDX,
|
---|
74 | EPSCON2_IDX,
|
---|
75 | R30PS_IDX,
|
---|
76 | R30AW_IDX,
|
---|
77 | NUM_OF_PHY_REGS
|
---|
78 | };
|
---|
79 | /**
|
---|
80 | * Emulation state of PHY.
|
---|
81 | */
|
---|
82 | struct Phy_st
|
---|
83 | {
|
---|
84 | /** Network controller instance this PHY is attached to. */
|
---|
85 | int iInstance;
|
---|
86 | /** Register storage. */
|
---|
87 | uint16_t au16Regs[NUM_OF_PHY_REGS];
|
---|
88 | /** Current state of serial MDIO interface. */
|
---|
89 | uint16_t u16State;
|
---|
90 | /** Current state of serial MDIO interface. */
|
---|
91 | uint16_t u16Acc;
|
---|
92 | /** Number of bits remaining to be shifted into/out of accumulator. */
|
---|
93 | uint16_t u16Cnt;
|
---|
94 | /** PHY register offset selected for MDIO operation. */
|
---|
95 | uint16_t u16RegAdr;
|
---|
96 | };
|
---|
97 | }
|
---|
98 |
|
---|
99 | #define MDIO_IDLE 0
|
---|
100 | #define MDIO_ST 1
|
---|
101 | #define MDIO_OP_ADR 2
|
---|
102 | #define MDIO_TA_RD 3
|
---|
103 | #define MDIO_TA_WR 4
|
---|
104 | #define MDIO_READ 5
|
---|
105 | #define MDIO_WRITE 6
|
---|
106 |
|
---|
107 | #define MDIO_READ_OP 2
|
---|
108 | #define MDIO_WRITE_OP 1
|
---|
109 |
|
---|
110 | typedef struct Phy::Phy_st PHY;
|
---|
111 | typedef PHY *PPHY;
|
---|
112 |
|
---|
113 | /* Interface *****************************************************************/
|
---|
114 | namespace Phy
|
---|
115 | {
|
---|
116 | /** Initialize PHY. */
|
---|
117 | void init(PPHY pPhy, int iNICInstance, uint16_t u16EPid);
|
---|
118 | /** Read PHY register at specified address. */
|
---|
119 | uint16_t readRegister(PPHY pPhy, uint32_t u32Address);
|
---|
120 | /** Write to PHY register at specified address. */
|
---|
121 | void writeRegister(PPHY pPhy, uint32_t u32Address, uint16_t u16Value);
|
---|
122 | /** Read the value on MDIO pin. */
|
---|
123 | bool readMDIO(PPHY pPhy);
|
---|
124 | /** Set the value of MDIO pin. */
|
---|
125 | void writeMDIO(PPHY pPhy, bool fPin);
|
---|
126 | /** Hardware reset. */
|
---|
127 | void hardReset(PPHY pPhy);
|
---|
128 | /** Query link status. */
|
---|
129 | bool isLinkUp(PPHY pPhy);
|
---|
130 | /** Set link status. */
|
---|
131 | void setLinkStatus(PPHY pPhy, bool fLinkIsUp);
|
---|
132 | /** Save PHY state. */
|
---|
133 | int saveState(PSSMHANDLE pSSMHandle, PPHY pPhy);
|
---|
134 | /** Restore previously saved PHY state. */
|
---|
135 | int loadState(PSSMHANDLE pSSMHandle, PPHY pPhy);
|
---|
136 | }
|
---|
137 |
|
---|
138 | #endif
|
---|
139 |
|
---|