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