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#ifndef ETH_PHY_H
29#define ETH_PHY_H
30
31#include "qemu-common.h"
32
33
34
35#define PHY_CTRL 0x00
36#define PHY_STATUS 0x01
37#define PHY_ID1 0x02
38#define PHY_ID2 0x03
39#define PHY_AUTONEG_ADV 0x04
40#define PHY_LP_ABILITY 0x05
41#define PHY_AUTONEG_EXP 0x06
42#define PHY_NEXT_PAGE_TX 0x07
43#define PHY_LP_NEXT_PAGE 0x08
44#define PHY_1000T_CTRL 0x09
45#define PHY_1000T_STATUS 0x0A
46#define PHY_EXT_STATUS 0x0F
47#define PHY_SPEC_CTRL 0x10
48#define PHY_SPEC_STATUS 0x11
49#define NUM_PHY_REGS 0x1F
50
51
52#define PHY_CTRL_REG_UNIDIR_EN 5
53#define PHY_CTRLREG_SPEED_SEL_MSB 6
54#define PHY_CTRLREG_COLLISION_TEST 7
55#define PHY_CTRLREG_DUPLEX_MODE 8
56#define PHY_CTRLREG_RST_AUTONEG 9
57#define PHY_CTRLREG_ISOLATE 10
58#define PHY_CTRLREG_POWER_DWN 11
59#define PHY_CTRLREG_AUTONEG_EN 12
60#define PHY_CTRLREG_SPEED_SEL_LSB 13
61#define PHY_CTRLREG_LOOPBACK 14
62#define PHY_CTRLREG_RESET 15
63
64
65#define PHY_STAT_EXT_CAP 0
66#define PHY_STAT_JAB_DETECT 1
67#define PHY_STAT_LINK_STAT 2
68#define PHY_STAT_AUTONEG_CAP 3
69#define PHY_STAT_REMOTE_FAL 4
70#define PHY_STAT_AUTONEG_COMP 5
71#define PHY_STAT_PREM_SUPPRESS 6
72#define PHY_STAT_UNIDIR_CAP 7
73#define PHY_STAT_EXT_STAT_CAP 8
74#define PHY_STAT_100B_T2_HD 9
75#define PHY_STAT_100B_T2_FD 10
76#define PHY_STAT_10MBPS_HD 11
77#define PHY_STAT_10MBPS_FD 12
78#define PHY_STAT_100BX_HD 13
79#define PHY_STAT_100BX_FD 14
80#define PHY_STAT_T4 15
81
82
83#define PHY_EXT_STAT_1000BT_HD 12
84#define PHY_EXT_STAT_1000BT_FD 13
85#define PHY_EXT_STAT_1000BX_HD 14
86#define PHY_EXT_STAT_1000BX_FD 15
87
88
89#define M(X) (uint16_t) (1 << X)
90
91#define PHY_CTRL_RST 0x8000
92#define PHY_CTRL_ANEG_RST 0x0200
93
94
95#define PHY_ADVERTISE_10HALF 0x0020
96#define PHY_ADVERTISE_10FULL 0x0040
97#define PHY_ADVERTISE_100HALF 0x0080
98#define PHY_ADVERTISE_100FULL 0x0100
99
100#define TYPE_ETH_PHY "eth-phy"
101
102#define ETHPHY(obj) OBJECT_CHECK(EthPhy, (obj), TYPE_ETH_PHY)
103#define ETHPHY_CLASS(klass) OBJECT_CLASS_CHECK(EthPhyClass, (klass),\
104 TYPE_ETH_PHY)
105#define ETHPHY_GET_CLASS(obj) \
106 OBJECT_GET_CLASS(EthPhyClass, (obj), TYPE_ETH_PHY)
107
108static const uint16_t default_readonly_mask[32] = {
109 [PHY_CTRL] = PHY_CTRL_RST | PHY_CTRL_ANEG_RST,
110 [PHY_ID1] = 0xffff,
111 [PHY_ID2] = 0xffff,
112 [PHY_LP_ABILITY] = 0xffff,
113 [PHY_SPEC_STATUS] = 0xffff,
114};
115
116typedef struct PhyPartInfo {
117 const char *partname;
118
119 uint16_t phy_id1;
120 uint16_t phy_id2;
121
122 bool autoneg;
123 bool gmii;
124} PhyPartInfo;
125
126#define PHYINFO(_part_name, _id1, _id2, _autoneg, _gmii) \
127 .partname = (_part_name),\
128 .phy_id1 = (_id1),\
129 .phy_id2 = (_id2),\
130 .autoneg = (_autoneg),\
131 .gmii = (_gmii),\
132
133static const PhyPartInfo devices[] = {
134 { PHYINFO("88e1116r", 0x0141, 0x0e50, 1, 1) },
135 { PHYINFO("88e1116", 0x0141, 0x0e50, 1, 1) },
136 { PHYINFO("dp83867", 0x2000, 0xa231, 1, 1) },
137 { PHYINFO("88e1118r", 0x0141, 0x0e10, 1, 1) },
138 { PHYINFO("88e1510", 0x0141, 0x0dd0, 1, 1) },
139};
140
141
142typedef struct EthPhy {
143 MDIOSlave parent_object;
144
145
146 uint16_t regs[NUM_PHY_REGS];
147 const uint16_t *regs_readonly_mask;
148
149 bool link;
150
151 PhyPartInfo *part;
152} EthPhy;
153
154typedef struct EthPhyClass {
155 MDIOSlaveClass parent_class;
156
157 PhyPartInfo *part;
158} EthPhyClass;
159
160#endif
161