2 * QEMU Xilinx 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
25 #include <zlib.h> /* For crc32 */
27 #include "hw/sysbus.h"
29 #include "net/checksum.h"
31 #ifdef CADENCE_GEM_ERR_DEBUG
32 #define DB_PRINT(...) do { \
33 fprintf(stderr, ": %s: ", __func__); \
34 fprintf(stderr, ## __VA_ARGS__); \
40 #define GEM_NWCTRL (0x00000000/4) /* Network Control reg */
41 #define GEM_NWCFG (0x00000004/4) /* Network Config reg */
42 #define GEM_NWSTATUS (0x00000008/4) /* Network Status reg */
43 #define GEM_USERIO (0x0000000C/4) /* User IO reg */
44 #define GEM_DMACFG (0x00000010/4) /* DMA Control reg */
45 #define GEM_TXSTATUS (0x00000014/4) /* TX Status reg */
46 #define GEM_RXQBASE (0x00000018/4) /* RX Q Base address reg */
47 #define GEM_TXQBASE (0x0000001C/4) /* TX Q Base address reg */
48 #define GEM_RXSTATUS (0x00000020/4) /* RX Status reg */
49 #define GEM_ISR (0x00000024/4) /* Interrupt Status reg */
50 #define GEM_IER (0x00000028/4) /* Interrupt Enable reg */
51 #define GEM_IDR (0x0000002C/4) /* Interrupt Disable reg */
52 #define GEM_IMR (0x00000030/4) /* Interrupt Mask reg */
53 #define GEM_PHYMNTNC (0x00000034/4) /* Phy Maintaince reg */
54 #define GEM_RXPAUSE (0x00000038/4) /* RX Pause Time reg */
55 #define GEM_TXPAUSE (0x0000003C/4) /* TX Pause Time reg */
56 #define GEM_TXPARTIALSF (0x00000040/4) /* TX Partial Store and Forward */
57 #define GEM_RXPARTIALSF (0x00000044/4) /* RX Partial Store and Forward */
58 #define GEM_HASHLO (0x00000080/4) /* Hash Low address reg */
59 #define GEM_HASHHI (0x00000084/4) /* Hash High address reg */
60 #define GEM_SPADDR1LO (0x00000088/4) /* Specific addr 1 low reg */
61 #define GEM_SPADDR1HI (0x0000008C/4) /* Specific addr 1 high reg */
62 #define GEM_SPADDR2LO (0x00000090/4) /* Specific addr 2 low reg */
63 #define GEM_SPADDR2HI (0x00000094/4) /* Specific addr 2 high reg */
64 #define GEM_SPADDR3LO (0x00000098/4) /* Specific addr 3 low reg */
65 #define GEM_SPADDR3HI (0x0000009C/4) /* Specific addr 3 high reg */
66 #define GEM_SPADDR4LO (0x000000A0/4) /* Specific addr 4 low reg */
67 #define GEM_SPADDR4HI (0x000000A4/4) /* Specific addr 4 high reg */
68 #define GEM_TIDMATCH1 (0x000000A8/4) /* Type ID1 Match reg */
69 #define GEM_TIDMATCH2 (0x000000AC/4) /* Type ID2 Match reg */
70 #define GEM_TIDMATCH3 (0x000000B0/4) /* Type ID3 Match reg */
71 #define GEM_TIDMATCH4 (0x000000B4/4) /* Type ID4 Match reg */
72 #define GEM_WOLAN (0x000000B8/4) /* Wake on LAN reg */
73 #define GEM_IPGSTRETCH (0x000000BC/4) /* IPG Stretch reg */
74 #define GEM_SVLAN (0x000000C0/4) /* Stacked VLAN reg */
75 #define GEM_MODID (0x000000FC/4) /* Module ID reg */
76 #define GEM_OCTTXLO (0x00000100/4) /* Octects transmitted Low reg */
77 #define GEM_OCTTXHI (0x00000104/4) /* Octects transmitted High reg */
78 #define GEM_TXCNT (0x00000108/4) /* Error-free Frames transmitted */
79 #define GEM_TXBCNT (0x0000010C/4) /* Error-free Broadcast Frames */
80 #define GEM_TXMCNT (0x00000110/4) /* Error-free Multicast Frame */
81 #define GEM_TXPAUSECNT (0x00000114/4) /* Pause Frames Transmitted */
82 #define GEM_TX64CNT (0x00000118/4) /* Error-free 64 TX */
83 #define GEM_TX65CNT (0x0000011C/4) /* Error-free 65-127 TX */
84 #define GEM_TX128CNT (0x00000120/4) /* Error-free 128-255 TX */
85 #define GEM_TX256CNT (0x00000124/4) /* Error-free 256-511 */
86 #define GEM_TX512CNT (0x00000128/4) /* Error-free 512-1023 TX */
87 #define GEM_TX1024CNT (0x0000012C/4) /* Error-free 1024-1518 TX */
88 #define GEM_TX1519CNT (0x00000130/4) /* Error-free larger than 1519 TX */
89 #define GEM_TXURUNCNT (0x00000134/4) /* TX under run error counter */
90 #define GEM_SINGLECOLLCNT (0x00000138/4) /* Single Collision Frames */
91 #define GEM_MULTCOLLCNT (0x0000013C/4) /* Multiple Collision Frames */
92 #define GEM_EXCESSCOLLCNT (0x00000140/4) /* Excessive Collision Frames */
93 #define GEM_LATECOLLCNT (0x00000144/4) /* Late Collision Frames */
94 #define GEM_DEFERTXCNT (0x00000148/4) /* Deferred Transmission Frames */
95 #define GEM_CSENSECNT (0x0000014C/4) /* Carrier Sense Error Counter */
96 #define GEM_OCTRXLO (0x00000150/4) /* Octects Received register Low */
97 #define GEM_OCTRXHI (0x00000154/4) /* Octects Received register High */
98 #define GEM_RXCNT (0x00000158/4) /* Error-free Frames Received */
99 #define GEM_RXBROADCNT (0x0000015C/4) /* Error-free Broadcast Frames RX */
100 #define GEM_RXMULTICNT (0x00000160/4) /* Error-free Multicast Frames RX */
101 #define GEM_RXPAUSECNT (0x00000164/4) /* Pause Frames Received Counter */
102 #define GEM_RX64CNT (0x00000168/4) /* Error-free 64 byte Frames RX */
103 #define GEM_RX65CNT (0x0000016C/4) /* Error-free 65-127B Frames RX */
104 #define GEM_RX128CNT (0x00000170/4) /* Error-free 128-255B Frames RX */
105 #define GEM_RX256CNT (0x00000174/4) /* Error-free 256-512B Frames RX */
106 #define GEM_RX512CNT (0x00000178/4) /* Error-free 512-1023B Frames RX */
107 #define GEM_RX1024CNT (0x0000017C/4) /* Error-free 1024-1518B Frames RX */
108 #define GEM_RX1519CNT (0x00000180/4) /* Error-free 1519-max Frames RX */
109 #define GEM_RXUNDERCNT (0x00000184/4) /* Undersize Frames Received */
110 #define GEM_RXOVERCNT (0x00000188/4) /* Oversize Frames Received */
111 #define GEM_RXJABCNT (0x0000018C/4) /* Jabbers Received Counter */
112 #define GEM_RXFCSCNT (0x00000190/4) /* Frame Check seq. Error Counter */
113 #define GEM_RXLENERRCNT (0x00000194/4) /* Length Field Error Counter */
114 #define GEM_RXSYMERRCNT (0x00000198/4) /* Symbol Error Counter */
115 #define GEM_RXALIGNERRCNT (0x0000019C/4) /* Alignment Error Counter */
116 #define GEM_RXRSCERRCNT (0x000001A0/4) /* Receive Resource Error Counter */
117 #define GEM_RXORUNCNT (0x000001A4/4) /* Receive Overrun Counter */
118 #define GEM_RXIPCSERRCNT (0x000001A8/4) /* IP header Checksum Error Counter */
119 #define GEM_RXTCPCCNT (0x000001AC/4) /* TCP Checksum Error Counter */
120 #define GEM_RXUDPCCNT (0x000001B0/4) /* UDP Checksum Error Counter */
122 #define GEM_1588S (0x000001D0/4) /* 1588 Timer Seconds */
123 #define GEM_1588NS (0x000001D4/4) /* 1588 Timer Nanoseconds */
124 #define GEM_1588ADJ (0x000001D8/4) /* 1588 Timer Adjust */
125 #define GEM_1588INC (0x000001DC/4) /* 1588 Timer Increment */
126 #define GEM_PTPETXS (0x000001E0/4) /* PTP Event Frame Transmitted (s) */
127 #define GEM_PTPETXNS (0x000001E4/4) /* PTP Event Frame Transmitted (ns) */
128 #define GEM_PTPERXS (0x000001E8/4) /* PTP Event Frame Received (s) */
129 #define GEM_PTPERXNS (0x000001EC/4) /* PTP Event Frame Received (ns) */
130 #define GEM_PTPPTXS (0x000001E0/4) /* PTP Peer Frame Transmitted (s) */
131 #define GEM_PTPPTXNS (0x000001E4/4) /* PTP Peer Frame Transmitted (ns) */
132 #define GEM_PTPPRXS (0x000001E8/4) /* PTP Peer Frame Received (s) */
133 #define GEM_PTPPRXNS (0x000001EC/4) /* PTP Peer Frame Received (ns) */
135 /* Design Configuration Registers */
136 #define GEM_DESCONF (0x00000280/4)
137 #define GEM_DESCONF2 (0x00000284/4)
138 #define GEM_DESCONF3 (0x00000288/4)
139 #define GEM_DESCONF4 (0x0000028C/4)
140 #define GEM_DESCONF5 (0x00000290/4)
141 #define GEM_DESCONF6 (0x00000294/4)
142 #define GEM_DESCONF7 (0x00000298/4)
144 #define GEM_MAXREG (0x00000640/4) /* Last valid GEM address */
146 /*****************************************/
147 #define GEM_NWCTRL_TXSTART 0x00000200 /* Transmit Enable */
148 #define GEM_NWCTRL_TXENA 0x00000008 /* Transmit Enable */
149 #define GEM_NWCTRL_RXENA 0x00000004 /* Receive Enable */
150 #define GEM_NWCTRL_LOCALLOOP 0x00000002 /* Local Loopback */
152 #define GEM_NWCFG_STRIP_FCS 0x00020000 /* Strip FCS field */
153 #define GEM_NWCFG_LERR_DISC 0x00010000 /* Discard RX frames with lenth err */
154 #define GEM_NWCFG_BUFF_OFST_M 0x0000C000 /* Receive buffer offset mask */
155 #define GEM_NWCFG_BUFF_OFST_S 14 /* Receive buffer offset shift */
156 #define GEM_NWCFG_UCAST_HASH 0x00000080 /* accept unicast if hash match */
157 #define GEM_NWCFG_MCAST_HASH 0x00000040 /* accept multicast if hash match */
158 #define GEM_NWCFG_BCAST_REJ 0x00000020 /* Reject broadcast packets */
159 #define GEM_NWCFG_PROMISC 0x00000010 /* Accept all packets */
161 #define GEM_DMACFG_RBUFSZ_M 0x007F0000 /* DMA RX Buffer Size mask */
162 #define GEM_DMACFG_RBUFSZ_S 16 /* DMA RX Buffer Size shift */
163 #define GEM_DMACFG_RBUFSZ_MUL 64 /* DMA RX Buffer Size multiplier */
164 #define GEM_DMACFG_TXCSUM_OFFL 0x00000800 /* Transmit checksum offload */
166 #define GEM_TXSTATUS_TXCMPL 0x00000020 /* Transmit Complete */
167 #define GEM_TXSTATUS_USED 0x00000001 /* sw owned descriptor encountered */
169 #define GEM_RXSTATUS_FRMRCVD 0x00000002 /* Frame received */
170 #define GEM_RXSTATUS_NOBUF 0x00000001 /* Buffer unavailable */
172 /* GEM_ISR GEM_IER GEM_IDR GEM_IMR */
173 #define GEM_INT_TXCMPL 0x00000080 /* Transmit Complete */
174 #define GEM_INT_TXUSED 0x00000008
175 #define GEM_INT_RXUSED 0x00000004
176 #define GEM_INT_RXCMPL 0x00000002
178 #define GEM_PHYMNTNC_OP_R 0x20000000 /* read operation */
179 #define GEM_PHYMNTNC_OP_W 0x10000000 /* write operation */
180 #define GEM_PHYMNTNC_ADDR 0x0F800000 /* Address bits */
181 #define GEM_PHYMNTNC_ADDR_SHFT 23
182 #define GEM_PHYMNTNC_REG 0x007C0000 /* register bits */
183 #define GEM_PHYMNTNC_REG_SHIFT 18
185 /* Marvell PHY definitions */
186 #define BOARD_PHY_ADDRESS 23 /* PHY address we will emulate a device at */
188 #define PHY_REG_CONTROL 0
189 #define PHY_REG_STATUS 1
190 #define PHY_REG_PHYID1 2
191 #define PHY_REG_PHYID2 3
192 #define PHY_REG_ANEGADV 4
193 #define PHY_REG_LINKPABIL 5
194 #define PHY_REG_ANEGEXP 6
195 #define PHY_REG_NEXTP 7
196 #define PHY_REG_LINKPNEXTP 8
197 #define PHY_REG_100BTCTRL 9
198 #define PHY_REG_1000BTSTAT 10
199 #define PHY_REG_EXTSTAT 15
200 #define PHY_REG_PHYSPCFC_CTL 16
201 #define PHY_REG_PHYSPCFC_ST 17
202 #define PHY_REG_INT_EN 18
203 #define PHY_REG_INT_ST 19
204 #define PHY_REG_EXT_PHYSPCFC_CTL 20
205 #define PHY_REG_RXERR 21
206 #define PHY_REG_EACD 22
207 #define PHY_REG_LED 24
208 #define PHY_REG_LED_OVRD 25
209 #define PHY_REG_EXT_PHYSPCFC_CTL2 26
210 #define PHY_REG_EXT_PHYSPCFC_ST 27
211 #define PHY_REG_CABLE_DIAG 28
213 #define PHY_REG_CONTROL_RST 0x8000
214 #define PHY_REG_CONTROL_LOOP 0x4000
215 #define PHY_REG_CONTROL_ANEG 0x1000
217 #define PHY_REG_STATUS_LINK 0x0004
218 #define PHY_REG_STATUS_ANEGCMPL 0x0020
220 #define PHY_REG_INT_ST_ANEGCMPL 0x0800
221 #define PHY_REG_INT_ST_LINKC 0x0400
222 #define PHY_REG_INT_ST_ENERGY 0x0010
224 /***********************************************************************/
225 #define GEM_RX_REJECT (-1)
226 #define GEM_RX_PROMISCUOUS_ACCEPT (-2)
227 #define GEM_RX_BROADCAST_ACCEPT (-3)
228 #define GEM_RX_MULTICAST_HASH_ACCEPT (-4)
229 #define GEM_RX_UNICAST_HASH_ACCEPT (-5)
231 #define GEM_RX_SAR_ACCEPT 0
233 /***********************************************************************/
235 #define DESC_1_USED 0x80000000
236 #define DESC_1_LENGTH 0x00001FFF
238 #define DESC_1_TX_WRAP 0x40000000
239 #define DESC_1_TX_LAST 0x00008000
241 #define DESC_0_RX_WRAP 0x00000002
242 #define DESC_0_RX_OWNERSHIP 0x00000001
244 #define R_DESC_1_RX_SAR_SHIFT 25
245 #define R_DESC_1_RX_SAR_LENGTH 2
246 #define R_DESC_1_RX_UNICAST_HASH (1 << 29)
247 #define R_DESC_1_RX_MULTICAST_HASH (1 << 30)
248 #define R_DESC_1_RX_BROADCAST (1 << 31)
250 #define DESC_1_RX_SOF 0x00004000
251 #define DESC_1_RX_EOF 0x00008000
253 static inline unsigned tx_desc_get_buffer(unsigned *desc)
258 static inline unsigned tx_desc_get_used(unsigned *desc)
260 return (desc[1] & DESC_1_USED) ? 1 : 0;
263 static inline void tx_desc_set_used(unsigned *desc)
265 desc[1] |= DESC_1_USED;
268 static inline unsigned tx_desc_get_wrap(unsigned *desc)
270 return (desc[1] & DESC_1_TX_WRAP) ? 1 : 0;
273 static inline unsigned tx_desc_get_last(unsigned *desc)
275 return (desc[1] & DESC_1_TX_LAST) ? 1 : 0;
278 static inline unsigned tx_desc_get_length(unsigned *desc)
280 return desc[1] & DESC_1_LENGTH;
283 static inline void print_gem_tx_desc(unsigned *desc)
285 DB_PRINT("TXDESC:\n");
286 DB_PRINT("bufaddr: 0x%08x\n", *desc);
287 DB_PRINT("used_hw: %d\n", tx_desc_get_used(desc));
288 DB_PRINT("wrap: %d\n", tx_desc_get_wrap(desc));
289 DB_PRINT("last: %d\n", tx_desc_get_last(desc));
290 DB_PRINT("length: %d\n", tx_desc_get_length(desc));
293 static inline unsigned rx_desc_get_buffer(unsigned *desc)
295 return desc[0] & ~0x3UL;
298 static inline unsigned rx_desc_get_wrap(unsigned *desc)
300 return desc[0] & DESC_0_RX_WRAP ? 1 : 0;
303 static inline unsigned rx_desc_get_ownership(unsigned *desc)
305 return desc[0] & DESC_0_RX_OWNERSHIP ? 1 : 0;
308 static inline void rx_desc_set_ownership(unsigned *desc)
310 desc[0] |= DESC_0_RX_OWNERSHIP;
313 static inline void rx_desc_set_sof(unsigned *desc)
315 desc[1] |= DESC_1_RX_SOF;
318 static inline void rx_desc_set_eof(unsigned *desc)
320 desc[1] |= DESC_1_RX_EOF;
323 static inline void rx_desc_set_length(unsigned *desc, unsigned len)
325 desc[1] &= ~DESC_1_LENGTH;
329 static inline void rx_desc_set_broadcast(unsigned *desc)
331 desc[1] |= R_DESC_1_RX_BROADCAST;
334 static inline void rx_desc_set_unicast_hash(unsigned *desc)
336 desc[1] |= R_DESC_1_RX_UNICAST_HASH;
339 static inline void rx_desc_set_multicast_hash(unsigned *desc)
341 desc[1] |= R_DESC_1_RX_MULTICAST_HASH;
344 static inline void rx_desc_set_sar(unsigned *desc, int sar_idx)
346 desc[1] = deposit32(desc[1], R_DESC_1_RX_SAR_SHIFT, R_DESC_1_RX_SAR_LENGTH,
350 #define TYPE_CADENCE_GEM "cadence_gem"
351 #define GEM(obj) OBJECT_CHECK(GemState, (obj), TYPE_CADENCE_GEM)
353 typedef struct GemState {
354 SysBusDevice parent_obj;
361 /* GEM registers backing store */
362 uint32_t regs[GEM_MAXREG];
363 /* Mask of register bits which are write only */
364 uint32_t regs_wo[GEM_MAXREG];
365 /* Mask of register bits which are read only */
366 uint32_t regs_ro[GEM_MAXREG];
367 /* Mask of register bits which are clear on read */
368 uint32_t regs_rtc[GEM_MAXREG];
369 /* Mask of register bits which are write 1 to clear */
370 uint32_t regs_w1c[GEM_MAXREG];
372 /* PHY registers backing store */
373 uint16_t phy_regs[32];
375 uint8_t phy_loop; /* Are we in phy loopback? */
377 /* The current DMA descriptor pointers */
378 uint32_t rx_desc_addr;
379 uint32_t tx_desc_addr;
385 /* The broadcast MAC address: 0xFFFFFFFFFFFF */
386 const uint8_t broadcast_addr[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
389 * gem_init_register_masks:
390 * One time initialization.
391 * Set masks to identify which register bits have magical clear properties
393 static void gem_init_register_masks(GemState *s)
395 /* Mask of register bits which are read only*/
396 memset(&s->regs_ro[0], 0, sizeof(s->regs_ro));
397 s->regs_ro[GEM_NWCTRL] = 0xFFF80000;
398 s->regs_ro[GEM_NWSTATUS] = 0xFFFFFFFF;
399 s->regs_ro[GEM_DMACFG] = 0xFE00F000;
400 s->regs_ro[GEM_TXSTATUS] = 0xFFFFFE08;
401 s->regs_ro[GEM_RXQBASE] = 0x00000003;
402 s->regs_ro[GEM_TXQBASE] = 0x00000003;
403 s->regs_ro[GEM_RXSTATUS] = 0xFFFFFFF0;
404 s->regs_ro[GEM_ISR] = 0xFFFFFFFF;
405 s->regs_ro[GEM_IMR] = 0xFFFFFFFF;
406 s->regs_ro[GEM_MODID] = 0xFFFFFFFF;
408 /* Mask of register bits which are clear on read */
409 memset(&s->regs_rtc[0], 0, sizeof(s->regs_rtc));
410 s->regs_rtc[GEM_ISR] = 0xFFFFFFFF;
412 /* Mask of register bits which are write 1 to clear */
413 memset(&s->regs_w1c[0], 0, sizeof(s->regs_w1c));
414 s->regs_w1c[GEM_TXSTATUS] = 0x000001F7;
415 s->regs_w1c[GEM_RXSTATUS] = 0x0000000F;
417 /* Mask of register bits which are write only */
418 memset(&s->regs_wo[0], 0, sizeof(s->regs_wo));
419 s->regs_wo[GEM_NWCTRL] = 0x00073E60;
420 s->regs_wo[GEM_IER] = 0x07FFFFFF;
421 s->regs_wo[GEM_IDR] = 0x07FFFFFF;
426 * Make the emulated PHY link state match the QEMU "interface" state.
428 static void phy_update_link(GemState *s)
430 DB_PRINT("down %d\n", qemu_get_queue(s->nic)->link_down);
432 /* Autonegotiation status mirrors link status. */
433 if (qemu_get_queue(s->nic)->link_down) {
434 s->phy_regs[PHY_REG_STATUS] &= ~(PHY_REG_STATUS_ANEGCMPL |
435 PHY_REG_STATUS_LINK);
436 s->phy_regs[PHY_REG_INT_ST] |= PHY_REG_INT_ST_LINKC;
438 s->phy_regs[PHY_REG_STATUS] |= (PHY_REG_STATUS_ANEGCMPL |
439 PHY_REG_STATUS_LINK);
440 s->phy_regs[PHY_REG_INT_ST] |= (PHY_REG_INT_ST_LINKC |
441 PHY_REG_INT_ST_ANEGCMPL |
442 PHY_REG_INT_ST_ENERGY);
446 static int gem_can_receive(NetClientState *nc)
450 s = qemu_get_nic_opaque(nc);
454 /* Do nothing if receive is not enabled. */
455 if (!(s->regs[GEM_NWCTRL] & GEM_NWCTRL_RXENA)) {
463 * gem_update_int_status:
464 * Raise or lower interrupt based on current status.
466 static void gem_update_int_status(GemState *s)
468 if (s->regs[GEM_ISR]) {
469 DB_PRINT("asserting int. (0x%08x)\n", s->regs[GEM_ISR]);
470 qemu_set_irq(s->irq, 1);
475 * gem_receive_updatestats:
476 * Increment receive statistics.
478 static void gem_receive_updatestats(GemState *s, const uint8_t *packet,
483 /* Total octets (bytes) received */
484 octets = ((uint64_t)(s->regs[GEM_OCTRXLO]) << 32) |
485 s->regs[GEM_OCTRXHI];
487 s->regs[GEM_OCTRXLO] = octets >> 32;
488 s->regs[GEM_OCTRXHI] = octets;
490 /* Error-free Frames received */
491 s->regs[GEM_RXCNT]++;
493 /* Error-free Broadcast Frames counter */
494 if (!memcmp(packet, broadcast_addr, 6)) {
495 s->regs[GEM_RXBROADCNT]++;
498 /* Error-free Multicast Frames counter */
499 if (packet[0] == 0x01) {
500 s->regs[GEM_RXMULTICNT]++;
504 s->regs[GEM_RX64CNT]++;
505 } else if (bytes <= 127) {
506 s->regs[GEM_RX65CNT]++;
507 } else if (bytes <= 255) {
508 s->regs[GEM_RX128CNT]++;
509 } else if (bytes <= 511) {
510 s->regs[GEM_RX256CNT]++;
511 } else if (bytes <= 1023) {
512 s->regs[GEM_RX512CNT]++;
513 } else if (bytes <= 1518) {
514 s->regs[GEM_RX1024CNT]++;
516 s->regs[GEM_RX1519CNT]++;
521 * Get the MAC Address bit from the specified position
523 static unsigned get_bit(const uint8_t *mac, unsigned bit)
528 byte >>= (bit & 0x7);
535 * Calculate a GEM MAC Address hash index
537 static unsigned calc_mac_hash(const uint8_t *mac)
539 int index_bit, mac_bit;
544 for (index_bit = 5; index_bit >= 0; index_bit--) {
545 hash_index |= (get_bit(mac, mac_bit) ^
546 get_bit(mac, mac_bit + 6) ^
547 get_bit(mac, mac_bit + 12) ^
548 get_bit(mac, mac_bit + 18) ^
549 get_bit(mac, mac_bit + 24) ^
550 get_bit(mac, mac_bit + 30) ^
551 get_bit(mac, mac_bit + 36) ^
552 get_bit(mac, mac_bit + 42)) << index_bit;
560 * gem_mac_address_filter:
561 * Accept or reject this destination address?
563 * GEM_RX_REJECT: reject
564 * >= 0: Specific address accept (which matched SAR is returned)
565 * others for various other modes of accept:
566 * GEM_RM_PROMISCUOUS_ACCEPT, GEM_RX_BROADCAST_ACCEPT,
567 * GEM_RX_MULTICAST_HASH_ACCEPT or GEM_RX_UNICAST_HASH_ACCEPT
569 static int gem_mac_address_filter(GemState *s, const uint8_t *packet)
574 /* Promiscuous mode? */
575 if (s->regs[GEM_NWCFG] & GEM_NWCFG_PROMISC) {
576 return GEM_RX_PROMISCUOUS_ACCEPT;
579 if (!memcmp(packet, broadcast_addr, 6)) {
580 /* Reject broadcast packets? */
581 if (s->regs[GEM_NWCFG] & GEM_NWCFG_BCAST_REJ) {
582 return GEM_RX_REJECT;
584 return GEM_RX_BROADCAST_ACCEPT;
587 /* Accept packets -w- hash match? */
588 if ((packet[0] == 0x01 && (s->regs[GEM_NWCFG] & GEM_NWCFG_MCAST_HASH)) ||
589 (packet[0] != 0x01 && (s->regs[GEM_NWCFG] & GEM_NWCFG_UCAST_HASH))) {
592 hash_index = calc_mac_hash(packet);
593 if (hash_index < 32) {
594 if (s->regs[GEM_HASHLO] & (1<<hash_index)) {
595 return packet[0] == 0x01 ? GEM_RX_MULTICAST_HASH_ACCEPT :
596 GEM_RX_UNICAST_HASH_ACCEPT;
600 if (s->regs[GEM_HASHHI] & (1<<hash_index)) {
601 return packet[0] == 0x01 ? GEM_RX_MULTICAST_HASH_ACCEPT :
602 GEM_RX_UNICAST_HASH_ACCEPT;
607 /* Check all 4 specific addresses */
608 gem_spaddr = (uint8_t *)&(s->regs[GEM_SPADDR1LO]);
609 for (i = 3; i >= 0; i--) {
610 if (!memcmp(packet, gem_spaddr + 8 * i, 6)) {
611 return GEM_RX_SAR_ACCEPT + i;
615 /* No address match; reject the packet */
616 return GEM_RX_REJECT;
619 static void gem_get_rx_desc(GemState *s)
621 DB_PRINT("read descriptor 0x%x\n", (unsigned)s->rx_desc_addr);
622 /* read current descriptor */
623 cpu_physical_memory_read(s->rx_desc_addr,
624 (uint8_t *)s->rx_desc, sizeof(s->rx_desc));
626 /* Descriptor owned by software ? */
627 if (rx_desc_get_ownership(s->rx_desc) == 1) {
628 DB_PRINT("descriptor 0x%x owned by sw.\n",
629 (unsigned)s->rx_desc_addr);
630 s->regs[GEM_RXSTATUS] |= GEM_RXSTATUS_NOBUF;
631 s->regs[GEM_ISR] |= GEM_INT_RXUSED & ~(s->regs[GEM_IMR]);
632 /* Handle interrupt consequences */
633 gem_update_int_status(s);
639 * Fit a packet handed to us by QEMU into the receive descriptor ring.
641 static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size)
644 unsigned rxbufsize, bytes_to_copy;
645 unsigned rxbuf_offset;
648 bool first_desc = true;
651 s = qemu_get_nic_opaque(nc);
653 /* Is this destination MAC address "for us" ? */
654 maf = gem_mac_address_filter(s, buf);
655 if (maf == GEM_RX_REJECT) {
659 /* Discard packets with receive length error enabled ? */
660 if (s->regs[GEM_NWCFG] & GEM_NWCFG_LERR_DISC) {
663 /* Fish the ethertype / length field out of the RX packet */
664 type_len = buf[12] << 8 | buf[13];
665 /* It is a length field, not an ethertype */
666 if (type_len < 0x600) {
667 if (size < type_len) {
675 * Determine configured receive buffer offset (probably 0)
677 rxbuf_offset = (s->regs[GEM_NWCFG] & GEM_NWCFG_BUFF_OFST_M) >>
678 GEM_NWCFG_BUFF_OFST_S;
680 /* The configure size of each receive buffer. Determines how many
681 * buffers needed to hold this packet.
683 rxbufsize = ((s->regs[GEM_DMACFG] & GEM_DMACFG_RBUFSZ_M) >>
684 GEM_DMACFG_RBUFSZ_S) * GEM_DMACFG_RBUFSZ_MUL;
685 bytes_to_copy = size;
687 /* Strip of FCS field ? (usually yes) */
688 if (s->regs[GEM_NWCFG] & GEM_NWCFG_STRIP_FCS) {
689 rxbuf_ptr = (void *)buf;
694 /* The application wants the FCS field, which QEMU does not provide.
695 * We must try and caclculate one.
698 memcpy(rxbuf, buf, size);
699 memset(rxbuf + size, 0, sizeof(rxbuf) - size);
701 crc_val = cpu_to_le32(crc32(0, rxbuf, MAX(size, 60)));
707 memcpy(rxbuf + crc_offset, &crc_val, sizeof(crc_val));
713 /* Pad to minimum length */
718 DB_PRINT("config bufsize: %d packet size: %ld\n", rxbufsize, size);
720 while (bytes_to_copy) {
721 /* Do nothing if receive is not enabled. */
722 if (!gem_can_receive(nc)) {
727 DB_PRINT("copy %d bytes to 0x%x\n", MIN(bytes_to_copy, rxbufsize),
728 rx_desc_get_buffer(s->rx_desc));
730 /* Copy packet data to emulated DMA buffer */
731 cpu_physical_memory_write(rx_desc_get_buffer(s->rx_desc) + rxbuf_offset,
732 rxbuf_ptr, MIN(bytes_to_copy, rxbufsize));
733 bytes_to_copy -= MIN(bytes_to_copy, rxbufsize);
734 rxbuf_ptr += MIN(bytes_to_copy, rxbufsize);
736 /* Update the descriptor. */
738 rx_desc_set_sof(s->rx_desc);
741 if (bytes_to_copy == 0) {
742 rx_desc_set_eof(s->rx_desc);
743 rx_desc_set_length(s->rx_desc, size);
745 rx_desc_set_ownership(s->rx_desc);
748 case GEM_RX_PROMISCUOUS_ACCEPT:
750 case GEM_RX_BROADCAST_ACCEPT:
751 rx_desc_set_broadcast(s->rx_desc);
753 case GEM_RX_UNICAST_HASH_ACCEPT:
754 rx_desc_set_unicast_hash(s->rx_desc);
756 case GEM_RX_MULTICAST_HASH_ACCEPT:
757 rx_desc_set_multicast_hash(s->rx_desc);
762 rx_desc_set_sar(s->rx_desc, maf);
765 /* Descriptor write-back. */
766 cpu_physical_memory_write(s->rx_desc_addr,
767 (uint8_t *)s->rx_desc, sizeof(s->rx_desc));
769 /* Next descriptor */
770 if (rx_desc_get_wrap(s->rx_desc)) {
771 DB_PRINT("wrapping RX descriptor list\n");
772 s->rx_desc_addr = s->regs[GEM_RXQBASE];
774 DB_PRINT("incrementing RX descriptor list\n");
775 s->rx_desc_addr += 8;
781 gem_receive_updatestats(s, buf, size);
783 s->regs[GEM_RXSTATUS] |= GEM_RXSTATUS_FRMRCVD;
784 s->regs[GEM_ISR] |= GEM_INT_RXCMPL & ~(s->regs[GEM_IMR]);
786 /* Handle interrupt consequences */
787 gem_update_int_status(s);
793 * gem_transmit_updatestats:
794 * Increment transmit statistics.
796 static void gem_transmit_updatestats(GemState *s, const uint8_t *packet,
801 /* Total octets (bytes) transmitted */
802 octets = ((uint64_t)(s->regs[GEM_OCTTXLO]) << 32) |
803 s->regs[GEM_OCTTXHI];
805 s->regs[GEM_OCTTXLO] = octets >> 32;
806 s->regs[GEM_OCTTXHI] = octets;
808 /* Error-free Frames transmitted */
809 s->regs[GEM_TXCNT]++;
811 /* Error-free Broadcast Frames counter */
812 if (!memcmp(packet, broadcast_addr, 6)) {
813 s->regs[GEM_TXBCNT]++;
816 /* Error-free Multicast Frames counter */
817 if (packet[0] == 0x01) {
818 s->regs[GEM_TXMCNT]++;
822 s->regs[GEM_TX64CNT]++;
823 } else if (bytes <= 127) {
824 s->regs[GEM_TX65CNT]++;
825 } else if (bytes <= 255) {
826 s->regs[GEM_TX128CNT]++;
827 } else if (bytes <= 511) {
828 s->regs[GEM_TX256CNT]++;
829 } else if (bytes <= 1023) {
830 s->regs[GEM_TX512CNT]++;
831 } else if (bytes <= 1518) {
832 s->regs[GEM_TX1024CNT]++;
834 s->regs[GEM_TX1519CNT]++;
840 * Fish packets out of the descriptor ring and feed them to QEMU
842 static void gem_transmit(GemState *s)
845 hwaddr packet_desc_addr;
846 uint8_t tx_packet[2048];
848 unsigned total_bytes;
850 /* Do nothing if transmit is not enabled. */
851 if (!(s->regs[GEM_NWCTRL] & GEM_NWCTRL_TXENA)) {
857 /* The packet we will hand off to qemu.
858 * Packets scattered across multiple descriptors are gathered to this
859 * one contiguous buffer first.
864 /* read current descriptor */
865 packet_desc_addr = s->tx_desc_addr;
866 cpu_physical_memory_read(packet_desc_addr,
867 (uint8_t *)&desc[0], sizeof(desc));
868 /* Handle all descriptors owned by hardware */
869 while (tx_desc_get_used(desc) == 0) {
871 /* Do nothing if transmit is not enabled. */
872 if (!(s->regs[GEM_NWCTRL] & GEM_NWCTRL_TXENA)) {
875 print_gem_tx_desc(desc);
877 /* The real hardware would eat this (and possibly crash).
878 * For QEMU let's lend a helping hand.
880 if ((tx_desc_get_buffer(desc) == 0) ||
881 (tx_desc_get_length(desc) == 0)) {
882 DB_PRINT("Invalid TX descriptor @ 0x%x\n",
883 (unsigned)packet_desc_addr);
887 /* Gather this fragment of the packet from "dma memory" to our contig.
890 cpu_physical_memory_read(tx_desc_get_buffer(desc), p,
891 tx_desc_get_length(desc));
892 p += tx_desc_get_length(desc);
893 total_bytes += tx_desc_get_length(desc);
895 /* Last descriptor for this packet; hand the whole thing off */
896 if (tx_desc_get_last(desc)) {
897 /* Modify the 1st descriptor of this packet to be owned by
900 cpu_physical_memory_read(s->tx_desc_addr,
901 (uint8_t *)&desc[0], sizeof(desc));
902 tx_desc_set_used(desc);
903 cpu_physical_memory_write(s->tx_desc_addr,
904 (uint8_t *)&desc[0], sizeof(desc));
905 /* Advance the hardare current descriptor past this packet */
906 if (tx_desc_get_wrap(desc)) {
907 s->tx_desc_addr = s->regs[GEM_TXQBASE];
909 s->tx_desc_addr = packet_desc_addr + 8;
911 DB_PRINT("TX descriptor next: 0x%08x\n", s->tx_desc_addr);
913 s->regs[GEM_TXSTATUS] |= GEM_TXSTATUS_TXCMPL;
914 s->regs[GEM_ISR] |= GEM_INT_TXCMPL & ~(s->regs[GEM_IMR]);
916 /* Handle interrupt consequences */
917 gem_update_int_status(s);
919 /* Is checksum offload enabled? */
920 if (s->regs[GEM_DMACFG] & GEM_DMACFG_TXCSUM_OFFL) {
921 net_checksum_calculate(tx_packet, total_bytes);
924 /* Update MAC statistics */
925 gem_transmit_updatestats(s, tx_packet, total_bytes);
927 /* Send the packet somewhere */
928 if (s->phy_loop || (s->regs[GEM_NWCTRL] & GEM_NWCTRL_LOCALLOOP)) {
929 gem_receive(qemu_get_queue(s->nic), tx_packet, total_bytes);
931 qemu_send_packet(qemu_get_queue(s->nic), tx_packet,
935 /* Prepare for next packet */
940 /* read next descriptor */
941 if (tx_desc_get_wrap(desc)) {
942 packet_desc_addr = s->regs[GEM_TXQBASE];
944 packet_desc_addr += 8;
946 cpu_physical_memory_read(packet_desc_addr,
947 (uint8_t *)&desc[0], sizeof(desc));
950 if (tx_desc_get_used(desc)) {
951 s->regs[GEM_TXSTATUS] |= GEM_TXSTATUS_USED;
952 s->regs[GEM_ISR] |= GEM_INT_TXUSED & ~(s->regs[GEM_IMR]);
953 gem_update_int_status(s);
957 static void gem_phy_reset(GemState *s)
959 memset(&s->phy_regs[0], 0, sizeof(s->phy_regs));
960 s->phy_regs[PHY_REG_CONTROL] = 0x1140;
961 s->phy_regs[PHY_REG_STATUS] = 0x7969;
962 s->phy_regs[PHY_REG_PHYID1] = 0x0141;
963 s->phy_regs[PHY_REG_PHYID2] = 0x0CC2;
964 s->phy_regs[PHY_REG_ANEGADV] = 0x01E1;
965 s->phy_regs[PHY_REG_LINKPABIL] = 0xCDE1;
966 s->phy_regs[PHY_REG_ANEGEXP] = 0x000F;
967 s->phy_regs[PHY_REG_NEXTP] = 0x2001;
968 s->phy_regs[PHY_REG_LINKPNEXTP] = 0x40E6;
969 s->phy_regs[PHY_REG_100BTCTRL] = 0x0300;
970 s->phy_regs[PHY_REG_1000BTSTAT] = 0x7C00;
971 s->phy_regs[PHY_REG_EXTSTAT] = 0x3000;
972 s->phy_regs[PHY_REG_PHYSPCFC_CTL] = 0x0078;
973 s->phy_regs[PHY_REG_PHYSPCFC_ST] = 0xBC00;
974 s->phy_regs[PHY_REG_EXT_PHYSPCFC_CTL] = 0x0C60;
975 s->phy_regs[PHY_REG_LED] = 0x4100;
976 s->phy_regs[PHY_REG_EXT_PHYSPCFC_CTL2] = 0x000A;
977 s->phy_regs[PHY_REG_EXT_PHYSPCFC_ST] = 0x848B;
982 static void gem_reset(DeviceState *d)
984 GemState *s = GEM(d);
988 /* Set post reset register values */
989 memset(&s->regs[0], 0, sizeof(s->regs));
990 s->regs[GEM_NWCFG] = 0x00080000;
991 s->regs[GEM_NWSTATUS] = 0x00000006;
992 s->regs[GEM_DMACFG] = 0x00020784;
993 s->regs[GEM_IMR] = 0x07ffffff;
994 s->regs[GEM_TXPAUSE] = 0x0000ffff;
995 s->regs[GEM_TXPARTIALSF] = 0x000003ff;
996 s->regs[GEM_RXPARTIALSF] = 0x000003ff;
997 s->regs[GEM_MODID] = 0x00020118;
998 s->regs[GEM_DESCONF] = 0x02500111;
999 s->regs[GEM_DESCONF2] = 0x2ab13fff;
1000 s->regs[GEM_DESCONF5] = 0x002f2145;
1001 s->regs[GEM_DESCONF6] = 0x00000200;
1005 gem_update_int_status(s);
1008 static uint16_t gem_phy_read(GemState *s, unsigned reg_num)
1010 DB_PRINT("reg: %d value: 0x%04x\n", reg_num, s->phy_regs[reg_num]);
1011 return s->phy_regs[reg_num];
1014 static void gem_phy_write(GemState *s, unsigned reg_num, uint16_t val)
1016 DB_PRINT("reg: %d value: 0x%04x\n", reg_num, val);
1019 case PHY_REG_CONTROL:
1020 if (val & PHY_REG_CONTROL_RST) {
1023 val &= ~(PHY_REG_CONTROL_RST | PHY_REG_CONTROL_LOOP);
1026 if (val & PHY_REG_CONTROL_ANEG) {
1027 /* Complete autonegotiation immediately */
1028 val &= ~PHY_REG_CONTROL_ANEG;
1029 s->phy_regs[PHY_REG_STATUS] |= PHY_REG_STATUS_ANEGCMPL;
1031 if (val & PHY_REG_CONTROL_LOOP) {
1032 DB_PRINT("PHY placed in loopback\n");
1039 s->phy_regs[reg_num] = val;
1044 * Read a GEM register.
1046 static uint64_t gem_read(void *opaque, hwaddr offset, unsigned size)
1051 s = (GemState *)opaque;
1054 retval = s->regs[offset];
1056 DB_PRINT("offset: 0x%04x read: 0x%08x\n", (unsigned)offset*4, retval);
1060 DB_PRINT("lowering irq on ISR read\n");
1061 qemu_set_irq(s->irq, 0);
1064 if (retval & GEM_PHYMNTNC_OP_R) {
1065 uint32_t phy_addr, reg_num;
1067 phy_addr = (retval & GEM_PHYMNTNC_ADDR) >> GEM_PHYMNTNC_ADDR_SHFT;
1068 if (phy_addr == BOARD_PHY_ADDRESS) {
1069 reg_num = (retval & GEM_PHYMNTNC_REG) >> GEM_PHYMNTNC_REG_SHIFT;
1070 retval &= 0xFFFF0000;
1071 retval |= gem_phy_read(s, reg_num);
1073 retval |= 0xFFFF; /* No device at this address */
1079 /* Squash read to clear bits */
1080 s->regs[offset] &= ~(s->regs_rtc[offset]);
1082 /* Do not provide write only bits */
1083 retval &= ~(s->regs_wo[offset]);
1085 DB_PRINT("0x%08x\n", retval);
1091 * Write a GEM register.
1093 static void gem_write(void *opaque, hwaddr offset, uint64_t val,
1096 GemState *s = (GemState *)opaque;
1099 DB_PRINT("offset: 0x%04x write: 0x%08x ", (unsigned)offset, (unsigned)val);
1102 /* Squash bits which are read only in write value */
1103 val &= ~(s->regs_ro[offset]);
1104 /* Preserve (only) bits which are read only in register */
1105 readonly = s->regs[offset];
1106 readonly &= s->regs_ro[offset];
1108 /* Squash bits which are write 1 to clear */
1109 val &= ~(s->regs_w1c[offset] & val);
1111 /* Copy register write to backing store */
1112 s->regs[offset] = val | readonly;
1114 /* Handle register write side effects */
1117 if (val & GEM_NWCTRL_RXENA) {
1120 if (val & GEM_NWCTRL_TXSTART) {
1123 if (!(val & GEM_NWCTRL_TXENA)) {
1124 /* Reset to start of Q when transmit disabled. */
1125 s->tx_desc_addr = s->regs[GEM_TXQBASE];
1127 if (val & GEM_NWCTRL_RXENA) {
1128 qemu_flush_queued_packets(qemu_get_queue(s->nic));
1133 gem_update_int_status(s);
1136 s->rx_desc_addr = val;
1139 s->tx_desc_addr = val;
1142 gem_update_int_status(s);
1145 s->regs[GEM_IMR] &= ~val;
1146 gem_update_int_status(s);
1149 s->regs[GEM_IMR] |= val;
1150 gem_update_int_status(s);
1153 if (val & GEM_PHYMNTNC_OP_W) {
1154 uint32_t phy_addr, reg_num;
1156 phy_addr = (val & GEM_PHYMNTNC_ADDR) >> GEM_PHYMNTNC_ADDR_SHFT;
1157 if (phy_addr == BOARD_PHY_ADDRESS) {
1158 reg_num = (val & GEM_PHYMNTNC_REG) >> GEM_PHYMNTNC_REG_SHIFT;
1159 gem_phy_write(s, reg_num, val);
1165 DB_PRINT("newval: 0x%08x\n", s->regs[offset]);
1168 static const MemoryRegionOps gem_ops = {
1171 .endianness = DEVICE_LITTLE_ENDIAN,
1174 static void gem_cleanup(NetClientState *nc)
1176 GemState *s = qemu_get_nic_opaque(nc);
1182 static void gem_set_link(NetClientState *nc)
1185 phy_update_link(qemu_get_nic_opaque(nc));
1188 static NetClientInfo net_gem_info = {
1189 .type = NET_CLIENT_OPTIONS_KIND_NIC,
1190 .size = sizeof(NICState),
1191 .can_receive = gem_can_receive,
1192 .receive = gem_receive,
1193 .cleanup = gem_cleanup,
1194 .link_status_changed = gem_set_link,
1197 static int gem_init(SysBusDevice *sbd)
1199 DeviceState *dev = DEVICE(sbd);
1200 GemState *s = GEM(dev);
1204 gem_init_register_masks(s);
1205 memory_region_init_io(&s->iomem, OBJECT(s), &gem_ops, s,
1206 "enet", sizeof(s->regs));
1207 sysbus_init_mmio(sbd, &s->iomem);
1208 sysbus_init_irq(sbd, &s->irq);
1209 qemu_macaddr_default_if_unset(&s->conf.macaddr);
1211 s->nic = qemu_new_nic(&net_gem_info, &s->conf,
1212 object_get_typename(OBJECT(dev)), dev->id, s);
1217 static const VMStateDescription vmstate_cadence_gem = {
1218 .name = "cadence_gem",
1220 .minimum_version_id = 1,
1221 .minimum_version_id_old = 1,
1222 .fields = (VMStateField[]) {
1223 VMSTATE_UINT32_ARRAY(regs, GemState, GEM_MAXREG),
1224 VMSTATE_UINT16_ARRAY(phy_regs, GemState, 32),
1225 VMSTATE_UINT8(phy_loop, GemState),
1226 VMSTATE_UINT32(rx_desc_addr, GemState),
1227 VMSTATE_UINT32(tx_desc_addr, GemState),
1231 static Property gem_properties[] = {
1232 DEFINE_NIC_PROPERTIES(GemState, conf),
1233 DEFINE_PROP_END_OF_LIST(),
1236 static void gem_class_init(ObjectClass *klass, void *data)
1238 DeviceClass *dc = DEVICE_CLASS(klass);
1239 SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
1241 sdc->init = gem_init;
1242 dc->props = gem_properties;
1243 dc->vmsd = &vmstate_cadence_gem;
1244 dc->reset = gem_reset;
1247 static const TypeInfo gem_info = {
1248 .name = TYPE_CADENCE_GEM,
1249 .parent = TYPE_SYS_BUS_DEVICE,
1250 .instance_size = sizeof(GemState),
1251 .class_init = gem_class_init,
1254 static void gem_register_types(void)
1256 type_register_static(&gem_info);
1259 type_init(gem_register_types)