xref: /qemu/include/hw/net/imx_fec.h (revision a699b410d7120dd67bc6c9beae44868780866f09)
1fcbd8018SJean-Christophe Dubois /*
2*a699b410SJean-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 
30*a699b410SJean-Christophe Dubois #define TYPE_IMX_ENET "imx.enet"
31*a699b410SJean-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
55db0de352SJean-Christophe Dubois #define ENET_RDSR              96
56db0de352SJean-Christophe Dubois #define ENET_TDSR              97
57db0de352SJean-Christophe Dubois #define ENET_MRBR              98
58*a699b410SJean-Christophe Dubois #define ENET_RSFL              100
59*a699b410SJean-Christophe Dubois #define ENET_RSEM              101
60*a699b410SJean-Christophe Dubois #define ENET_RAEM              102
61*a699b410SJean-Christophe Dubois #define ENET_RAFL              103
62*a699b410SJean-Christophe Dubois #define ENET_TSEM              104
63*a699b410SJean-Christophe Dubois #define ENET_TAEM              105
64*a699b410SJean-Christophe Dubois #define ENET_TAFL              106
65*a699b410SJean-Christophe Dubois #define ENET_TIPG              107
66*a699b410SJean-Christophe Dubois #define ENET_FTRL              108
67*a699b410SJean-Christophe Dubois #define ENET_TACC              112
68*a699b410SJean-Christophe Dubois #define ENET_RACC              113
69db0de352SJean-Christophe Dubois #define ENET_MIIGSK_CFGR       192
70db0de352SJean-Christophe Dubois #define ENET_MIIGSK_ENR        194
71*a699b410SJean-Christophe Dubois #define ENET_ATCR              256
72*a699b410SJean-Christophe Dubois #define ENET_ATVR              257
73*a699b410SJean-Christophe Dubois #define ENET_ATOFF             258
74*a699b410SJean-Christophe Dubois #define ENET_ATPER             259
75*a699b410SJean-Christophe Dubois #define ENET_ATCOR             260
76*a699b410SJean-Christophe Dubois #define ENET_ATINC             261
77*a699b410SJean-Christophe Dubois #define ENET_ATSTMP            262
78*a699b410SJean-Christophe Dubois #define ENET_TGSR              385
79*a699b410SJean-Christophe Dubois #define ENET_TCSR0             386
80*a699b410SJean-Christophe Dubois #define ENET_TCCR0             387
81*a699b410SJean-Christophe Dubois #define ENET_TCSR1             388
82*a699b410SJean-Christophe Dubois #define ENET_TCCR1             389
83*a699b410SJean-Christophe Dubois #define ENET_TCSR2             390
84*a699b410SJean-Christophe Dubois #define ENET_TCCR2             391
85*a699b410SJean-Christophe Dubois #define ENET_TCSR3             392
86*a699b410SJean-Christophe Dubois #define ENET_TCCR3             393
87db0de352SJean-Christophe Dubois #define ENET_MAX               400
88db0de352SJean-Christophe Dubois 
891bb3c371SJean-Christophe Dubois #define ENET_MAX_FRAME_SIZE    2032
90fcbd8018SJean-Christophe Dubois 
91*a699b410SJean-Christophe Dubois /* EIR and EIMR */
921bb3c371SJean-Christophe Dubois #define ENET_INT_HB            (1 << 31)
931bb3c371SJean-Christophe Dubois #define ENET_INT_BABR          (1 << 30)
941bb3c371SJean-Christophe Dubois #define ENET_INT_BABT          (1 << 29)
951bb3c371SJean-Christophe Dubois #define ENET_INT_GRA           (1 << 28)
961bb3c371SJean-Christophe Dubois #define ENET_INT_TXF           (1 << 27)
971bb3c371SJean-Christophe Dubois #define ENET_INT_TXB           (1 << 26)
981bb3c371SJean-Christophe Dubois #define ENET_INT_RXF           (1 << 25)
991bb3c371SJean-Christophe Dubois #define ENET_INT_RXB           (1 << 24)
1001bb3c371SJean-Christophe Dubois #define ENET_INT_MII           (1 << 23)
1011bb3c371SJean-Christophe Dubois #define ENET_INT_EBERR         (1 << 22)
1021bb3c371SJean-Christophe Dubois #define ENET_INT_LC            (1 << 21)
1031bb3c371SJean-Christophe Dubois #define ENET_INT_RL            (1 << 20)
1041bb3c371SJean-Christophe Dubois #define ENET_INT_UN            (1 << 19)
105*a699b410SJean-Christophe Dubois #define ENET_INT_PLR           (1 << 18)
106*a699b410SJean-Christophe Dubois #define ENET_INT_WAKEUP        (1 << 17)
107*a699b410SJean-Christophe Dubois #define ENET_INT_TS_AVAIL      (1 << 16)
108*a699b410SJean-Christophe Dubois #define ENET_INT_TS_TIMER      (1 << 15)
109*a699b410SJean-Christophe Dubois 
110*a699b410SJean-Christophe Dubois #define ENET_INT_MAC           (ENET_INT_HB | ENET_INT_BABR | ENET_INT_BABT | \
111*a699b410SJean-Christophe Dubois                                 ENET_INT_GRA | ENET_INT_TXF | ENET_INT_TXB | \
112*a699b410SJean-Christophe Dubois                                 ENET_INT_RXF | ENET_INT_RXB | ENET_INT_MII | \
113*a699b410SJean-Christophe Dubois                                 ENET_INT_EBERR | ENET_INT_LC | ENET_INT_RL | \
114*a699b410SJean-Christophe Dubois                                 ENET_INT_UN | ENET_INT_PLR | ENET_INT_WAKEUP | \
115*a699b410SJean-Christophe Dubois                                 ENET_INT_TS_AVAIL)
116fcbd8018SJean-Christophe Dubois 
117db0de352SJean-Christophe Dubois /* RDAR */
118db0de352SJean-Christophe Dubois #define ENET_RDAR_RDAR         (1 << 24)
119db0de352SJean-Christophe Dubois 
120db0de352SJean-Christophe Dubois /* TDAR */
121db0de352SJean-Christophe Dubois #define ENET_TDAR_TDAR         (1 << 24)
122db0de352SJean-Christophe Dubois 
123*a699b410SJean-Christophe Dubois /* ECR */
1241bb3c371SJean-Christophe Dubois #define ENET_ECR_RESET         (1 << 0)
1251bb3c371SJean-Christophe Dubois #define ENET_ECR_ETHEREN       (1 << 1)
126*a699b410SJean-Christophe Dubois #define ENET_ECR_MAGICEN       (1 << 2)
127*a699b410SJean-Christophe Dubois #define ENET_ECR_SLEEP         (1 << 3)
128*a699b410SJean-Christophe Dubois #define ENET_ECR_EN1588        (1 << 4)
129*a699b410SJean-Christophe Dubois #define ENET_ECR_SPEED         (1 << 5)
130*a699b410SJean-Christophe Dubois #define ENET_ECR_DBGEN         (1 << 6)
131*a699b410SJean-Christophe Dubois #define ENET_ECR_STOPEN        (1 << 7)
132*a699b410SJean-Christophe Dubois #define ENET_ECR_DSBWP         (1 << 8)
133*a699b410SJean-Christophe Dubois 
134*a699b410SJean-Christophe Dubois /* MIBC */
135*a699b410SJean-Christophe Dubois #define ENET_MIBC_MIB_DIS      (1 << 31)
136*a699b410SJean-Christophe Dubois #define ENET_MIBC_MIB_IDLE     (1 << 30)
137*a699b410SJean-Christophe Dubois #define ENET_MIBC_MIB_CLEAR    (1 << 29)
138*a699b410SJean-Christophe Dubois 
139*a699b410SJean-Christophe Dubois /* RCR */
140*a699b410SJean-Christophe Dubois #define ENET_RCR_LOOP          (1 << 0)
141*a699b410SJean-Christophe Dubois #define ENET_RCR_DRT           (1 << 1)
142*a699b410SJean-Christophe Dubois #define ENET_RCR_MII_MODE      (1 << 2)
143*a699b410SJean-Christophe Dubois #define ENET_RCR_PROM          (1 << 3)
144*a699b410SJean-Christophe Dubois #define ENET_RCR_BC_REJ        (1 << 4)
145*a699b410SJean-Christophe Dubois #define ENET_RCR_FCE           (1 << 5)
146*a699b410SJean-Christophe Dubois #define ENET_RCR_RGMII_EN      (1 << 6)
147*a699b410SJean-Christophe Dubois #define ENET_RCR_RMII_MODE     (1 << 8)
148*a699b410SJean-Christophe Dubois #define ENET_RCR_RMII_10T      (1 << 9)
149*a699b410SJean-Christophe Dubois #define ENET_RCR_PADEN         (1 << 12)
150*a699b410SJean-Christophe Dubois #define ENET_RCR_PAUFWD        (1 << 13)
151*a699b410SJean-Christophe Dubois #define ENET_RCR_CRCFWD        (1 << 14)
152*a699b410SJean-Christophe Dubois #define ENET_RCR_CFEN          (1 << 15)
153*a699b410SJean-Christophe Dubois #define ENET_RCR_MAX_FL_SHIFT  (16)
154*a699b410SJean-Christophe Dubois #define ENET_RCR_MAX_FL_LENGTH (14)
155*a699b410SJean-Christophe Dubois #define ENET_RCR_NLC           (1 << 30)
156*a699b410SJean-Christophe Dubois #define ENET_RCR_GRS           (1 << 31)
157*a699b410SJean-Christophe Dubois 
158*a699b410SJean-Christophe Dubois /* TCR */
159*a699b410SJean-Christophe Dubois #define ENET_TCR_GTS           (1 << 0)
160*a699b410SJean-Christophe Dubois #define ENET_TCR_FDEN          (1 << 2)
161*a699b410SJean-Christophe Dubois #define ENET_TCR_TFC_PAUSE     (1 << 3)
162*a699b410SJean-Christophe Dubois #define ENET_TCR_RFC_PAUSE     (1 << 4)
163*a699b410SJean-Christophe Dubois #define ENET_TCR_ADDSEL_SHIFT  (5)
164*a699b410SJean-Christophe Dubois #define ENET_TCR_ADDSEL_LENGTH (3)
165*a699b410SJean-Christophe Dubois #define ENET_TCR_CRCFWD        (1 << 9)
166*a699b410SJean-Christophe Dubois 
167*a699b410SJean-Christophe Dubois /* RDSR */
168*a699b410SJean-Christophe Dubois #define ENET_TWFR_TFWR_SHIFT   (0)
169*a699b410SJean-Christophe Dubois #define ENET_TWFR_TFWR_LENGTH  (6)
170*a699b410SJean-Christophe Dubois #define ENET_TWFR_STRFWD       (1 << 8)
171fcbd8018SJean-Christophe Dubois 
172fcbd8018SJean-Christophe Dubois /* Buffer Descriptor.  */
173fcbd8018SJean-Christophe Dubois typedef struct {
174fcbd8018SJean-Christophe Dubois     uint16_t length;
175fcbd8018SJean-Christophe Dubois     uint16_t flags;
176fcbd8018SJean-Christophe Dubois     uint32_t data;
177fcbd8018SJean-Christophe Dubois } IMXFECBufDesc;
178fcbd8018SJean-Christophe Dubois 
1791bb3c371SJean-Christophe Dubois #define ENET_BD_R              (1 << 15)
1801bb3c371SJean-Christophe Dubois #define ENET_BD_E              (1 << 15)
1811bb3c371SJean-Christophe Dubois #define ENET_BD_O1             (1 << 14)
1821bb3c371SJean-Christophe Dubois #define ENET_BD_W              (1 << 13)
1831bb3c371SJean-Christophe Dubois #define ENET_BD_O2             (1 << 12)
1841bb3c371SJean-Christophe Dubois #define ENET_BD_L              (1 << 11)
1851bb3c371SJean-Christophe Dubois #define ENET_BD_TC             (1 << 10)
1861bb3c371SJean-Christophe Dubois #define ENET_BD_ABC            (1 << 9)
1871bb3c371SJean-Christophe Dubois #define ENET_BD_M              (1 << 8)
1881bb3c371SJean-Christophe Dubois #define ENET_BD_BC             (1 << 7)
1891bb3c371SJean-Christophe Dubois #define ENET_BD_MC             (1 << 6)
1901bb3c371SJean-Christophe Dubois #define ENET_BD_LG             (1 << 5)
1911bb3c371SJean-Christophe Dubois #define ENET_BD_NO             (1 << 4)
1921bb3c371SJean-Christophe Dubois #define ENET_BD_CR             (1 << 2)
1931bb3c371SJean-Christophe Dubois #define ENET_BD_OV             (1 << 1)
1941bb3c371SJean-Christophe Dubois #define ENET_BD_TR             (1 << 0)
195fcbd8018SJean-Christophe Dubois 
196*a699b410SJean-Christophe Dubois typedef struct {
197*a699b410SJean-Christophe Dubois     uint16_t length;
198*a699b410SJean-Christophe Dubois     uint16_t flags;
199*a699b410SJean-Christophe Dubois     uint32_t data;
200*a699b410SJean-Christophe Dubois     uint16_t status;
201*a699b410SJean-Christophe Dubois     uint16_t option;
202*a699b410SJean-Christophe Dubois     uint16_t checksum;
203*a699b410SJean-Christophe Dubois     uint16_t head_proto;
204*a699b410SJean-Christophe Dubois     uint32_t last_buffer;
205*a699b410SJean-Christophe Dubois     uint32_t timestamp;
206*a699b410SJean-Christophe Dubois     uint32_t reserved[2];
207*a699b410SJean-Christophe Dubois } IMXENETBufDesc;
208*a699b410SJean-Christophe Dubois 
209*a699b410SJean-Christophe Dubois #define ENET_BD_ME             (1 << 15)
210*a699b410SJean-Christophe Dubois #define ENET_BD_TX_INT         (1 << 14)
211*a699b410SJean-Christophe Dubois #define ENET_BD_TS             (1 << 13)
212*a699b410SJean-Christophe Dubois #define ENET_BD_PINS           (1 << 12)
213*a699b410SJean-Christophe Dubois #define ENET_BD_IINS           (1 << 11)
214*a699b410SJean-Christophe Dubois #define ENET_BD_PE             (1 << 10)
215*a699b410SJean-Christophe Dubois #define ENET_BD_CE             (1 << 9)
216*a699b410SJean-Christophe Dubois #define ENET_BD_UC             (1 << 8)
217*a699b410SJean-Christophe Dubois #define ENET_BD_RX_INT         (1 << 7)
218*a699b410SJean-Christophe Dubois 
219*a699b410SJean-Christophe Dubois #define ENET_BD_TXE            (1 << 15)
220*a699b410SJean-Christophe Dubois #define ENET_BD_UE             (1 << 13)
221*a699b410SJean-Christophe Dubois #define ENET_BD_EE             (1 << 12)
222*a699b410SJean-Christophe Dubois #define ENET_BD_FE             (1 << 11)
223*a699b410SJean-Christophe Dubois #define ENET_BD_LCE            (1 << 10)
224*a699b410SJean-Christophe Dubois #define ENET_BD_OE             (1 << 9)
225*a699b410SJean-Christophe Dubois #define ENET_BD_TSE            (1 << 8)
226*a699b410SJean-Christophe Dubois #define ENET_BD_ICE            (1 << 5)
227*a699b410SJean-Christophe Dubois #define ENET_BD_PCR            (1 << 4)
228*a699b410SJean-Christophe Dubois #define ENET_BD_VLAN           (1 << 2)
229*a699b410SJean-Christophe Dubois #define ENET_BD_IPV6           (1 << 1)
230*a699b410SJean-Christophe Dubois #define ENET_BD_FRAG           (1 << 0)
231*a699b410SJean-Christophe Dubois 
232*a699b410SJean-Christophe Dubois #define ENET_BD_BDU            (1 << 31)
233*a699b410SJean-Christophe Dubois 
234fcbd8018SJean-Christophe Dubois typedef struct IMXFECState {
235fcbd8018SJean-Christophe Dubois     /*< private >*/
236fcbd8018SJean-Christophe Dubois     SysBusDevice parent_obj;
237fcbd8018SJean-Christophe Dubois 
238fcbd8018SJean-Christophe Dubois     /*< public >*/
239fcbd8018SJean-Christophe Dubois     NICState *nic;
240fcbd8018SJean-Christophe Dubois     NICConf conf;
241*a699b410SJean-Christophe Dubois     qemu_irq irq[2];
242fcbd8018SJean-Christophe Dubois     MemoryRegion iomem;
243fcbd8018SJean-Christophe Dubois 
244db0de352SJean-Christophe Dubois     uint32_t regs[ENET_MAX];
245fcbd8018SJean-Christophe Dubois     uint32_t rx_descriptor;
246fcbd8018SJean-Christophe Dubois     uint32_t tx_descriptor;
247fcbd8018SJean-Christophe Dubois 
248fcbd8018SJean-Christophe Dubois     uint32_t phy_status;
249fcbd8018SJean-Christophe Dubois     uint32_t phy_control;
250fcbd8018SJean-Christophe Dubois     uint32_t phy_advertise;
251fcbd8018SJean-Christophe Dubois     uint32_t phy_int;
252fcbd8018SJean-Christophe Dubois     uint32_t phy_int_mask;
253*a699b410SJean-Christophe Dubois 
254*a699b410SJean-Christophe Dubois     bool is_fec;
255fcbd8018SJean-Christophe Dubois } IMXFECState;
256fcbd8018SJean-Christophe Dubois 
257fcbd8018SJean-Christophe Dubois #endif
258