net: cadence_gem: Define access permission for interrupt registers
[qemu/ar7.git] / hw / net / cadence_gem.c
blob72e7cf99d7c9d6a3ceabdc79fdefbf3c7e1478d3
1 /*
2 * QEMU Cadence GEM emulation
4 * Copyright (c) 2011 Xilinx, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
25 #include "qemu/osdep.h"
26 #include <zlib.h> /* For crc32 */
28 #include "hw/irq.h"
29 #include "hw/net/cadence_gem.h"
30 #include "hw/qdev-properties.h"
31 #include "migration/vmstate.h"
32 #include "qapi/error.h"
33 #include "qemu/log.h"
34 #include "qemu/module.h"
35 #include "sysemu/dma.h"
36 #include "net/checksum.h"
38 #define CADENCE_GEM_ERR_DEBUG 0
39 #define DB_PRINT(...) do {\
40 if (CADENCE_GEM_ERR_DEBUG) { \
41 qemu_log(": %s: ", __func__); \
42 qemu_log(__VA_ARGS__); \
43 } \
44 } while (0)
46 #define GEM_NWCTRL (0x00000000/4) /* Network Control reg */
47 #define GEM_NWCFG (0x00000004/4) /* Network Config reg */
48 #define GEM_NWSTATUS (0x00000008/4) /* Network Status reg */
49 #define GEM_USERIO (0x0000000C/4) /* User IO reg */
50 #define GEM_DMACFG (0x00000010/4) /* DMA Control reg */
51 #define GEM_TXSTATUS (0x00000014/4) /* TX Status reg */
52 #define GEM_RXQBASE (0x00000018/4) /* RX Q Base address reg */
53 #define GEM_TXQBASE (0x0000001C/4) /* TX Q Base address reg */
54 #define GEM_RXSTATUS (0x00000020/4) /* RX Status reg */
55 #define GEM_ISR (0x00000024/4) /* Interrupt Status reg */
56 #define GEM_IER (0x00000028/4) /* Interrupt Enable reg */
57 #define GEM_IDR (0x0000002C/4) /* Interrupt Disable reg */
58 #define GEM_IMR (0x00000030/4) /* Interrupt Mask reg */
59 #define GEM_PHYMNTNC (0x00000034/4) /* Phy Maintenance reg */
60 #define GEM_RXPAUSE (0x00000038/4) /* RX Pause Time reg */
61 #define GEM_TXPAUSE (0x0000003C/4) /* TX Pause Time reg */
62 #define GEM_TXPARTIALSF (0x00000040/4) /* TX Partial Store and Forward */
63 #define GEM_RXPARTIALSF (0x00000044/4) /* RX Partial Store and Forward */
64 #define GEM_HASHLO (0x00000080/4) /* Hash Low address reg */
65 #define GEM_HASHHI (0x00000084/4) /* Hash High address reg */
66 #define GEM_SPADDR1LO (0x00000088/4) /* Specific addr 1 low reg */
67 #define GEM_SPADDR1HI (0x0000008C/4) /* Specific addr 1 high reg */
68 #define GEM_SPADDR2LO (0x00000090/4) /* Specific addr 2 low reg */
69 #define GEM_SPADDR2HI (0x00000094/4) /* Specific addr 2 high reg */
70 #define GEM_SPADDR3LO (0x00000098/4) /* Specific addr 3 low reg */
71 #define GEM_SPADDR3HI (0x0000009C/4) /* Specific addr 3 high reg */
72 #define GEM_SPADDR4LO (0x000000A0/4) /* Specific addr 4 low reg */
73 #define GEM_SPADDR4HI (0x000000A4/4) /* Specific addr 4 high reg */
74 #define GEM_TIDMATCH1 (0x000000A8/4) /* Type ID1 Match reg */
75 #define GEM_TIDMATCH2 (0x000000AC/4) /* Type ID2 Match reg */
76 #define GEM_TIDMATCH3 (0x000000B0/4) /* Type ID3 Match reg */
77 #define GEM_TIDMATCH4 (0x000000B4/4) /* Type ID4 Match reg */
78 #define GEM_WOLAN (0x000000B8/4) /* Wake on LAN reg */
79 #define GEM_IPGSTRETCH (0x000000BC/4) /* IPG Stretch reg */
80 #define GEM_SVLAN (0x000000C0/4) /* Stacked VLAN reg */
81 #define GEM_MODID (0x000000FC/4) /* Module ID reg */
82 #define GEM_OCTTXLO (0x00000100/4) /* Octects transmitted Low reg */
83 #define GEM_OCTTXHI (0x00000104/4) /* Octects transmitted High reg */
84 #define GEM_TXCNT (0x00000108/4) /* Error-free Frames transmitted */
85 #define GEM_TXBCNT (0x0000010C/4) /* Error-free Broadcast Frames */
86 #define GEM_TXMCNT (0x00000110/4) /* Error-free Multicast Frame */
87 #define GEM_TXPAUSECNT (0x00000114/4) /* Pause Frames Transmitted */
88 #define GEM_TX64CNT (0x00000118/4) /* Error-free 64 TX */
89 #define GEM_TX65CNT (0x0000011C/4) /* Error-free 65-127 TX */
90 #define GEM_TX128CNT (0x00000120/4) /* Error-free 128-255 TX */
91 #define GEM_TX256CNT (0x00000124/4) /* Error-free 256-511 */
92 #define GEM_TX512CNT (0x00000128/4) /* Error-free 512-1023 TX */
93 #define GEM_TX1024CNT (0x0000012C/4) /* Error-free 1024-1518 TX */
94 #define GEM_TX1519CNT (0x00000130/4) /* Error-free larger than 1519 TX */
95 #define GEM_TXURUNCNT (0x00000134/4) /* TX under run error counter */
96 #define GEM_SINGLECOLLCNT (0x00000138/4) /* Single Collision Frames */
97 #define GEM_MULTCOLLCNT (0x0000013C/4) /* Multiple Collision Frames */
98 #define GEM_EXCESSCOLLCNT (0x00000140/4) /* Excessive Collision Frames */
99 #define GEM_LATECOLLCNT (0x00000144/4) /* Late Collision Frames */
100 #define GEM_DEFERTXCNT (0x00000148/4) /* Deferred Transmission Frames */
101 #define GEM_CSENSECNT (0x0000014C/4) /* Carrier Sense Error Counter */
102 #define GEM_OCTRXLO (0x00000150/4) /* Octects Received register Low */
103 #define GEM_OCTRXHI (0x00000154/4) /* Octects Received register High */
104 #define GEM_RXCNT (0x00000158/4) /* Error-free Frames Received */
105 #define GEM_RXBROADCNT (0x0000015C/4) /* Error-free Broadcast Frames RX */
106 #define GEM_RXMULTICNT (0x00000160/4) /* Error-free Multicast Frames RX */
107 #define GEM_RXPAUSECNT (0x00000164/4) /* Pause Frames Received Counter */
108 #define GEM_RX64CNT (0x00000168/4) /* Error-free 64 byte Frames RX */
109 #define GEM_RX65CNT (0x0000016C/4) /* Error-free 65-127B Frames RX */
110 #define GEM_RX128CNT (0x00000170/4) /* Error-free 128-255B Frames RX */
111 #define GEM_RX256CNT (0x00000174/4) /* Error-free 256-512B Frames RX */
112 #define GEM_RX512CNT (0x00000178/4) /* Error-free 512-1023B Frames RX */
113 #define GEM_RX1024CNT (0x0000017C/4) /* Error-free 1024-1518B Frames RX */
114 #define GEM_RX1519CNT (0x00000180/4) /* Error-free 1519-max Frames RX */
115 #define GEM_RXUNDERCNT (0x00000184/4) /* Undersize Frames Received */
116 #define GEM_RXOVERCNT (0x00000188/4) /* Oversize Frames Received */
117 #define GEM_RXJABCNT (0x0000018C/4) /* Jabbers Received Counter */
118 #define GEM_RXFCSCNT (0x00000190/4) /* Frame Check seq. Error Counter */
119 #define GEM_RXLENERRCNT (0x00000194/4) /* Length Field Error Counter */
120 #define GEM_RXSYMERRCNT (0x00000198/4) /* Symbol Error Counter */
121 #define GEM_RXALIGNERRCNT (0x0000019C/4) /* Alignment Error Counter */
122 #define GEM_RXRSCERRCNT (0x000001A0/4) /* Receive Resource Error Counter */
123 #define GEM_RXORUNCNT (0x000001A4/4) /* Receive Overrun Counter */
124 #define GEM_RXIPCSERRCNT (0x000001A8/4) /* IP header Checksum Error Counter */
125 #define GEM_RXTCPCCNT (0x000001AC/4) /* TCP Checksum Error Counter */
126 #define GEM_RXUDPCCNT (0x000001B0/4) /* UDP Checksum Error Counter */
128 #define GEM_1588S (0x000001D0/4) /* 1588 Timer Seconds */
129 #define GEM_1588NS (0x000001D4/4) /* 1588 Timer Nanoseconds */
130 #define GEM_1588ADJ (0x000001D8/4) /* 1588 Timer Adjust */
131 #define GEM_1588INC (0x000001DC/4) /* 1588 Timer Increment */
132 #define GEM_PTPETXS (0x000001E0/4) /* PTP Event Frame Transmitted (s) */
133 #define GEM_PTPETXNS (0x000001E4/4) /* PTP Event Frame Transmitted (ns) */
134 #define GEM_PTPERXS (0x000001E8/4) /* PTP Event Frame Received (s) */
135 #define GEM_PTPERXNS (0x000001EC/4) /* PTP Event Frame Received (ns) */
136 #define GEM_PTPPTXS (0x000001E0/4) /* PTP Peer Frame Transmitted (s) */
137 #define GEM_PTPPTXNS (0x000001E4/4) /* PTP Peer Frame Transmitted (ns) */
138 #define GEM_PTPPRXS (0x000001E8/4) /* PTP Peer Frame Received (s) */
139 #define GEM_PTPPRXNS (0x000001EC/4) /* PTP Peer Frame Received (ns) */
141 /* Design Configuration Registers */
142 #define GEM_DESCONF (0x00000280/4)
143 #define GEM_DESCONF2 (0x00000284/4)
144 #define GEM_DESCONF3 (0x00000288/4)
145 #define GEM_DESCONF4 (0x0000028C/4)
146 #define GEM_DESCONF5 (0x00000290/4)
147 #define GEM_DESCONF6 (0x00000294/4)
148 #define GEM_DESCONF6_64B_MASK (1U << 23)
149 #define GEM_DESCONF7 (0x00000298/4)
151 #define GEM_INT_Q1_STATUS (0x00000400 / 4)
152 #define GEM_INT_Q1_MASK (0x00000640 / 4)
154 #define GEM_TRANSMIT_Q1_PTR (0x00000440 / 4)
155 #define GEM_TRANSMIT_Q7_PTR (GEM_TRANSMIT_Q1_PTR + 6)
157 #define GEM_RECEIVE_Q1_PTR (0x00000480 / 4)
158 #define GEM_RECEIVE_Q7_PTR (GEM_RECEIVE_Q1_PTR + 6)
160 #define GEM_TBQPH (0x000004C8 / 4)
161 #define GEM_RBQPH (0x000004D4 / 4)
163 #define GEM_INT_Q1_ENABLE (0x00000600 / 4)
164 #define GEM_INT_Q7_ENABLE (GEM_INT_Q1_ENABLE + 6)
166 #define GEM_INT_Q1_DISABLE (0x00000620 / 4)
167 #define GEM_INT_Q7_DISABLE (GEM_INT_Q1_DISABLE + 6)
169 #define GEM_INT_Q1_MASK (0x00000640 / 4)
170 #define GEM_INT_Q7_MASK (GEM_INT_Q1_MASK + 6)
172 #define GEM_SCREENING_TYPE1_REGISTER_0 (0x00000500 / 4)
174 #define GEM_ST1R_UDP_PORT_MATCH_ENABLE (1 << 29)
175 #define GEM_ST1R_DSTC_ENABLE (1 << 28)
176 #define GEM_ST1R_UDP_PORT_MATCH_SHIFT (12)
177 #define GEM_ST1R_UDP_PORT_MATCH_WIDTH (27 - GEM_ST1R_UDP_PORT_MATCH_SHIFT + 1)
178 #define GEM_ST1R_DSTC_MATCH_SHIFT (4)
179 #define GEM_ST1R_DSTC_MATCH_WIDTH (11 - GEM_ST1R_DSTC_MATCH_SHIFT + 1)
180 #define GEM_ST1R_QUEUE_SHIFT (0)
181 #define GEM_ST1R_QUEUE_WIDTH (3 - GEM_ST1R_QUEUE_SHIFT + 1)
183 #define GEM_SCREENING_TYPE2_REGISTER_0 (0x00000540 / 4)
185 #define GEM_ST2R_COMPARE_A_ENABLE (1 << 18)
186 #define GEM_ST2R_COMPARE_A_SHIFT (13)
187 #define GEM_ST2R_COMPARE_WIDTH (17 - GEM_ST2R_COMPARE_A_SHIFT + 1)
188 #define GEM_ST2R_ETHERTYPE_ENABLE (1 << 12)
189 #define GEM_ST2R_ETHERTYPE_INDEX_SHIFT (9)
190 #define GEM_ST2R_ETHERTYPE_INDEX_WIDTH (11 - GEM_ST2R_ETHERTYPE_INDEX_SHIFT \
191 + 1)
192 #define GEM_ST2R_QUEUE_SHIFT (0)
193 #define GEM_ST2R_QUEUE_WIDTH (3 - GEM_ST2R_QUEUE_SHIFT + 1)
195 #define GEM_SCREENING_TYPE2_ETHERTYPE_REG_0 (0x000006e0 / 4)
196 #define GEM_TYPE2_COMPARE_0_WORD_0 (0x00000700 / 4)
198 #define GEM_T2CW1_COMPARE_OFFSET_SHIFT (7)
199 #define GEM_T2CW1_COMPARE_OFFSET_WIDTH (8 - GEM_T2CW1_COMPARE_OFFSET_SHIFT + 1)
200 #define GEM_T2CW1_OFFSET_VALUE_SHIFT (0)
201 #define GEM_T2CW1_OFFSET_VALUE_WIDTH (6 - GEM_T2CW1_OFFSET_VALUE_SHIFT + 1)
203 /*****************************************/
204 #define GEM_NWCTRL_TXSTART 0x00000200 /* Transmit Enable */
205 #define GEM_NWCTRL_TXENA 0x00000008 /* Transmit Enable */
206 #define GEM_NWCTRL_RXENA 0x00000004 /* Receive Enable */
207 #define GEM_NWCTRL_LOCALLOOP 0x00000002 /* Local Loopback */
209 #define GEM_NWCFG_STRIP_FCS 0x00020000 /* Strip FCS field */
210 #define GEM_NWCFG_LERR_DISC 0x00010000 /* Discard RX frames with len err */
211 #define GEM_NWCFG_BUFF_OFST_M 0x0000C000 /* Receive buffer offset mask */
212 #define GEM_NWCFG_BUFF_OFST_S 14 /* Receive buffer offset shift */
213 #define GEM_NWCFG_UCAST_HASH 0x00000080 /* accept unicast if hash match */
214 #define GEM_NWCFG_MCAST_HASH 0x00000040 /* accept multicast if hash match */
215 #define GEM_NWCFG_BCAST_REJ 0x00000020 /* Reject broadcast packets */
216 #define GEM_NWCFG_PROMISC 0x00000010 /* Accept all packets */
218 #define GEM_DMACFG_ADDR_64B (1U << 30)
219 #define GEM_DMACFG_TX_BD_EXT (1U << 29)
220 #define GEM_DMACFG_RX_BD_EXT (1U << 28)
221 #define GEM_DMACFG_RBUFSZ_M 0x00FF0000 /* DMA RX Buffer Size mask */
222 #define GEM_DMACFG_RBUFSZ_S 16 /* DMA RX Buffer Size shift */
223 #define GEM_DMACFG_RBUFSZ_MUL 64 /* DMA RX Buffer Size multiplier */
224 #define GEM_DMACFG_TXCSUM_OFFL 0x00000800 /* Transmit checksum offload */
226 #define GEM_TXSTATUS_TXCMPL 0x00000020 /* Transmit Complete */
227 #define GEM_TXSTATUS_USED 0x00000001 /* sw owned descriptor encountered */
229 #define GEM_RXSTATUS_FRMRCVD 0x00000002 /* Frame received */
230 #define GEM_RXSTATUS_NOBUF 0x00000001 /* Buffer unavailable */
232 /* GEM_ISR GEM_IER GEM_IDR GEM_IMR */
233 #define GEM_INT_TXCMPL 0x00000080 /* Transmit Complete */
234 #define GEM_INT_TXUSED 0x00000008
235 #define GEM_INT_RXUSED 0x00000004
236 #define GEM_INT_RXCMPL 0x00000002
238 #define GEM_PHYMNTNC_OP_R 0x20000000 /* read operation */
239 #define GEM_PHYMNTNC_OP_W 0x10000000 /* write operation */
240 #define GEM_PHYMNTNC_ADDR 0x0F800000 /* Address bits */
241 #define GEM_PHYMNTNC_ADDR_SHFT 23
242 #define GEM_PHYMNTNC_REG 0x007C0000 /* register bits */
243 #define GEM_PHYMNTNC_REG_SHIFT 18
245 /* Marvell PHY definitions */
246 #define BOARD_PHY_ADDRESS 23 /* PHY address we will emulate a device at */
248 #define PHY_REG_CONTROL 0
249 #define PHY_REG_STATUS 1
250 #define PHY_REG_PHYID1 2
251 #define PHY_REG_PHYID2 3
252 #define PHY_REG_ANEGADV 4
253 #define PHY_REG_LINKPABIL 5
254 #define PHY_REG_ANEGEXP 6
255 #define PHY_REG_NEXTP 7
256 #define PHY_REG_LINKPNEXTP 8
257 #define PHY_REG_100BTCTRL 9
258 #define PHY_REG_1000BTSTAT 10
259 #define PHY_REG_EXTSTAT 15
260 #define PHY_REG_PHYSPCFC_CTL 16
261 #define PHY_REG_PHYSPCFC_ST 17
262 #define PHY_REG_INT_EN 18
263 #define PHY_REG_INT_ST 19
264 #define PHY_REG_EXT_PHYSPCFC_CTL 20
265 #define PHY_REG_RXERR 21
266 #define PHY_REG_EACD 22
267 #define PHY_REG_LED 24
268 #define PHY_REG_LED_OVRD 25
269 #define PHY_REG_EXT_PHYSPCFC_CTL2 26
270 #define PHY_REG_EXT_PHYSPCFC_ST 27
271 #define PHY_REG_CABLE_DIAG 28
273 #define PHY_REG_CONTROL_RST 0x8000
274 #define PHY_REG_CONTROL_LOOP 0x4000
275 #define PHY_REG_CONTROL_ANEG 0x1000
276 #define PHY_REG_CONTROL_ANRESTART 0x0200
278 #define PHY_REG_STATUS_LINK 0x0004
279 #define PHY_REG_STATUS_ANEGCMPL 0x0020
281 #define PHY_REG_INT_ST_ANEGCMPL 0x0800
282 #define PHY_REG_INT_ST_LINKC 0x0400
283 #define PHY_REG_INT_ST_ENERGY 0x0010
285 /***********************************************************************/
286 #define GEM_RX_REJECT (-1)
287 #define GEM_RX_PROMISCUOUS_ACCEPT (-2)
288 #define GEM_RX_BROADCAST_ACCEPT (-3)
289 #define GEM_RX_MULTICAST_HASH_ACCEPT (-4)
290 #define GEM_RX_UNICAST_HASH_ACCEPT (-5)
292 #define GEM_RX_SAR_ACCEPT 0
294 /***********************************************************************/
296 #define DESC_1_USED 0x80000000
297 #define DESC_1_LENGTH 0x00001FFF
299 #define DESC_1_TX_WRAP 0x40000000
300 #define DESC_1_TX_LAST 0x00008000
302 #define DESC_0_RX_WRAP 0x00000002
303 #define DESC_0_RX_OWNERSHIP 0x00000001
305 #define R_DESC_1_RX_SAR_SHIFT 25
306 #define R_DESC_1_RX_SAR_LENGTH 2
307 #define R_DESC_1_RX_SAR_MATCH (1 << 27)
308 #define R_DESC_1_RX_UNICAST_HASH (1 << 29)
309 #define R_DESC_1_RX_MULTICAST_HASH (1 << 30)
310 #define R_DESC_1_RX_BROADCAST (1 << 31)
312 #define DESC_1_RX_SOF 0x00004000
313 #define DESC_1_RX_EOF 0x00008000
315 #define GEM_MODID_VALUE 0x00020118
317 static inline uint64_t tx_desc_get_buffer(CadenceGEMState *s, uint32_t *desc)
319 uint64_t ret = desc[0];
321 if (s->regs[GEM_DMACFG] & GEM_DMACFG_ADDR_64B) {
322 ret |= (uint64_t)desc[2] << 32;
324 return ret;
327 static inline unsigned tx_desc_get_used(uint32_t *desc)
329 return (desc[1] & DESC_1_USED) ? 1 : 0;
332 static inline void tx_desc_set_used(uint32_t *desc)
334 desc[1] |= DESC_1_USED;
337 static inline unsigned tx_desc_get_wrap(uint32_t *desc)
339 return (desc[1] & DESC_1_TX_WRAP) ? 1 : 0;
342 static inline unsigned tx_desc_get_last(uint32_t *desc)
344 return (desc[1] & DESC_1_TX_LAST) ? 1 : 0;
347 static inline void tx_desc_set_last(uint32_t *desc)
349 desc[1] |= DESC_1_TX_LAST;
352 static inline unsigned tx_desc_get_length(uint32_t *desc)
354 return desc[1] & DESC_1_LENGTH;
357 static inline void print_gem_tx_desc(uint32_t *desc, uint8_t queue)
359 DB_PRINT("TXDESC (queue %" PRId8 "):\n", queue);
360 DB_PRINT("bufaddr: 0x%08x\n", *desc);
361 DB_PRINT("used_hw: %d\n", tx_desc_get_used(desc));
362 DB_PRINT("wrap: %d\n", tx_desc_get_wrap(desc));
363 DB_PRINT("last: %d\n", tx_desc_get_last(desc));
364 DB_PRINT("length: %d\n", tx_desc_get_length(desc));
367 static inline uint64_t rx_desc_get_buffer(CadenceGEMState *s, uint32_t *desc)
369 uint64_t ret = desc[0] & ~0x3UL;
371 if (s->regs[GEM_DMACFG] & GEM_DMACFG_ADDR_64B) {
372 ret |= (uint64_t)desc[2] << 32;
374 return ret;
377 static inline int gem_get_desc_len(CadenceGEMState *s, bool rx_n_tx)
379 int ret = 2;
381 if (s->regs[GEM_DMACFG] & GEM_DMACFG_ADDR_64B) {
382 ret += 2;
384 if (s->regs[GEM_DMACFG] & (rx_n_tx ? GEM_DMACFG_RX_BD_EXT
385 : GEM_DMACFG_TX_BD_EXT)) {
386 ret += 2;
389 assert(ret <= DESC_MAX_NUM_WORDS);
390 return ret;
393 static inline unsigned rx_desc_get_wrap(uint32_t *desc)
395 return desc[0] & DESC_0_RX_WRAP ? 1 : 0;
398 static inline unsigned rx_desc_get_ownership(uint32_t *desc)
400 return desc[0] & DESC_0_RX_OWNERSHIP ? 1 : 0;
403 static inline void rx_desc_set_ownership(uint32_t *desc)
405 desc[0] |= DESC_0_RX_OWNERSHIP;
408 static inline void rx_desc_set_sof(uint32_t *desc)
410 desc[1] |= DESC_1_RX_SOF;
413 static inline void rx_desc_clear_control(uint32_t *desc)
415 desc[1] = 0;
418 static inline void rx_desc_set_eof(uint32_t *desc)
420 desc[1] |= DESC_1_RX_EOF;
423 static inline void rx_desc_set_length(uint32_t *desc, unsigned len)
425 desc[1] &= ~DESC_1_LENGTH;
426 desc[1] |= len;
429 static inline void rx_desc_set_broadcast(uint32_t *desc)
431 desc[1] |= R_DESC_1_RX_BROADCAST;
434 static inline void rx_desc_set_unicast_hash(uint32_t *desc)
436 desc[1] |= R_DESC_1_RX_UNICAST_HASH;
439 static inline void rx_desc_set_multicast_hash(uint32_t *desc)
441 desc[1] |= R_DESC_1_RX_MULTICAST_HASH;
444 static inline void rx_desc_set_sar(uint32_t *desc, int sar_idx)
446 desc[1] = deposit32(desc[1], R_DESC_1_RX_SAR_SHIFT, R_DESC_1_RX_SAR_LENGTH,
447 sar_idx);
448 desc[1] |= R_DESC_1_RX_SAR_MATCH;
451 /* The broadcast MAC address: 0xFFFFFFFFFFFF */
452 static const uint8_t broadcast_addr[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
455 * gem_init_register_masks:
456 * One time initialization.
457 * Set masks to identify which register bits have magical clear properties
459 static void gem_init_register_masks(CadenceGEMState *s)
461 unsigned int i;
462 /* Mask of register bits which are read only */
463 memset(&s->regs_ro[0], 0, sizeof(s->regs_ro));
464 s->regs_ro[GEM_NWCTRL] = 0xFFF80000;
465 s->regs_ro[GEM_NWSTATUS] = 0xFFFFFFFF;
466 s->regs_ro[GEM_DMACFG] = 0x8E00F000;
467 s->regs_ro[GEM_TXSTATUS] = 0xFFFFFE08;
468 s->regs_ro[GEM_RXQBASE] = 0x00000003;
469 s->regs_ro[GEM_TXQBASE] = 0x00000003;
470 s->regs_ro[GEM_RXSTATUS] = 0xFFFFFFF0;
471 s->regs_ro[GEM_ISR] = 0xFFFFFFFF;
472 s->regs_ro[GEM_IMR] = 0xFFFFFFFF;
473 s->regs_ro[GEM_MODID] = 0xFFFFFFFF;
474 for (i = 0; i < s->num_priority_queues; i++) {
475 s->regs_ro[GEM_INT_Q1_STATUS + i] = 0xFFFFFFFF;
476 s->regs_ro[GEM_INT_Q1_ENABLE + i] = 0xFFFFF319;
477 s->regs_ro[GEM_INT_Q1_DISABLE + i] = 0xFFFFF319;
478 s->regs_ro[GEM_INT_Q1_MASK + i] = 0xFFFFFFFF;
481 /* Mask of register bits which are clear on read */
482 memset(&s->regs_rtc[0], 0, sizeof(s->regs_rtc));
483 s->regs_rtc[GEM_ISR] = 0xFFFFFFFF;
484 for (i = 0; i < s->num_priority_queues; i++) {
485 s->regs_rtc[GEM_INT_Q1_STATUS + i] = 0x00000CE6;
488 /* Mask of register bits which are write 1 to clear */
489 memset(&s->regs_w1c[0], 0, sizeof(s->regs_w1c));
490 s->regs_w1c[GEM_TXSTATUS] = 0x000001F7;
491 s->regs_w1c[GEM_RXSTATUS] = 0x0000000F;
493 /* Mask of register bits which are write only */
494 memset(&s->regs_wo[0], 0, sizeof(s->regs_wo));
495 s->regs_wo[GEM_NWCTRL] = 0x00073E60;
496 s->regs_wo[GEM_IER] = 0x07FFFFFF;
497 s->regs_wo[GEM_IDR] = 0x07FFFFFF;
498 for (i = 0; i < s->num_priority_queues; i++) {
499 s->regs_wo[GEM_INT_Q1_ENABLE + i] = 0x00000CE6;
500 s->regs_wo[GEM_INT_Q1_DISABLE + i] = 0x00000CE6;
505 * phy_update_link:
506 * Make the emulated PHY link state match the QEMU "interface" state.
508 static void phy_update_link(CadenceGEMState *s)
510 DB_PRINT("down %d\n", qemu_get_queue(s->nic)->link_down);
512 /* Autonegotiation status mirrors link status. */
513 if (qemu_get_queue(s->nic)->link_down) {
514 s->phy_regs[PHY_REG_STATUS] &= ~(PHY_REG_STATUS_ANEGCMPL |
515 PHY_REG_STATUS_LINK);
516 s->phy_regs[PHY_REG_INT_ST] |= PHY_REG_INT_ST_LINKC;
517 } else {
518 s->phy_regs[PHY_REG_STATUS] |= (PHY_REG_STATUS_ANEGCMPL |
519 PHY_REG_STATUS_LINK);
520 s->phy_regs[PHY_REG_INT_ST] |= (PHY_REG_INT_ST_LINKC |
521 PHY_REG_INT_ST_ANEGCMPL |
522 PHY_REG_INT_ST_ENERGY);
526 static bool gem_can_receive(NetClientState *nc)
528 CadenceGEMState *s;
529 int i;
531 s = qemu_get_nic_opaque(nc);
533 /* Do nothing if receive is not enabled. */
534 if (!(s->regs[GEM_NWCTRL] & GEM_NWCTRL_RXENA)) {
535 if (s->can_rx_state != 1) {
536 s->can_rx_state = 1;
537 DB_PRINT("can't receive - no enable\n");
539 return false;
542 for (i = 0; i < s->num_priority_queues; i++) {
543 if (rx_desc_get_ownership(s->rx_desc[i]) != 1) {
544 break;
548 if (i == s->num_priority_queues) {
549 if (s->can_rx_state != 2) {
550 s->can_rx_state = 2;
551 DB_PRINT("can't receive - all the buffer descriptors are busy\n");
553 return false;
556 if (s->can_rx_state != 0) {
557 s->can_rx_state = 0;
558 DB_PRINT("can receive\n");
560 return true;
564 * gem_update_int_status:
565 * Raise or lower interrupt based on current status.
567 static void gem_update_int_status(CadenceGEMState *s)
569 int i;
571 qemu_set_irq(s->irq[0], !!s->regs[GEM_ISR]);
573 for (i = 1; i < s->num_priority_queues; ++i) {
574 qemu_set_irq(s->irq[i], !!s->regs[GEM_INT_Q1_STATUS + i - 1]);
579 * gem_receive_updatestats:
580 * Increment receive statistics.
582 static void gem_receive_updatestats(CadenceGEMState *s, const uint8_t *packet,
583 unsigned bytes)
585 uint64_t octets;
587 /* Total octets (bytes) received */
588 octets = ((uint64_t)(s->regs[GEM_OCTRXLO]) << 32) |
589 s->regs[GEM_OCTRXHI];
590 octets += bytes;
591 s->regs[GEM_OCTRXLO] = octets >> 32;
592 s->regs[GEM_OCTRXHI] = octets;
594 /* Error-free Frames received */
595 s->regs[GEM_RXCNT]++;
597 /* Error-free Broadcast Frames counter */
598 if (!memcmp(packet, broadcast_addr, 6)) {
599 s->regs[GEM_RXBROADCNT]++;
602 /* Error-free Multicast Frames counter */
603 if (packet[0] == 0x01) {
604 s->regs[GEM_RXMULTICNT]++;
607 if (bytes <= 64) {
608 s->regs[GEM_RX64CNT]++;
609 } else if (bytes <= 127) {
610 s->regs[GEM_RX65CNT]++;
611 } else if (bytes <= 255) {
612 s->regs[GEM_RX128CNT]++;
613 } else if (bytes <= 511) {
614 s->regs[GEM_RX256CNT]++;
615 } else if (bytes <= 1023) {
616 s->regs[GEM_RX512CNT]++;
617 } else if (bytes <= 1518) {
618 s->regs[GEM_RX1024CNT]++;
619 } else {
620 s->regs[GEM_RX1519CNT]++;
625 * Get the MAC Address bit from the specified position
627 static unsigned get_bit(const uint8_t *mac, unsigned bit)
629 unsigned byte;
631 byte = mac[bit / 8];
632 byte >>= (bit & 0x7);
633 byte &= 1;
635 return byte;
639 * Calculate a GEM MAC Address hash index
641 static unsigned calc_mac_hash(const uint8_t *mac)
643 int index_bit, mac_bit;
644 unsigned hash_index;
646 hash_index = 0;
647 mac_bit = 5;
648 for (index_bit = 5; index_bit >= 0; index_bit--) {
649 hash_index |= (get_bit(mac, mac_bit) ^
650 get_bit(mac, mac_bit + 6) ^
651 get_bit(mac, mac_bit + 12) ^
652 get_bit(mac, mac_bit + 18) ^
653 get_bit(mac, mac_bit + 24) ^
654 get_bit(mac, mac_bit + 30) ^
655 get_bit(mac, mac_bit + 36) ^
656 get_bit(mac, mac_bit + 42)) << index_bit;
657 mac_bit--;
660 return hash_index;
664 * gem_mac_address_filter:
665 * Accept or reject this destination address?
666 * Returns:
667 * GEM_RX_REJECT: reject
668 * >= 0: Specific address accept (which matched SAR is returned)
669 * others for various other modes of accept:
670 * GEM_RM_PROMISCUOUS_ACCEPT, GEM_RX_BROADCAST_ACCEPT,
671 * GEM_RX_MULTICAST_HASH_ACCEPT or GEM_RX_UNICAST_HASH_ACCEPT
673 static int gem_mac_address_filter(CadenceGEMState *s, const uint8_t *packet)
675 uint8_t *gem_spaddr;
676 int i;
678 /* Promiscuous mode? */
679 if (s->regs[GEM_NWCFG] & GEM_NWCFG_PROMISC) {
680 return GEM_RX_PROMISCUOUS_ACCEPT;
683 if (!memcmp(packet, broadcast_addr, 6)) {
684 /* Reject broadcast packets? */
685 if (s->regs[GEM_NWCFG] & GEM_NWCFG_BCAST_REJ) {
686 return GEM_RX_REJECT;
688 return GEM_RX_BROADCAST_ACCEPT;
691 /* Accept packets -w- hash match? */
692 if ((packet[0] == 0x01 && (s->regs[GEM_NWCFG] & GEM_NWCFG_MCAST_HASH)) ||
693 (packet[0] != 0x01 && (s->regs[GEM_NWCFG] & GEM_NWCFG_UCAST_HASH))) {
694 unsigned hash_index;
696 hash_index = calc_mac_hash(packet);
697 if (hash_index < 32) {
698 if (s->regs[GEM_HASHLO] & (1<<hash_index)) {
699 return packet[0] == 0x01 ? GEM_RX_MULTICAST_HASH_ACCEPT :
700 GEM_RX_UNICAST_HASH_ACCEPT;
702 } else {
703 hash_index -= 32;
704 if (s->regs[GEM_HASHHI] & (1<<hash_index)) {
705 return packet[0] == 0x01 ? GEM_RX_MULTICAST_HASH_ACCEPT :
706 GEM_RX_UNICAST_HASH_ACCEPT;
711 /* Check all 4 specific addresses */
712 gem_spaddr = (uint8_t *)&(s->regs[GEM_SPADDR1LO]);
713 for (i = 3; i >= 0; i--) {
714 if (s->sar_active[i] && !memcmp(packet, gem_spaddr + 8 * i, 6)) {
715 return GEM_RX_SAR_ACCEPT + i;
719 /* No address match; reject the packet */
720 return GEM_RX_REJECT;
723 /* Figure out which queue the received data should be sent to */
724 static int get_queue_from_screen(CadenceGEMState *s, uint8_t *rxbuf_ptr,
725 unsigned rxbufsize)
727 uint32_t reg;
728 bool matched, mismatched;
729 int i, j;
731 for (i = 0; i < s->num_type1_screeners; i++) {
732 reg = s->regs[GEM_SCREENING_TYPE1_REGISTER_0 + i];
733 matched = false;
734 mismatched = false;
736 /* Screening is based on UDP Port */
737 if (reg & GEM_ST1R_UDP_PORT_MATCH_ENABLE) {
738 uint16_t udp_port = rxbuf_ptr[14 + 22] << 8 | rxbuf_ptr[14 + 23];
739 if (udp_port == extract32(reg, GEM_ST1R_UDP_PORT_MATCH_SHIFT,
740 GEM_ST1R_UDP_PORT_MATCH_WIDTH)) {
741 matched = true;
742 } else {
743 mismatched = true;
747 /* Screening is based on DS/TC */
748 if (reg & GEM_ST1R_DSTC_ENABLE) {
749 uint8_t dscp = rxbuf_ptr[14 + 1];
750 if (dscp == extract32(reg, GEM_ST1R_DSTC_MATCH_SHIFT,
751 GEM_ST1R_DSTC_MATCH_WIDTH)) {
752 matched = true;
753 } else {
754 mismatched = true;
758 if (matched && !mismatched) {
759 return extract32(reg, GEM_ST1R_QUEUE_SHIFT, GEM_ST1R_QUEUE_WIDTH);
763 for (i = 0; i < s->num_type2_screeners; i++) {
764 reg = s->regs[GEM_SCREENING_TYPE2_REGISTER_0 + i];
765 matched = false;
766 mismatched = false;
768 if (reg & GEM_ST2R_ETHERTYPE_ENABLE) {
769 uint16_t type = rxbuf_ptr[12] << 8 | rxbuf_ptr[13];
770 int et_idx = extract32(reg, GEM_ST2R_ETHERTYPE_INDEX_SHIFT,
771 GEM_ST2R_ETHERTYPE_INDEX_WIDTH);
773 if (et_idx > s->num_type2_screeners) {
774 qemu_log_mask(LOG_GUEST_ERROR, "Out of range ethertype "
775 "register index: %d\n", et_idx);
777 if (type == s->regs[GEM_SCREENING_TYPE2_ETHERTYPE_REG_0 +
778 et_idx]) {
779 matched = true;
780 } else {
781 mismatched = true;
785 /* Compare A, B, C */
786 for (j = 0; j < 3; j++) {
787 uint32_t cr0, cr1, mask;
788 uint16_t rx_cmp;
789 int offset;
790 int cr_idx = extract32(reg, GEM_ST2R_COMPARE_A_SHIFT + j * 6,
791 GEM_ST2R_COMPARE_WIDTH);
793 if (!(reg & (GEM_ST2R_COMPARE_A_ENABLE << (j * 6)))) {
794 continue;
796 if (cr_idx > s->num_type2_screeners) {
797 qemu_log_mask(LOG_GUEST_ERROR, "Out of range compare "
798 "register index: %d\n", cr_idx);
801 cr0 = s->regs[GEM_TYPE2_COMPARE_0_WORD_0 + cr_idx * 2];
802 cr1 = s->regs[GEM_TYPE2_COMPARE_0_WORD_0 + cr_idx * 2 + 1];
803 offset = extract32(cr1, GEM_T2CW1_OFFSET_VALUE_SHIFT,
804 GEM_T2CW1_OFFSET_VALUE_WIDTH);
806 switch (extract32(cr1, GEM_T2CW1_COMPARE_OFFSET_SHIFT,
807 GEM_T2CW1_COMPARE_OFFSET_WIDTH)) {
808 case 3: /* Skip UDP header */
809 qemu_log_mask(LOG_UNIMP, "TCP compare offsets"
810 "unimplemented - assuming UDP\n");
811 offset += 8;
812 /* Fallthrough */
813 case 2: /* skip the IP header */
814 offset += 20;
815 /* Fallthrough */
816 case 1: /* Count from after the ethertype */
817 offset += 14;
818 break;
819 case 0:
820 /* Offset from start of frame */
821 break;
824 rx_cmp = rxbuf_ptr[offset] << 8 | rxbuf_ptr[offset];
825 mask = extract32(cr0, 0, 16);
827 if ((rx_cmp & mask) == (extract32(cr0, 16, 16) & mask)) {
828 matched = true;
829 } else {
830 mismatched = true;
834 if (matched && !mismatched) {
835 return extract32(reg, GEM_ST2R_QUEUE_SHIFT, GEM_ST2R_QUEUE_WIDTH);
839 /* We made it here, assume it's queue 0 */
840 return 0;
843 static uint32_t gem_get_queue_base_addr(CadenceGEMState *s, bool tx, int q)
845 uint32_t base_addr = 0;
847 switch (q) {
848 case 0:
849 base_addr = s->regs[tx ? GEM_TXQBASE : GEM_RXQBASE];
850 break;
851 case 1 ... (MAX_PRIORITY_QUEUES - 1):
852 base_addr = s->regs[(tx ? GEM_TRANSMIT_Q1_PTR :
853 GEM_RECEIVE_Q1_PTR) + q - 1];
854 break;
855 default:
856 g_assert_not_reached();
859 return base_addr;
862 static inline uint32_t gem_get_tx_queue_base_addr(CadenceGEMState *s, int q)
864 return gem_get_queue_base_addr(s, true, q);
867 static inline uint32_t gem_get_rx_queue_base_addr(CadenceGEMState *s, int q)
869 return gem_get_queue_base_addr(s, false, q);
872 static hwaddr gem_get_desc_addr(CadenceGEMState *s, bool tx, int q)
874 hwaddr desc_addr = 0;
876 if (s->regs[GEM_DMACFG] & GEM_DMACFG_ADDR_64B) {
877 desc_addr = s->regs[tx ? GEM_TBQPH : GEM_RBQPH];
879 desc_addr <<= 32;
880 desc_addr |= tx ? s->tx_desc_addr[q] : s->rx_desc_addr[q];
881 return desc_addr;
884 static hwaddr gem_get_tx_desc_addr(CadenceGEMState *s, int q)
886 return gem_get_desc_addr(s, true, q);
889 static hwaddr gem_get_rx_desc_addr(CadenceGEMState *s, int q)
891 return gem_get_desc_addr(s, false, q);
894 static void gem_get_rx_desc(CadenceGEMState *s, int q)
896 hwaddr desc_addr = gem_get_rx_desc_addr(s, q);
898 DB_PRINT("read descriptor 0x%" HWADDR_PRIx "\n", desc_addr);
900 /* read current descriptor */
901 address_space_read(&s->dma_as, desc_addr, MEMTXATTRS_UNSPECIFIED,
902 s->rx_desc[q],
903 sizeof(uint32_t) * gem_get_desc_len(s, true));
905 /* Descriptor owned by software ? */
906 if (rx_desc_get_ownership(s->rx_desc[q]) == 1) {
907 DB_PRINT("descriptor 0x%" HWADDR_PRIx " owned by sw.\n", desc_addr);
908 s->regs[GEM_RXSTATUS] |= GEM_RXSTATUS_NOBUF;
909 s->regs[GEM_ISR] |= GEM_INT_RXUSED & ~(s->regs[GEM_IMR]);
910 /* Handle interrupt consequences */
911 gem_update_int_status(s);
916 * gem_receive:
917 * Fit a packet handed to us by QEMU into the receive descriptor ring.
919 static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size)
921 CadenceGEMState *s;
922 unsigned rxbufsize, bytes_to_copy;
923 unsigned rxbuf_offset;
924 uint8_t rxbuf[2048];
925 uint8_t *rxbuf_ptr;
926 bool first_desc = true;
927 int maf;
928 int q = 0;
930 s = qemu_get_nic_opaque(nc);
932 /* Is this destination MAC address "for us" ? */
933 maf = gem_mac_address_filter(s, buf);
934 if (maf == GEM_RX_REJECT) {
935 return -1;
938 /* Discard packets with receive length error enabled ? */
939 if (s->regs[GEM_NWCFG] & GEM_NWCFG_LERR_DISC) {
940 unsigned type_len;
942 /* Fish the ethertype / length field out of the RX packet */
943 type_len = buf[12] << 8 | buf[13];
944 /* It is a length field, not an ethertype */
945 if (type_len < 0x600) {
946 if (size < type_len) {
947 /* discard */
948 return -1;
954 * Determine configured receive buffer offset (probably 0)
956 rxbuf_offset = (s->regs[GEM_NWCFG] & GEM_NWCFG_BUFF_OFST_M) >>
957 GEM_NWCFG_BUFF_OFST_S;
959 /* The configure size of each receive buffer. Determines how many
960 * buffers needed to hold this packet.
962 rxbufsize = ((s->regs[GEM_DMACFG] & GEM_DMACFG_RBUFSZ_M) >>
963 GEM_DMACFG_RBUFSZ_S) * GEM_DMACFG_RBUFSZ_MUL;
964 bytes_to_copy = size;
966 /* Hardware allows a zero value here but warns against it. To avoid QEMU
967 * indefinite loops we enforce a minimum value here
969 if (rxbufsize < GEM_DMACFG_RBUFSZ_MUL) {
970 rxbufsize = GEM_DMACFG_RBUFSZ_MUL;
973 /* Pad to minimum length. Assume FCS field is stripped, logic
974 * below will increment it to the real minimum of 64 when
975 * not FCS stripping
977 if (size < 60) {
978 size = 60;
981 /* Strip of FCS field ? (usually yes) */
982 if (s->regs[GEM_NWCFG] & GEM_NWCFG_STRIP_FCS) {
983 rxbuf_ptr = (void *)buf;
984 } else {
985 unsigned crc_val;
987 if (size > sizeof(rxbuf) - sizeof(crc_val)) {
988 size = sizeof(rxbuf) - sizeof(crc_val);
990 bytes_to_copy = size;
991 /* The application wants the FCS field, which QEMU does not provide.
992 * We must try and calculate one.
995 memcpy(rxbuf, buf, size);
996 memset(rxbuf + size, 0, sizeof(rxbuf) - size);
997 rxbuf_ptr = rxbuf;
998 crc_val = cpu_to_le32(crc32(0, rxbuf, MAX(size, 60)));
999 memcpy(rxbuf + size, &crc_val, sizeof(crc_val));
1001 bytes_to_copy += 4;
1002 size += 4;
1005 DB_PRINT("config bufsize: %u packet size: %zd\n", rxbufsize, size);
1007 /* Find which queue we are targeting */
1008 q = get_queue_from_screen(s, rxbuf_ptr, rxbufsize);
1010 while (bytes_to_copy) {
1011 hwaddr desc_addr;
1013 /* Do nothing if receive is not enabled. */
1014 if (!gem_can_receive(nc)) {
1015 return -1;
1018 DB_PRINT("copy %" PRIu32 " bytes to 0x%" PRIx64 "\n",
1019 MIN(bytes_to_copy, rxbufsize),
1020 rx_desc_get_buffer(s, s->rx_desc[q]));
1022 /* Copy packet data to emulated DMA buffer */
1023 address_space_write(&s->dma_as, rx_desc_get_buffer(s, s->rx_desc[q]) +
1024 rxbuf_offset,
1025 MEMTXATTRS_UNSPECIFIED, rxbuf_ptr,
1026 MIN(bytes_to_copy, rxbufsize));
1027 rxbuf_ptr += MIN(bytes_to_copy, rxbufsize);
1028 bytes_to_copy -= MIN(bytes_to_copy, rxbufsize);
1030 rx_desc_clear_control(s->rx_desc[q]);
1032 /* Update the descriptor. */
1033 if (first_desc) {
1034 rx_desc_set_sof(s->rx_desc[q]);
1035 first_desc = false;
1037 if (bytes_to_copy == 0) {
1038 rx_desc_set_eof(s->rx_desc[q]);
1039 rx_desc_set_length(s->rx_desc[q], size);
1041 rx_desc_set_ownership(s->rx_desc[q]);
1043 switch (maf) {
1044 case GEM_RX_PROMISCUOUS_ACCEPT:
1045 break;
1046 case GEM_RX_BROADCAST_ACCEPT:
1047 rx_desc_set_broadcast(s->rx_desc[q]);
1048 break;
1049 case GEM_RX_UNICAST_HASH_ACCEPT:
1050 rx_desc_set_unicast_hash(s->rx_desc[q]);
1051 break;
1052 case GEM_RX_MULTICAST_HASH_ACCEPT:
1053 rx_desc_set_multicast_hash(s->rx_desc[q]);
1054 break;
1055 case GEM_RX_REJECT:
1056 abort();
1057 default: /* SAR */
1058 rx_desc_set_sar(s->rx_desc[q], maf);
1061 /* Descriptor write-back. */
1062 desc_addr = gem_get_rx_desc_addr(s, q);
1063 address_space_write(&s->dma_as, desc_addr, MEMTXATTRS_UNSPECIFIED,
1064 s->rx_desc[q],
1065 sizeof(uint32_t) * gem_get_desc_len(s, true));
1067 /* Next descriptor */
1068 if (rx_desc_get_wrap(s->rx_desc[q])) {
1069 DB_PRINT("wrapping RX descriptor list\n");
1070 s->rx_desc_addr[q] = gem_get_rx_queue_base_addr(s, q);
1071 } else {
1072 DB_PRINT("incrementing RX descriptor list\n");
1073 s->rx_desc_addr[q] += 4 * gem_get_desc_len(s, true);
1076 gem_get_rx_desc(s, q);
1079 /* Count it */
1080 gem_receive_updatestats(s, buf, size);
1082 s->regs[GEM_RXSTATUS] |= GEM_RXSTATUS_FRMRCVD;
1083 s->regs[GEM_ISR] |= GEM_INT_RXCMPL & ~(s->regs[GEM_IMR]);
1085 /* Handle interrupt consequences */
1086 gem_update_int_status(s);
1088 return size;
1092 * gem_transmit_updatestats:
1093 * Increment transmit statistics.
1095 static void gem_transmit_updatestats(CadenceGEMState *s, const uint8_t *packet,
1096 unsigned bytes)
1098 uint64_t octets;
1100 /* Total octets (bytes) transmitted */
1101 octets = ((uint64_t)(s->regs[GEM_OCTTXLO]) << 32) |
1102 s->regs[GEM_OCTTXHI];
1103 octets += bytes;
1104 s->regs[GEM_OCTTXLO] = octets >> 32;
1105 s->regs[GEM_OCTTXHI] = octets;
1107 /* Error-free Frames transmitted */
1108 s->regs[GEM_TXCNT]++;
1110 /* Error-free Broadcast Frames counter */
1111 if (!memcmp(packet, broadcast_addr, 6)) {
1112 s->regs[GEM_TXBCNT]++;
1115 /* Error-free Multicast Frames counter */
1116 if (packet[0] == 0x01) {
1117 s->regs[GEM_TXMCNT]++;
1120 if (bytes <= 64) {
1121 s->regs[GEM_TX64CNT]++;
1122 } else if (bytes <= 127) {
1123 s->regs[GEM_TX65CNT]++;
1124 } else if (bytes <= 255) {
1125 s->regs[GEM_TX128CNT]++;
1126 } else if (bytes <= 511) {
1127 s->regs[GEM_TX256CNT]++;
1128 } else if (bytes <= 1023) {
1129 s->regs[GEM_TX512CNT]++;
1130 } else if (bytes <= 1518) {
1131 s->regs[GEM_TX1024CNT]++;
1132 } else {
1133 s->regs[GEM_TX1519CNT]++;
1138 * gem_transmit:
1139 * Fish packets out of the descriptor ring and feed them to QEMU
1141 static void gem_transmit(CadenceGEMState *s)
1143 uint32_t desc[DESC_MAX_NUM_WORDS];
1144 hwaddr packet_desc_addr;
1145 uint8_t tx_packet[2048];
1146 uint8_t *p;
1147 unsigned total_bytes;
1148 int q = 0;
1150 /* Do nothing if transmit is not enabled. */
1151 if (!(s->regs[GEM_NWCTRL] & GEM_NWCTRL_TXENA)) {
1152 return;
1155 DB_PRINT("\n");
1157 /* The packet we will hand off to QEMU.
1158 * Packets scattered across multiple descriptors are gathered to this
1159 * one contiguous buffer first.
1161 p = tx_packet;
1162 total_bytes = 0;
1164 for (q = s->num_priority_queues - 1; q >= 0; q--) {
1165 /* read current descriptor */
1166 packet_desc_addr = gem_get_tx_desc_addr(s, q);
1168 DB_PRINT("read descriptor 0x%" HWADDR_PRIx "\n", packet_desc_addr);
1169 address_space_read(&s->dma_as, packet_desc_addr,
1170 MEMTXATTRS_UNSPECIFIED, desc,
1171 sizeof(uint32_t) * gem_get_desc_len(s, false));
1172 /* Handle all descriptors owned by hardware */
1173 while (tx_desc_get_used(desc) == 0) {
1175 /* Do nothing if transmit is not enabled. */
1176 if (!(s->regs[GEM_NWCTRL] & GEM_NWCTRL_TXENA)) {
1177 return;
1179 print_gem_tx_desc(desc, q);
1181 /* The real hardware would eat this (and possibly crash).
1182 * For QEMU let's lend a helping hand.
1184 if ((tx_desc_get_buffer(s, desc) == 0) ||
1185 (tx_desc_get_length(desc) == 0)) {
1186 DB_PRINT("Invalid TX descriptor @ 0x%" HWADDR_PRIx "\n",
1187 packet_desc_addr);
1188 break;
1191 if (tx_desc_get_length(desc) > sizeof(tx_packet) -
1192 (p - tx_packet)) {
1193 DB_PRINT("TX descriptor @ 0x%" HWADDR_PRIx \
1194 " too large: size 0x%x space 0x%zx\n",
1195 packet_desc_addr, tx_desc_get_length(desc),
1196 sizeof(tx_packet) - (p - tx_packet));
1197 break;
1200 /* Gather this fragment of the packet from "dma memory" to our
1201 * contig buffer.
1203 address_space_read(&s->dma_as, tx_desc_get_buffer(s, desc),
1204 MEMTXATTRS_UNSPECIFIED,
1205 p, tx_desc_get_length(desc));
1206 p += tx_desc_get_length(desc);
1207 total_bytes += tx_desc_get_length(desc);
1209 /* Last descriptor for this packet; hand the whole thing off */
1210 if (tx_desc_get_last(desc)) {
1211 uint32_t desc_first[DESC_MAX_NUM_WORDS];
1212 hwaddr desc_addr = gem_get_tx_desc_addr(s, q);
1214 /* Modify the 1st descriptor of this packet to be owned by
1215 * the processor.
1217 address_space_read(&s->dma_as, desc_addr,
1218 MEMTXATTRS_UNSPECIFIED, desc_first,
1219 sizeof(desc_first));
1220 tx_desc_set_used(desc_first);
1221 address_space_write(&s->dma_as, desc_addr,
1222 MEMTXATTRS_UNSPECIFIED, desc_first,
1223 sizeof(desc_first));
1224 /* Advance the hardware current descriptor past this packet */
1225 if (tx_desc_get_wrap(desc)) {
1226 s->tx_desc_addr[q] = gem_get_tx_queue_base_addr(s, q);
1227 } else {
1228 s->tx_desc_addr[q] = packet_desc_addr +
1229 4 * gem_get_desc_len(s, false);
1231 DB_PRINT("TX descriptor next: 0x%08x\n", s->tx_desc_addr[q]);
1233 s->regs[GEM_TXSTATUS] |= GEM_TXSTATUS_TXCMPL;
1234 s->regs[GEM_ISR] |= GEM_INT_TXCMPL & ~(s->regs[GEM_IMR]);
1236 /* Update queue interrupt status */
1237 if (s->num_priority_queues > 1) {
1238 s->regs[GEM_INT_Q1_STATUS + q] |=
1239 GEM_INT_TXCMPL & ~(s->regs[GEM_INT_Q1_MASK + q]);
1242 /* Handle interrupt consequences */
1243 gem_update_int_status(s);
1245 /* Is checksum offload enabled? */
1246 if (s->regs[GEM_DMACFG] & GEM_DMACFG_TXCSUM_OFFL) {
1247 net_checksum_calculate(tx_packet, total_bytes);
1250 /* Update MAC statistics */
1251 gem_transmit_updatestats(s, tx_packet, total_bytes);
1253 /* Send the packet somewhere */
1254 if (s->phy_loop || (s->regs[GEM_NWCTRL] &
1255 GEM_NWCTRL_LOCALLOOP)) {
1256 gem_receive(qemu_get_queue(s->nic), tx_packet,
1257 total_bytes);
1258 } else {
1259 qemu_send_packet(qemu_get_queue(s->nic), tx_packet,
1260 total_bytes);
1263 /* Prepare for next packet */
1264 p = tx_packet;
1265 total_bytes = 0;
1268 /* read next descriptor */
1269 if (tx_desc_get_wrap(desc)) {
1270 tx_desc_set_last(desc);
1272 if (s->regs[GEM_DMACFG] & GEM_DMACFG_ADDR_64B) {
1273 packet_desc_addr = s->regs[GEM_TBQPH];
1274 packet_desc_addr <<= 32;
1275 } else {
1276 packet_desc_addr = 0;
1278 packet_desc_addr |= gem_get_tx_queue_base_addr(s, q);
1279 } else {
1280 packet_desc_addr += 4 * gem_get_desc_len(s, false);
1282 DB_PRINT("read descriptor 0x%" HWADDR_PRIx "\n", packet_desc_addr);
1283 address_space_read(&s->dma_as, packet_desc_addr,
1284 MEMTXATTRS_UNSPECIFIED, desc,
1285 sizeof(uint32_t) * gem_get_desc_len(s, false));
1288 if (tx_desc_get_used(desc)) {
1289 s->regs[GEM_TXSTATUS] |= GEM_TXSTATUS_USED;
1290 s->regs[GEM_ISR] |= GEM_INT_TXUSED & ~(s->regs[GEM_IMR]);
1291 gem_update_int_status(s);
1296 static void gem_phy_reset(CadenceGEMState *s)
1298 memset(&s->phy_regs[0], 0, sizeof(s->phy_regs));
1299 s->phy_regs[PHY_REG_CONTROL] = 0x1140;
1300 s->phy_regs[PHY_REG_STATUS] = 0x7969;
1301 s->phy_regs[PHY_REG_PHYID1] = 0x0141;
1302 s->phy_regs[PHY_REG_PHYID2] = 0x0CC2;
1303 s->phy_regs[PHY_REG_ANEGADV] = 0x01E1;
1304 s->phy_regs[PHY_REG_LINKPABIL] = 0xCDE1;
1305 s->phy_regs[PHY_REG_ANEGEXP] = 0x000F;
1306 s->phy_regs[PHY_REG_NEXTP] = 0x2001;
1307 s->phy_regs[PHY_REG_LINKPNEXTP] = 0x40E6;
1308 s->phy_regs[PHY_REG_100BTCTRL] = 0x0300;
1309 s->phy_regs[PHY_REG_1000BTSTAT] = 0x7C00;
1310 s->phy_regs[PHY_REG_EXTSTAT] = 0x3000;
1311 s->phy_regs[PHY_REG_PHYSPCFC_CTL] = 0x0078;
1312 s->phy_regs[PHY_REG_PHYSPCFC_ST] = 0x7C00;
1313 s->phy_regs[PHY_REG_EXT_PHYSPCFC_CTL] = 0x0C60;
1314 s->phy_regs[PHY_REG_LED] = 0x4100;
1315 s->phy_regs[PHY_REG_EXT_PHYSPCFC_CTL2] = 0x000A;
1316 s->phy_regs[PHY_REG_EXT_PHYSPCFC_ST] = 0x848B;
1318 phy_update_link(s);
1321 static void gem_reset(DeviceState *d)
1323 int i;
1324 CadenceGEMState *s = CADENCE_GEM(d);
1325 const uint8_t *a;
1326 uint32_t queues_mask = 0;
1328 DB_PRINT("\n");
1330 /* Set post reset register values */
1331 memset(&s->regs[0], 0, sizeof(s->regs));
1332 s->regs[GEM_NWCFG] = 0x00080000;
1333 s->regs[GEM_NWSTATUS] = 0x00000006;
1334 s->regs[GEM_DMACFG] = 0x00020784;
1335 s->regs[GEM_IMR] = 0x07ffffff;
1336 s->regs[GEM_TXPAUSE] = 0x0000ffff;
1337 s->regs[GEM_TXPARTIALSF] = 0x000003ff;
1338 s->regs[GEM_RXPARTIALSF] = 0x000003ff;
1339 s->regs[GEM_MODID] = s->revision;
1340 s->regs[GEM_DESCONF] = 0x02500111;
1341 s->regs[GEM_DESCONF2] = 0x2ab13fff;
1342 s->regs[GEM_DESCONF5] = 0x002f2045;
1343 s->regs[GEM_DESCONF6] = GEM_DESCONF6_64B_MASK;
1345 if (s->num_priority_queues > 1) {
1346 queues_mask = MAKE_64BIT_MASK(1, s->num_priority_queues - 1);
1347 s->regs[GEM_DESCONF6] |= queues_mask;
1350 /* Set MAC address */
1351 a = &s->conf.macaddr.a[0];
1352 s->regs[GEM_SPADDR1LO] = a[0] | (a[1] << 8) | (a[2] << 16) | (a[3] << 24);
1353 s->regs[GEM_SPADDR1HI] = a[4] | (a[5] << 8);
1355 for (i = 0; i < 4; i++) {
1356 s->sar_active[i] = false;
1359 gem_phy_reset(s);
1361 gem_update_int_status(s);
1364 static uint16_t gem_phy_read(CadenceGEMState *s, unsigned reg_num)
1366 DB_PRINT("reg: %d value: 0x%04x\n", reg_num, s->phy_regs[reg_num]);
1367 return s->phy_regs[reg_num];
1370 static void gem_phy_write(CadenceGEMState *s, unsigned reg_num, uint16_t val)
1372 DB_PRINT("reg: %d value: 0x%04x\n", reg_num, val);
1374 switch (reg_num) {
1375 case PHY_REG_CONTROL:
1376 if (val & PHY_REG_CONTROL_RST) {
1377 /* Phy reset */
1378 gem_phy_reset(s);
1379 val &= ~(PHY_REG_CONTROL_RST | PHY_REG_CONTROL_LOOP);
1380 s->phy_loop = 0;
1382 if (val & PHY_REG_CONTROL_ANEG) {
1383 /* Complete autonegotiation immediately */
1384 val &= ~(PHY_REG_CONTROL_ANEG | PHY_REG_CONTROL_ANRESTART);
1385 s->phy_regs[PHY_REG_STATUS] |= PHY_REG_STATUS_ANEGCMPL;
1387 if (val & PHY_REG_CONTROL_LOOP) {
1388 DB_PRINT("PHY placed in loopback\n");
1389 s->phy_loop = 1;
1390 } else {
1391 s->phy_loop = 0;
1393 break;
1395 s->phy_regs[reg_num] = val;
1399 * gem_read32:
1400 * Read a GEM register.
1402 static uint64_t gem_read(void *opaque, hwaddr offset, unsigned size)
1404 CadenceGEMState *s;
1405 uint32_t retval;
1406 s = (CadenceGEMState *)opaque;
1408 offset >>= 2;
1409 retval = s->regs[offset];
1411 DB_PRINT("offset: 0x%04x read: 0x%08x\n", (unsigned)offset*4, retval);
1413 switch (offset) {
1414 case GEM_ISR:
1415 DB_PRINT("lowering irqs on ISR read\n");
1416 /* The interrupts get updated at the end of the function. */
1417 break;
1418 case GEM_PHYMNTNC:
1419 if (retval & GEM_PHYMNTNC_OP_R) {
1420 uint32_t phy_addr, reg_num;
1422 phy_addr = (retval & GEM_PHYMNTNC_ADDR) >> GEM_PHYMNTNC_ADDR_SHFT;
1423 if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0) {
1424 reg_num = (retval & GEM_PHYMNTNC_REG) >> GEM_PHYMNTNC_REG_SHIFT;
1425 retval &= 0xFFFF0000;
1426 retval |= gem_phy_read(s, reg_num);
1427 } else {
1428 retval |= 0xFFFF; /* No device at this address */
1431 break;
1434 /* Squash read to clear bits */
1435 s->regs[offset] &= ~(s->regs_rtc[offset]);
1437 /* Do not provide write only bits */
1438 retval &= ~(s->regs_wo[offset]);
1440 DB_PRINT("0x%08x\n", retval);
1441 gem_update_int_status(s);
1442 return retval;
1446 * gem_write32:
1447 * Write a GEM register.
1449 static void gem_write(void *opaque, hwaddr offset, uint64_t val,
1450 unsigned size)
1452 CadenceGEMState *s = (CadenceGEMState *)opaque;
1453 uint32_t readonly;
1454 int i;
1456 DB_PRINT("offset: 0x%04x write: 0x%08x ", (unsigned)offset, (unsigned)val);
1457 offset >>= 2;
1459 /* Squash bits which are read only in write value */
1460 val &= ~(s->regs_ro[offset]);
1461 /* Preserve (only) bits which are read only and wtc in register */
1462 readonly = s->regs[offset] & (s->regs_ro[offset] | s->regs_w1c[offset]);
1464 /* Copy register write to backing store */
1465 s->regs[offset] = (val & ~s->regs_w1c[offset]) | readonly;
1467 /* do w1c */
1468 s->regs[offset] &= ~(s->regs_w1c[offset] & val);
1470 /* Handle register write side effects */
1471 switch (offset) {
1472 case GEM_NWCTRL:
1473 if (val & GEM_NWCTRL_RXENA) {
1474 for (i = 0; i < s->num_priority_queues; ++i) {
1475 gem_get_rx_desc(s, i);
1478 if (val & GEM_NWCTRL_TXSTART) {
1479 gem_transmit(s);
1481 if (!(val & GEM_NWCTRL_TXENA)) {
1482 /* Reset to start of Q when transmit disabled. */
1483 for (i = 0; i < s->num_priority_queues; i++) {
1484 s->tx_desc_addr[i] = gem_get_tx_queue_base_addr(s, i);
1487 if (gem_can_receive(qemu_get_queue(s->nic))) {
1488 qemu_flush_queued_packets(qemu_get_queue(s->nic));
1490 break;
1492 case GEM_TXSTATUS:
1493 gem_update_int_status(s);
1494 break;
1495 case GEM_RXQBASE:
1496 s->rx_desc_addr[0] = val;
1497 break;
1498 case GEM_RECEIVE_Q1_PTR ... GEM_RECEIVE_Q7_PTR:
1499 s->rx_desc_addr[offset - GEM_RECEIVE_Q1_PTR + 1] = val;
1500 break;
1501 case GEM_TXQBASE:
1502 s->tx_desc_addr[0] = val;
1503 break;
1504 case GEM_TRANSMIT_Q1_PTR ... GEM_TRANSMIT_Q7_PTR:
1505 s->tx_desc_addr[offset - GEM_TRANSMIT_Q1_PTR + 1] = val;
1506 break;
1507 case GEM_RXSTATUS:
1508 gem_update_int_status(s);
1509 break;
1510 case GEM_IER:
1511 s->regs[GEM_IMR] &= ~val;
1512 gem_update_int_status(s);
1513 break;
1514 case GEM_INT_Q1_ENABLE ... GEM_INT_Q7_ENABLE:
1515 s->regs[GEM_INT_Q1_MASK + offset - GEM_INT_Q1_ENABLE] &= ~val;
1516 gem_update_int_status(s);
1517 break;
1518 case GEM_IDR:
1519 s->regs[GEM_IMR] |= val;
1520 gem_update_int_status(s);
1521 break;
1522 case GEM_INT_Q1_DISABLE ... GEM_INT_Q7_DISABLE:
1523 s->regs[GEM_INT_Q1_MASK + offset - GEM_INT_Q1_DISABLE] |= val;
1524 gem_update_int_status(s);
1525 break;
1526 case GEM_SPADDR1LO:
1527 case GEM_SPADDR2LO:
1528 case GEM_SPADDR3LO:
1529 case GEM_SPADDR4LO:
1530 s->sar_active[(offset - GEM_SPADDR1LO) / 2] = false;
1531 break;
1532 case GEM_SPADDR1HI:
1533 case GEM_SPADDR2HI:
1534 case GEM_SPADDR3HI:
1535 case GEM_SPADDR4HI:
1536 s->sar_active[(offset - GEM_SPADDR1HI) / 2] = true;
1537 break;
1538 case GEM_PHYMNTNC:
1539 if (val & GEM_PHYMNTNC_OP_W) {
1540 uint32_t phy_addr, reg_num;
1542 phy_addr = (val & GEM_PHYMNTNC_ADDR) >> GEM_PHYMNTNC_ADDR_SHFT;
1543 if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0) {
1544 reg_num = (val & GEM_PHYMNTNC_REG) >> GEM_PHYMNTNC_REG_SHIFT;
1545 gem_phy_write(s, reg_num, val);
1548 break;
1551 DB_PRINT("newval: 0x%08x\n", s->regs[offset]);
1554 static const MemoryRegionOps gem_ops = {
1555 .read = gem_read,
1556 .write = gem_write,
1557 .endianness = DEVICE_LITTLE_ENDIAN,
1560 static void gem_set_link(NetClientState *nc)
1562 CadenceGEMState *s = qemu_get_nic_opaque(nc);
1564 DB_PRINT("\n");
1565 phy_update_link(s);
1566 gem_update_int_status(s);
1569 static NetClientInfo net_gem_info = {
1570 .type = NET_CLIENT_DRIVER_NIC,
1571 .size = sizeof(NICState),
1572 .can_receive = gem_can_receive,
1573 .receive = gem_receive,
1574 .link_status_changed = gem_set_link,
1577 static void gem_realize(DeviceState *dev, Error **errp)
1579 CadenceGEMState *s = CADENCE_GEM(dev);
1580 int i;
1582 address_space_init(&s->dma_as,
1583 s->dma_mr ? s->dma_mr : get_system_memory(), "dma");
1585 if (s->num_priority_queues == 0 ||
1586 s->num_priority_queues > MAX_PRIORITY_QUEUES) {
1587 error_setg(errp, "Invalid num-priority-queues value: %" PRIx8,
1588 s->num_priority_queues);
1589 return;
1590 } else if (s->num_type1_screeners > MAX_TYPE1_SCREENERS) {
1591 error_setg(errp, "Invalid num-type1-screeners value: %" PRIx8,
1592 s->num_type1_screeners);
1593 return;
1594 } else if (s->num_type2_screeners > MAX_TYPE2_SCREENERS) {
1595 error_setg(errp, "Invalid num-type2-screeners value: %" PRIx8,
1596 s->num_type2_screeners);
1597 return;
1600 for (i = 0; i < s->num_priority_queues; ++i) {
1601 sysbus_init_irq(SYS_BUS_DEVICE(dev), &s->irq[i]);
1604 qemu_macaddr_default_if_unset(&s->conf.macaddr);
1606 s->nic = qemu_new_nic(&net_gem_info, &s->conf,
1607 object_get_typename(OBJECT(dev)), dev->id, s);
1610 static void gem_init(Object *obj)
1612 CadenceGEMState *s = CADENCE_GEM(obj);
1613 DeviceState *dev = DEVICE(obj);
1615 DB_PRINT("\n");
1617 gem_init_register_masks(s);
1618 memory_region_init_io(&s->iomem, OBJECT(s), &gem_ops, s,
1619 "enet", sizeof(s->regs));
1621 sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->iomem);
1623 object_property_add_link(obj, "dma", TYPE_MEMORY_REGION,
1624 (Object **)&s->dma_mr,
1625 qdev_prop_allow_set_link_before_realize,
1626 OBJ_PROP_LINK_STRONG);
1629 static const VMStateDescription vmstate_cadence_gem = {
1630 .name = "cadence_gem",
1631 .version_id = 4,
1632 .minimum_version_id = 4,
1633 .fields = (VMStateField[]) {
1634 VMSTATE_UINT32_ARRAY(regs, CadenceGEMState, CADENCE_GEM_MAXREG),
1635 VMSTATE_UINT16_ARRAY(phy_regs, CadenceGEMState, 32),
1636 VMSTATE_UINT8(phy_loop, CadenceGEMState),
1637 VMSTATE_UINT32_ARRAY(rx_desc_addr, CadenceGEMState,
1638 MAX_PRIORITY_QUEUES),
1639 VMSTATE_UINT32_ARRAY(tx_desc_addr, CadenceGEMState,
1640 MAX_PRIORITY_QUEUES),
1641 VMSTATE_BOOL_ARRAY(sar_active, CadenceGEMState, 4),
1642 VMSTATE_END_OF_LIST(),
1646 static Property gem_properties[] = {
1647 DEFINE_NIC_PROPERTIES(CadenceGEMState, conf),
1648 DEFINE_PROP_UINT32("revision", CadenceGEMState, revision,
1649 GEM_MODID_VALUE),
1650 DEFINE_PROP_UINT8("num-priority-queues", CadenceGEMState,
1651 num_priority_queues, 1),
1652 DEFINE_PROP_UINT8("num-type1-screeners", CadenceGEMState,
1653 num_type1_screeners, 4),
1654 DEFINE_PROP_UINT8("num-type2-screeners", CadenceGEMState,
1655 num_type2_screeners, 4),
1656 DEFINE_PROP_END_OF_LIST(),
1659 static void gem_class_init(ObjectClass *klass, void *data)
1661 DeviceClass *dc = DEVICE_CLASS(klass);
1663 dc->realize = gem_realize;
1664 device_class_set_props(dc, gem_properties);
1665 dc->vmsd = &vmstate_cadence_gem;
1666 dc->reset = gem_reset;
1669 static const TypeInfo gem_info = {
1670 .name = TYPE_CADENCE_GEM,
1671 .parent = TYPE_SYS_BUS_DEVICE,
1672 .instance_size = sizeof(CadenceGEMState),
1673 .instance_init = gem_init,
1674 .class_init = gem_class_init,
1677 static void gem_register_types(void)
1679 type_register_static(&gem_info);
1682 type_init(gem_register_types)