1fcbd8018SJean-Christophe Dubois /* 2a699b410SJean-Christophe Dubois * i.MX FEC/ENET Ethernet Controller emulation. 3fcbd8018SJean-Christophe Dubois * 4fcbd8018SJean-Christophe Dubois * Copyright (c) 2013 Jean-Christophe Dubois. <jcd@tribudubois.net> 5fcbd8018SJean-Christophe Dubois * 6fcbd8018SJean-Christophe Dubois * Based on Coldfire Fast Ethernet Controller emulation. 7fcbd8018SJean-Christophe Dubois * 8fcbd8018SJean-Christophe Dubois * Copyright (c) 2007 CodeSourcery. 9fcbd8018SJean-Christophe Dubois * 10fcbd8018SJean-Christophe Dubois * This program is free software; you can redistribute it and/or modify it 11fcbd8018SJean-Christophe Dubois * under the terms of the GNU General Public License as published by the 12fcbd8018SJean-Christophe Dubois * Free Software Foundation; either version 2 of the License, or 13fcbd8018SJean-Christophe Dubois * (at your option) any later version. 14fcbd8018SJean-Christophe Dubois * 15fcbd8018SJean-Christophe Dubois * This program is distributed in the hope that it will be useful, but WITHOUT 16fcbd8018SJean-Christophe Dubois * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17fcbd8018SJean-Christophe Dubois * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 18fcbd8018SJean-Christophe Dubois * for more details. 19fcbd8018SJean-Christophe Dubois * 20fcbd8018SJean-Christophe Dubois * You should have received a copy of the GNU General Public License along 21fcbd8018SJean-Christophe Dubois * with this program; if not, see <http://www.gnu.org/licenses/>. 22fcbd8018SJean-Christophe Dubois */ 23fcbd8018SJean-Christophe Dubois 24fcbd8018SJean-Christophe Dubois #ifndef IMX_FEC_H 25fcbd8018SJean-Christophe Dubois #define IMX_FEC_H 26db1015e9SEduardo Habkost #include "qom/object.h" 27fcbd8018SJean-Christophe Dubois 28fcbd8018SJean-Christophe Dubois #define TYPE_IMX_FEC "imx.fec" 298063396bSEduardo Habkost OBJECT_DECLARE_SIMPLE_TYPE(IMXFECState, IMX_FEC) 30fcbd8018SJean-Christophe Dubois 31a699b410SJean-Christophe Dubois #define TYPE_IMX_ENET "imx.enet" 32a699b410SJean-Christophe Dubois 33fcbd8018SJean-Christophe Dubois #include "hw/sysbus.h" 34*c01194e1SBernhard Beschow #include "hw/net/lan9118_phy.h" 35*c01194e1SBernhard Beschow #include "hw/irq.h" 36fcbd8018SJean-Christophe Dubois #include "net/net.h" 37fcbd8018SJean-Christophe Dubois 38db0de352SJean-Christophe Dubois #define ENET_EIR 1 39db0de352SJean-Christophe Dubois #define ENET_EIMR 2 40db0de352SJean-Christophe Dubois #define ENET_RDAR 4 41db0de352SJean-Christophe Dubois #define ENET_TDAR 5 42db0de352SJean-Christophe Dubois #define ENET_ECR 9 43db0de352SJean-Christophe Dubois #define ENET_MMFR 16 44db0de352SJean-Christophe Dubois #define ENET_MSCR 17 45db0de352SJean-Christophe Dubois #define ENET_MIBC 25 46db0de352SJean-Christophe Dubois #define ENET_RCR 33 47db0de352SJean-Christophe Dubois #define ENET_TCR 49 48db0de352SJean-Christophe Dubois #define ENET_PALR 57 49db0de352SJean-Christophe Dubois #define ENET_PAUR 58 50db0de352SJean-Christophe Dubois #define ENET_OPD 59 51db0de352SJean-Christophe Dubois #define ENET_IAUR 70 52db0de352SJean-Christophe Dubois #define ENET_IALR 71 53db0de352SJean-Christophe Dubois #define ENET_GAUR 72 54db0de352SJean-Christophe Dubois #define ENET_GALR 73 55db0de352SJean-Christophe Dubois #define ENET_TFWR 81 56db0de352SJean-Christophe Dubois #define ENET_FRBR 83 57db0de352SJean-Christophe Dubois #define ENET_FRSR 84 58f93f961cSAndrey Smirnov #define ENET_TDSR1 89 59f93f961cSAndrey Smirnov #define ENET_TDSR2 92 60db0de352SJean-Christophe Dubois #define ENET_RDSR 96 61db0de352SJean-Christophe Dubois #define ENET_TDSR 97 62db0de352SJean-Christophe Dubois #define ENET_MRBR 98 63a699b410SJean-Christophe Dubois #define ENET_RSFL 100 64a699b410SJean-Christophe Dubois #define ENET_RSEM 101 65a699b410SJean-Christophe Dubois #define ENET_RAEM 102 66a699b410SJean-Christophe Dubois #define ENET_RAFL 103 67a699b410SJean-Christophe Dubois #define ENET_TSEM 104 68a699b410SJean-Christophe Dubois #define ENET_TAEM 105 69a699b410SJean-Christophe Dubois #define ENET_TAFL 106 70a699b410SJean-Christophe Dubois #define ENET_TIPG 107 71a699b410SJean-Christophe Dubois #define ENET_FTRL 108 72a699b410SJean-Christophe Dubois #define ENET_TACC 112 73a699b410SJean-Christophe Dubois #define ENET_RACC 113 74f93f961cSAndrey Smirnov #define ENET_TDAR1 121 75f93f961cSAndrey Smirnov #define ENET_TDAR2 123 76db0de352SJean-Christophe Dubois #define ENET_MIIGSK_CFGR 192 77db0de352SJean-Christophe Dubois #define ENET_MIIGSK_ENR 194 78a699b410SJean-Christophe Dubois #define ENET_ATCR 256 79a699b410SJean-Christophe Dubois #define ENET_ATVR 257 80a699b410SJean-Christophe Dubois #define ENET_ATOFF 258 81a699b410SJean-Christophe Dubois #define ENET_ATPER 259 82a699b410SJean-Christophe Dubois #define ENET_ATCOR 260 83a699b410SJean-Christophe Dubois #define ENET_ATINC 261 84a699b410SJean-Christophe Dubois #define ENET_ATSTMP 262 85a699b410SJean-Christophe Dubois #define ENET_TGSR 385 86a699b410SJean-Christophe Dubois #define ENET_TCSR0 386 87a699b410SJean-Christophe Dubois #define ENET_TCCR0 387 88a699b410SJean-Christophe Dubois #define ENET_TCSR1 388 89a699b410SJean-Christophe Dubois #define ENET_TCCR1 389 90a699b410SJean-Christophe Dubois #define ENET_TCSR2 390 91a699b410SJean-Christophe Dubois #define ENET_TCCR2 391 92a699b410SJean-Christophe Dubois #define ENET_TCSR3 392 93a699b410SJean-Christophe Dubois #define ENET_TCCR3 393 94db0de352SJean-Christophe Dubois #define ENET_MAX 400 95db0de352SJean-Christophe Dubois 96fcbd8018SJean-Christophe Dubois 97a699b410SJean-Christophe Dubois /* EIR and EIMR */ 981bb3c371SJean-Christophe Dubois #define ENET_INT_HB (1 << 31) 991bb3c371SJean-Christophe Dubois #define ENET_INT_BABR (1 << 30) 1001bb3c371SJean-Christophe Dubois #define ENET_INT_BABT (1 << 29) 1011bb3c371SJean-Christophe Dubois #define ENET_INT_GRA (1 << 28) 1021bb3c371SJean-Christophe Dubois #define ENET_INT_TXF (1 << 27) 1031bb3c371SJean-Christophe Dubois #define ENET_INT_TXB (1 << 26) 1041bb3c371SJean-Christophe Dubois #define ENET_INT_RXF (1 << 25) 1051bb3c371SJean-Christophe Dubois #define ENET_INT_RXB (1 << 24) 1061bb3c371SJean-Christophe Dubois #define ENET_INT_MII (1 << 23) 1071bb3c371SJean-Christophe Dubois #define ENET_INT_EBERR (1 << 22) 1081bb3c371SJean-Christophe Dubois #define ENET_INT_LC (1 << 21) 1091bb3c371SJean-Christophe Dubois #define ENET_INT_RL (1 << 20) 1101bb3c371SJean-Christophe Dubois #define ENET_INT_UN (1 << 19) 111a699b410SJean-Christophe Dubois #define ENET_INT_PLR (1 << 18) 112a699b410SJean-Christophe Dubois #define ENET_INT_WAKEUP (1 << 17) 113a699b410SJean-Christophe Dubois #define ENET_INT_TS_AVAIL (1 << 16) 114a699b410SJean-Christophe Dubois #define ENET_INT_TS_TIMER (1 << 15) 115f93f961cSAndrey Smirnov #define ENET_INT_TXF2 (1 << 7) 116f93f961cSAndrey Smirnov #define ENET_INT_TXB2 (1 << 6) 117f93f961cSAndrey Smirnov #define ENET_INT_TXF1 (1 << 3) 118f93f961cSAndrey Smirnov #define ENET_INT_TXB1 (1 << 2) 119a699b410SJean-Christophe Dubois 120a699b410SJean-Christophe Dubois #define ENET_INT_MAC (ENET_INT_HB | ENET_INT_BABR | ENET_INT_BABT | \ 121a699b410SJean-Christophe Dubois ENET_INT_GRA | ENET_INT_TXF | ENET_INT_TXB | \ 122a699b410SJean-Christophe Dubois ENET_INT_RXF | ENET_INT_RXB | ENET_INT_MII | \ 123a699b410SJean-Christophe Dubois ENET_INT_EBERR | ENET_INT_LC | ENET_INT_RL | \ 124a699b410SJean-Christophe Dubois ENET_INT_UN | ENET_INT_PLR | ENET_INT_WAKEUP | \ 125f93f961cSAndrey Smirnov ENET_INT_TS_AVAIL | ENET_INT_TXF1 | \ 126f93f961cSAndrey Smirnov ENET_INT_TXB1 | ENET_INT_TXF2 | ENET_INT_TXB2) 127fcbd8018SJean-Christophe Dubois 128db0de352SJean-Christophe Dubois /* RDAR */ 129db0de352SJean-Christophe Dubois #define ENET_RDAR_RDAR (1 << 24) 130db0de352SJean-Christophe Dubois 131db0de352SJean-Christophe Dubois /* TDAR */ 132db0de352SJean-Christophe Dubois #define ENET_TDAR_TDAR (1 << 24) 133db0de352SJean-Christophe Dubois 134a699b410SJean-Christophe Dubois /* ECR */ 1351bb3c371SJean-Christophe Dubois #define ENET_ECR_RESET (1 << 0) 1361bb3c371SJean-Christophe Dubois #define ENET_ECR_ETHEREN (1 << 1) 137a699b410SJean-Christophe Dubois #define ENET_ECR_MAGICEN (1 << 2) 138a699b410SJean-Christophe Dubois #define ENET_ECR_SLEEP (1 << 3) 139a699b410SJean-Christophe Dubois #define ENET_ECR_EN1588 (1 << 4) 140a699b410SJean-Christophe Dubois #define ENET_ECR_SPEED (1 << 5) 141a699b410SJean-Christophe Dubois #define ENET_ECR_DBGEN (1 << 6) 142a699b410SJean-Christophe Dubois #define ENET_ECR_STOPEN (1 << 7) 143a699b410SJean-Christophe Dubois #define ENET_ECR_DSBWP (1 << 8) 144a699b410SJean-Christophe Dubois 145a699b410SJean-Christophe Dubois /* MIBC */ 146a699b410SJean-Christophe Dubois #define ENET_MIBC_MIB_DIS (1 << 31) 147a699b410SJean-Christophe Dubois #define ENET_MIBC_MIB_IDLE (1 << 30) 148a699b410SJean-Christophe Dubois #define ENET_MIBC_MIB_CLEAR (1 << 29) 149a699b410SJean-Christophe Dubois 150a699b410SJean-Christophe Dubois /* RCR */ 151a699b410SJean-Christophe Dubois #define ENET_RCR_LOOP (1 << 0) 152a699b410SJean-Christophe Dubois #define ENET_RCR_DRT (1 << 1) 153a699b410SJean-Christophe Dubois #define ENET_RCR_MII_MODE (1 << 2) 154a699b410SJean-Christophe Dubois #define ENET_RCR_PROM (1 << 3) 155a699b410SJean-Christophe Dubois #define ENET_RCR_BC_REJ (1 << 4) 156a699b410SJean-Christophe Dubois #define ENET_RCR_FCE (1 << 5) 157a699b410SJean-Christophe Dubois #define ENET_RCR_RGMII_EN (1 << 6) 158a699b410SJean-Christophe Dubois #define ENET_RCR_RMII_MODE (1 << 8) 159a699b410SJean-Christophe Dubois #define ENET_RCR_RMII_10T (1 << 9) 160a699b410SJean-Christophe Dubois #define ENET_RCR_PADEN (1 << 12) 161a699b410SJean-Christophe Dubois #define ENET_RCR_PAUFWD (1 << 13) 162a699b410SJean-Christophe Dubois #define ENET_RCR_CRCFWD (1 << 14) 163a699b410SJean-Christophe Dubois #define ENET_RCR_CFEN (1 << 15) 164a699b410SJean-Christophe Dubois #define ENET_RCR_MAX_FL_SHIFT (16) 165a699b410SJean-Christophe Dubois #define ENET_RCR_MAX_FL_LENGTH (14) 166a699b410SJean-Christophe Dubois #define ENET_RCR_NLC (1 << 30) 167a699b410SJean-Christophe Dubois #define ENET_RCR_GRS (1 << 31) 168a699b410SJean-Christophe Dubois 169ff9a7feeSAndrey Smirnov #define ENET_MAX_FRAME_SIZE (1 << ENET_RCR_MAX_FL_LENGTH) 170ff9a7feeSAndrey Smirnov 171a699b410SJean-Christophe Dubois /* TCR */ 172a699b410SJean-Christophe Dubois #define ENET_TCR_GTS (1 << 0) 173a699b410SJean-Christophe Dubois #define ENET_TCR_FDEN (1 << 2) 174a699b410SJean-Christophe Dubois #define ENET_TCR_TFC_PAUSE (1 << 3) 175a699b410SJean-Christophe Dubois #define ENET_TCR_RFC_PAUSE (1 << 4) 176a699b410SJean-Christophe Dubois #define ENET_TCR_ADDSEL_SHIFT (5) 177a699b410SJean-Christophe Dubois #define ENET_TCR_ADDSEL_LENGTH (3) 178a699b410SJean-Christophe Dubois #define ENET_TCR_CRCFWD (1 << 9) 179a699b410SJean-Christophe Dubois 180a699b410SJean-Christophe Dubois /* RDSR */ 181a699b410SJean-Christophe Dubois #define ENET_TWFR_TFWR_SHIFT (0) 182a699b410SJean-Christophe Dubois #define ENET_TWFR_TFWR_LENGTH (6) 183a699b410SJean-Christophe Dubois #define ENET_TWFR_STRFWD (1 << 8) 184fcbd8018SJean-Christophe Dubois 185ebdd8cddSAndrey Smirnov #define ENET_RACC_SHIFT16 BIT(7) 186ebdd8cddSAndrey Smirnov 187fcbd8018SJean-Christophe Dubois /* Buffer Descriptor. */ 188fcbd8018SJean-Christophe Dubois typedef struct { 189fcbd8018SJean-Christophe Dubois uint16_t length; 190fcbd8018SJean-Christophe Dubois uint16_t flags; 191fcbd8018SJean-Christophe Dubois uint32_t data; 192fcbd8018SJean-Christophe Dubois } IMXFECBufDesc; 193fcbd8018SJean-Christophe Dubois 1941bb3c371SJean-Christophe Dubois #define ENET_BD_R (1 << 15) 1951bb3c371SJean-Christophe Dubois #define ENET_BD_E (1 << 15) 1961bb3c371SJean-Christophe Dubois #define ENET_BD_O1 (1 << 14) 1971bb3c371SJean-Christophe Dubois #define ENET_BD_W (1 << 13) 1981bb3c371SJean-Christophe Dubois #define ENET_BD_O2 (1 << 12) 1991bb3c371SJean-Christophe Dubois #define ENET_BD_L (1 << 11) 2001bb3c371SJean-Christophe Dubois #define ENET_BD_TC (1 << 10) 2011bb3c371SJean-Christophe Dubois #define ENET_BD_ABC (1 << 9) 2021bb3c371SJean-Christophe Dubois #define ENET_BD_M (1 << 8) 2031bb3c371SJean-Christophe Dubois #define ENET_BD_BC (1 << 7) 2041bb3c371SJean-Christophe Dubois #define ENET_BD_MC (1 << 6) 2051bb3c371SJean-Christophe Dubois #define ENET_BD_LG (1 << 5) 2061bb3c371SJean-Christophe Dubois #define ENET_BD_NO (1 << 4) 2071bb3c371SJean-Christophe Dubois #define ENET_BD_CR (1 << 2) 2081bb3c371SJean-Christophe Dubois #define ENET_BD_OV (1 << 1) 2091bb3c371SJean-Christophe Dubois #define ENET_BD_TR (1 << 0) 210fcbd8018SJean-Christophe Dubois 211a699b410SJean-Christophe Dubois typedef struct { 212a699b410SJean-Christophe Dubois uint16_t length; 213a699b410SJean-Christophe Dubois uint16_t flags; 214a699b410SJean-Christophe Dubois uint32_t data; 215a699b410SJean-Christophe Dubois uint16_t status; 216a699b410SJean-Christophe Dubois uint16_t option; 217a699b410SJean-Christophe Dubois uint16_t checksum; 218a699b410SJean-Christophe Dubois uint16_t head_proto; 219a699b410SJean-Christophe Dubois uint32_t last_buffer; 220a699b410SJean-Christophe Dubois uint32_t timestamp; 221a699b410SJean-Christophe Dubois uint32_t reserved[2]; 222a699b410SJean-Christophe Dubois } IMXENETBufDesc; 223a699b410SJean-Christophe Dubois 224a699b410SJean-Christophe Dubois #define ENET_BD_ME (1 << 15) 225a699b410SJean-Christophe Dubois #define ENET_BD_TX_INT (1 << 14) 226a699b410SJean-Christophe Dubois #define ENET_BD_TS (1 << 13) 227a699b410SJean-Christophe Dubois #define ENET_BD_PINS (1 << 12) 228a699b410SJean-Christophe Dubois #define ENET_BD_IINS (1 << 11) 229a699b410SJean-Christophe Dubois #define ENET_BD_PE (1 << 10) 230a699b410SJean-Christophe Dubois #define ENET_BD_CE (1 << 9) 231a699b410SJean-Christophe Dubois #define ENET_BD_UC (1 << 8) 232a699b410SJean-Christophe Dubois #define ENET_BD_RX_INT (1 << 7) 233a699b410SJean-Christophe Dubois 234a699b410SJean-Christophe Dubois #define ENET_BD_TXE (1 << 15) 235a699b410SJean-Christophe Dubois #define ENET_BD_UE (1 << 13) 236a699b410SJean-Christophe Dubois #define ENET_BD_EE (1 << 12) 237a699b410SJean-Christophe Dubois #define ENET_BD_FE (1 << 11) 238a699b410SJean-Christophe Dubois #define ENET_BD_LCE (1 << 10) 239a699b410SJean-Christophe Dubois #define ENET_BD_OE (1 << 9) 240a699b410SJean-Christophe Dubois #define ENET_BD_TSE (1 << 8) 241a699b410SJean-Christophe Dubois #define ENET_BD_ICE (1 << 5) 242a699b410SJean-Christophe Dubois #define ENET_BD_PCR (1 << 4) 243a699b410SJean-Christophe Dubois #define ENET_BD_VLAN (1 << 2) 244a699b410SJean-Christophe Dubois #define ENET_BD_IPV6 (1 << 1) 245a699b410SJean-Christophe Dubois #define ENET_BD_FRAG (1 << 0) 246a699b410SJean-Christophe Dubois 247a699b410SJean-Christophe Dubois #define ENET_BD_BDU (1 << 31) 248a699b410SJean-Christophe Dubois 249f93f961cSAndrey Smirnov #define ENET_TX_RING_NUM 3 250f93f961cSAndrey Smirnov 251831858adSAndrey Smirnov #define FSL_IMX25_FEC_SIZE 0x4000 252f93f961cSAndrey Smirnov 253db1015e9SEduardo Habkost struct IMXFECState { 254fcbd8018SJean-Christophe Dubois /*< private >*/ 255fcbd8018SJean-Christophe Dubois SysBusDevice parent_obj; 256fcbd8018SJean-Christophe Dubois 257fcbd8018SJean-Christophe Dubois /*< public >*/ 258fcbd8018SJean-Christophe Dubois NICState *nic; 259fcbd8018SJean-Christophe Dubois NICConf conf; 260a699b410SJean-Christophe Dubois qemu_irq irq[2]; 261fcbd8018SJean-Christophe Dubois MemoryRegion iomem; 262fcbd8018SJean-Christophe Dubois 263db0de352SJean-Christophe Dubois uint32_t regs[ENET_MAX]; 264fcbd8018SJean-Christophe Dubois uint32_t rx_descriptor; 265f93f961cSAndrey Smirnov 266f93f961cSAndrey Smirnov uint32_t tx_descriptor[ENET_TX_RING_NUM]; 267f93f961cSAndrey Smirnov uint32_t tx_ring_num; 268fcbd8018SJean-Christophe Dubois 269*c01194e1SBernhard Beschow Lan9118PhyState mii; 270*c01194e1SBernhard Beschow IRQState mii_irq; 271461c51adSJean-Christophe Dubois uint32_t phy_num; 272df3f5efeSGuenter Roeck bool phy_connected; 273df3f5efeSGuenter Roeck struct IMXFECState *phy_consumer; 274a699b410SJean-Christophe Dubois 275a699b410SJean-Christophe Dubois bool is_fec; 2767bac20dcSAndrey Smirnov 2777bac20dcSAndrey Smirnov /* Buffer used to assemble a Tx frame */ 2787bac20dcSAndrey Smirnov uint8_t frame[ENET_MAX_FRAME_SIZE]; 279db1015e9SEduardo Habkost }; 280fcbd8018SJean-Christophe Dubois 281fcbd8018SJean-Christophe Dubois #endif 282