1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#ifndef NPCM7XX_EMC_H
18#define NPCM7XX_EMC_H
19
20#include "hw/irq.h"
21#include "hw/sysbus.h"
22#include "net/net.h"
23
24
25enum NPCM7xxPWMRegister {
26
27 REG_CAMCMR,
28 REG_CAMEN,
29
30
31 REG_CAMM_BASE,
32 REG_CAML_BASE,
33 REG_CAMML_LAST = 0x21,
34
35 REG_TXDLSA = 0x22,
36 REG_RXDLSA,
37 REG_MCMDR,
38 REG_MIID,
39 REG_MIIDA,
40 REG_FFTCR,
41 REG_TSDR,
42 REG_RSDR,
43 REG_DMARFC,
44 REG_MIEN,
45
46
47 REG_MISTA,
48 REG_MGSTA,
49 REG_MPCNT,
50 REG_MRPC,
51 REG_MRPCC,
52 REG_MREPC,
53 REG_DMARFS,
54 REG_CTXDSA,
55 REG_CTXBSA,
56 REG_CRXDSA,
57 REG_CRXBSA,
58
59 NPCM7XX_NUM_EMC_REGS,
60};
61
62
63
64#define REG_CAMCMR_ECMP (1 << 4)
65
66#define REG_CAMCMR_CCAM (1 << 3)
67
68#define REG_CAMCMR_ABP (1 << 2)
69
70#define REG_CAMCMR_AMP (1 << 1)
71
72#define REG_CAMCMR_AUP (1 << 0)
73
74
75
76#define REG_MCMDR_SWR (1 << 24)
77
78#define REG_MCMDR_LBK (1 << 21)
79
80#define REG_MCMDR_OPMOD (1 << 20)
81
82#define REG_MCMDR_ENMDC (1 << 19)
83
84#define REG_MCMDR_FDUP (1 << 18)
85
86#define REG_MCMDR_ENSEQ (1 << 17)
87
88#define REG_MCMDR_SDPZ (1 << 16)
89
90#define REG_MCMDR_NDEF (1 << 9)
91
92#define REG_MCMDR_TXON (1 << 8)
93
94#define REG_MCMDR_SPCRC (1 << 5)
95
96#define REG_MCMDR_AEP (1 << 4)
97
98#define REG_MCMDR_ACP (1 << 3)
99
100#define REG_MCMDR_ARP (1 << 2)
101
102#define REG_MCMDR_ALP (1 << 1)
103
104#define REG_MCMDR_RXON (1 << 0)
105
106
107
108#define REG_MIEN_ENTDU (1 << 23)
109
110#define REG_MIEN_ENTXCP (1 << 18)
111
112#define REG_MIEN_ENTXINTR (1 << 16)
113
114#define REG_MIEN_ENRDU (1 << 10)
115
116#define REG_MIEN_ENRXGD (1 << 4)
117
118#define REG_MIEN_ENRXINTR (1 << 0)
119
120
121
122
123#define REG_MISTA_TXBERR (1 << 24)
124
125#define REG_MISTA_TDU (1 << 23)
126
127#define REG_MISTA_TXCP (1 << 18)
128
129#define REG_MISTA_TXINTR (1 << 16)
130
131#define REG_MISTA_RXBERR (1 << 11)
132
133#define REG_MISTA_RDU (1 << 10)
134
135#define REG_MISTA_DENI (1 << 9)
136
137#define REG_MISTA_DFOI (1 << 8)
138
139#define REG_MISTA_RXGD (1 << 4)
140
141#define REG_MISTA_PTLE (1 << 3)
142
143#define REG_MISTA_RXINTR (1 << 0)
144
145
146
147#define REG_MGSTA_TXHA (1 << 11)
148
149#define REG_MGSTA_RXHA (1 << 11)
150
151
152
153#define REG_DMARFC_RXMS(word) extract32((word), 0, 16)
154
155
156
157#define REG_MIIDA_BUSY (1 << 17)
158
159
160typedef struct NPCM7xxEMCTxDesc NPCM7xxEMCTxDesc;
161typedef struct NPCM7xxEMCRxDesc NPCM7xxEMCRxDesc;
162
163struct NPCM7xxEMCTxDesc {
164 uint32_t flags;
165 uint32_t txbsa;
166 uint32_t status_and_length;
167 uint32_t ntxdsa;
168};
169
170struct NPCM7xxEMCRxDesc {
171 uint32_t status_and_length;
172 uint32_t rxbsa;
173 uint32_t reserved;
174 uint32_t nrxdsa;
175};
176
177
178
179#define TX_DESC_FLAG_OWNER_MASK (1 << 31)
180
181#define TX_DESC_FLAG_INTEN (1 << 2)
182
183#define TX_DESC_FLAG_CRCAPP (1 << 1)
184
185#define TX_DESC_FLAG_PADEN (1 << 0)
186
187
188
189#define TX_DESC_STATUS_CCNT_SHIFT 28
190#define TX_DESC_STATUS_CCNT_BITSIZE 4
191
192#define TX_DESC_STATUS_SQE (1 << 26)
193
194#define TX_DESC_STATUS_PAU (1 << 25)
195
196#define TX_DESC_STATUS_TXHA (1 << 24)
197
198#define TX_DESC_STATUS_LC (1 << 23)
199
200#define TX_DESC_STATUS_TXABT (1 << 22)
201
202#define TX_DESC_STATUS_NCS (1 << 21)
203
204#define TX_DESC_STATUS_EXDEF (1 << 20)
205
206#define TX_DESC_STATUS_TXCP (1 << 19)
207
208#define TX_DESC_STATUS_DEF (1 << 17)
209
210#define TX_DESC_STATUS_TXINTR (1 << 16)
211
212#define TX_DESC_PKT_LEN(word) extract32((word), 0, 16)
213
214
215#define TX_DESC_TXBSA(word) ((uint32_t) (word) & ~3u)
216
217
218#define TX_DESC_NTXDSA(word) ((uint32_t) (word) & ~3u)
219
220
221
222#define RX_DESC_STATUS_OWNER_SHIFT 30
223#define RX_DESC_STATUS_OWNER_BITSIZE 2
224#define RX_DESC_STATUS_OWNER_MASK (3 << RX_DESC_STATUS_OWNER_SHIFT)
225
226#define RX_DESC_STATUS_RP (1 << 22)
227
228#define RX_DESC_STATUS_ALIE (1 << 21)
229
230#define RX_DESC_STATUS_RXGD (1 << 20)
231
232#define RX_DESC_STATUS_PTLE (1 << 19)
233
234#define RX_DESC_STATUS_CRCE (1 << 17)
235
236#define RX_DESC_STATUS_RXINTR (1 << 16)
237
238#define RX_DESC_PKT_LEN(word) extract32((word), 0, 16)
239
240
241#define RX_DESC_RXBSA(word) ((uint32_t) (word) & ~3u)
242
243
244#define RX_DESC_NRXDSA(word) ((uint32_t) (word) & ~3u)
245
246
247#define MIN_PACKET_LENGTH 64
248
249struct NPCM7xxEMCState {
250
251 SysBusDevice parent;
252
253
254 MemoryRegion iomem;
255
256 qemu_irq tx_irq;
257 qemu_irq rx_irq;
258
259 NICState *nic;
260 NICConf conf;
261
262
263 uint8_t emc_num;
264
265 uint32_t regs[NPCM7XX_NUM_EMC_REGS];
266
267
268
269
270
271 bool tx_active;
272
273
274
275
276
277 bool rx_active;
278};
279
280#define TYPE_NPCM7XX_EMC "npcm7xx-emc"
281OBJECT_DECLARE_SIMPLE_TYPE(NPCM7xxEMCState, NPCM7XX_EMC)
282
283#endif
284