149ab747fSPaolo Bonzini /* 2116d5546SPeter Crosthwaite * QEMU Cadence GEM emulation 349ab747fSPaolo Bonzini * 449ab747fSPaolo Bonzini * Copyright (c) 2011 Xilinx, Inc. 549ab747fSPaolo Bonzini * 649ab747fSPaolo Bonzini * Permission is hereby granted, free of charge, to any person obtaining a copy 749ab747fSPaolo Bonzini * of this software and associated documentation files (the "Software"), to deal 849ab747fSPaolo Bonzini * in the Software without restriction, including without limitation the rights 949ab747fSPaolo Bonzini * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 1049ab747fSPaolo Bonzini * copies of the Software, and to permit persons to whom the Software is 1149ab747fSPaolo Bonzini * furnished to do so, subject to the following conditions: 1249ab747fSPaolo Bonzini * 1349ab747fSPaolo Bonzini * The above copyright notice and this permission notice shall be included in 1449ab747fSPaolo Bonzini * all copies or substantial portions of the Software. 1549ab747fSPaolo Bonzini * 1649ab747fSPaolo Bonzini * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1749ab747fSPaolo Bonzini * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1849ab747fSPaolo Bonzini * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1949ab747fSPaolo Bonzini * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 2049ab747fSPaolo Bonzini * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 2149ab747fSPaolo Bonzini * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 2249ab747fSPaolo Bonzini * THE SOFTWARE. 2349ab747fSPaolo Bonzini */ 2449ab747fSPaolo Bonzini 258ef94f0bSPeter Maydell #include "qemu/osdep.h" 2649ab747fSPaolo Bonzini #include <zlib.h> /* For crc32 */ 2749ab747fSPaolo Bonzini 28f49856d4SPeter Crosthwaite #include "hw/net/cadence_gem.h" 292bf57f73SAlistair Francis #include "qapi/error.h" 30e8e49943SAlistair Francis #include "qemu/log.h" 3149ab747fSPaolo Bonzini #include "net/checksum.h" 3249ab747fSPaolo Bonzini 3349ab747fSPaolo Bonzini #ifdef CADENCE_GEM_ERR_DEBUG 3449ab747fSPaolo Bonzini #define DB_PRINT(...) do { \ 3549ab747fSPaolo Bonzini fprintf(stderr, ": %s: ", __func__); \ 3649ab747fSPaolo Bonzini fprintf(stderr, ## __VA_ARGS__); \ 3749ab747fSPaolo Bonzini } while (0); 3849ab747fSPaolo Bonzini #else 3949ab747fSPaolo Bonzini #define DB_PRINT(...) 4049ab747fSPaolo Bonzini #endif 4149ab747fSPaolo Bonzini 4249ab747fSPaolo Bonzini #define GEM_NWCTRL (0x00000000/4) /* Network Control reg */ 4349ab747fSPaolo Bonzini #define GEM_NWCFG (0x00000004/4) /* Network Config reg */ 4449ab747fSPaolo Bonzini #define GEM_NWSTATUS (0x00000008/4) /* Network Status reg */ 4549ab747fSPaolo Bonzini #define GEM_USERIO (0x0000000C/4) /* User IO reg */ 4649ab747fSPaolo Bonzini #define GEM_DMACFG (0x00000010/4) /* DMA Control reg */ 4749ab747fSPaolo Bonzini #define GEM_TXSTATUS (0x00000014/4) /* TX Status reg */ 4849ab747fSPaolo Bonzini #define GEM_RXQBASE (0x00000018/4) /* RX Q Base address reg */ 4949ab747fSPaolo Bonzini #define GEM_TXQBASE (0x0000001C/4) /* TX Q Base address reg */ 5049ab747fSPaolo Bonzini #define GEM_RXSTATUS (0x00000020/4) /* RX Status reg */ 5149ab747fSPaolo Bonzini #define GEM_ISR (0x00000024/4) /* Interrupt Status reg */ 5249ab747fSPaolo Bonzini #define GEM_IER (0x00000028/4) /* Interrupt Enable reg */ 5349ab747fSPaolo Bonzini #define GEM_IDR (0x0000002C/4) /* Interrupt Disable reg */ 5449ab747fSPaolo Bonzini #define GEM_IMR (0x00000030/4) /* Interrupt Mask reg */ 553048ed6aSPeter Crosthwaite #define GEM_PHYMNTNC (0x00000034/4) /* Phy Maintenance reg */ 5649ab747fSPaolo Bonzini #define GEM_RXPAUSE (0x00000038/4) /* RX Pause Time reg */ 5749ab747fSPaolo Bonzini #define GEM_TXPAUSE (0x0000003C/4) /* TX Pause Time reg */ 5849ab747fSPaolo Bonzini #define GEM_TXPARTIALSF (0x00000040/4) /* TX Partial Store and Forward */ 5949ab747fSPaolo Bonzini #define GEM_RXPARTIALSF (0x00000044/4) /* RX Partial Store and Forward */ 6049ab747fSPaolo Bonzini #define GEM_HASHLO (0x00000080/4) /* Hash Low address reg */ 6149ab747fSPaolo Bonzini #define GEM_HASHHI (0x00000084/4) /* Hash High address reg */ 6249ab747fSPaolo Bonzini #define GEM_SPADDR1LO (0x00000088/4) /* Specific addr 1 low reg */ 6349ab747fSPaolo Bonzini #define GEM_SPADDR1HI (0x0000008C/4) /* Specific addr 1 high reg */ 6449ab747fSPaolo Bonzini #define GEM_SPADDR2LO (0x00000090/4) /* Specific addr 2 low reg */ 6549ab747fSPaolo Bonzini #define GEM_SPADDR2HI (0x00000094/4) /* Specific addr 2 high reg */ 6649ab747fSPaolo Bonzini #define GEM_SPADDR3LO (0x00000098/4) /* Specific addr 3 low reg */ 6749ab747fSPaolo Bonzini #define GEM_SPADDR3HI (0x0000009C/4) /* Specific addr 3 high reg */ 6849ab747fSPaolo Bonzini #define GEM_SPADDR4LO (0x000000A0/4) /* Specific addr 4 low reg */ 6949ab747fSPaolo Bonzini #define GEM_SPADDR4HI (0x000000A4/4) /* Specific addr 4 high reg */ 7049ab747fSPaolo Bonzini #define GEM_TIDMATCH1 (0x000000A8/4) /* Type ID1 Match reg */ 7149ab747fSPaolo Bonzini #define GEM_TIDMATCH2 (0x000000AC/4) /* Type ID2 Match reg */ 7249ab747fSPaolo Bonzini #define GEM_TIDMATCH3 (0x000000B0/4) /* Type ID3 Match reg */ 7349ab747fSPaolo Bonzini #define GEM_TIDMATCH4 (0x000000B4/4) /* Type ID4 Match reg */ 7449ab747fSPaolo Bonzini #define GEM_WOLAN (0x000000B8/4) /* Wake on LAN reg */ 7549ab747fSPaolo Bonzini #define GEM_IPGSTRETCH (0x000000BC/4) /* IPG Stretch reg */ 7649ab747fSPaolo Bonzini #define GEM_SVLAN (0x000000C0/4) /* Stacked VLAN reg */ 7749ab747fSPaolo Bonzini #define GEM_MODID (0x000000FC/4) /* Module ID reg */ 7849ab747fSPaolo Bonzini #define GEM_OCTTXLO (0x00000100/4) /* Octects transmitted Low reg */ 7949ab747fSPaolo Bonzini #define GEM_OCTTXHI (0x00000104/4) /* Octects transmitted High reg */ 8049ab747fSPaolo Bonzini #define GEM_TXCNT (0x00000108/4) /* Error-free Frames transmitted */ 8149ab747fSPaolo Bonzini #define GEM_TXBCNT (0x0000010C/4) /* Error-free Broadcast Frames */ 8249ab747fSPaolo Bonzini #define GEM_TXMCNT (0x00000110/4) /* Error-free Multicast Frame */ 8349ab747fSPaolo Bonzini #define GEM_TXPAUSECNT (0x00000114/4) /* Pause Frames Transmitted */ 8449ab747fSPaolo Bonzini #define GEM_TX64CNT (0x00000118/4) /* Error-free 64 TX */ 8549ab747fSPaolo Bonzini #define GEM_TX65CNT (0x0000011C/4) /* Error-free 65-127 TX */ 8649ab747fSPaolo Bonzini #define GEM_TX128CNT (0x00000120/4) /* Error-free 128-255 TX */ 8749ab747fSPaolo Bonzini #define GEM_TX256CNT (0x00000124/4) /* Error-free 256-511 */ 8849ab747fSPaolo Bonzini #define GEM_TX512CNT (0x00000128/4) /* Error-free 512-1023 TX */ 8949ab747fSPaolo Bonzini #define GEM_TX1024CNT (0x0000012C/4) /* Error-free 1024-1518 TX */ 9049ab747fSPaolo Bonzini #define GEM_TX1519CNT (0x00000130/4) /* Error-free larger than 1519 TX */ 9149ab747fSPaolo Bonzini #define GEM_TXURUNCNT (0x00000134/4) /* TX under run error counter */ 9249ab747fSPaolo Bonzini #define GEM_SINGLECOLLCNT (0x00000138/4) /* Single Collision Frames */ 9349ab747fSPaolo Bonzini #define GEM_MULTCOLLCNT (0x0000013C/4) /* Multiple Collision Frames */ 9449ab747fSPaolo Bonzini #define GEM_EXCESSCOLLCNT (0x00000140/4) /* Excessive Collision Frames */ 9549ab747fSPaolo Bonzini #define GEM_LATECOLLCNT (0x00000144/4) /* Late Collision Frames */ 9649ab747fSPaolo Bonzini #define GEM_DEFERTXCNT (0x00000148/4) /* Deferred Transmission Frames */ 9749ab747fSPaolo Bonzini #define GEM_CSENSECNT (0x0000014C/4) /* Carrier Sense Error Counter */ 9849ab747fSPaolo Bonzini #define GEM_OCTRXLO (0x00000150/4) /* Octects Received register Low */ 9949ab747fSPaolo Bonzini #define GEM_OCTRXHI (0x00000154/4) /* Octects Received register High */ 10049ab747fSPaolo Bonzini #define GEM_RXCNT (0x00000158/4) /* Error-free Frames Received */ 10149ab747fSPaolo Bonzini #define GEM_RXBROADCNT (0x0000015C/4) /* Error-free Broadcast Frames RX */ 10249ab747fSPaolo Bonzini #define GEM_RXMULTICNT (0x00000160/4) /* Error-free Multicast Frames RX */ 10349ab747fSPaolo Bonzini #define GEM_RXPAUSECNT (0x00000164/4) /* Pause Frames Received Counter */ 10449ab747fSPaolo Bonzini #define GEM_RX64CNT (0x00000168/4) /* Error-free 64 byte Frames RX */ 10549ab747fSPaolo Bonzini #define GEM_RX65CNT (0x0000016C/4) /* Error-free 65-127B Frames RX */ 10649ab747fSPaolo Bonzini #define GEM_RX128CNT (0x00000170/4) /* Error-free 128-255B Frames RX */ 10749ab747fSPaolo Bonzini #define GEM_RX256CNT (0x00000174/4) /* Error-free 256-512B Frames RX */ 10849ab747fSPaolo Bonzini #define GEM_RX512CNT (0x00000178/4) /* Error-free 512-1023B Frames RX */ 10949ab747fSPaolo Bonzini #define GEM_RX1024CNT (0x0000017C/4) /* Error-free 1024-1518B Frames RX */ 11049ab747fSPaolo Bonzini #define GEM_RX1519CNT (0x00000180/4) /* Error-free 1519-max Frames RX */ 11149ab747fSPaolo Bonzini #define GEM_RXUNDERCNT (0x00000184/4) /* Undersize Frames Received */ 11249ab747fSPaolo Bonzini #define GEM_RXOVERCNT (0x00000188/4) /* Oversize Frames Received */ 11349ab747fSPaolo Bonzini #define GEM_RXJABCNT (0x0000018C/4) /* Jabbers Received Counter */ 11449ab747fSPaolo Bonzini #define GEM_RXFCSCNT (0x00000190/4) /* Frame Check seq. Error Counter */ 11549ab747fSPaolo Bonzini #define GEM_RXLENERRCNT (0x00000194/4) /* Length Field Error Counter */ 11649ab747fSPaolo Bonzini #define GEM_RXSYMERRCNT (0x00000198/4) /* Symbol Error Counter */ 11749ab747fSPaolo Bonzini #define GEM_RXALIGNERRCNT (0x0000019C/4) /* Alignment Error Counter */ 11849ab747fSPaolo Bonzini #define GEM_RXRSCERRCNT (0x000001A0/4) /* Receive Resource Error Counter */ 11949ab747fSPaolo Bonzini #define GEM_RXORUNCNT (0x000001A4/4) /* Receive Overrun Counter */ 12049ab747fSPaolo Bonzini #define GEM_RXIPCSERRCNT (0x000001A8/4) /* IP header Checksum Error Counter */ 12149ab747fSPaolo Bonzini #define GEM_RXTCPCCNT (0x000001AC/4) /* TCP Checksum Error Counter */ 12249ab747fSPaolo Bonzini #define GEM_RXUDPCCNT (0x000001B0/4) /* UDP Checksum Error Counter */ 12349ab747fSPaolo Bonzini 12449ab747fSPaolo Bonzini #define GEM_1588S (0x000001D0/4) /* 1588 Timer Seconds */ 12549ab747fSPaolo Bonzini #define GEM_1588NS (0x000001D4/4) /* 1588 Timer Nanoseconds */ 12649ab747fSPaolo Bonzini #define GEM_1588ADJ (0x000001D8/4) /* 1588 Timer Adjust */ 12749ab747fSPaolo Bonzini #define GEM_1588INC (0x000001DC/4) /* 1588 Timer Increment */ 12849ab747fSPaolo Bonzini #define GEM_PTPETXS (0x000001E0/4) /* PTP Event Frame Transmitted (s) */ 12949ab747fSPaolo Bonzini #define GEM_PTPETXNS (0x000001E4/4) /* PTP Event Frame Transmitted (ns) */ 13049ab747fSPaolo Bonzini #define GEM_PTPERXS (0x000001E8/4) /* PTP Event Frame Received (s) */ 13149ab747fSPaolo Bonzini #define GEM_PTPERXNS (0x000001EC/4) /* PTP Event Frame Received (ns) */ 13249ab747fSPaolo Bonzini #define GEM_PTPPTXS (0x000001E0/4) /* PTP Peer Frame Transmitted (s) */ 13349ab747fSPaolo Bonzini #define GEM_PTPPTXNS (0x000001E4/4) /* PTP Peer Frame Transmitted (ns) */ 13449ab747fSPaolo Bonzini #define GEM_PTPPRXS (0x000001E8/4) /* PTP Peer Frame Received (s) */ 13549ab747fSPaolo Bonzini #define GEM_PTPPRXNS (0x000001EC/4) /* PTP Peer Frame Received (ns) */ 13649ab747fSPaolo Bonzini 13749ab747fSPaolo Bonzini /* Design Configuration Registers */ 13849ab747fSPaolo Bonzini #define GEM_DESCONF (0x00000280/4) 13949ab747fSPaolo Bonzini #define GEM_DESCONF2 (0x00000284/4) 14049ab747fSPaolo Bonzini #define GEM_DESCONF3 (0x00000288/4) 14149ab747fSPaolo Bonzini #define GEM_DESCONF4 (0x0000028C/4) 14249ab747fSPaolo Bonzini #define GEM_DESCONF5 (0x00000290/4) 14349ab747fSPaolo Bonzini #define GEM_DESCONF6 (0x00000294/4) 14449ab747fSPaolo Bonzini #define GEM_DESCONF7 (0x00000298/4) 14549ab747fSPaolo Bonzini 146*67101725SAlistair Francis #define GEM_INT_Q1_STATUS (0x00000400 / 4) 147*67101725SAlistair Francis #define GEM_INT_Q1_MASK (0x00000640 / 4) 148*67101725SAlistair Francis 149*67101725SAlistair Francis #define GEM_TRANSMIT_Q1_PTR (0x00000440 / 4) 150*67101725SAlistair Francis #define GEM_TRANSMIT_Q15_PTR (GEM_TRANSMIT_Q1_PTR + 14) 151*67101725SAlistair Francis 152*67101725SAlistair Francis #define GEM_RECEIVE_Q1_PTR (0x00000480 / 4) 153*67101725SAlistair Francis #define GEM_RECEIVE_Q15_PTR (GEM_RECEIVE_Q1_PTR + 14) 154*67101725SAlistair Francis 155*67101725SAlistair Francis #define GEM_INT_Q1_ENABLE (0x00000600 / 4) 156*67101725SAlistair Francis #define GEM_INT_Q7_ENABLE (GEM_INT_Q1_ENABLE + 6) 157*67101725SAlistair Francis #define GEM_INT_Q8_ENABLE (0x00000660 / 4) 158*67101725SAlistair Francis #define GEM_INT_Q15_ENABLE (GEM_INT_Q8_ENABLE + 7) 159*67101725SAlistair Francis 160*67101725SAlistair Francis #define GEM_INT_Q1_DISABLE (0x00000620 / 4) 161*67101725SAlistair Francis #define GEM_INT_Q7_DISABLE (GEM_INT_Q1_DISABLE + 6) 162*67101725SAlistair Francis #define GEM_INT_Q8_DISABLE (0x00000680 / 4) 163*67101725SAlistair Francis #define GEM_INT_Q15_DISABLE (GEM_INT_Q8_DISABLE + 7) 164*67101725SAlistair Francis 165*67101725SAlistair Francis #define GEM_INT_Q1_MASK (0x00000640 / 4) 166*67101725SAlistair Francis #define GEM_INT_Q7_MASK (GEM_INT_Q1_MASK + 6) 167*67101725SAlistair Francis #define GEM_INT_Q8_MASK (0x000006A0 / 4) 168*67101725SAlistair Francis #define GEM_INT_Q15_MASK (GEM_INT_Q8_MASK + 7) 169*67101725SAlistair Francis 170e8e49943SAlistair Francis #define GEM_SCREENING_TYPE1_REGISTER_0 (0x00000500 / 4) 171e8e49943SAlistair Francis 172e8e49943SAlistair Francis #define GEM_ST1R_UDP_PORT_MATCH_ENABLE (1 << 29) 173e8e49943SAlistair Francis #define GEM_ST1R_DSTC_ENABLE (1 << 28) 174e8e49943SAlistair Francis #define GEM_ST1R_UDP_PORT_MATCH_SHIFT (12) 175e8e49943SAlistair Francis #define GEM_ST1R_UDP_PORT_MATCH_WIDTH (27 - GEM_ST1R_UDP_PORT_MATCH_SHIFT + 1) 176e8e49943SAlistair Francis #define GEM_ST1R_DSTC_MATCH_SHIFT (4) 177e8e49943SAlistair Francis #define GEM_ST1R_DSTC_MATCH_WIDTH (11 - GEM_ST1R_DSTC_MATCH_SHIFT + 1) 178e8e49943SAlistair Francis #define GEM_ST1R_QUEUE_SHIFT (0) 179e8e49943SAlistair Francis #define GEM_ST1R_QUEUE_WIDTH (3 - GEM_ST1R_QUEUE_SHIFT + 1) 180e8e49943SAlistair Francis 181e8e49943SAlistair Francis #define GEM_SCREENING_TYPE2_REGISTER_0 (0x00000540 / 4) 182e8e49943SAlistair Francis 183e8e49943SAlistair Francis #define GEM_ST2R_COMPARE_A_ENABLE (1 << 18) 184e8e49943SAlistair Francis #define GEM_ST2R_COMPARE_A_SHIFT (13) 185e8e49943SAlistair Francis #define GEM_ST2R_COMPARE_WIDTH (17 - GEM_ST2R_COMPARE_A_SHIFT + 1) 186e8e49943SAlistair Francis #define GEM_ST2R_ETHERTYPE_ENABLE (1 << 12) 187e8e49943SAlistair Francis #define GEM_ST2R_ETHERTYPE_INDEX_SHIFT (9) 188e8e49943SAlistair Francis #define GEM_ST2R_ETHERTYPE_INDEX_WIDTH (11 - GEM_ST2R_ETHERTYPE_INDEX_SHIFT \ 189e8e49943SAlistair Francis + 1) 190e8e49943SAlistair Francis #define GEM_ST2R_QUEUE_SHIFT (0) 191e8e49943SAlistair Francis #define GEM_ST2R_QUEUE_WIDTH (3 - GEM_ST2R_QUEUE_SHIFT + 1) 192e8e49943SAlistair Francis 193e8e49943SAlistair Francis #define GEM_SCREENING_TYPE2_ETHERTYPE_REG_0 (0x000006e0 / 4) 194e8e49943SAlistair Francis #define GEM_TYPE2_COMPARE_0_WORD_0 (0x00000700 / 4) 195e8e49943SAlistair Francis 196e8e49943SAlistair Francis #define GEM_T2CW1_COMPARE_OFFSET_SHIFT (7) 197e8e49943SAlistair Francis #define GEM_T2CW1_COMPARE_OFFSET_WIDTH (8 - GEM_T2CW1_COMPARE_OFFSET_SHIFT + 1) 198e8e49943SAlistair Francis #define GEM_T2CW1_OFFSET_VALUE_SHIFT (0) 199e8e49943SAlistair Francis #define GEM_T2CW1_OFFSET_VALUE_WIDTH (6 - GEM_T2CW1_OFFSET_VALUE_SHIFT + 1) 200e8e49943SAlistair Francis 20149ab747fSPaolo Bonzini /*****************************************/ 20249ab747fSPaolo Bonzini #define GEM_NWCTRL_TXSTART 0x00000200 /* Transmit Enable */ 20349ab747fSPaolo Bonzini #define GEM_NWCTRL_TXENA 0x00000008 /* Transmit Enable */ 20449ab747fSPaolo Bonzini #define GEM_NWCTRL_RXENA 0x00000004 /* Receive Enable */ 20549ab747fSPaolo Bonzini #define GEM_NWCTRL_LOCALLOOP 0x00000002 /* Local Loopback */ 20649ab747fSPaolo Bonzini 20749ab747fSPaolo Bonzini #define GEM_NWCFG_STRIP_FCS 0x00020000 /* Strip FCS field */ 2083048ed6aSPeter Crosthwaite #define GEM_NWCFG_LERR_DISC 0x00010000 /* Discard RX frames with len err */ 20949ab747fSPaolo Bonzini #define GEM_NWCFG_BUFF_OFST_M 0x0000C000 /* Receive buffer offset mask */ 21049ab747fSPaolo Bonzini #define GEM_NWCFG_BUFF_OFST_S 14 /* Receive buffer offset shift */ 21149ab747fSPaolo Bonzini #define GEM_NWCFG_UCAST_HASH 0x00000080 /* accept unicast if hash match */ 21249ab747fSPaolo Bonzini #define GEM_NWCFG_MCAST_HASH 0x00000040 /* accept multicast if hash match */ 21349ab747fSPaolo Bonzini #define GEM_NWCFG_BCAST_REJ 0x00000020 /* Reject broadcast packets */ 21449ab747fSPaolo Bonzini #define GEM_NWCFG_PROMISC 0x00000010 /* Accept all packets */ 21549ab747fSPaolo Bonzini 2162801339fSSai Pavan Boddu #define GEM_DMACFG_RBUFSZ_M 0x00FF0000 /* DMA RX Buffer Size mask */ 21749ab747fSPaolo Bonzini #define GEM_DMACFG_RBUFSZ_S 16 /* DMA RX Buffer Size shift */ 21849ab747fSPaolo Bonzini #define GEM_DMACFG_RBUFSZ_MUL 64 /* DMA RX Buffer Size multiplier */ 21949ab747fSPaolo Bonzini #define GEM_DMACFG_TXCSUM_OFFL 0x00000800 /* Transmit checksum offload */ 22049ab747fSPaolo Bonzini 22149ab747fSPaolo Bonzini #define GEM_TXSTATUS_TXCMPL 0x00000020 /* Transmit Complete */ 22249ab747fSPaolo Bonzini #define GEM_TXSTATUS_USED 0x00000001 /* sw owned descriptor encountered */ 22349ab747fSPaolo Bonzini 22449ab747fSPaolo Bonzini #define GEM_RXSTATUS_FRMRCVD 0x00000002 /* Frame received */ 22549ab747fSPaolo Bonzini #define GEM_RXSTATUS_NOBUF 0x00000001 /* Buffer unavailable */ 22649ab747fSPaolo Bonzini 22749ab747fSPaolo Bonzini /* GEM_ISR GEM_IER GEM_IDR GEM_IMR */ 22849ab747fSPaolo Bonzini #define GEM_INT_TXCMPL 0x00000080 /* Transmit Complete */ 22949ab747fSPaolo Bonzini #define GEM_INT_TXUSED 0x00000008 23049ab747fSPaolo Bonzini #define GEM_INT_RXUSED 0x00000004 23149ab747fSPaolo Bonzini #define GEM_INT_RXCMPL 0x00000002 23249ab747fSPaolo Bonzini 23349ab747fSPaolo Bonzini #define GEM_PHYMNTNC_OP_R 0x20000000 /* read operation */ 23449ab747fSPaolo Bonzini #define GEM_PHYMNTNC_OP_W 0x10000000 /* write operation */ 23549ab747fSPaolo Bonzini #define GEM_PHYMNTNC_ADDR 0x0F800000 /* Address bits */ 23649ab747fSPaolo Bonzini #define GEM_PHYMNTNC_ADDR_SHFT 23 23749ab747fSPaolo Bonzini #define GEM_PHYMNTNC_REG 0x007C0000 /* register bits */ 23849ab747fSPaolo Bonzini #define GEM_PHYMNTNC_REG_SHIFT 18 23949ab747fSPaolo Bonzini 24049ab747fSPaolo Bonzini /* Marvell PHY definitions */ 24149ab747fSPaolo Bonzini #define BOARD_PHY_ADDRESS 23 /* PHY address we will emulate a device at */ 24249ab747fSPaolo Bonzini 24349ab747fSPaolo Bonzini #define PHY_REG_CONTROL 0 24449ab747fSPaolo Bonzini #define PHY_REG_STATUS 1 24549ab747fSPaolo Bonzini #define PHY_REG_PHYID1 2 24649ab747fSPaolo Bonzini #define PHY_REG_PHYID2 3 24749ab747fSPaolo Bonzini #define PHY_REG_ANEGADV 4 24849ab747fSPaolo Bonzini #define PHY_REG_LINKPABIL 5 24949ab747fSPaolo Bonzini #define PHY_REG_ANEGEXP 6 25049ab747fSPaolo Bonzini #define PHY_REG_NEXTP 7 25149ab747fSPaolo Bonzini #define PHY_REG_LINKPNEXTP 8 25249ab747fSPaolo Bonzini #define PHY_REG_100BTCTRL 9 25349ab747fSPaolo Bonzini #define PHY_REG_1000BTSTAT 10 25449ab747fSPaolo Bonzini #define PHY_REG_EXTSTAT 15 25549ab747fSPaolo Bonzini #define PHY_REG_PHYSPCFC_CTL 16 25649ab747fSPaolo Bonzini #define PHY_REG_PHYSPCFC_ST 17 25749ab747fSPaolo Bonzini #define PHY_REG_INT_EN 18 25849ab747fSPaolo Bonzini #define PHY_REG_INT_ST 19 25949ab747fSPaolo Bonzini #define PHY_REG_EXT_PHYSPCFC_CTL 20 26049ab747fSPaolo Bonzini #define PHY_REG_RXERR 21 26149ab747fSPaolo Bonzini #define PHY_REG_EACD 22 26249ab747fSPaolo Bonzini #define PHY_REG_LED 24 26349ab747fSPaolo Bonzini #define PHY_REG_LED_OVRD 25 26449ab747fSPaolo Bonzini #define PHY_REG_EXT_PHYSPCFC_CTL2 26 26549ab747fSPaolo Bonzini #define PHY_REG_EXT_PHYSPCFC_ST 27 26649ab747fSPaolo Bonzini #define PHY_REG_CABLE_DIAG 28 26749ab747fSPaolo Bonzini 26849ab747fSPaolo Bonzini #define PHY_REG_CONTROL_RST 0x8000 26949ab747fSPaolo Bonzini #define PHY_REG_CONTROL_LOOP 0x4000 27049ab747fSPaolo Bonzini #define PHY_REG_CONTROL_ANEG 0x1000 27149ab747fSPaolo Bonzini 27249ab747fSPaolo Bonzini #define PHY_REG_STATUS_LINK 0x0004 27349ab747fSPaolo Bonzini #define PHY_REG_STATUS_ANEGCMPL 0x0020 27449ab747fSPaolo Bonzini 27549ab747fSPaolo Bonzini #define PHY_REG_INT_ST_ANEGCMPL 0x0800 27649ab747fSPaolo Bonzini #define PHY_REG_INT_ST_LINKC 0x0400 27749ab747fSPaolo Bonzini #define PHY_REG_INT_ST_ENERGY 0x0010 27849ab747fSPaolo Bonzini 27949ab747fSPaolo Bonzini /***********************************************************************/ 28063af1e0cSPeter Crosthwaite #define GEM_RX_REJECT (-1) 28163af1e0cSPeter Crosthwaite #define GEM_RX_PROMISCUOUS_ACCEPT (-2) 28263af1e0cSPeter Crosthwaite #define GEM_RX_BROADCAST_ACCEPT (-3) 28363af1e0cSPeter Crosthwaite #define GEM_RX_MULTICAST_HASH_ACCEPT (-4) 28463af1e0cSPeter Crosthwaite #define GEM_RX_UNICAST_HASH_ACCEPT (-5) 28563af1e0cSPeter Crosthwaite 28663af1e0cSPeter Crosthwaite #define GEM_RX_SAR_ACCEPT 0 28749ab747fSPaolo Bonzini 28849ab747fSPaolo Bonzini /***********************************************************************/ 28949ab747fSPaolo Bonzini 29049ab747fSPaolo Bonzini #define DESC_1_USED 0x80000000 29149ab747fSPaolo Bonzini #define DESC_1_LENGTH 0x00001FFF 29249ab747fSPaolo Bonzini 29349ab747fSPaolo Bonzini #define DESC_1_TX_WRAP 0x40000000 29449ab747fSPaolo Bonzini #define DESC_1_TX_LAST 0x00008000 29549ab747fSPaolo Bonzini 29649ab747fSPaolo Bonzini #define DESC_0_RX_WRAP 0x00000002 29749ab747fSPaolo Bonzini #define DESC_0_RX_OWNERSHIP 0x00000001 29849ab747fSPaolo Bonzini 29963af1e0cSPeter Crosthwaite #define R_DESC_1_RX_SAR_SHIFT 25 30063af1e0cSPeter Crosthwaite #define R_DESC_1_RX_SAR_LENGTH 2 301a03f7429SPeter Crosthwaite #define R_DESC_1_RX_SAR_MATCH (1 << 27) 30263af1e0cSPeter Crosthwaite #define R_DESC_1_RX_UNICAST_HASH (1 << 29) 30363af1e0cSPeter Crosthwaite #define R_DESC_1_RX_MULTICAST_HASH (1 << 30) 30463af1e0cSPeter Crosthwaite #define R_DESC_1_RX_BROADCAST (1 << 31) 30563af1e0cSPeter Crosthwaite 30649ab747fSPaolo Bonzini #define DESC_1_RX_SOF 0x00004000 30749ab747fSPaolo Bonzini #define DESC_1_RX_EOF 0x00008000 30849ab747fSPaolo Bonzini 30949ab747fSPaolo Bonzini static inline unsigned tx_desc_get_buffer(unsigned *desc) 31049ab747fSPaolo Bonzini { 31149ab747fSPaolo Bonzini return desc[0]; 31249ab747fSPaolo Bonzini } 31349ab747fSPaolo Bonzini 31449ab747fSPaolo Bonzini static inline unsigned tx_desc_get_used(unsigned *desc) 31549ab747fSPaolo Bonzini { 31649ab747fSPaolo Bonzini return (desc[1] & DESC_1_USED) ? 1 : 0; 31749ab747fSPaolo Bonzini } 31849ab747fSPaolo Bonzini 31949ab747fSPaolo Bonzini static inline void tx_desc_set_used(unsigned *desc) 32049ab747fSPaolo Bonzini { 32149ab747fSPaolo Bonzini desc[1] |= DESC_1_USED; 32249ab747fSPaolo Bonzini } 32349ab747fSPaolo Bonzini 32449ab747fSPaolo Bonzini static inline unsigned tx_desc_get_wrap(unsigned *desc) 32549ab747fSPaolo Bonzini { 32649ab747fSPaolo Bonzini return (desc[1] & DESC_1_TX_WRAP) ? 1 : 0; 32749ab747fSPaolo Bonzini } 32849ab747fSPaolo Bonzini 32949ab747fSPaolo Bonzini static inline unsigned tx_desc_get_last(unsigned *desc) 33049ab747fSPaolo Bonzini { 33149ab747fSPaolo Bonzini return (desc[1] & DESC_1_TX_LAST) ? 1 : 0; 33249ab747fSPaolo Bonzini } 33349ab747fSPaolo Bonzini 334cbdab58dSAlistair Francis static inline void tx_desc_set_last(unsigned *desc) 335cbdab58dSAlistair Francis { 336cbdab58dSAlistair Francis desc[1] |= DESC_1_TX_LAST; 337cbdab58dSAlistair Francis } 338cbdab58dSAlistair Francis 33949ab747fSPaolo Bonzini static inline unsigned tx_desc_get_length(unsigned *desc) 34049ab747fSPaolo Bonzini { 34149ab747fSPaolo Bonzini return desc[1] & DESC_1_LENGTH; 34249ab747fSPaolo Bonzini } 34349ab747fSPaolo Bonzini 344*67101725SAlistair Francis static inline void print_gem_tx_desc(unsigned *desc, uint8_t queue) 34549ab747fSPaolo Bonzini { 346*67101725SAlistair Francis DB_PRINT("TXDESC (queue %" PRId8 "):\n", queue); 34749ab747fSPaolo Bonzini DB_PRINT("bufaddr: 0x%08x\n", *desc); 34849ab747fSPaolo Bonzini DB_PRINT("used_hw: %d\n", tx_desc_get_used(desc)); 34949ab747fSPaolo Bonzini DB_PRINT("wrap: %d\n", tx_desc_get_wrap(desc)); 35049ab747fSPaolo Bonzini DB_PRINT("last: %d\n", tx_desc_get_last(desc)); 35149ab747fSPaolo Bonzini DB_PRINT("length: %d\n", tx_desc_get_length(desc)); 35249ab747fSPaolo Bonzini } 35349ab747fSPaolo Bonzini 35449ab747fSPaolo Bonzini static inline unsigned rx_desc_get_buffer(unsigned *desc) 35549ab747fSPaolo Bonzini { 35649ab747fSPaolo Bonzini return desc[0] & ~0x3UL; 35749ab747fSPaolo Bonzini } 35849ab747fSPaolo Bonzini 35949ab747fSPaolo Bonzini static inline unsigned rx_desc_get_wrap(unsigned *desc) 36049ab747fSPaolo Bonzini { 36149ab747fSPaolo Bonzini return desc[0] & DESC_0_RX_WRAP ? 1 : 0; 36249ab747fSPaolo Bonzini } 36349ab747fSPaolo Bonzini 36449ab747fSPaolo Bonzini static inline unsigned rx_desc_get_ownership(unsigned *desc) 36549ab747fSPaolo Bonzini { 36649ab747fSPaolo Bonzini return desc[0] & DESC_0_RX_OWNERSHIP ? 1 : 0; 36749ab747fSPaolo Bonzini } 36849ab747fSPaolo Bonzini 36949ab747fSPaolo Bonzini static inline void rx_desc_set_ownership(unsigned *desc) 37049ab747fSPaolo Bonzini { 37149ab747fSPaolo Bonzini desc[0] |= DESC_0_RX_OWNERSHIP; 37249ab747fSPaolo Bonzini } 37349ab747fSPaolo Bonzini 37449ab747fSPaolo Bonzini static inline void rx_desc_set_sof(unsigned *desc) 37549ab747fSPaolo Bonzini { 37649ab747fSPaolo Bonzini desc[1] |= DESC_1_RX_SOF; 37749ab747fSPaolo Bonzini } 37849ab747fSPaolo Bonzini 37949ab747fSPaolo Bonzini static inline void rx_desc_set_eof(unsigned *desc) 38049ab747fSPaolo Bonzini { 38149ab747fSPaolo Bonzini desc[1] |= DESC_1_RX_EOF; 38249ab747fSPaolo Bonzini } 38349ab747fSPaolo Bonzini 38449ab747fSPaolo Bonzini static inline void rx_desc_set_length(unsigned *desc, unsigned len) 38549ab747fSPaolo Bonzini { 38649ab747fSPaolo Bonzini desc[1] &= ~DESC_1_LENGTH; 38749ab747fSPaolo Bonzini desc[1] |= len; 38849ab747fSPaolo Bonzini } 38949ab747fSPaolo Bonzini 39063af1e0cSPeter Crosthwaite static inline void rx_desc_set_broadcast(unsigned *desc) 39163af1e0cSPeter Crosthwaite { 39263af1e0cSPeter Crosthwaite desc[1] |= R_DESC_1_RX_BROADCAST; 39363af1e0cSPeter Crosthwaite } 39463af1e0cSPeter Crosthwaite 39563af1e0cSPeter Crosthwaite static inline void rx_desc_set_unicast_hash(unsigned *desc) 39663af1e0cSPeter Crosthwaite { 39763af1e0cSPeter Crosthwaite desc[1] |= R_DESC_1_RX_UNICAST_HASH; 39863af1e0cSPeter Crosthwaite } 39963af1e0cSPeter Crosthwaite 40063af1e0cSPeter Crosthwaite static inline void rx_desc_set_multicast_hash(unsigned *desc) 40163af1e0cSPeter Crosthwaite { 40263af1e0cSPeter Crosthwaite desc[1] |= R_DESC_1_RX_MULTICAST_HASH; 40363af1e0cSPeter Crosthwaite } 40463af1e0cSPeter Crosthwaite 40563af1e0cSPeter Crosthwaite static inline void rx_desc_set_sar(unsigned *desc, int sar_idx) 40663af1e0cSPeter Crosthwaite { 40763af1e0cSPeter Crosthwaite desc[1] = deposit32(desc[1], R_DESC_1_RX_SAR_SHIFT, R_DESC_1_RX_SAR_LENGTH, 40863af1e0cSPeter Crosthwaite sar_idx); 409a03f7429SPeter Crosthwaite desc[1] |= R_DESC_1_RX_SAR_MATCH; 41063af1e0cSPeter Crosthwaite } 41163af1e0cSPeter Crosthwaite 41249ab747fSPaolo Bonzini /* The broadcast MAC address: 0xFFFFFFFFFFFF */ 4136a0a70b0SStefan Weil static const uint8_t broadcast_addr[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; 41449ab747fSPaolo Bonzini 41549ab747fSPaolo Bonzini /* 41649ab747fSPaolo Bonzini * gem_init_register_masks: 41749ab747fSPaolo Bonzini * One time initialization. 41849ab747fSPaolo Bonzini * Set masks to identify which register bits have magical clear properties 41949ab747fSPaolo Bonzini */ 420448f19e2SPeter Crosthwaite static void gem_init_register_masks(CadenceGEMState *s) 42149ab747fSPaolo Bonzini { 42249ab747fSPaolo Bonzini /* Mask of register bits which are read only */ 42349ab747fSPaolo Bonzini memset(&s->regs_ro[0], 0, sizeof(s->regs_ro)); 42449ab747fSPaolo Bonzini s->regs_ro[GEM_NWCTRL] = 0xFFF80000; 42549ab747fSPaolo Bonzini s->regs_ro[GEM_NWSTATUS] = 0xFFFFFFFF; 42649ab747fSPaolo Bonzini s->regs_ro[GEM_DMACFG] = 0xFE00F000; 42749ab747fSPaolo Bonzini s->regs_ro[GEM_TXSTATUS] = 0xFFFFFE08; 42849ab747fSPaolo Bonzini s->regs_ro[GEM_RXQBASE] = 0x00000003; 42949ab747fSPaolo Bonzini s->regs_ro[GEM_TXQBASE] = 0x00000003; 43049ab747fSPaolo Bonzini s->regs_ro[GEM_RXSTATUS] = 0xFFFFFFF0; 43149ab747fSPaolo Bonzini s->regs_ro[GEM_ISR] = 0xFFFFFFFF; 43249ab747fSPaolo Bonzini s->regs_ro[GEM_IMR] = 0xFFFFFFFF; 43349ab747fSPaolo Bonzini s->regs_ro[GEM_MODID] = 0xFFFFFFFF; 43449ab747fSPaolo Bonzini 43549ab747fSPaolo Bonzini /* Mask of register bits which are clear on read */ 43649ab747fSPaolo Bonzini memset(&s->regs_rtc[0], 0, sizeof(s->regs_rtc)); 43749ab747fSPaolo Bonzini s->regs_rtc[GEM_ISR] = 0xFFFFFFFF; 43849ab747fSPaolo Bonzini 43949ab747fSPaolo Bonzini /* Mask of register bits which are write 1 to clear */ 44049ab747fSPaolo Bonzini memset(&s->regs_w1c[0], 0, sizeof(s->regs_w1c)); 44149ab747fSPaolo Bonzini s->regs_w1c[GEM_TXSTATUS] = 0x000001F7; 44249ab747fSPaolo Bonzini s->regs_w1c[GEM_RXSTATUS] = 0x0000000F; 44349ab747fSPaolo Bonzini 44449ab747fSPaolo Bonzini /* Mask of register bits which are write only */ 44549ab747fSPaolo Bonzini memset(&s->regs_wo[0], 0, sizeof(s->regs_wo)); 44649ab747fSPaolo Bonzini s->regs_wo[GEM_NWCTRL] = 0x00073E60; 44749ab747fSPaolo Bonzini s->regs_wo[GEM_IER] = 0x07FFFFFF; 44849ab747fSPaolo Bonzini s->regs_wo[GEM_IDR] = 0x07FFFFFF; 44949ab747fSPaolo Bonzini } 45049ab747fSPaolo Bonzini 45149ab747fSPaolo Bonzini /* 45249ab747fSPaolo Bonzini * phy_update_link: 45349ab747fSPaolo Bonzini * Make the emulated PHY link state match the QEMU "interface" state. 45449ab747fSPaolo Bonzini */ 455448f19e2SPeter Crosthwaite static void phy_update_link(CadenceGEMState *s) 45649ab747fSPaolo Bonzini { 45749ab747fSPaolo Bonzini DB_PRINT("down %d\n", qemu_get_queue(s->nic)->link_down); 45849ab747fSPaolo Bonzini 45949ab747fSPaolo Bonzini /* Autonegotiation status mirrors link status. */ 46049ab747fSPaolo Bonzini if (qemu_get_queue(s->nic)->link_down) { 46149ab747fSPaolo Bonzini s->phy_regs[PHY_REG_STATUS] &= ~(PHY_REG_STATUS_ANEGCMPL | 46249ab747fSPaolo Bonzini PHY_REG_STATUS_LINK); 46349ab747fSPaolo Bonzini s->phy_regs[PHY_REG_INT_ST] |= PHY_REG_INT_ST_LINKC; 46449ab747fSPaolo Bonzini } else { 46549ab747fSPaolo Bonzini s->phy_regs[PHY_REG_STATUS] |= (PHY_REG_STATUS_ANEGCMPL | 46649ab747fSPaolo Bonzini PHY_REG_STATUS_LINK); 46749ab747fSPaolo Bonzini s->phy_regs[PHY_REG_INT_ST] |= (PHY_REG_INT_ST_LINKC | 46849ab747fSPaolo Bonzini PHY_REG_INT_ST_ANEGCMPL | 46949ab747fSPaolo Bonzini PHY_REG_INT_ST_ENERGY); 47049ab747fSPaolo Bonzini } 47149ab747fSPaolo Bonzini } 47249ab747fSPaolo Bonzini 47349ab747fSPaolo Bonzini static int gem_can_receive(NetClientState *nc) 47449ab747fSPaolo Bonzini { 475448f19e2SPeter Crosthwaite CadenceGEMState *s; 476*67101725SAlistair Francis int i; 47749ab747fSPaolo Bonzini 47849ab747fSPaolo Bonzini s = qemu_get_nic_opaque(nc); 47949ab747fSPaolo Bonzini 48049ab747fSPaolo Bonzini /* Do nothing if receive is not enabled. */ 48149ab747fSPaolo Bonzini if (!(s->regs[GEM_NWCTRL] & GEM_NWCTRL_RXENA)) { 4823ae5725fSPeter Crosthwaite if (s->can_rx_state != 1) { 4833ae5725fSPeter Crosthwaite s->can_rx_state = 1; 4843ae5725fSPeter Crosthwaite DB_PRINT("can't receive - no enable\n"); 4853ae5725fSPeter Crosthwaite } 48649ab747fSPaolo Bonzini return 0; 48749ab747fSPaolo Bonzini } 48849ab747fSPaolo Bonzini 489*67101725SAlistair Francis for (i = 0; i < s->num_priority_queues; i++) { 490*67101725SAlistair Francis if (rx_desc_get_ownership(s->rx_desc[i]) == 1) { 4918202aa53SPeter Crosthwaite if (s->can_rx_state != 2) { 4928202aa53SPeter Crosthwaite s->can_rx_state = 2; 493*67101725SAlistair Francis DB_PRINT("can't receive - busy buffer descriptor (q%d) 0x%x\n", 494*67101725SAlistair Francis i, s->rx_desc_addr[i]); 4958202aa53SPeter Crosthwaite } 4968202aa53SPeter Crosthwaite return 0; 4978202aa53SPeter Crosthwaite } 498*67101725SAlistair Francis } 4998202aa53SPeter Crosthwaite 5003ae5725fSPeter Crosthwaite if (s->can_rx_state != 0) { 5013ae5725fSPeter Crosthwaite s->can_rx_state = 0; 502*67101725SAlistair Francis DB_PRINT("can receive\n"); 5033ae5725fSPeter Crosthwaite } 50449ab747fSPaolo Bonzini return 1; 50549ab747fSPaolo Bonzini } 50649ab747fSPaolo Bonzini 50749ab747fSPaolo Bonzini /* 50849ab747fSPaolo Bonzini * gem_update_int_status: 50949ab747fSPaolo Bonzini * Raise or lower interrupt based on current status. 51049ab747fSPaolo Bonzini */ 511448f19e2SPeter Crosthwaite static void gem_update_int_status(CadenceGEMState *s) 51249ab747fSPaolo Bonzini { 513*67101725SAlistair Francis int i; 514*67101725SAlistair Francis 515*67101725SAlistair Francis if ((s->num_priority_queues == 1) && s->regs[GEM_ISR]) { 516*67101725SAlistair Francis /* No priority queues, just trigger the interrupt */ 517*67101725SAlistair Francis DB_PRINT("asserting int.\n", i); 5182bf57f73SAlistair Francis qemu_set_irq(s->irq[0], 1); 519*67101725SAlistair Francis return; 520*67101725SAlistair Francis } 521*67101725SAlistair Francis 522*67101725SAlistair Francis for (i = 0; i < s->num_priority_queues; ++i) { 523*67101725SAlistair Francis if (s->regs[GEM_INT_Q1_STATUS + i]) { 524*67101725SAlistair Francis DB_PRINT("asserting int. (q=%d)\n", i); 525*67101725SAlistair Francis qemu_set_irq(s->irq[i], 1); 526*67101725SAlistair Francis } 52749ab747fSPaolo Bonzini } 52849ab747fSPaolo Bonzini } 52949ab747fSPaolo Bonzini 53049ab747fSPaolo Bonzini /* 53149ab747fSPaolo Bonzini * gem_receive_updatestats: 53249ab747fSPaolo Bonzini * Increment receive statistics. 53349ab747fSPaolo Bonzini */ 534448f19e2SPeter Crosthwaite static void gem_receive_updatestats(CadenceGEMState *s, const uint8_t *packet, 53549ab747fSPaolo Bonzini unsigned bytes) 53649ab747fSPaolo Bonzini { 53749ab747fSPaolo Bonzini uint64_t octets; 53849ab747fSPaolo Bonzini 53949ab747fSPaolo Bonzini /* Total octets (bytes) received */ 54049ab747fSPaolo Bonzini octets = ((uint64_t)(s->regs[GEM_OCTRXLO]) << 32) | 54149ab747fSPaolo Bonzini s->regs[GEM_OCTRXHI]; 54249ab747fSPaolo Bonzini octets += bytes; 54349ab747fSPaolo Bonzini s->regs[GEM_OCTRXLO] = octets >> 32; 54449ab747fSPaolo Bonzini s->regs[GEM_OCTRXHI] = octets; 54549ab747fSPaolo Bonzini 54649ab747fSPaolo Bonzini /* Error-free Frames received */ 54749ab747fSPaolo Bonzini s->regs[GEM_RXCNT]++; 54849ab747fSPaolo Bonzini 54949ab747fSPaolo Bonzini /* Error-free Broadcast Frames counter */ 55049ab747fSPaolo Bonzini if (!memcmp(packet, broadcast_addr, 6)) { 55149ab747fSPaolo Bonzini s->regs[GEM_RXBROADCNT]++; 55249ab747fSPaolo Bonzini } 55349ab747fSPaolo Bonzini 55449ab747fSPaolo Bonzini /* Error-free Multicast Frames counter */ 55549ab747fSPaolo Bonzini if (packet[0] == 0x01) { 55649ab747fSPaolo Bonzini s->regs[GEM_RXMULTICNT]++; 55749ab747fSPaolo Bonzini } 55849ab747fSPaolo Bonzini 55949ab747fSPaolo Bonzini if (bytes <= 64) { 56049ab747fSPaolo Bonzini s->regs[GEM_RX64CNT]++; 56149ab747fSPaolo Bonzini } else if (bytes <= 127) { 56249ab747fSPaolo Bonzini s->regs[GEM_RX65CNT]++; 56349ab747fSPaolo Bonzini } else if (bytes <= 255) { 56449ab747fSPaolo Bonzini s->regs[GEM_RX128CNT]++; 56549ab747fSPaolo Bonzini } else if (bytes <= 511) { 56649ab747fSPaolo Bonzini s->regs[GEM_RX256CNT]++; 56749ab747fSPaolo Bonzini } else if (bytes <= 1023) { 56849ab747fSPaolo Bonzini s->regs[GEM_RX512CNT]++; 56949ab747fSPaolo Bonzini } else if (bytes <= 1518) { 57049ab747fSPaolo Bonzini s->regs[GEM_RX1024CNT]++; 57149ab747fSPaolo Bonzini } else { 57249ab747fSPaolo Bonzini s->regs[GEM_RX1519CNT]++; 57349ab747fSPaolo Bonzini } 57449ab747fSPaolo Bonzini } 57549ab747fSPaolo Bonzini 57649ab747fSPaolo Bonzini /* 57749ab747fSPaolo Bonzini * Get the MAC Address bit from the specified position 57849ab747fSPaolo Bonzini */ 57949ab747fSPaolo Bonzini static unsigned get_bit(const uint8_t *mac, unsigned bit) 58049ab747fSPaolo Bonzini { 58149ab747fSPaolo Bonzini unsigned byte; 58249ab747fSPaolo Bonzini 58349ab747fSPaolo Bonzini byte = mac[bit / 8]; 58449ab747fSPaolo Bonzini byte >>= (bit & 0x7); 58549ab747fSPaolo Bonzini byte &= 1; 58649ab747fSPaolo Bonzini 58749ab747fSPaolo Bonzini return byte; 58849ab747fSPaolo Bonzini } 58949ab747fSPaolo Bonzini 59049ab747fSPaolo Bonzini /* 59149ab747fSPaolo Bonzini * Calculate a GEM MAC Address hash index 59249ab747fSPaolo Bonzini */ 59349ab747fSPaolo Bonzini static unsigned calc_mac_hash(const uint8_t *mac) 59449ab747fSPaolo Bonzini { 59549ab747fSPaolo Bonzini int index_bit, mac_bit; 59649ab747fSPaolo Bonzini unsigned hash_index; 59749ab747fSPaolo Bonzini 59849ab747fSPaolo Bonzini hash_index = 0; 59949ab747fSPaolo Bonzini mac_bit = 5; 60049ab747fSPaolo Bonzini for (index_bit = 5; index_bit >= 0; index_bit--) { 60149ab747fSPaolo Bonzini hash_index |= (get_bit(mac, mac_bit) ^ 60249ab747fSPaolo Bonzini get_bit(mac, mac_bit + 6) ^ 60349ab747fSPaolo Bonzini get_bit(mac, mac_bit + 12) ^ 60449ab747fSPaolo Bonzini get_bit(mac, mac_bit + 18) ^ 60549ab747fSPaolo Bonzini get_bit(mac, mac_bit + 24) ^ 60649ab747fSPaolo Bonzini get_bit(mac, mac_bit + 30) ^ 60749ab747fSPaolo Bonzini get_bit(mac, mac_bit + 36) ^ 60849ab747fSPaolo Bonzini get_bit(mac, mac_bit + 42)) << index_bit; 60949ab747fSPaolo Bonzini mac_bit--; 61049ab747fSPaolo Bonzini } 61149ab747fSPaolo Bonzini 61249ab747fSPaolo Bonzini return hash_index; 61349ab747fSPaolo Bonzini } 61449ab747fSPaolo Bonzini 61549ab747fSPaolo Bonzini /* 61649ab747fSPaolo Bonzini * gem_mac_address_filter: 61749ab747fSPaolo Bonzini * Accept or reject this destination address? 61849ab747fSPaolo Bonzini * Returns: 61949ab747fSPaolo Bonzini * GEM_RX_REJECT: reject 62063af1e0cSPeter Crosthwaite * >= 0: Specific address accept (which matched SAR is returned) 62163af1e0cSPeter Crosthwaite * others for various other modes of accept: 62263af1e0cSPeter Crosthwaite * GEM_RM_PROMISCUOUS_ACCEPT, GEM_RX_BROADCAST_ACCEPT, 62363af1e0cSPeter Crosthwaite * GEM_RX_MULTICAST_HASH_ACCEPT or GEM_RX_UNICAST_HASH_ACCEPT 62449ab747fSPaolo Bonzini */ 625448f19e2SPeter Crosthwaite static int gem_mac_address_filter(CadenceGEMState *s, const uint8_t *packet) 62649ab747fSPaolo Bonzini { 62749ab747fSPaolo Bonzini uint8_t *gem_spaddr; 62849ab747fSPaolo Bonzini int i; 62949ab747fSPaolo Bonzini 63049ab747fSPaolo Bonzini /* Promiscuous mode? */ 63149ab747fSPaolo Bonzini if (s->regs[GEM_NWCFG] & GEM_NWCFG_PROMISC) { 63263af1e0cSPeter Crosthwaite return GEM_RX_PROMISCUOUS_ACCEPT; 63349ab747fSPaolo Bonzini } 63449ab747fSPaolo Bonzini 63549ab747fSPaolo Bonzini if (!memcmp(packet, broadcast_addr, 6)) { 63649ab747fSPaolo Bonzini /* Reject broadcast packets? */ 63749ab747fSPaolo Bonzini if (s->regs[GEM_NWCFG] & GEM_NWCFG_BCAST_REJ) { 63849ab747fSPaolo Bonzini return GEM_RX_REJECT; 63949ab747fSPaolo Bonzini } 64063af1e0cSPeter Crosthwaite return GEM_RX_BROADCAST_ACCEPT; 64149ab747fSPaolo Bonzini } 64249ab747fSPaolo Bonzini 64349ab747fSPaolo Bonzini /* Accept packets -w- hash match? */ 64449ab747fSPaolo Bonzini if ((packet[0] == 0x01 && (s->regs[GEM_NWCFG] & GEM_NWCFG_MCAST_HASH)) || 64549ab747fSPaolo Bonzini (packet[0] != 0x01 && (s->regs[GEM_NWCFG] & GEM_NWCFG_UCAST_HASH))) { 64649ab747fSPaolo Bonzini unsigned hash_index; 64749ab747fSPaolo Bonzini 64849ab747fSPaolo Bonzini hash_index = calc_mac_hash(packet); 64949ab747fSPaolo Bonzini if (hash_index < 32) { 65049ab747fSPaolo Bonzini if (s->regs[GEM_HASHLO] & (1<<hash_index)) { 65163af1e0cSPeter Crosthwaite return packet[0] == 0x01 ? GEM_RX_MULTICAST_HASH_ACCEPT : 65263af1e0cSPeter Crosthwaite GEM_RX_UNICAST_HASH_ACCEPT; 65349ab747fSPaolo Bonzini } 65449ab747fSPaolo Bonzini } else { 65549ab747fSPaolo Bonzini hash_index -= 32; 65649ab747fSPaolo Bonzini if (s->regs[GEM_HASHHI] & (1<<hash_index)) { 65763af1e0cSPeter Crosthwaite return packet[0] == 0x01 ? GEM_RX_MULTICAST_HASH_ACCEPT : 65863af1e0cSPeter Crosthwaite GEM_RX_UNICAST_HASH_ACCEPT; 65949ab747fSPaolo Bonzini } 66049ab747fSPaolo Bonzini } 66149ab747fSPaolo Bonzini } 66249ab747fSPaolo Bonzini 66349ab747fSPaolo Bonzini /* Check all 4 specific addresses */ 66449ab747fSPaolo Bonzini gem_spaddr = (uint8_t *)&(s->regs[GEM_SPADDR1LO]); 66563af1e0cSPeter Crosthwaite for (i = 3; i >= 0; i--) { 66664eb9301SPeter Crosthwaite if (s->sar_active[i] && !memcmp(packet, gem_spaddr + 8 * i, 6)) { 66763af1e0cSPeter Crosthwaite return GEM_RX_SAR_ACCEPT + i; 66849ab747fSPaolo Bonzini } 66949ab747fSPaolo Bonzini } 67049ab747fSPaolo Bonzini 67149ab747fSPaolo Bonzini /* No address match; reject the packet */ 67249ab747fSPaolo Bonzini return GEM_RX_REJECT; 67349ab747fSPaolo Bonzini } 67449ab747fSPaolo Bonzini 675e8e49943SAlistair Francis /* Figure out which queue the received data should be sent to */ 676e8e49943SAlistair Francis static int get_queue_from_screen(CadenceGEMState *s, uint8_t *rxbuf_ptr, 677e8e49943SAlistair Francis unsigned rxbufsize) 678e8e49943SAlistair Francis { 679e8e49943SAlistair Francis uint32_t reg; 680e8e49943SAlistair Francis bool matched, mismatched; 681e8e49943SAlistair Francis int i, j; 682e8e49943SAlistair Francis 683e8e49943SAlistair Francis for (i = 0; i < s->num_type1_screeners; i++) { 684e8e49943SAlistair Francis reg = s->regs[GEM_SCREENING_TYPE1_REGISTER_0 + i]; 685e8e49943SAlistair Francis matched = false; 686e8e49943SAlistair Francis mismatched = false; 687e8e49943SAlistair Francis 688e8e49943SAlistair Francis /* Screening is based on UDP Port */ 689e8e49943SAlistair Francis if (reg & GEM_ST1R_UDP_PORT_MATCH_ENABLE) { 690e8e49943SAlistair Francis uint16_t udp_port = rxbuf_ptr[14 + 22] << 8 | rxbuf_ptr[14 + 23]; 691e8e49943SAlistair Francis if (udp_port == extract32(reg, GEM_ST1R_UDP_PORT_MATCH_SHIFT, 692e8e49943SAlistair Francis GEM_ST1R_UDP_PORT_MATCH_WIDTH)) { 693e8e49943SAlistair Francis matched = true; 694e8e49943SAlistair Francis } else { 695e8e49943SAlistair Francis mismatched = true; 696e8e49943SAlistair Francis } 697e8e49943SAlistair Francis } 698e8e49943SAlistair Francis 699e8e49943SAlistair Francis /* Screening is based on DS/TC */ 700e8e49943SAlistair Francis if (reg & GEM_ST1R_DSTC_ENABLE) { 701e8e49943SAlistair Francis uint8_t dscp = rxbuf_ptr[14 + 1]; 702e8e49943SAlistair Francis if (dscp == extract32(reg, GEM_ST1R_DSTC_MATCH_SHIFT, 703e8e49943SAlistair Francis GEM_ST1R_DSTC_MATCH_WIDTH)) { 704e8e49943SAlistair Francis matched = true; 705e8e49943SAlistair Francis } else { 706e8e49943SAlistair Francis mismatched = true; 707e8e49943SAlistair Francis } 708e8e49943SAlistair Francis } 709e8e49943SAlistair Francis 710e8e49943SAlistair Francis if (matched && !mismatched) { 711e8e49943SAlistair Francis return extract32(reg, GEM_ST1R_QUEUE_SHIFT, GEM_ST1R_QUEUE_WIDTH); 712e8e49943SAlistair Francis } 713e8e49943SAlistair Francis } 714e8e49943SAlistair Francis 715e8e49943SAlistair Francis for (i = 0; i < s->num_type2_screeners; i++) { 716e8e49943SAlistair Francis reg = s->regs[GEM_SCREENING_TYPE2_REGISTER_0 + i]; 717e8e49943SAlistair Francis matched = false; 718e8e49943SAlistair Francis mismatched = false; 719e8e49943SAlistair Francis 720e8e49943SAlistair Francis if (reg & GEM_ST2R_ETHERTYPE_ENABLE) { 721e8e49943SAlistair Francis uint16_t type = rxbuf_ptr[12] << 8 | rxbuf_ptr[13]; 722e8e49943SAlistair Francis int et_idx = extract32(reg, GEM_ST2R_ETHERTYPE_INDEX_SHIFT, 723e8e49943SAlistair Francis GEM_ST2R_ETHERTYPE_INDEX_WIDTH); 724e8e49943SAlistair Francis 725e8e49943SAlistair Francis if (et_idx > s->num_type2_screeners) { 726e8e49943SAlistair Francis qemu_log_mask(LOG_GUEST_ERROR, "Out of range ethertype " 727e8e49943SAlistair Francis "register index: %d\n", et_idx); 728e8e49943SAlistair Francis } 729e8e49943SAlistair Francis if (type == s->regs[GEM_SCREENING_TYPE2_ETHERTYPE_REG_0 + 730e8e49943SAlistair Francis et_idx]) { 731e8e49943SAlistair Francis matched = true; 732e8e49943SAlistair Francis } else { 733e8e49943SAlistair Francis mismatched = true; 734e8e49943SAlistair Francis } 735e8e49943SAlistair Francis } 736e8e49943SAlistair Francis 737e8e49943SAlistair Francis /* Compare A, B, C */ 738e8e49943SAlistair Francis for (j = 0; j < 3; j++) { 739e8e49943SAlistair Francis uint32_t cr0, cr1, mask; 740e8e49943SAlistair Francis uint16_t rx_cmp; 741e8e49943SAlistair Francis int offset; 742e8e49943SAlistair Francis int cr_idx = extract32(reg, GEM_ST2R_COMPARE_A_SHIFT + j * 6, 743e8e49943SAlistair Francis GEM_ST2R_COMPARE_WIDTH); 744e8e49943SAlistair Francis 745e8e49943SAlistair Francis if (!(reg & (GEM_ST2R_COMPARE_A_ENABLE << (j * 6)))) { 746e8e49943SAlistair Francis continue; 747e8e49943SAlistair Francis } 748e8e49943SAlistair Francis if (cr_idx > s->num_type2_screeners) { 749e8e49943SAlistair Francis qemu_log_mask(LOG_GUEST_ERROR, "Out of range compare " 750e8e49943SAlistair Francis "register index: %d\n", cr_idx); 751e8e49943SAlistair Francis } 752e8e49943SAlistair Francis 753e8e49943SAlistair Francis cr0 = s->regs[GEM_TYPE2_COMPARE_0_WORD_0 + cr_idx * 2]; 754e8e49943SAlistair Francis cr1 = s->regs[GEM_TYPE2_COMPARE_0_WORD_0 + cr_idx * 2 + 1]; 755e8e49943SAlistair Francis offset = extract32(cr1, GEM_T2CW1_OFFSET_VALUE_SHIFT, 756e8e49943SAlistair Francis GEM_T2CW1_OFFSET_VALUE_WIDTH); 757e8e49943SAlistair Francis 758e8e49943SAlistair Francis switch (extract32(cr1, GEM_T2CW1_COMPARE_OFFSET_SHIFT, 759e8e49943SAlistair Francis GEM_T2CW1_COMPARE_OFFSET_WIDTH)) { 760e8e49943SAlistair Francis case 3: /* Skip UDP header */ 761e8e49943SAlistair Francis qemu_log_mask(LOG_UNIMP, "TCP compare offsets" 762e8e49943SAlistair Francis "unimplemented - assuming UDP\n"); 763e8e49943SAlistair Francis offset += 8; 764e8e49943SAlistair Francis /* Fallthrough */ 765e8e49943SAlistair Francis case 2: /* skip the IP header */ 766e8e49943SAlistair Francis offset += 20; 767e8e49943SAlistair Francis /* Fallthrough */ 768e8e49943SAlistair Francis case 1: /* Count from after the ethertype */ 769e8e49943SAlistair Francis offset += 14; 770e8e49943SAlistair Francis break; 771e8e49943SAlistair Francis case 0: 772e8e49943SAlistair Francis /* Offset from start of frame */ 773e8e49943SAlistair Francis break; 774e8e49943SAlistair Francis } 775e8e49943SAlistair Francis 776e8e49943SAlistair Francis rx_cmp = rxbuf_ptr[offset] << 8 | rxbuf_ptr[offset]; 777e8e49943SAlistair Francis mask = extract32(cr0, 0, 16); 778e8e49943SAlistair Francis 779e8e49943SAlistair Francis if ((rx_cmp & mask) == (extract32(cr0, 16, 16) & mask)) { 780e8e49943SAlistair Francis matched = true; 781e8e49943SAlistair Francis } else { 782e8e49943SAlistair Francis mismatched = true; 783e8e49943SAlistair Francis } 784e8e49943SAlistair Francis } 785e8e49943SAlistair Francis 786e8e49943SAlistair Francis if (matched && !mismatched) { 787e8e49943SAlistair Francis return extract32(reg, GEM_ST2R_QUEUE_SHIFT, GEM_ST2R_QUEUE_WIDTH); 788e8e49943SAlistair Francis } 789e8e49943SAlistair Francis } 790e8e49943SAlistair Francis 791e8e49943SAlistair Francis /* We made it here, assume it's queue 0 */ 792e8e49943SAlistair Francis return 0; 793e8e49943SAlistair Francis } 794e8e49943SAlistair Francis 795*67101725SAlistair Francis static void gem_get_rx_desc(CadenceGEMState *s, int q) 79606c2fe95SPeter Crosthwaite { 797*67101725SAlistair Francis DB_PRINT("read descriptor 0x%x\n", (unsigned)s->rx_desc_addr[q]); 79806c2fe95SPeter Crosthwaite /* read current descriptor */ 7992bf57f73SAlistair Francis cpu_physical_memory_read(s->rx_desc_addr[0], 8002bf57f73SAlistair Francis (uint8_t *)s->rx_desc[0], sizeof(s->rx_desc[0])); 80106c2fe95SPeter Crosthwaite 80206c2fe95SPeter Crosthwaite /* Descriptor owned by software ? */ 803*67101725SAlistair Francis if (rx_desc_get_ownership(s->rx_desc[q]) == 1) { 80406c2fe95SPeter Crosthwaite DB_PRINT("descriptor 0x%x owned by sw.\n", 805*67101725SAlistair Francis (unsigned)s->rx_desc_addr[q]); 80606c2fe95SPeter Crosthwaite s->regs[GEM_RXSTATUS] |= GEM_RXSTATUS_NOBUF; 80706c2fe95SPeter Crosthwaite s->regs[GEM_ISR] |= GEM_INT_RXUSED & ~(s->regs[GEM_IMR]); 80806c2fe95SPeter Crosthwaite /* Handle interrupt consequences */ 80906c2fe95SPeter Crosthwaite gem_update_int_status(s); 81006c2fe95SPeter Crosthwaite } 81106c2fe95SPeter Crosthwaite } 81206c2fe95SPeter Crosthwaite 81349ab747fSPaolo Bonzini /* 81449ab747fSPaolo Bonzini * gem_receive: 81549ab747fSPaolo Bonzini * Fit a packet handed to us by QEMU into the receive descriptor ring. 81649ab747fSPaolo Bonzini */ 81749ab747fSPaolo Bonzini static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size) 81849ab747fSPaolo Bonzini { 819448f19e2SPeter Crosthwaite CadenceGEMState *s; 82049ab747fSPaolo Bonzini unsigned rxbufsize, bytes_to_copy; 82149ab747fSPaolo Bonzini unsigned rxbuf_offset; 82249ab747fSPaolo Bonzini uint8_t rxbuf[2048]; 82349ab747fSPaolo Bonzini uint8_t *rxbuf_ptr; 8243b2c97f9SEdgar E. Iglesias bool first_desc = true; 82563af1e0cSPeter Crosthwaite int maf; 8262bf57f73SAlistair Francis int q = 0; 82749ab747fSPaolo Bonzini 82849ab747fSPaolo Bonzini s = qemu_get_nic_opaque(nc); 82949ab747fSPaolo Bonzini 83049ab747fSPaolo Bonzini /* Is this destination MAC address "for us" ? */ 83163af1e0cSPeter Crosthwaite maf = gem_mac_address_filter(s, buf); 83263af1e0cSPeter Crosthwaite if (maf == GEM_RX_REJECT) { 83349ab747fSPaolo Bonzini return -1; 83449ab747fSPaolo Bonzini } 83549ab747fSPaolo Bonzini 83649ab747fSPaolo Bonzini /* Discard packets with receive length error enabled ? */ 83749ab747fSPaolo Bonzini if (s->regs[GEM_NWCFG] & GEM_NWCFG_LERR_DISC) { 83849ab747fSPaolo Bonzini unsigned type_len; 83949ab747fSPaolo Bonzini 84049ab747fSPaolo Bonzini /* Fish the ethertype / length field out of the RX packet */ 84149ab747fSPaolo Bonzini type_len = buf[12] << 8 | buf[13]; 84249ab747fSPaolo Bonzini /* It is a length field, not an ethertype */ 84349ab747fSPaolo Bonzini if (type_len < 0x600) { 84449ab747fSPaolo Bonzini if (size < type_len) { 84549ab747fSPaolo Bonzini /* discard */ 84649ab747fSPaolo Bonzini return -1; 84749ab747fSPaolo Bonzini } 84849ab747fSPaolo Bonzini } 84949ab747fSPaolo Bonzini } 85049ab747fSPaolo Bonzini 85149ab747fSPaolo Bonzini /* 85249ab747fSPaolo Bonzini * Determine configured receive buffer offset (probably 0) 85349ab747fSPaolo Bonzini */ 85449ab747fSPaolo Bonzini rxbuf_offset = (s->regs[GEM_NWCFG] & GEM_NWCFG_BUFF_OFST_M) >> 85549ab747fSPaolo Bonzini GEM_NWCFG_BUFF_OFST_S; 85649ab747fSPaolo Bonzini 85749ab747fSPaolo Bonzini /* The configure size of each receive buffer. Determines how many 85849ab747fSPaolo Bonzini * buffers needed to hold this packet. 85949ab747fSPaolo Bonzini */ 86049ab747fSPaolo Bonzini rxbufsize = ((s->regs[GEM_DMACFG] & GEM_DMACFG_RBUFSZ_M) >> 86149ab747fSPaolo Bonzini GEM_DMACFG_RBUFSZ_S) * GEM_DMACFG_RBUFSZ_MUL; 86249ab747fSPaolo Bonzini bytes_to_copy = size; 86349ab747fSPaolo Bonzini 864f265ae8cSAlistair Francis /* Hardware allows a zero value here but warns against it. To avoid QEMU 865f265ae8cSAlistair Francis * indefinite loops we enforce a minimum value here 866f265ae8cSAlistair Francis */ 867f265ae8cSAlistair Francis if (rxbufsize < GEM_DMACFG_RBUFSZ_MUL) { 868f265ae8cSAlistair Francis rxbufsize = GEM_DMACFG_RBUFSZ_MUL; 869f265ae8cSAlistair Francis } 870f265ae8cSAlistair Francis 871191946c5SPeter Crosthwaite /* Pad to minimum length. Assume FCS field is stripped, logic 872191946c5SPeter Crosthwaite * below will increment it to the real minimum of 64 when 873191946c5SPeter Crosthwaite * not FCS stripping 874191946c5SPeter Crosthwaite */ 875191946c5SPeter Crosthwaite if (size < 60) { 876191946c5SPeter Crosthwaite size = 60; 877191946c5SPeter Crosthwaite } 878191946c5SPeter Crosthwaite 87949ab747fSPaolo Bonzini /* Strip of FCS field ? (usually yes) */ 88049ab747fSPaolo Bonzini if (s->regs[GEM_NWCFG] & GEM_NWCFG_STRIP_FCS) { 88149ab747fSPaolo Bonzini rxbuf_ptr = (void *)buf; 88249ab747fSPaolo Bonzini } else { 88349ab747fSPaolo Bonzini unsigned crc_val; 88449ab747fSPaolo Bonzini 885244381ecSPrasad J Pandit if (size > sizeof(rxbuf) - sizeof(crc_val)) { 886244381ecSPrasad J Pandit size = sizeof(rxbuf) - sizeof(crc_val); 887244381ecSPrasad J Pandit } 888244381ecSPrasad J Pandit bytes_to_copy = size; 88949ab747fSPaolo Bonzini /* The application wants the FCS field, which QEMU does not provide. 8903048ed6aSPeter Crosthwaite * We must try and calculate one. 89149ab747fSPaolo Bonzini */ 89249ab747fSPaolo Bonzini 89349ab747fSPaolo Bonzini memcpy(rxbuf, buf, size); 89449ab747fSPaolo Bonzini memset(rxbuf + size, 0, sizeof(rxbuf) - size); 89549ab747fSPaolo Bonzini rxbuf_ptr = rxbuf; 89649ab747fSPaolo Bonzini crc_val = cpu_to_le32(crc32(0, rxbuf, MAX(size, 60))); 897c94239feSPeter Maydell memcpy(rxbuf + size, &crc_val, sizeof(crc_val)); 89849ab747fSPaolo Bonzini 89949ab747fSPaolo Bonzini bytes_to_copy += 4; 90049ab747fSPaolo Bonzini size += 4; 90149ab747fSPaolo Bonzini } 90249ab747fSPaolo Bonzini 90349ab747fSPaolo Bonzini DB_PRINT("config bufsize: %d packet size: %ld\n", rxbufsize, size); 90449ab747fSPaolo Bonzini 905e8e49943SAlistair Francis /* Find which queue we are targetting */ 906e8e49943SAlistair Francis q = get_queue_from_screen(s, rxbuf_ptr, rxbufsize); 907e8e49943SAlistair Francis 9087cfd65e4SPeter Crosthwaite while (bytes_to_copy) { 90906c2fe95SPeter Crosthwaite /* Do nothing if receive is not enabled. */ 91006c2fe95SPeter Crosthwaite if (!gem_can_receive(nc)) { 91106c2fe95SPeter Crosthwaite assert(!first_desc); 91249ab747fSPaolo Bonzini return -1; 91349ab747fSPaolo Bonzini } 91449ab747fSPaolo Bonzini 91549ab747fSPaolo Bonzini DB_PRINT("copy %d bytes to 0x%x\n", MIN(bytes_to_copy, rxbufsize), 9162bf57f73SAlistair Francis rx_desc_get_buffer(s->rx_desc[q])); 91749ab747fSPaolo Bonzini 91849ab747fSPaolo Bonzini /* Copy packet data to emulated DMA buffer */ 9192bf57f73SAlistair Francis cpu_physical_memory_write(rx_desc_get_buffer(s->rx_desc[q]) + 9202bf57f73SAlistair Francis rxbuf_offset, 92149ab747fSPaolo Bonzini rxbuf_ptr, MIN(bytes_to_copy, rxbufsize)); 92249ab747fSPaolo Bonzini rxbuf_ptr += MIN(bytes_to_copy, rxbufsize); 92330570698SPeter Crosthwaite bytes_to_copy -= MIN(bytes_to_copy, rxbufsize); 9243b2c97f9SEdgar E. Iglesias 9253b2c97f9SEdgar E. Iglesias /* Update the descriptor. */ 9263b2c97f9SEdgar E. Iglesias if (first_desc) { 9272bf57f73SAlistair Francis rx_desc_set_sof(s->rx_desc[q]); 9283b2c97f9SEdgar E. Iglesias first_desc = false; 9293b2c97f9SEdgar E. Iglesias } 9303b2c97f9SEdgar E. Iglesias if (bytes_to_copy == 0) { 9312bf57f73SAlistair Francis rx_desc_set_eof(s->rx_desc[q]); 9322bf57f73SAlistair Francis rx_desc_set_length(s->rx_desc[q], size); 9333b2c97f9SEdgar E. Iglesias } 9342bf57f73SAlistair Francis rx_desc_set_ownership(s->rx_desc[q]); 93563af1e0cSPeter Crosthwaite 93663af1e0cSPeter Crosthwaite switch (maf) { 93763af1e0cSPeter Crosthwaite case GEM_RX_PROMISCUOUS_ACCEPT: 93863af1e0cSPeter Crosthwaite break; 93963af1e0cSPeter Crosthwaite case GEM_RX_BROADCAST_ACCEPT: 9402bf57f73SAlistair Francis rx_desc_set_broadcast(s->rx_desc[q]); 94163af1e0cSPeter Crosthwaite break; 94263af1e0cSPeter Crosthwaite case GEM_RX_UNICAST_HASH_ACCEPT: 9432bf57f73SAlistair Francis rx_desc_set_unicast_hash(s->rx_desc[q]); 94463af1e0cSPeter Crosthwaite break; 94563af1e0cSPeter Crosthwaite case GEM_RX_MULTICAST_HASH_ACCEPT: 9462bf57f73SAlistair Francis rx_desc_set_multicast_hash(s->rx_desc[q]); 94763af1e0cSPeter Crosthwaite break; 94863af1e0cSPeter Crosthwaite case GEM_RX_REJECT: 94963af1e0cSPeter Crosthwaite abort(); 95063af1e0cSPeter Crosthwaite default: /* SAR */ 9512bf57f73SAlistair Francis rx_desc_set_sar(s->rx_desc[q], maf); 95263af1e0cSPeter Crosthwaite } 95363af1e0cSPeter Crosthwaite 9543b2c97f9SEdgar E. Iglesias /* Descriptor write-back. */ 9552bf57f73SAlistair Francis cpu_physical_memory_write(s->rx_desc_addr[q], 9562bf57f73SAlistair Francis (uint8_t *)s->rx_desc[q], 9572bf57f73SAlistair Francis sizeof(s->rx_desc[q])); 9583b2c97f9SEdgar E. Iglesias 95949ab747fSPaolo Bonzini /* Next descriptor */ 9602bf57f73SAlistair Francis if (rx_desc_get_wrap(s->rx_desc[q])) { 96149ab747fSPaolo Bonzini DB_PRINT("wrapping RX descriptor list\n"); 9622bf57f73SAlistair Francis s->rx_desc_addr[q] = s->regs[GEM_RXQBASE]; 96349ab747fSPaolo Bonzini } else { 96449ab747fSPaolo Bonzini DB_PRINT("incrementing RX descriptor list\n"); 9652bf57f73SAlistair Francis s->rx_desc_addr[q] += 8; 96649ab747fSPaolo Bonzini } 967*67101725SAlistair Francis 968*67101725SAlistair Francis gem_get_rx_desc(s, q); 9697cfd65e4SPeter Crosthwaite } 97049ab747fSPaolo Bonzini 97149ab747fSPaolo Bonzini /* Count it */ 97249ab747fSPaolo Bonzini gem_receive_updatestats(s, buf, size); 97349ab747fSPaolo Bonzini 97449ab747fSPaolo Bonzini s->regs[GEM_RXSTATUS] |= GEM_RXSTATUS_FRMRCVD; 97549ab747fSPaolo Bonzini s->regs[GEM_ISR] |= GEM_INT_RXCMPL & ~(s->regs[GEM_IMR]); 97649ab747fSPaolo Bonzini 97749ab747fSPaolo Bonzini /* Handle interrupt consequences */ 97849ab747fSPaolo Bonzini gem_update_int_status(s); 97949ab747fSPaolo Bonzini 98049ab747fSPaolo Bonzini return size; 98149ab747fSPaolo Bonzini } 98249ab747fSPaolo Bonzini 98349ab747fSPaolo Bonzini /* 98449ab747fSPaolo Bonzini * gem_transmit_updatestats: 98549ab747fSPaolo Bonzini * Increment transmit statistics. 98649ab747fSPaolo Bonzini */ 987448f19e2SPeter Crosthwaite static void gem_transmit_updatestats(CadenceGEMState *s, const uint8_t *packet, 98849ab747fSPaolo Bonzini unsigned bytes) 98949ab747fSPaolo Bonzini { 99049ab747fSPaolo Bonzini uint64_t octets; 99149ab747fSPaolo Bonzini 99249ab747fSPaolo Bonzini /* Total octets (bytes) transmitted */ 99349ab747fSPaolo Bonzini octets = ((uint64_t)(s->regs[GEM_OCTTXLO]) << 32) | 99449ab747fSPaolo Bonzini s->regs[GEM_OCTTXHI]; 99549ab747fSPaolo Bonzini octets += bytes; 99649ab747fSPaolo Bonzini s->regs[GEM_OCTTXLO] = octets >> 32; 99749ab747fSPaolo Bonzini s->regs[GEM_OCTTXHI] = octets; 99849ab747fSPaolo Bonzini 99949ab747fSPaolo Bonzini /* Error-free Frames transmitted */ 100049ab747fSPaolo Bonzini s->regs[GEM_TXCNT]++; 100149ab747fSPaolo Bonzini 100249ab747fSPaolo Bonzini /* Error-free Broadcast Frames counter */ 100349ab747fSPaolo Bonzini if (!memcmp(packet, broadcast_addr, 6)) { 100449ab747fSPaolo Bonzini s->regs[GEM_TXBCNT]++; 100549ab747fSPaolo Bonzini } 100649ab747fSPaolo Bonzini 100749ab747fSPaolo Bonzini /* Error-free Multicast Frames counter */ 100849ab747fSPaolo Bonzini if (packet[0] == 0x01) { 100949ab747fSPaolo Bonzini s->regs[GEM_TXMCNT]++; 101049ab747fSPaolo Bonzini } 101149ab747fSPaolo Bonzini 101249ab747fSPaolo Bonzini if (bytes <= 64) { 101349ab747fSPaolo Bonzini s->regs[GEM_TX64CNT]++; 101449ab747fSPaolo Bonzini } else if (bytes <= 127) { 101549ab747fSPaolo Bonzini s->regs[GEM_TX65CNT]++; 101649ab747fSPaolo Bonzini } else if (bytes <= 255) { 101749ab747fSPaolo Bonzini s->regs[GEM_TX128CNT]++; 101849ab747fSPaolo Bonzini } else if (bytes <= 511) { 101949ab747fSPaolo Bonzini s->regs[GEM_TX256CNT]++; 102049ab747fSPaolo Bonzini } else if (bytes <= 1023) { 102149ab747fSPaolo Bonzini s->regs[GEM_TX512CNT]++; 102249ab747fSPaolo Bonzini } else if (bytes <= 1518) { 102349ab747fSPaolo Bonzini s->regs[GEM_TX1024CNT]++; 102449ab747fSPaolo Bonzini } else { 102549ab747fSPaolo Bonzini s->regs[GEM_TX1519CNT]++; 102649ab747fSPaolo Bonzini } 102749ab747fSPaolo Bonzini } 102849ab747fSPaolo Bonzini 102949ab747fSPaolo Bonzini /* 103049ab747fSPaolo Bonzini * gem_transmit: 103149ab747fSPaolo Bonzini * Fish packets out of the descriptor ring and feed them to QEMU 103249ab747fSPaolo Bonzini */ 1033448f19e2SPeter Crosthwaite static void gem_transmit(CadenceGEMState *s) 103449ab747fSPaolo Bonzini { 103549ab747fSPaolo Bonzini unsigned desc[2]; 103649ab747fSPaolo Bonzini hwaddr packet_desc_addr; 103749ab747fSPaolo Bonzini uint8_t tx_packet[2048]; 103849ab747fSPaolo Bonzini uint8_t *p; 103949ab747fSPaolo Bonzini unsigned total_bytes; 10402bf57f73SAlistair Francis int q = 0; 104149ab747fSPaolo Bonzini 104249ab747fSPaolo Bonzini /* Do nothing if transmit is not enabled. */ 104349ab747fSPaolo Bonzini if (!(s->regs[GEM_NWCTRL] & GEM_NWCTRL_TXENA)) { 104449ab747fSPaolo Bonzini return; 104549ab747fSPaolo Bonzini } 104649ab747fSPaolo Bonzini 104749ab747fSPaolo Bonzini DB_PRINT("\n"); 104849ab747fSPaolo Bonzini 10493048ed6aSPeter Crosthwaite /* The packet we will hand off to QEMU. 105049ab747fSPaolo Bonzini * Packets scattered across multiple descriptors are gathered to this 105149ab747fSPaolo Bonzini * one contiguous buffer first. 105249ab747fSPaolo Bonzini */ 105349ab747fSPaolo Bonzini p = tx_packet; 105449ab747fSPaolo Bonzini total_bytes = 0; 105549ab747fSPaolo Bonzini 1056*67101725SAlistair Francis for (q = s->num_priority_queues - 1; q >= 0; q--) { 105749ab747fSPaolo Bonzini /* read current descriptor */ 10582bf57f73SAlistair Francis packet_desc_addr = s->tx_desc_addr[q]; 1059fa15286aSPeter Crosthwaite 1060fa15286aSPeter Crosthwaite DB_PRINT("read descriptor 0x%" HWADDR_PRIx "\n", packet_desc_addr); 106149ab747fSPaolo Bonzini cpu_physical_memory_read(packet_desc_addr, 1062ef18c2f5SPeter Crosthwaite (uint8_t *)desc, sizeof(desc)); 106349ab747fSPaolo Bonzini /* Handle all descriptors owned by hardware */ 106449ab747fSPaolo Bonzini while (tx_desc_get_used(desc) == 0) { 106549ab747fSPaolo Bonzini 106649ab747fSPaolo Bonzini /* Do nothing if transmit is not enabled. */ 106749ab747fSPaolo Bonzini if (!(s->regs[GEM_NWCTRL] & GEM_NWCTRL_TXENA)) { 106849ab747fSPaolo Bonzini return; 106949ab747fSPaolo Bonzini } 1070*67101725SAlistair Francis print_gem_tx_desc(desc, q); 107149ab747fSPaolo Bonzini 107249ab747fSPaolo Bonzini /* The real hardware would eat this (and possibly crash). 107349ab747fSPaolo Bonzini * For QEMU let's lend a helping hand. 107449ab747fSPaolo Bonzini */ 107549ab747fSPaolo Bonzini if ((tx_desc_get_buffer(desc) == 0) || 107649ab747fSPaolo Bonzini (tx_desc_get_length(desc) == 0)) { 107749ab747fSPaolo Bonzini DB_PRINT("Invalid TX descriptor @ 0x%x\n", 107849ab747fSPaolo Bonzini (unsigned)packet_desc_addr); 107949ab747fSPaolo Bonzini break; 108049ab747fSPaolo Bonzini } 108149ab747fSPaolo Bonzini 1082d7f05365SMichael S. Tsirkin if (tx_desc_get_length(desc) > sizeof(tx_packet) - (p - tx_packet)) { 1083d7f05365SMichael S. Tsirkin DB_PRINT("TX descriptor @ 0x%x too large: size 0x%x space 0x%x\n", 1084d7f05365SMichael S. Tsirkin (unsigned)packet_desc_addr, 1085d7f05365SMichael S. Tsirkin (unsigned)tx_desc_get_length(desc), 1086d7f05365SMichael S. Tsirkin sizeof(tx_packet) - (p - tx_packet)); 1087d7f05365SMichael S. Tsirkin break; 1088d7f05365SMichael S. Tsirkin } 1089d7f05365SMichael S. Tsirkin 109049ab747fSPaolo Bonzini /* Gather this fragment of the packet from "dma memory" to our contig. 109149ab747fSPaolo Bonzini * buffer. 109249ab747fSPaolo Bonzini */ 109349ab747fSPaolo Bonzini cpu_physical_memory_read(tx_desc_get_buffer(desc), p, 109449ab747fSPaolo Bonzini tx_desc_get_length(desc)); 109549ab747fSPaolo Bonzini p += tx_desc_get_length(desc); 109649ab747fSPaolo Bonzini total_bytes += tx_desc_get_length(desc); 109749ab747fSPaolo Bonzini 109849ab747fSPaolo Bonzini /* Last descriptor for this packet; hand the whole thing off */ 109949ab747fSPaolo Bonzini if (tx_desc_get_last(desc)) { 11006ab57a6bSPeter Crosthwaite unsigned desc_first[2]; 11016ab57a6bSPeter Crosthwaite 110249ab747fSPaolo Bonzini /* Modify the 1st descriptor of this packet to be owned by 110349ab747fSPaolo Bonzini * the processor. 110449ab747fSPaolo Bonzini */ 11052bf57f73SAlistair Francis cpu_physical_memory_read(s->tx_desc_addr[q], (uint8_t *)desc_first, 11066ab57a6bSPeter Crosthwaite sizeof(desc_first)); 11076ab57a6bSPeter Crosthwaite tx_desc_set_used(desc_first); 11082bf57f73SAlistair Francis cpu_physical_memory_write(s->tx_desc_addr[q], (uint8_t *)desc_first, 11096ab57a6bSPeter Crosthwaite sizeof(desc_first)); 11103048ed6aSPeter Crosthwaite /* Advance the hardware current descriptor past this packet */ 111149ab747fSPaolo Bonzini if (tx_desc_get_wrap(desc)) { 11122bf57f73SAlistair Francis s->tx_desc_addr[q] = s->regs[GEM_TXQBASE]; 111349ab747fSPaolo Bonzini } else { 11142bf57f73SAlistair Francis s->tx_desc_addr[q] = packet_desc_addr + 8; 111549ab747fSPaolo Bonzini } 11162bf57f73SAlistair Francis DB_PRINT("TX descriptor next: 0x%08x\n", s->tx_desc_addr[q]); 111749ab747fSPaolo Bonzini 111849ab747fSPaolo Bonzini s->regs[GEM_TXSTATUS] |= GEM_TXSTATUS_TXCMPL; 111949ab747fSPaolo Bonzini s->regs[GEM_ISR] |= GEM_INT_TXCMPL & ~(s->regs[GEM_IMR]); 112049ab747fSPaolo Bonzini 1121*67101725SAlistair Francis /* Update queue interrupt status */ 1122*67101725SAlistair Francis if (s->num_priority_queues > 1) { 1123*67101725SAlistair Francis s->regs[GEM_INT_Q1_STATUS + q] |= 1124*67101725SAlistair Francis GEM_INT_TXCMPL & ~(s->regs[GEM_INT_Q1_MASK + q]); 1125*67101725SAlistair Francis } 1126*67101725SAlistair Francis 112749ab747fSPaolo Bonzini /* Handle interrupt consequences */ 112849ab747fSPaolo Bonzini gem_update_int_status(s); 112949ab747fSPaolo Bonzini 113049ab747fSPaolo Bonzini /* Is checksum offload enabled? */ 113149ab747fSPaolo Bonzini if (s->regs[GEM_DMACFG] & GEM_DMACFG_TXCSUM_OFFL) { 113249ab747fSPaolo Bonzini net_checksum_calculate(tx_packet, total_bytes); 113349ab747fSPaolo Bonzini } 113449ab747fSPaolo Bonzini 113549ab747fSPaolo Bonzini /* Update MAC statistics */ 113649ab747fSPaolo Bonzini gem_transmit_updatestats(s, tx_packet, total_bytes); 113749ab747fSPaolo Bonzini 113849ab747fSPaolo Bonzini /* Send the packet somewhere */ 113924e822eaSPeter Crosthwaite if (s->phy_loop || (s->regs[GEM_NWCTRL] & GEM_NWCTRL_LOCALLOOP)) { 114049ab747fSPaolo Bonzini gem_receive(qemu_get_queue(s->nic), tx_packet, total_bytes); 114149ab747fSPaolo Bonzini } else { 114249ab747fSPaolo Bonzini qemu_send_packet(qemu_get_queue(s->nic), tx_packet, 114349ab747fSPaolo Bonzini total_bytes); 114449ab747fSPaolo Bonzini } 114549ab747fSPaolo Bonzini 114649ab747fSPaolo Bonzini /* Prepare for next packet */ 114749ab747fSPaolo Bonzini p = tx_packet; 114849ab747fSPaolo Bonzini total_bytes = 0; 114949ab747fSPaolo Bonzini } 115049ab747fSPaolo Bonzini 115149ab747fSPaolo Bonzini /* read next descriptor */ 115249ab747fSPaolo Bonzini if (tx_desc_get_wrap(desc)) { 1153cbdab58dSAlistair Francis tx_desc_set_last(desc); 115449ab747fSPaolo Bonzini packet_desc_addr = s->regs[GEM_TXQBASE]; 115549ab747fSPaolo Bonzini } else { 115649ab747fSPaolo Bonzini packet_desc_addr += 8; 115749ab747fSPaolo Bonzini } 1158fa15286aSPeter Crosthwaite DB_PRINT("read descriptor 0x%" HWADDR_PRIx "\n", packet_desc_addr); 115949ab747fSPaolo Bonzini cpu_physical_memory_read(packet_desc_addr, 1160ef18c2f5SPeter Crosthwaite (uint8_t *)desc, sizeof(desc)); 116149ab747fSPaolo Bonzini } 116249ab747fSPaolo Bonzini 116349ab747fSPaolo Bonzini if (tx_desc_get_used(desc)) { 116449ab747fSPaolo Bonzini s->regs[GEM_TXSTATUS] |= GEM_TXSTATUS_USED; 116549ab747fSPaolo Bonzini s->regs[GEM_ISR] |= GEM_INT_TXUSED & ~(s->regs[GEM_IMR]); 116649ab747fSPaolo Bonzini gem_update_int_status(s); 116749ab747fSPaolo Bonzini } 116849ab747fSPaolo Bonzini } 1169*67101725SAlistair Francis } 117049ab747fSPaolo Bonzini 1171448f19e2SPeter Crosthwaite static void gem_phy_reset(CadenceGEMState *s) 117249ab747fSPaolo Bonzini { 117349ab747fSPaolo Bonzini memset(&s->phy_regs[0], 0, sizeof(s->phy_regs)); 117449ab747fSPaolo Bonzini s->phy_regs[PHY_REG_CONTROL] = 0x1140; 117549ab747fSPaolo Bonzini s->phy_regs[PHY_REG_STATUS] = 0x7969; 117649ab747fSPaolo Bonzini s->phy_regs[PHY_REG_PHYID1] = 0x0141; 117749ab747fSPaolo Bonzini s->phy_regs[PHY_REG_PHYID2] = 0x0CC2; 117849ab747fSPaolo Bonzini s->phy_regs[PHY_REG_ANEGADV] = 0x01E1; 117949ab747fSPaolo Bonzini s->phy_regs[PHY_REG_LINKPABIL] = 0xCDE1; 118049ab747fSPaolo Bonzini s->phy_regs[PHY_REG_ANEGEXP] = 0x000F; 118149ab747fSPaolo Bonzini s->phy_regs[PHY_REG_NEXTP] = 0x2001; 118249ab747fSPaolo Bonzini s->phy_regs[PHY_REG_LINKPNEXTP] = 0x40E6; 118349ab747fSPaolo Bonzini s->phy_regs[PHY_REG_100BTCTRL] = 0x0300; 118449ab747fSPaolo Bonzini s->phy_regs[PHY_REG_1000BTSTAT] = 0x7C00; 118549ab747fSPaolo Bonzini s->phy_regs[PHY_REG_EXTSTAT] = 0x3000; 118649ab747fSPaolo Bonzini s->phy_regs[PHY_REG_PHYSPCFC_CTL] = 0x0078; 11877777b7a0SAlistair Francis s->phy_regs[PHY_REG_PHYSPCFC_ST] = 0x7C00; 118849ab747fSPaolo Bonzini s->phy_regs[PHY_REG_EXT_PHYSPCFC_CTL] = 0x0C60; 118949ab747fSPaolo Bonzini s->phy_regs[PHY_REG_LED] = 0x4100; 119049ab747fSPaolo Bonzini s->phy_regs[PHY_REG_EXT_PHYSPCFC_CTL2] = 0x000A; 119149ab747fSPaolo Bonzini s->phy_regs[PHY_REG_EXT_PHYSPCFC_ST] = 0x848B; 119249ab747fSPaolo Bonzini 119349ab747fSPaolo Bonzini phy_update_link(s); 119449ab747fSPaolo Bonzini } 119549ab747fSPaolo Bonzini 119649ab747fSPaolo Bonzini static void gem_reset(DeviceState *d) 119749ab747fSPaolo Bonzini { 119864eb9301SPeter Crosthwaite int i; 1199448f19e2SPeter Crosthwaite CadenceGEMState *s = CADENCE_GEM(d); 1200afb4c51fSSebastian Huber const uint8_t *a; 120149ab747fSPaolo Bonzini 120249ab747fSPaolo Bonzini DB_PRINT("\n"); 120349ab747fSPaolo Bonzini 120449ab747fSPaolo Bonzini /* Set post reset register values */ 120549ab747fSPaolo Bonzini memset(&s->regs[0], 0, sizeof(s->regs)); 120649ab747fSPaolo Bonzini s->regs[GEM_NWCFG] = 0x00080000; 120749ab747fSPaolo Bonzini s->regs[GEM_NWSTATUS] = 0x00000006; 120849ab747fSPaolo Bonzini s->regs[GEM_DMACFG] = 0x00020784; 120949ab747fSPaolo Bonzini s->regs[GEM_IMR] = 0x07ffffff; 121049ab747fSPaolo Bonzini s->regs[GEM_TXPAUSE] = 0x0000ffff; 121149ab747fSPaolo Bonzini s->regs[GEM_TXPARTIALSF] = 0x000003ff; 121249ab747fSPaolo Bonzini s->regs[GEM_RXPARTIALSF] = 0x000003ff; 121349ab747fSPaolo Bonzini s->regs[GEM_MODID] = 0x00020118; 121449ab747fSPaolo Bonzini s->regs[GEM_DESCONF] = 0x02500111; 121549ab747fSPaolo Bonzini s->regs[GEM_DESCONF2] = 0x2ab13fff; 121649ab747fSPaolo Bonzini s->regs[GEM_DESCONF5] = 0x002f2145; 121749ab747fSPaolo Bonzini s->regs[GEM_DESCONF6] = 0x00000200; 121849ab747fSPaolo Bonzini 1219afb4c51fSSebastian Huber /* Set MAC address */ 1220afb4c51fSSebastian Huber a = &s->conf.macaddr.a[0]; 1221afb4c51fSSebastian Huber s->regs[GEM_SPADDR1LO] = a[0] | (a[1] << 8) | (a[2] << 16) | (a[3] << 24); 1222afb4c51fSSebastian Huber s->regs[GEM_SPADDR1HI] = a[4] | (a[5] << 8); 1223afb4c51fSSebastian Huber 122464eb9301SPeter Crosthwaite for (i = 0; i < 4; i++) { 122564eb9301SPeter Crosthwaite s->sar_active[i] = false; 122664eb9301SPeter Crosthwaite } 122764eb9301SPeter Crosthwaite 122849ab747fSPaolo Bonzini gem_phy_reset(s); 122949ab747fSPaolo Bonzini 123049ab747fSPaolo Bonzini gem_update_int_status(s); 123149ab747fSPaolo Bonzini } 123249ab747fSPaolo Bonzini 1233448f19e2SPeter Crosthwaite static uint16_t gem_phy_read(CadenceGEMState *s, unsigned reg_num) 123449ab747fSPaolo Bonzini { 123549ab747fSPaolo Bonzini DB_PRINT("reg: %d value: 0x%04x\n", reg_num, s->phy_regs[reg_num]); 123649ab747fSPaolo Bonzini return s->phy_regs[reg_num]; 123749ab747fSPaolo Bonzini } 123849ab747fSPaolo Bonzini 1239448f19e2SPeter Crosthwaite static void gem_phy_write(CadenceGEMState *s, unsigned reg_num, uint16_t val) 124049ab747fSPaolo Bonzini { 124149ab747fSPaolo Bonzini DB_PRINT("reg: %d value: 0x%04x\n", reg_num, val); 124249ab747fSPaolo Bonzini 124349ab747fSPaolo Bonzini switch (reg_num) { 124449ab747fSPaolo Bonzini case PHY_REG_CONTROL: 124549ab747fSPaolo Bonzini if (val & PHY_REG_CONTROL_RST) { 124649ab747fSPaolo Bonzini /* Phy reset */ 124749ab747fSPaolo Bonzini gem_phy_reset(s); 124849ab747fSPaolo Bonzini val &= ~(PHY_REG_CONTROL_RST | PHY_REG_CONTROL_LOOP); 124949ab747fSPaolo Bonzini s->phy_loop = 0; 125049ab747fSPaolo Bonzini } 125149ab747fSPaolo Bonzini if (val & PHY_REG_CONTROL_ANEG) { 125249ab747fSPaolo Bonzini /* Complete autonegotiation immediately */ 125349ab747fSPaolo Bonzini val &= ~PHY_REG_CONTROL_ANEG; 125449ab747fSPaolo Bonzini s->phy_regs[PHY_REG_STATUS] |= PHY_REG_STATUS_ANEGCMPL; 125549ab747fSPaolo Bonzini } 125649ab747fSPaolo Bonzini if (val & PHY_REG_CONTROL_LOOP) { 125749ab747fSPaolo Bonzini DB_PRINT("PHY placed in loopback\n"); 125849ab747fSPaolo Bonzini s->phy_loop = 1; 125949ab747fSPaolo Bonzini } else { 126049ab747fSPaolo Bonzini s->phy_loop = 0; 126149ab747fSPaolo Bonzini } 126249ab747fSPaolo Bonzini break; 126349ab747fSPaolo Bonzini } 126449ab747fSPaolo Bonzini s->phy_regs[reg_num] = val; 126549ab747fSPaolo Bonzini } 126649ab747fSPaolo Bonzini 126749ab747fSPaolo Bonzini /* 126849ab747fSPaolo Bonzini * gem_read32: 126949ab747fSPaolo Bonzini * Read a GEM register. 127049ab747fSPaolo Bonzini */ 127149ab747fSPaolo Bonzini static uint64_t gem_read(void *opaque, hwaddr offset, unsigned size) 127249ab747fSPaolo Bonzini { 1273448f19e2SPeter Crosthwaite CadenceGEMState *s; 127449ab747fSPaolo Bonzini uint32_t retval; 1275*67101725SAlistair Francis int i; 1276448f19e2SPeter Crosthwaite s = (CadenceGEMState *)opaque; 127749ab747fSPaolo Bonzini 127849ab747fSPaolo Bonzini offset >>= 2; 127949ab747fSPaolo Bonzini retval = s->regs[offset]; 128049ab747fSPaolo Bonzini 128149ab747fSPaolo Bonzini DB_PRINT("offset: 0x%04x read: 0x%08x\n", (unsigned)offset*4, retval); 128249ab747fSPaolo Bonzini 128349ab747fSPaolo Bonzini switch (offset) { 128449ab747fSPaolo Bonzini case GEM_ISR: 1285*67101725SAlistair Francis DB_PRINT("lowering irqs on ISR read\n"); 1286*67101725SAlistair Francis for (i = 0; i < s->num_priority_queues; ++i) { 1287*67101725SAlistair Francis qemu_set_irq(s->irq[i], 0); 1288*67101725SAlistair Francis } 128949ab747fSPaolo Bonzini break; 129049ab747fSPaolo Bonzini case GEM_PHYMNTNC: 129149ab747fSPaolo Bonzini if (retval & GEM_PHYMNTNC_OP_R) { 129249ab747fSPaolo Bonzini uint32_t phy_addr, reg_num; 129349ab747fSPaolo Bonzini 129449ab747fSPaolo Bonzini phy_addr = (retval & GEM_PHYMNTNC_ADDR) >> GEM_PHYMNTNC_ADDR_SHFT; 129555389373SPeter Crosthwaite if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0) { 129649ab747fSPaolo Bonzini reg_num = (retval & GEM_PHYMNTNC_REG) >> GEM_PHYMNTNC_REG_SHIFT; 129749ab747fSPaolo Bonzini retval &= 0xFFFF0000; 129849ab747fSPaolo Bonzini retval |= gem_phy_read(s, reg_num); 129949ab747fSPaolo Bonzini } else { 130049ab747fSPaolo Bonzini retval |= 0xFFFF; /* No device at this address */ 130149ab747fSPaolo Bonzini } 130249ab747fSPaolo Bonzini } 130349ab747fSPaolo Bonzini break; 130449ab747fSPaolo Bonzini } 130549ab747fSPaolo Bonzini 130649ab747fSPaolo Bonzini /* Squash read to clear bits */ 130749ab747fSPaolo Bonzini s->regs[offset] &= ~(s->regs_rtc[offset]); 130849ab747fSPaolo Bonzini 130949ab747fSPaolo Bonzini /* Do not provide write only bits */ 131049ab747fSPaolo Bonzini retval &= ~(s->regs_wo[offset]); 131149ab747fSPaolo Bonzini 131249ab747fSPaolo Bonzini DB_PRINT("0x%08x\n", retval); 1313*67101725SAlistair Francis gem_update_int_status(s); 131449ab747fSPaolo Bonzini return retval; 131549ab747fSPaolo Bonzini } 131649ab747fSPaolo Bonzini 131749ab747fSPaolo Bonzini /* 131849ab747fSPaolo Bonzini * gem_write32: 131949ab747fSPaolo Bonzini * Write a GEM register. 132049ab747fSPaolo Bonzini */ 132149ab747fSPaolo Bonzini static void gem_write(void *opaque, hwaddr offset, uint64_t val, 132249ab747fSPaolo Bonzini unsigned size) 132349ab747fSPaolo Bonzini { 1324448f19e2SPeter Crosthwaite CadenceGEMState *s = (CadenceGEMState *)opaque; 132549ab747fSPaolo Bonzini uint32_t readonly; 1326*67101725SAlistair Francis int i; 132749ab747fSPaolo Bonzini 132849ab747fSPaolo Bonzini DB_PRINT("offset: 0x%04x write: 0x%08x ", (unsigned)offset, (unsigned)val); 132949ab747fSPaolo Bonzini offset >>= 2; 133049ab747fSPaolo Bonzini 133149ab747fSPaolo Bonzini /* Squash bits which are read only in write value */ 133249ab747fSPaolo Bonzini val &= ~(s->regs_ro[offset]); 1333e2314fdaSPeter Crosthwaite /* Preserve (only) bits which are read only and wtc in register */ 1334e2314fdaSPeter Crosthwaite readonly = s->regs[offset] & (s->regs_ro[offset] | s->regs_w1c[offset]); 133549ab747fSPaolo Bonzini 133649ab747fSPaolo Bonzini /* Copy register write to backing store */ 1337e2314fdaSPeter Crosthwaite s->regs[offset] = (val & ~s->regs_w1c[offset]) | readonly; 1338e2314fdaSPeter Crosthwaite 1339e2314fdaSPeter Crosthwaite /* do w1c */ 1340e2314fdaSPeter Crosthwaite s->regs[offset] &= ~(s->regs_w1c[offset] & val); 134149ab747fSPaolo Bonzini 134249ab747fSPaolo Bonzini /* Handle register write side effects */ 134349ab747fSPaolo Bonzini switch (offset) { 134449ab747fSPaolo Bonzini case GEM_NWCTRL: 134506c2fe95SPeter Crosthwaite if (val & GEM_NWCTRL_RXENA) { 1346*67101725SAlistair Francis for (i = 0; i < s->num_priority_queues; ++i) { 1347*67101725SAlistair Francis gem_get_rx_desc(s, i); 1348*67101725SAlistair Francis } 134906c2fe95SPeter Crosthwaite } 135049ab747fSPaolo Bonzini if (val & GEM_NWCTRL_TXSTART) { 135149ab747fSPaolo Bonzini gem_transmit(s); 135249ab747fSPaolo Bonzini } 135349ab747fSPaolo Bonzini if (!(val & GEM_NWCTRL_TXENA)) { 135449ab747fSPaolo Bonzini /* Reset to start of Q when transmit disabled. */ 1355*67101725SAlistair Francis for (i = 0; i < s->num_priority_queues; i++) { 1356*67101725SAlistair Francis s->tx_desc_addr[i] = s->regs[GEM_TXQBASE]; 1357*67101725SAlistair Francis } 135849ab747fSPaolo Bonzini } 13598202aa53SPeter Crosthwaite if (gem_can_receive(qemu_get_queue(s->nic))) { 136049ab747fSPaolo Bonzini qemu_flush_queued_packets(qemu_get_queue(s->nic)); 136149ab747fSPaolo Bonzini } 136249ab747fSPaolo Bonzini break; 136349ab747fSPaolo Bonzini 136449ab747fSPaolo Bonzini case GEM_TXSTATUS: 136549ab747fSPaolo Bonzini gem_update_int_status(s); 136649ab747fSPaolo Bonzini break; 136749ab747fSPaolo Bonzini case GEM_RXQBASE: 13682bf57f73SAlistair Francis s->rx_desc_addr[0] = val; 136949ab747fSPaolo Bonzini break; 1370*67101725SAlistair Francis case GEM_RECEIVE_Q1_PTR ... GEM_RECEIVE_Q15_PTR: 1371*67101725SAlistair Francis s->rx_desc_addr[offset - GEM_RECEIVE_Q1_PTR + 1] = val; 1372*67101725SAlistair Francis break; 137349ab747fSPaolo Bonzini case GEM_TXQBASE: 13742bf57f73SAlistair Francis s->tx_desc_addr[0] = val; 137549ab747fSPaolo Bonzini break; 1376*67101725SAlistair Francis case GEM_TRANSMIT_Q1_PTR ... GEM_TRANSMIT_Q15_PTR: 1377*67101725SAlistair Francis s->tx_desc_addr[offset - GEM_TRANSMIT_Q1_PTR + 1] = val; 1378*67101725SAlistair Francis break; 137949ab747fSPaolo Bonzini case GEM_RXSTATUS: 138049ab747fSPaolo Bonzini gem_update_int_status(s); 138149ab747fSPaolo Bonzini break; 138249ab747fSPaolo Bonzini case GEM_IER: 138349ab747fSPaolo Bonzini s->regs[GEM_IMR] &= ~val; 138449ab747fSPaolo Bonzini gem_update_int_status(s); 138549ab747fSPaolo Bonzini break; 1386*67101725SAlistair Francis case GEM_INT_Q1_ENABLE ... GEM_INT_Q7_ENABLE: 1387*67101725SAlistair Francis s->regs[GEM_INT_Q1_MASK + offset - GEM_INT_Q1_ENABLE] &= ~val; 1388*67101725SAlistair Francis gem_update_int_status(s); 1389*67101725SAlistair Francis break; 1390*67101725SAlistair Francis case GEM_INT_Q8_ENABLE ... GEM_INT_Q15_ENABLE: 1391*67101725SAlistair Francis s->regs[GEM_INT_Q8_MASK + offset - GEM_INT_Q8_ENABLE] &= ~val; 1392*67101725SAlistair Francis gem_update_int_status(s); 1393*67101725SAlistair Francis break; 139449ab747fSPaolo Bonzini case GEM_IDR: 139549ab747fSPaolo Bonzini s->regs[GEM_IMR] |= val; 139649ab747fSPaolo Bonzini gem_update_int_status(s); 139749ab747fSPaolo Bonzini break; 1398*67101725SAlistair Francis case GEM_INT_Q1_DISABLE ... GEM_INT_Q7_DISABLE: 1399*67101725SAlistair Francis s->regs[GEM_INT_Q1_MASK + offset - GEM_INT_Q1_DISABLE] |= val; 1400*67101725SAlistair Francis gem_update_int_status(s); 1401*67101725SAlistair Francis break; 1402*67101725SAlistair Francis case GEM_INT_Q8_DISABLE ... GEM_INT_Q15_DISABLE: 1403*67101725SAlistair Francis s->regs[GEM_INT_Q8_MASK + offset - GEM_INT_Q8_DISABLE] |= val; 1404*67101725SAlistair Francis gem_update_int_status(s); 1405*67101725SAlistair Francis break; 140664eb9301SPeter Crosthwaite case GEM_SPADDR1LO: 140764eb9301SPeter Crosthwaite case GEM_SPADDR2LO: 140864eb9301SPeter Crosthwaite case GEM_SPADDR3LO: 140964eb9301SPeter Crosthwaite case GEM_SPADDR4LO: 141064eb9301SPeter Crosthwaite s->sar_active[(offset - GEM_SPADDR1LO) / 2] = false; 141164eb9301SPeter Crosthwaite break; 141264eb9301SPeter Crosthwaite case GEM_SPADDR1HI: 141364eb9301SPeter Crosthwaite case GEM_SPADDR2HI: 141464eb9301SPeter Crosthwaite case GEM_SPADDR3HI: 141564eb9301SPeter Crosthwaite case GEM_SPADDR4HI: 141664eb9301SPeter Crosthwaite s->sar_active[(offset - GEM_SPADDR1HI) / 2] = true; 141764eb9301SPeter Crosthwaite break; 141849ab747fSPaolo Bonzini case GEM_PHYMNTNC: 141949ab747fSPaolo Bonzini if (val & GEM_PHYMNTNC_OP_W) { 142049ab747fSPaolo Bonzini uint32_t phy_addr, reg_num; 142149ab747fSPaolo Bonzini 142249ab747fSPaolo Bonzini phy_addr = (val & GEM_PHYMNTNC_ADDR) >> GEM_PHYMNTNC_ADDR_SHFT; 142355389373SPeter Crosthwaite if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0) { 142449ab747fSPaolo Bonzini reg_num = (val & GEM_PHYMNTNC_REG) >> GEM_PHYMNTNC_REG_SHIFT; 142549ab747fSPaolo Bonzini gem_phy_write(s, reg_num, val); 142649ab747fSPaolo Bonzini } 142749ab747fSPaolo Bonzini } 142849ab747fSPaolo Bonzini break; 142949ab747fSPaolo Bonzini } 143049ab747fSPaolo Bonzini 143149ab747fSPaolo Bonzini DB_PRINT("newval: 0x%08x\n", s->regs[offset]); 143249ab747fSPaolo Bonzini } 143349ab747fSPaolo Bonzini 143449ab747fSPaolo Bonzini static const MemoryRegionOps gem_ops = { 143549ab747fSPaolo Bonzini .read = gem_read, 143649ab747fSPaolo Bonzini .write = gem_write, 143749ab747fSPaolo Bonzini .endianness = DEVICE_LITTLE_ENDIAN, 143849ab747fSPaolo Bonzini }; 143949ab747fSPaolo Bonzini 144049ab747fSPaolo Bonzini static void gem_set_link(NetClientState *nc) 144149ab747fSPaolo Bonzini { 1442*67101725SAlistair Francis CadenceGEMState *s = qemu_get_nic_opaque(nc); 1443*67101725SAlistair Francis 144449ab747fSPaolo Bonzini DB_PRINT("\n"); 1445*67101725SAlistair Francis phy_update_link(s); 1446*67101725SAlistair Francis gem_update_int_status(s); 144749ab747fSPaolo Bonzini } 144849ab747fSPaolo Bonzini 144949ab747fSPaolo Bonzini static NetClientInfo net_gem_info = { 1450f394b2e2SEric Blake .type = NET_CLIENT_DRIVER_NIC, 145149ab747fSPaolo Bonzini .size = sizeof(NICState), 145249ab747fSPaolo Bonzini .can_receive = gem_can_receive, 145349ab747fSPaolo Bonzini .receive = gem_receive, 145449ab747fSPaolo Bonzini .link_status_changed = gem_set_link, 145549ab747fSPaolo Bonzini }; 145649ab747fSPaolo Bonzini 1457bcb39a65SAlistair Francis static void gem_realize(DeviceState *dev, Error **errp) 145849ab747fSPaolo Bonzini { 1459448f19e2SPeter Crosthwaite CadenceGEMState *s = CADENCE_GEM(dev); 1460*67101725SAlistair Francis int i; 146149ab747fSPaolo Bonzini 14622bf57f73SAlistair Francis if (s->num_priority_queues == 0 || 14632bf57f73SAlistair Francis s->num_priority_queues > MAX_PRIORITY_QUEUES) { 14642bf57f73SAlistair Francis error_setg(errp, "Invalid num-priority-queues value: %" PRIx8, 14652bf57f73SAlistair Francis s->num_priority_queues); 14662bf57f73SAlistair Francis return; 1467e8e49943SAlistair Francis } else if (s->num_type1_screeners > MAX_TYPE1_SCREENERS) { 1468e8e49943SAlistair Francis error_setg(errp, "Invalid num-type1-screeners value: %" PRIx8, 1469e8e49943SAlistair Francis s->num_type1_screeners); 1470e8e49943SAlistair Francis return; 1471e8e49943SAlistair Francis } else if (s->num_type2_screeners > MAX_TYPE2_SCREENERS) { 1472e8e49943SAlistair Francis error_setg(errp, "Invalid num-type2-screeners value: %" PRIx8, 1473e8e49943SAlistair Francis s->num_type2_screeners); 1474e8e49943SAlistair Francis return; 14752bf57f73SAlistair Francis } 14762bf57f73SAlistair Francis 1477*67101725SAlistair Francis for (i = 0; i < s->num_priority_queues; ++i) { 1478*67101725SAlistair Francis sysbus_init_irq(SYS_BUS_DEVICE(dev), &s->irq[i]); 1479*67101725SAlistair Francis } 1480bcb39a65SAlistair Francis 1481bcb39a65SAlistair Francis qemu_macaddr_default_if_unset(&s->conf.macaddr); 1482bcb39a65SAlistair Francis 1483bcb39a65SAlistair Francis s->nic = qemu_new_nic(&net_gem_info, &s->conf, 1484bcb39a65SAlistair Francis object_get_typename(OBJECT(dev)), dev->id, s); 1485bcb39a65SAlistair Francis } 1486bcb39a65SAlistair Francis 1487bcb39a65SAlistair Francis static void gem_init(Object *obj) 1488bcb39a65SAlistair Francis { 1489bcb39a65SAlistair Francis CadenceGEMState *s = CADENCE_GEM(obj); 1490bcb39a65SAlistair Francis DeviceState *dev = DEVICE(obj); 1491bcb39a65SAlistair Francis 149249ab747fSPaolo Bonzini DB_PRINT("\n"); 149349ab747fSPaolo Bonzini 149449ab747fSPaolo Bonzini gem_init_register_masks(s); 1495eedfac6fSPaolo Bonzini memory_region_init_io(&s->iomem, OBJECT(s), &gem_ops, s, 1496eedfac6fSPaolo Bonzini "enet", sizeof(s->regs)); 149749ab747fSPaolo Bonzini 1498bcb39a65SAlistair Francis sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->iomem); 149949ab747fSPaolo Bonzini } 150049ab747fSPaolo Bonzini 150149ab747fSPaolo Bonzini static const VMStateDescription vmstate_cadence_gem = { 150249ab747fSPaolo Bonzini .name = "cadence_gem", 1503e8e49943SAlistair Francis .version_id = 4, 1504e8e49943SAlistair Francis .minimum_version_id = 4, 150549ab747fSPaolo Bonzini .fields = (VMStateField[]) { 1506448f19e2SPeter Crosthwaite VMSTATE_UINT32_ARRAY(regs, CadenceGEMState, CADENCE_GEM_MAXREG), 1507448f19e2SPeter Crosthwaite VMSTATE_UINT16_ARRAY(phy_regs, CadenceGEMState, 32), 1508448f19e2SPeter Crosthwaite VMSTATE_UINT8(phy_loop, CadenceGEMState), 15092bf57f73SAlistair Francis VMSTATE_UINT32_ARRAY(rx_desc_addr, CadenceGEMState, 15102bf57f73SAlistair Francis MAX_PRIORITY_QUEUES), 15112bf57f73SAlistair Francis VMSTATE_UINT32_ARRAY(tx_desc_addr, CadenceGEMState, 15122bf57f73SAlistair Francis MAX_PRIORITY_QUEUES), 1513448f19e2SPeter Crosthwaite VMSTATE_BOOL_ARRAY(sar_active, CadenceGEMState, 4), 151417cf2c76SPeter Crosthwaite VMSTATE_END_OF_LIST(), 151549ab747fSPaolo Bonzini } 151649ab747fSPaolo Bonzini }; 151749ab747fSPaolo Bonzini 151849ab747fSPaolo Bonzini static Property gem_properties[] = { 1519448f19e2SPeter Crosthwaite DEFINE_NIC_PROPERTIES(CadenceGEMState, conf), 15202bf57f73SAlistair Francis DEFINE_PROP_UINT8("num-priority-queues", CadenceGEMState, 15212bf57f73SAlistair Francis num_priority_queues, 1), 1522e8e49943SAlistair Francis DEFINE_PROP_UINT8("num-type1-screeners", CadenceGEMState, 1523e8e49943SAlistair Francis num_type1_screeners, 4), 1524e8e49943SAlistair Francis DEFINE_PROP_UINT8("num-type2-screeners", CadenceGEMState, 1525e8e49943SAlistair Francis num_type2_screeners, 4), 152649ab747fSPaolo Bonzini DEFINE_PROP_END_OF_LIST(), 152749ab747fSPaolo Bonzini }; 152849ab747fSPaolo Bonzini 152949ab747fSPaolo Bonzini static void gem_class_init(ObjectClass *klass, void *data) 153049ab747fSPaolo Bonzini { 153149ab747fSPaolo Bonzini DeviceClass *dc = DEVICE_CLASS(klass); 153249ab747fSPaolo Bonzini 1533bcb39a65SAlistair Francis dc->realize = gem_realize; 153449ab747fSPaolo Bonzini dc->props = gem_properties; 153549ab747fSPaolo Bonzini dc->vmsd = &vmstate_cadence_gem; 153649ab747fSPaolo Bonzini dc->reset = gem_reset; 153749ab747fSPaolo Bonzini } 153849ab747fSPaolo Bonzini 153949ab747fSPaolo Bonzini static const TypeInfo gem_info = { 1540318643beSAndreas Färber .name = TYPE_CADENCE_GEM, 154149ab747fSPaolo Bonzini .parent = TYPE_SYS_BUS_DEVICE, 1542448f19e2SPeter Crosthwaite .instance_size = sizeof(CadenceGEMState), 1543bcb39a65SAlistair Francis .instance_init = gem_init, 1544318643beSAndreas Färber .class_init = gem_class_init, 154549ab747fSPaolo Bonzini }; 154649ab747fSPaolo Bonzini 154749ab747fSPaolo Bonzini static void gem_register_types(void) 154849ab747fSPaolo Bonzini { 154949ab747fSPaolo Bonzini type_register_static(&gem_info); 155049ab747fSPaolo Bonzini } 155149ab747fSPaolo Bonzini 155249ab747fSPaolo Bonzini type_init(gem_register_types) 1553