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" 34fcbd8018SJean-Christophe Dubois #include "net/net.h" 35fcbd8018SJean-Christophe Dubois 36db0de352SJean-Christophe Dubois #define ENET_EIR 1 37db0de352SJean-Christophe Dubois #define ENET_EIMR 2 38db0de352SJean-Christophe Dubois #define ENET_RDAR 4 39db0de352SJean-Christophe Dubois #define ENET_TDAR 5 40db0de352SJean-Christophe Dubois #define ENET_ECR 9 41db0de352SJean-Christophe Dubois #define ENET_MMFR 16 42db0de352SJean-Christophe Dubois #define ENET_MSCR 17 43db0de352SJean-Christophe Dubois #define ENET_MIBC 25 44db0de352SJean-Christophe Dubois #define ENET_RCR 33 45db0de352SJean-Christophe Dubois #define ENET_TCR 49 46db0de352SJean-Christophe Dubois #define ENET_PALR 57 47db0de352SJean-Christophe Dubois #define ENET_PAUR 58 48db0de352SJean-Christophe Dubois #define ENET_OPD 59 49db0de352SJean-Christophe Dubois #define ENET_IAUR 70 50db0de352SJean-Christophe Dubois #define ENET_IALR 71 51db0de352SJean-Christophe Dubois #define ENET_GAUR 72 52db0de352SJean-Christophe Dubois #define ENET_GALR 73 53db0de352SJean-Christophe Dubois #define ENET_TFWR 81 54db0de352SJean-Christophe Dubois #define ENET_FRBR 83 55db0de352SJean-Christophe Dubois #define ENET_FRSR 84 56f93f961cSAndrey Smirnov #define ENET_TDSR1 89 57f93f961cSAndrey Smirnov #define ENET_TDSR2 92 58db0de352SJean-Christophe Dubois #define ENET_RDSR 96 59db0de352SJean-Christophe Dubois #define ENET_TDSR 97 60db0de352SJean-Christophe Dubois #define ENET_MRBR 98 61a699b410SJean-Christophe Dubois #define ENET_RSFL 100 62a699b410SJean-Christophe Dubois #define ENET_RSEM 101 63a699b410SJean-Christophe Dubois #define ENET_RAEM 102 64a699b410SJean-Christophe Dubois #define ENET_RAFL 103 65a699b410SJean-Christophe Dubois #define ENET_TSEM 104 66a699b410SJean-Christophe Dubois #define ENET_TAEM 105 67a699b410SJean-Christophe Dubois #define ENET_TAFL 106 68a699b410SJean-Christophe Dubois #define ENET_TIPG 107 69a699b410SJean-Christophe Dubois #define ENET_FTRL 108 70a699b410SJean-Christophe Dubois #define ENET_TACC 112 71a699b410SJean-Christophe Dubois #define ENET_RACC 113 72f93f961cSAndrey Smirnov #define ENET_TDAR1 121 73f93f961cSAndrey Smirnov #define ENET_TDAR2 123 74db0de352SJean-Christophe Dubois #define ENET_MIIGSK_CFGR 192 75db0de352SJean-Christophe Dubois #define ENET_MIIGSK_ENR 194 76a699b410SJean-Christophe Dubois #define ENET_ATCR 256 77a699b410SJean-Christophe Dubois #define ENET_ATVR 257 78a699b410SJean-Christophe Dubois #define ENET_ATOFF 258 79a699b410SJean-Christophe Dubois #define ENET_ATPER 259 80a699b410SJean-Christophe Dubois #define ENET_ATCOR 260 81a699b410SJean-Christophe Dubois #define ENET_ATINC 261 82a699b410SJean-Christophe Dubois #define ENET_ATSTMP 262 83a699b410SJean-Christophe Dubois #define ENET_TGSR 385 84a699b410SJean-Christophe Dubois #define ENET_TCSR0 386 85a699b410SJean-Christophe Dubois #define ENET_TCCR0 387 86a699b410SJean-Christophe Dubois #define ENET_TCSR1 388 87a699b410SJean-Christophe Dubois #define ENET_TCCR1 389 88a699b410SJean-Christophe Dubois #define ENET_TCSR2 390 89a699b410SJean-Christophe Dubois #define ENET_TCCR2 391 90a699b410SJean-Christophe Dubois #define ENET_TCSR3 392 91a699b410SJean-Christophe Dubois #define ENET_TCCR3 393 92db0de352SJean-Christophe Dubois #define ENET_MAX 400 93db0de352SJean-Christophe Dubois 94fcbd8018SJean-Christophe Dubois 95a699b410SJean-Christophe Dubois /* EIR and EIMR */ 961bb3c371SJean-Christophe Dubois #define ENET_INT_HB (1 << 31) 971bb3c371SJean-Christophe Dubois #define ENET_INT_BABR (1 << 30) 981bb3c371SJean-Christophe Dubois #define ENET_INT_BABT (1 << 29) 991bb3c371SJean-Christophe Dubois #define ENET_INT_GRA (1 << 28) 1001bb3c371SJean-Christophe Dubois #define ENET_INT_TXF (1 << 27) 1011bb3c371SJean-Christophe Dubois #define ENET_INT_TXB (1 << 26) 1021bb3c371SJean-Christophe Dubois #define ENET_INT_RXF (1 << 25) 1031bb3c371SJean-Christophe Dubois #define ENET_INT_RXB (1 << 24) 1041bb3c371SJean-Christophe Dubois #define ENET_INT_MII (1 << 23) 1051bb3c371SJean-Christophe Dubois #define ENET_INT_EBERR (1 << 22) 1061bb3c371SJean-Christophe Dubois #define ENET_INT_LC (1 << 21) 1071bb3c371SJean-Christophe Dubois #define ENET_INT_RL (1 << 20) 1081bb3c371SJean-Christophe Dubois #define ENET_INT_UN (1 << 19) 109a699b410SJean-Christophe Dubois #define ENET_INT_PLR (1 << 18) 110a699b410SJean-Christophe Dubois #define ENET_INT_WAKEUP (1 << 17) 111a699b410SJean-Christophe Dubois #define ENET_INT_TS_AVAIL (1 << 16) 112a699b410SJean-Christophe Dubois #define ENET_INT_TS_TIMER (1 << 15) 113f93f961cSAndrey Smirnov #define ENET_INT_TXF2 (1 << 7) 114f93f961cSAndrey Smirnov #define ENET_INT_TXB2 (1 << 6) 115f93f961cSAndrey Smirnov #define ENET_INT_TXF1 (1 << 3) 116f93f961cSAndrey Smirnov #define ENET_INT_TXB1 (1 << 2) 117a699b410SJean-Christophe Dubois 118a699b410SJean-Christophe Dubois #define ENET_INT_MAC (ENET_INT_HB | ENET_INT_BABR | ENET_INT_BABT | \ 119a699b410SJean-Christophe Dubois ENET_INT_GRA | ENET_INT_TXF | ENET_INT_TXB | \ 120a699b410SJean-Christophe Dubois ENET_INT_RXF | ENET_INT_RXB | ENET_INT_MII | \ 121a699b410SJean-Christophe Dubois ENET_INT_EBERR | ENET_INT_LC | ENET_INT_RL | \ 122a699b410SJean-Christophe Dubois ENET_INT_UN | ENET_INT_PLR | ENET_INT_WAKEUP | \ 123f93f961cSAndrey Smirnov ENET_INT_TS_AVAIL | ENET_INT_TXF1 | \ 124f93f961cSAndrey Smirnov ENET_INT_TXB1 | ENET_INT_TXF2 | ENET_INT_TXB2) 125fcbd8018SJean-Christophe Dubois 126db0de352SJean-Christophe Dubois /* RDAR */ 127db0de352SJean-Christophe Dubois #define ENET_RDAR_RDAR (1 << 24) 128db0de352SJean-Christophe Dubois 129db0de352SJean-Christophe Dubois /* TDAR */ 130db0de352SJean-Christophe Dubois #define ENET_TDAR_TDAR (1 << 24) 131db0de352SJean-Christophe Dubois 132a699b410SJean-Christophe Dubois /* ECR */ 1331bb3c371SJean-Christophe Dubois #define ENET_ECR_RESET (1 << 0) 1341bb3c371SJean-Christophe Dubois #define ENET_ECR_ETHEREN (1 << 1) 135a699b410SJean-Christophe Dubois #define ENET_ECR_MAGICEN (1 << 2) 136a699b410SJean-Christophe Dubois #define ENET_ECR_SLEEP (1 << 3) 137a699b410SJean-Christophe Dubois #define ENET_ECR_EN1588 (1 << 4) 138a699b410SJean-Christophe Dubois #define ENET_ECR_SPEED (1 << 5) 139a699b410SJean-Christophe Dubois #define ENET_ECR_DBGEN (1 << 6) 140a699b410SJean-Christophe Dubois #define ENET_ECR_STOPEN (1 << 7) 141a699b410SJean-Christophe Dubois #define ENET_ECR_DSBWP (1 << 8) 142a699b410SJean-Christophe Dubois 143a699b410SJean-Christophe Dubois /* MIBC */ 144a699b410SJean-Christophe Dubois #define ENET_MIBC_MIB_DIS (1 << 31) 145a699b410SJean-Christophe Dubois #define ENET_MIBC_MIB_IDLE (1 << 30) 146a699b410SJean-Christophe Dubois #define ENET_MIBC_MIB_CLEAR (1 << 29) 147a699b410SJean-Christophe Dubois 148a699b410SJean-Christophe Dubois /* RCR */ 149a699b410SJean-Christophe Dubois #define ENET_RCR_LOOP (1 << 0) 150a699b410SJean-Christophe Dubois #define ENET_RCR_DRT (1 << 1) 151a699b410SJean-Christophe Dubois #define ENET_RCR_MII_MODE (1 << 2) 152a699b410SJean-Christophe Dubois #define ENET_RCR_PROM (1 << 3) 153a699b410SJean-Christophe Dubois #define ENET_RCR_BC_REJ (1 << 4) 154a699b410SJean-Christophe Dubois #define ENET_RCR_FCE (1 << 5) 155a699b410SJean-Christophe Dubois #define ENET_RCR_RGMII_EN (1 << 6) 156a699b410SJean-Christophe Dubois #define ENET_RCR_RMII_MODE (1 << 8) 157a699b410SJean-Christophe Dubois #define ENET_RCR_RMII_10T (1 << 9) 158a699b410SJean-Christophe Dubois #define ENET_RCR_PADEN (1 << 12) 159a699b410SJean-Christophe Dubois #define ENET_RCR_PAUFWD (1 << 13) 160a699b410SJean-Christophe Dubois #define ENET_RCR_CRCFWD (1 << 14) 161a699b410SJean-Christophe Dubois #define ENET_RCR_CFEN (1 << 15) 162a699b410SJean-Christophe Dubois #define ENET_RCR_MAX_FL_SHIFT (16) 163a699b410SJean-Christophe Dubois #define ENET_RCR_MAX_FL_LENGTH (14) 164a699b410SJean-Christophe Dubois #define ENET_RCR_NLC (1 << 30) 165a699b410SJean-Christophe Dubois #define ENET_RCR_GRS (1 << 31) 166a699b410SJean-Christophe Dubois 167ff9a7feeSAndrey Smirnov #define ENET_MAX_FRAME_SIZE (1 << ENET_RCR_MAX_FL_LENGTH) 168ff9a7feeSAndrey Smirnov 169a699b410SJean-Christophe Dubois /* TCR */ 170a699b410SJean-Christophe Dubois #define ENET_TCR_GTS (1 << 0) 171a699b410SJean-Christophe Dubois #define ENET_TCR_FDEN (1 << 2) 172a699b410SJean-Christophe Dubois #define ENET_TCR_TFC_PAUSE (1 << 3) 173a699b410SJean-Christophe Dubois #define ENET_TCR_RFC_PAUSE (1 << 4) 174a699b410SJean-Christophe Dubois #define ENET_TCR_ADDSEL_SHIFT (5) 175a699b410SJean-Christophe Dubois #define ENET_TCR_ADDSEL_LENGTH (3) 176a699b410SJean-Christophe Dubois #define ENET_TCR_CRCFWD (1 << 9) 177a699b410SJean-Christophe Dubois 178a699b410SJean-Christophe Dubois /* RDSR */ 179a699b410SJean-Christophe Dubois #define ENET_TWFR_TFWR_SHIFT (0) 180a699b410SJean-Christophe Dubois #define ENET_TWFR_TFWR_LENGTH (6) 181a699b410SJean-Christophe Dubois #define ENET_TWFR_STRFWD (1 << 8) 182fcbd8018SJean-Christophe Dubois 183ebdd8cddSAndrey Smirnov #define ENET_RACC_SHIFT16 BIT(7) 184ebdd8cddSAndrey Smirnov 185fcbd8018SJean-Christophe Dubois /* Buffer Descriptor. */ 186fcbd8018SJean-Christophe Dubois typedef struct { 187fcbd8018SJean-Christophe Dubois uint16_t length; 188fcbd8018SJean-Christophe Dubois uint16_t flags; 189fcbd8018SJean-Christophe Dubois uint32_t data; 190fcbd8018SJean-Christophe Dubois } IMXFECBufDesc; 191fcbd8018SJean-Christophe Dubois 1921bb3c371SJean-Christophe Dubois #define ENET_BD_R (1 << 15) 1931bb3c371SJean-Christophe Dubois #define ENET_BD_E (1 << 15) 1941bb3c371SJean-Christophe Dubois #define ENET_BD_O1 (1 << 14) 1951bb3c371SJean-Christophe Dubois #define ENET_BD_W (1 << 13) 1961bb3c371SJean-Christophe Dubois #define ENET_BD_O2 (1 << 12) 1971bb3c371SJean-Christophe Dubois #define ENET_BD_L (1 << 11) 1981bb3c371SJean-Christophe Dubois #define ENET_BD_TC (1 << 10) 1991bb3c371SJean-Christophe Dubois #define ENET_BD_ABC (1 << 9) 2001bb3c371SJean-Christophe Dubois #define ENET_BD_M (1 << 8) 2011bb3c371SJean-Christophe Dubois #define ENET_BD_BC (1 << 7) 2021bb3c371SJean-Christophe Dubois #define ENET_BD_MC (1 << 6) 2031bb3c371SJean-Christophe Dubois #define ENET_BD_LG (1 << 5) 2041bb3c371SJean-Christophe Dubois #define ENET_BD_NO (1 << 4) 2051bb3c371SJean-Christophe Dubois #define ENET_BD_CR (1 << 2) 2061bb3c371SJean-Christophe Dubois #define ENET_BD_OV (1 << 1) 2071bb3c371SJean-Christophe Dubois #define ENET_BD_TR (1 << 0) 208fcbd8018SJean-Christophe Dubois 209a699b410SJean-Christophe Dubois typedef struct { 210a699b410SJean-Christophe Dubois uint16_t length; 211a699b410SJean-Christophe Dubois uint16_t flags; 212a699b410SJean-Christophe Dubois uint32_t data; 213a699b410SJean-Christophe Dubois uint16_t status; 214a699b410SJean-Christophe Dubois uint16_t option; 215a699b410SJean-Christophe Dubois uint16_t checksum; 216a699b410SJean-Christophe Dubois uint16_t head_proto; 217a699b410SJean-Christophe Dubois uint32_t last_buffer; 218a699b410SJean-Christophe Dubois uint32_t timestamp; 219a699b410SJean-Christophe Dubois uint32_t reserved[2]; 220a699b410SJean-Christophe Dubois } IMXENETBufDesc; 221a699b410SJean-Christophe Dubois 222a699b410SJean-Christophe Dubois #define ENET_BD_ME (1 << 15) 223a699b410SJean-Christophe Dubois #define ENET_BD_TX_INT (1 << 14) 224a699b410SJean-Christophe Dubois #define ENET_BD_TS (1 << 13) 225a699b410SJean-Christophe Dubois #define ENET_BD_PINS (1 << 12) 226a699b410SJean-Christophe Dubois #define ENET_BD_IINS (1 << 11) 227a699b410SJean-Christophe Dubois #define ENET_BD_PE (1 << 10) 228a699b410SJean-Christophe Dubois #define ENET_BD_CE (1 << 9) 229a699b410SJean-Christophe Dubois #define ENET_BD_UC (1 << 8) 230a699b410SJean-Christophe Dubois #define ENET_BD_RX_INT (1 << 7) 231a699b410SJean-Christophe Dubois 232a699b410SJean-Christophe Dubois #define ENET_BD_TXE (1 << 15) 233a699b410SJean-Christophe Dubois #define ENET_BD_UE (1 << 13) 234a699b410SJean-Christophe Dubois #define ENET_BD_EE (1 << 12) 235a699b410SJean-Christophe Dubois #define ENET_BD_FE (1 << 11) 236a699b410SJean-Christophe Dubois #define ENET_BD_LCE (1 << 10) 237a699b410SJean-Christophe Dubois #define ENET_BD_OE (1 << 9) 238a699b410SJean-Christophe Dubois #define ENET_BD_TSE (1 << 8) 239a699b410SJean-Christophe Dubois #define ENET_BD_ICE (1 << 5) 240a699b410SJean-Christophe Dubois #define ENET_BD_PCR (1 << 4) 241a699b410SJean-Christophe Dubois #define ENET_BD_VLAN (1 << 2) 242a699b410SJean-Christophe Dubois #define ENET_BD_IPV6 (1 << 1) 243a699b410SJean-Christophe Dubois #define ENET_BD_FRAG (1 << 0) 244a699b410SJean-Christophe Dubois 245a699b410SJean-Christophe Dubois #define ENET_BD_BDU (1 << 31) 246a699b410SJean-Christophe Dubois 247f93f961cSAndrey Smirnov #define ENET_TX_RING_NUM 3 248f93f961cSAndrey Smirnov 249831858adSAndrey Smirnov #define FSL_IMX25_FEC_SIZE 0x4000 250f93f961cSAndrey Smirnov 251db1015e9SEduardo Habkost struct IMXFECState { 252fcbd8018SJean-Christophe Dubois /*< private >*/ 253fcbd8018SJean-Christophe Dubois SysBusDevice parent_obj; 254fcbd8018SJean-Christophe Dubois 255fcbd8018SJean-Christophe Dubois /*< public >*/ 256fcbd8018SJean-Christophe Dubois NICState *nic; 257fcbd8018SJean-Christophe Dubois NICConf conf; 258a699b410SJean-Christophe Dubois qemu_irq irq[2]; 259fcbd8018SJean-Christophe Dubois MemoryRegion iomem; 260fcbd8018SJean-Christophe Dubois 261db0de352SJean-Christophe Dubois uint32_t regs[ENET_MAX]; 262fcbd8018SJean-Christophe Dubois uint32_t rx_descriptor; 263f93f961cSAndrey Smirnov 264f93f961cSAndrey Smirnov uint32_t tx_descriptor[ENET_TX_RING_NUM]; 265f93f961cSAndrey Smirnov uint32_t tx_ring_num; 266fcbd8018SJean-Christophe Dubois 267fcbd8018SJean-Christophe Dubois uint32_t phy_status; 268fcbd8018SJean-Christophe Dubois uint32_t phy_control; 269fcbd8018SJean-Christophe Dubois uint32_t phy_advertise; 270fcbd8018SJean-Christophe Dubois uint32_t phy_int; 271fcbd8018SJean-Christophe Dubois uint32_t phy_int_mask; 272461c51adSJean-Christophe Dubois uint32_t phy_num; 273*df3f5efeSGuenter Roeck bool phy_connected; 274*df3f5efeSGuenter Roeck struct IMXFECState *phy_consumer; 275a699b410SJean-Christophe Dubois 276a699b410SJean-Christophe Dubois bool is_fec; 2777bac20dcSAndrey Smirnov 2787bac20dcSAndrey Smirnov /* Buffer used to assemble a Tx frame */ 2797bac20dcSAndrey Smirnov uint8_t frame[ENET_MAX_FRAME_SIZE]; 280db1015e9SEduardo Habkost }; 281fcbd8018SJean-Christophe Dubois 282fcbd8018SJean-Christophe Dubois #endif 283