blob: d8b4bda3ef9c339cb081e5d250494b30136de2b2 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +09002/*
Robert P. J. Day8c60f922016-05-04 04:47:31 -04003 * sh_eth.h - Driver for Renesas SuperH ethernet controller.
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +09004 *
Nobuhiro Iwamatsu4ad2c2a2012-08-02 22:08:40 +00005 * Copyright (C) 2008 - 2012 Renesas Solutions Corp.
6 * Copyright (c) 2008 - 2012 Nobuhiro Iwamatsu
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +09007 * Copyright (c) 2007 Carlos Munoz <carlos@kenati.com>
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +09008 */
9
Nobuhiro Iwamatsud8f5d502008-11-21 12:04:18 +090010#include <netdev.h>
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +090011#include <asm/types.h>
12
13#define SHETHER_NAME "sh_eth"
14
Nobuhiro Iwamatsu4ad2c2a2012-08-02 22:08:40 +000015#if defined(CONFIG_SH)
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +090016/* Malloc returns addresses in the P1 area (cacheable). However we need to
17 use area P2 (non-cacheable) */
18#define ADDR_TO_P2(addr) ((((int)(addr) & ~0xe0000000) | 0xa0000000))
19
20/* The ethernet controller needs to use physical addresses */
Yoshihiro Shimoda34cca922011-01-18 17:53:45 +090021#if defined(CONFIG_SH_32BIT)
22#define ADDR_TO_PHY(addr) ((((int)(addr) & ~0xe0000000) | 0x40000000))
23#else
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +090024#define ADDR_TO_PHY(addr) ((int)(addr) & ~0xe0000000)
Yoshihiro Shimoda34cca922011-01-18 17:53:45 +090025#endif
Nobuhiro Iwamatsu4ad2c2a2012-08-02 22:08:40 +000026#elif defined(CONFIG_ARM)
Chris Brandt71230772017-11-03 08:30:11 -050027#ifndef inl
28#define inl readl
Nobuhiro Iwamatsu4ad2c2a2012-08-02 22:08:40 +000029#define outl writel
Chris Brandt71230772017-11-03 08:30:11 -050030#endif
Nobuhiro Iwamatsu4ad2c2a2012-08-02 22:08:40 +000031#define ADDR_TO_PHY(addr) ((int)(addr))
32#define ADDR_TO_P2(addr) (addr)
33#endif /* defined(CONFIG_SH) */
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +090034
Nobuhiro Iwamatsu7a2142c2013-08-22 13:22:02 +090035/* base padding size is 16 */
36#ifndef CONFIG_SH_ETHER_ALIGNE_SIZE
37#define CONFIG_SH_ETHER_ALIGNE_SIZE 16
38#endif
39
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +090040/* Number of supported ports */
41#define MAX_PORT_NUM 2
42
43/* Buffers must be big enough to hold the largest ethernet frame. Also, rx
44 buffers must be a multiple of 32 bytes */
45#define MAX_BUF_SIZE (48 * 32)
46
47/* The number of tx descriptors must be large enough to point to 5 or more
48 frames. If each frame uses 2 descriptors, at least 10 descriptors are needed.
49 We use one descriptor per frame */
50#define NUM_TX_DESC 8
51
52/* The size of the tx descriptor is determined by how much padding is used.
53 4, 20, or 52 bytes of padding can be used */
Nobuhiro Iwamatsu7a2142c2013-08-22 13:22:02 +090054#define TX_DESC_PADDING (CONFIG_SH_ETHER_ALIGNE_SIZE - 12)
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +090055
Nobuhiro Iwamatsud8f5d502008-11-21 12:04:18 +090056/* Tx descriptor. We always use 3 bytes of padding */
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +090057struct tx_desc_s {
58 volatile u32 td0;
59 u32 td1;
60 u32 td2; /* Buffer start */
Nobuhiro Iwamatsu7a2142c2013-08-22 13:22:02 +090061 u8 padding[TX_DESC_PADDING]; /* aligned cache line size */
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +090062};
63
64/* There is no limitation in the number of rx descriptors */
65#define NUM_RX_DESC 8
66
67/* The size of the rx descriptor is determined by how much padding is used.
68 4, 20, or 52 bytes of padding can be used */
Nobuhiro Iwamatsu7a2142c2013-08-22 13:22:02 +090069#define RX_DESC_PADDING (CONFIG_SH_ETHER_ALIGNE_SIZE - 12)
Nobuhiro Iwamatsu7a2142c2013-08-22 13:22:02 +090070/* aligned cache line size */
71#define RX_BUF_ALIGNE_SIZE (CONFIG_SH_ETHER_ALIGNE_SIZE > 32 ? 64 : 32)
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +090072
73/* Rx descriptor. We always use 4 bytes of padding */
74struct rx_desc_s {
75 volatile u32 rd0;
76 volatile u32 rd1;
77 u32 rd2; /* Buffer start */
Nobuhiro Iwamatsu7a2142c2013-08-22 13:22:02 +090078 u8 padding[TX_DESC_PADDING]; /* aligned cache line size */
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +090079};
80
Nobuhiro Iwamatsud8f5d502008-11-21 12:04:18 +090081struct sh_eth_info {
Nobuhiro Iwamatsu1c822112014-11-04 09:15:47 +090082 struct tx_desc_s *tx_desc_alloc;
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +090083 struct tx_desc_s *tx_desc_base;
84 struct tx_desc_s *tx_desc_cur;
Nobuhiro Iwamatsu1c822112014-11-04 09:15:47 +090085 struct rx_desc_s *rx_desc_alloc;
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +090086 struct rx_desc_s *rx_desc_base;
87 struct rx_desc_s *rx_desc_cur;
Nobuhiro Iwamatsu1c822112014-11-04 09:15:47 +090088 u8 *rx_buf_alloc;
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +090089 u8 *rx_buf_base;
90 u8 mac_addr[6];
91 u8 phy_addr;
Nobuhiro Iwamatsud8f5d502008-11-21 12:04:18 +090092 struct eth_device *dev;
Yoshihiro Shimoda677f6cd2011-10-11 18:10:14 +090093 struct phy_device *phydev;
Nobuhiro Iwamatsuec921f12017-12-01 08:10:32 +090094 void __iomem *iobase;
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +090095};
96
Nobuhiro Iwamatsud8f5d502008-11-21 12:04:18 +090097struct sh_eth_dev {
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +090098 int port;
Nobuhiro Iwamatsud8f5d502008-11-21 12:04:18 +090099 struct sh_eth_info port_info[MAX_PORT_NUM];
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +0900100};
101
Yoshihiro Shimoda4c4aa6c2012-06-26 16:38:09 +0000102/* from linux/drivers/net/ethernet/renesas/sh_eth.h */
103enum {
104 /* E-DMAC registers */
105 EDSR = 0,
106 EDMR,
107 EDTRR,
108 EDRRR,
109 EESR,
110 EESIPR,
111 TDLAR,
112 TDFAR,
113 TDFXR,
114 TDFFR,
115 RDLAR,
116 RDFAR,
117 RDFXR,
118 RDFFR,
119 TRSCER,
120 RMFCR,
121 TFTR,
122 FDR,
123 RMCR,
124 EDOCR,
125 TFUCR,
126 RFOCR,
127 FCFTR,
128 RPADIR,
129 TRIMD,
130 RBWAR,
131 TBRAR,
132
133 /* Ether registers */
134 ECMR,
135 ECSR,
136 ECSIPR,
137 PIR,
138 PSR,
139 RDMLR,
140 PIPR,
141 RFLR,
142 IPGR,
143 APR,
144 MPR,
145 PFTCR,
146 PFRCR,
147 RFCR,
148 RFCF,
149 TPAUSER,
150 TPAUSECR,
151 BCFR,
152 BCFRR,
153 GECMR,
154 BCULR,
155 MAHR,
156 MALR,
157 TROCR,
158 CDCR,
159 LCCR,
160 CNDCR,
161 CEFCR,
162 FRECR,
163 TSFRCR,
164 TLFRCR,
165 CERCR,
166 CEECR,
Nobuhiro Iwamatsu72befd32013-08-22 13:22:04 +0900167 RMIIMR, /* R8A7790 */
Yoshihiro Shimoda4c4aa6c2012-06-26 16:38:09 +0000168 MAFCR,
169 RTRATE,
170 CSMR,
171 RMII_MII,
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +0900172
Yoshihiro Shimoda4c4aa6c2012-06-26 16:38:09 +0000173 /* This value must be written at last. */
174 SH_ETH_MAX_REGISTER_OFFSET,
175};
176
177static const u16 sh_eth_offset_gigabit[SH_ETH_MAX_REGISTER_OFFSET] = {
178 [EDSR] = 0x0000,
179 [EDMR] = 0x0400,
180 [EDTRR] = 0x0408,
181 [EDRRR] = 0x0410,
182 [EESR] = 0x0428,
183 [EESIPR] = 0x0430,
184 [TDLAR] = 0x0010,
185 [TDFAR] = 0x0014,
186 [TDFXR] = 0x0018,
187 [TDFFR] = 0x001c,
188 [RDLAR] = 0x0030,
189 [RDFAR] = 0x0034,
190 [RDFXR] = 0x0038,
191 [RDFFR] = 0x003c,
192 [TRSCER] = 0x0438,
193 [RMFCR] = 0x0440,
194 [TFTR] = 0x0448,
195 [FDR] = 0x0450,
196 [RMCR] = 0x0458,
197 [RPADIR] = 0x0460,
198 [FCFTR] = 0x0468,
199 [CSMR] = 0x04E4,
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +0900200
Yoshihiro Shimoda4c4aa6c2012-06-26 16:38:09 +0000201 [ECMR] = 0x0500,
202 [ECSR] = 0x0510,
203 [ECSIPR] = 0x0518,
204 [PIR] = 0x0520,
205 [PSR] = 0x0528,
206 [PIPR] = 0x052c,
207 [RFLR] = 0x0508,
208 [APR] = 0x0554,
209 [MPR] = 0x0558,
210 [PFTCR] = 0x055c,
211 [PFRCR] = 0x0560,
212 [TPAUSER] = 0x0564,
213 [GECMR] = 0x05b0,
214 [BCULR] = 0x05b4,
215 [MAHR] = 0x05c0,
216 [MALR] = 0x05c8,
217 [TROCR] = 0x0700,
218 [CDCR] = 0x0708,
219 [LCCR] = 0x0710,
220 [CEFCR] = 0x0740,
221 [FRECR] = 0x0748,
222 [TSFRCR] = 0x0750,
223 [TLFRCR] = 0x0758,
224 [RFCR] = 0x0760,
225 [CERCR] = 0x0768,
226 [CEECR] = 0x0770,
227 [MAFCR] = 0x0778,
228 [RMII_MII] = 0x0790,
229};
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +0900230
Yoshihiro Shimoda4c4aa6c2012-06-26 16:38:09 +0000231static const u16 sh_eth_offset_fast_sh4[SH_ETH_MAX_REGISTER_OFFSET] = {
232 [ECMR] = 0x0100,
233 [RFLR] = 0x0108,
234 [ECSR] = 0x0110,
235 [ECSIPR] = 0x0118,
236 [PIR] = 0x0120,
237 [PSR] = 0x0128,
238 [RDMLR] = 0x0140,
239 [IPGR] = 0x0150,
240 [APR] = 0x0154,
241 [MPR] = 0x0158,
242 [TPAUSER] = 0x0164,
243 [RFCF] = 0x0160,
244 [TPAUSECR] = 0x0168,
245 [BCFRR] = 0x016c,
246 [MAHR] = 0x01c0,
247 [MALR] = 0x01c8,
248 [TROCR] = 0x01d0,
249 [CDCR] = 0x01d4,
250 [LCCR] = 0x01d8,
251 [CNDCR] = 0x01dc,
252 [CEFCR] = 0x01e4,
253 [FRECR] = 0x01e8,
254 [TSFRCR] = 0x01ec,
255 [TLFRCR] = 0x01f0,
256 [RFCR] = 0x01f4,
257 [MAFCR] = 0x01f8,
258 [RTRATE] = 0x01fc,
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +0900259
Yoshihiro Shimoda4c4aa6c2012-06-26 16:38:09 +0000260 [EDMR] = 0x0000,
261 [EDTRR] = 0x0008,
262 [EDRRR] = 0x0010,
263 [TDLAR] = 0x0018,
264 [RDLAR] = 0x0020,
265 [EESR] = 0x0028,
266 [EESIPR] = 0x0030,
267 [TRSCER] = 0x0038,
268 [RMFCR] = 0x0040,
269 [TFTR] = 0x0048,
270 [FDR] = 0x0050,
271 [RMCR] = 0x0058,
272 [TFUCR] = 0x0064,
273 [RFOCR] = 0x0068,
Nobuhiro Iwamatsu72befd32013-08-22 13:22:04 +0900274 [RMIIMR] = 0x006C,
Yoshihiro Shimoda4c4aa6c2012-06-26 16:38:09 +0000275 [FCFTR] = 0x0070,
276 [RPADIR] = 0x0078,
277 [TRIMD] = 0x007c,
278 [RBWAR] = 0x00c8,
279 [RDFAR] = 0x00cc,
280 [TBRAR] = 0x00d4,
281 [TDFAR] = 0x00d8,
282};
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +0900283
Yoshihiro Shimoda4c4aa6c2012-06-26 16:38:09 +0000284/* Register Address */
285#if defined(CONFIG_CPU_SH7763) || defined(CONFIG_CPU_SH7734)
286#define SH_ETH_TYPE_GETHER
287#define BASE_IO_ADDR 0xfee00000
Yoshihiro Shimodac5901fb2013-12-18 16:04:04 +0900288#elif defined(CONFIG_CPU_SH7757) || \
289 defined(CONFIG_CPU_SH7752) || \
290 defined(CONFIG_CPU_SH7753)
Yoshihiro Shimoda36944902012-06-26 16:38:11 +0000291#if defined(CONFIG_SH_ETHER_USE_GETHER)
292#define SH_ETH_TYPE_GETHER
293#define BASE_IO_ADDR 0xfee00000
294#else
Yoshihiro Shimoda9d553032012-06-26 16:38:06 +0000295#define SH_ETH_TYPE_ETHER
Yoshihiro Shimoda34cca922011-01-18 17:53:45 +0900296#define BASE_IO_ADDR 0xfef00000
Yoshihiro Shimoda36944902012-06-26 16:38:11 +0000297#endif
Nobuhiro Iwamatsu4ad2c2a2012-08-02 22:08:40 +0000298#elif defined(CONFIG_R8A7740)
299#define SH_ETH_TYPE_GETHER
300#define BASE_IO_ADDR 0xE9A00000
Marek Vasutee2f21b2018-01-22 01:42:32 +0100301#elif defined(CONFIG_RCAR_GEN2)
Nobuhiro Iwamatsu72befd32013-08-22 13:22:04 +0900302#define SH_ETH_TYPE_ETHER
303#define BASE_IO_ADDR 0xEE700200
Nobuhiro Iwamatsu46288f42014-01-23 07:52:18 +0900304#elif defined(CONFIG_R7S72100)
305#define SH_ETH_TYPE_RZ
306#define BASE_IO_ADDR 0xE8203000
Yoshihiro Shimoda34cca922011-01-18 17:53:45 +0900307#endif
308
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +0900309/*
310 * Register's bits
311 * Copy from Linux driver source code
312 */
Nobuhiro Iwamatsu46288f42014-01-23 07:52:18 +0900313#if defined(SH_ETH_TYPE_GETHER) || defined(SH_ETH_TYPE_RZ)
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +0900314/* EDSR */
315enum EDSR_BIT {
316 EDSR_ENT = 0x01, EDSR_ENR = 0x02,
317};
318#define EDSR_ENALL (EDSR_ENT|EDSR_ENR)
319#endif
320
321/* EDMR */
322enum DMAC_M_BIT {
323 EDMR_DL1 = 0x20, EDMR_DL0 = 0x10,
Nobuhiro Iwamatsu46288f42014-01-23 07:52:18 +0900324#if defined(SH_ETH_TYPE_GETHER) || defined(SH_ETH_TYPE_RZ)
Nobuhiro Iwamatsu58802902012-02-02 21:28:49 +0000325 EDMR_SRST = 0x03, /* Receive/Send reset */
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +0900326 EMDR_DESC_R = 0x30, /* Descriptor reserve size */
327 EDMR_EL = 0x40, /* Litte endian */
Yoshihiro Shimoda9d553032012-06-26 16:38:06 +0000328#elif defined(SH_ETH_TYPE_ETHER)
Yoshihiro Shimoda34cca922011-01-18 17:53:45 +0900329 EDMR_SRST = 0x01,
330 EMDR_DESC_R = 0x30, /* Descriptor reserve size */
331 EDMR_EL = 0x40, /* Litte endian */
Yoshihiro Shimoda9d553032012-06-26 16:38:06 +0000332#else
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +0900333 EDMR_SRST = 0x01,
334#endif
335};
336
Nobuhiro Iwamatsu7a2142c2013-08-22 13:22:02 +0900337#if CONFIG_SH_ETHER_ALIGNE_SIZE == 64
338# define EMDR_DESC EDMR_DL1
339#elif CONFIG_SH_ETHER_ALIGNE_SIZE == 32
340# define EMDR_DESC EDMR_DL0
341#elif CONFIG_SH_ETHER_ALIGNE_SIZE == 16 /* Default */
342# define EMDR_DESC 0
343#endif
344
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +0900345/* RFLR */
346#define RFLR_RFL_MIN 0x05EE /* Recv Frame length 1518 byte */
347
348/* EDTRR */
349enum DMAC_T_BIT {
Nobuhiro Iwamatsu46288f42014-01-23 07:52:18 +0900350#if defined(SH_ETH_TYPE_GETHER) || defined(SH_ETH_TYPE_RZ)
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +0900351 EDTRR_TRNS = 0x03,
352#else
353 EDTRR_TRNS = 0x01,
354#endif
355};
356
357/* GECMR */
358enum GECMR_BIT {
Yoshihiro Shimodac5901fb2013-12-18 16:04:04 +0900359#if defined(CONFIG_CPU_SH7757) || \
360 defined(CONFIG_CPU_SH7752) || \
361 defined(CONFIG_CPU_SH7753)
Yoshihiro Shimoda36944902012-06-26 16:38:11 +0000362 GECMR_1000B = 0x20, GECMR_100B = 0x01, GECMR_10B = 0x00,
363#else
Simon Muntonc2d704f2009-02-02 09:44:08 +0000364 GECMR_1000B = 0x01, GECMR_100B = 0x04, GECMR_10B = 0x00,
Yoshihiro Shimoda36944902012-06-26 16:38:11 +0000365#endif
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +0900366};
367
368/* EDRRR*/
369enum EDRRR_R_BIT {
370 EDRRR_R = 0x01,
371};
372
373/* TPAUSER */
374enum TPAUSER_BIT {
375 TPAUSER_TPAUSE = 0x0000ffff,
376 TPAUSER_UNLIMITED = 0,
377};
378
379/* BCFR */
380enum BCFR_BIT {
381 BCFR_RPAUSE = 0x0000ffff,
382 BCFR_UNLIMITED = 0,
383};
384
385/* PIR */
386enum PIR_BIT {
387 PIR_MDI = 0x08, PIR_MDO = 0x04, PIR_MMD = 0x02, PIR_MDC = 0x01,
388};
389
390/* PSR */
391enum PHY_STATUS_BIT { PHY_ST_LINK = 0x01, };
392
393/* EESR */
394enum EESR_BIT {
Yoshihiro Shimoda9d553032012-06-26 16:38:06 +0000395#if defined(SH_ETH_TYPE_ETHER)
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +0900396 EESR_TWB = 0x40000000,
397#else
398 EESR_TWB = 0xC0000000,
399 EESR_TC1 = 0x20000000,
400 EESR_TUC = 0x10000000,
401 EESR_ROC = 0x80000000,
402#endif
403 EESR_TABT = 0x04000000,
404 EESR_RABT = 0x02000000, EESR_RFRMER = 0x01000000,
Yoshihiro Shimoda9d553032012-06-26 16:38:06 +0000405#if defined(SH_ETH_TYPE_ETHER)
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +0900406 EESR_ADE = 0x00800000,
407#endif
408 EESR_ECI = 0x00400000,
409 EESR_FTC = 0x00200000, EESR_TDE = 0x00100000,
410 EESR_TFE = 0x00080000, EESR_FRC = 0x00040000,
411 EESR_RDE = 0x00020000, EESR_RFE = 0x00010000,
Yoshihiro Shimoda9d553032012-06-26 16:38:06 +0000412#if defined(SH_ETH_TYPE_ETHER)
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +0900413 EESR_CND = 0x00000800,
414#endif
415 EESR_DLC = 0x00000400,
416 EESR_CD = 0x00000200, EESR_RTO = 0x00000100,
417 EESR_RMAF = 0x00000080, EESR_CEEF = 0x00000040,
418 EESR_CELF = 0x00000020, EESR_RRF = 0x00000010,
Nobuhiro Iwamatsu8d14b252014-01-23 07:52:20 +0900419 EESR_RTLF = 0x00000008, EESR_RTSF = 0x00000004,
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +0900420 EESR_PRE = 0x00000002, EESR_CERF = 0x00000001,
421};
422
423
Nobuhiro Iwamatsu46288f42014-01-23 07:52:18 +0900424#if defined(SH_ETH_TYPE_GETHER) || defined(SH_ETH_TYPE_RZ)
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +0900425# define TX_CHECK (EESR_TC1 | EESR_FTC)
426# define EESR_ERR_CHECK (EESR_TWB | EESR_TABT | EESR_RABT | EESR_RDE \
427 | EESR_RFRMER | EESR_TFE | EESR_TDE | EESR_ECI)
428# define TX_ERROR_CEHCK (EESR_TWB | EESR_TABT | EESR_TDE | EESR_TFE)
429
430#else
431# define TX_CHECK (EESR_FTC | EESR_CND | EESR_DLC | EESR_CD | EESR_RTO)
432# define EESR_ERR_CHECK (EESR_TWB | EESR_TABT | EESR_RABT | EESR_RDE \
433 | EESR_RFRMER | EESR_ADE | EESR_TFE | EESR_TDE | EESR_ECI)
434# define TX_ERROR_CEHCK (EESR_TWB | EESR_TABT | EESR_ADE | EESR_TDE | EESR_TFE)
435#endif
436
437/* EESIPR */
438enum DMAC_IM_BIT {
439 DMAC_M_TWB = 0x40000000, DMAC_M_TABT = 0x04000000,
440 DMAC_M_RABT = 0x02000000,
441 DMAC_M_RFRMER = 0x01000000, DMAC_M_ADF = 0x00800000,
442 DMAC_M_ECI = 0x00400000, DMAC_M_FTC = 0x00200000,
443 DMAC_M_TDE = 0x00100000, DMAC_M_TFE = 0x00080000,
444 DMAC_M_FRC = 0x00040000, DMAC_M_RDE = 0x00020000,
445 DMAC_M_RFE = 0x00010000, DMAC_M_TINT4 = 0x00000800,
446 DMAC_M_TINT3 = 0x00000400, DMAC_M_TINT2 = 0x00000200,
447 DMAC_M_TINT1 = 0x00000100, DMAC_M_RINT8 = 0x00000080,
448 DMAC_M_RINT5 = 0x00000010, DMAC_M_RINT4 = 0x00000008,
449 DMAC_M_RINT3 = 0x00000004, DMAC_M_RINT2 = 0x00000002,
450 DMAC_M_RINT1 = 0x00000001,
451};
452
453/* Receive descriptor bit */
454enum RD_STS_BIT {
455 RD_RACT = 0x80000000, RD_RDLE = 0x40000000,
456 RD_RFP1 = 0x20000000, RD_RFP0 = 0x10000000,
457 RD_RFE = 0x08000000, RD_RFS10 = 0x00000200,
458 RD_RFS9 = 0x00000100, RD_RFS8 = 0x00000080,
459 RD_RFS7 = 0x00000040, RD_RFS6 = 0x00000020,
460 RD_RFS5 = 0x00000010, RD_RFS4 = 0x00000008,
461 RD_RFS3 = 0x00000004, RD_RFS2 = 0x00000002,
462 RD_RFS1 = 0x00000001,
463};
464#define RDF1ST RD_RFP1
465#define RDFEND RD_RFP0
466#define RD_RFP (RD_RFP1|RD_RFP0)
467
468/* RDFFR*/
469enum RDFFR_BIT {
470 RDFFR_RDLF = 0x01,
471};
472
473/* FCFTR */
474enum FCFTR_BIT {
475 FCFTR_RFF2 = 0x00040000, FCFTR_RFF1 = 0x00020000,
476 FCFTR_RFF0 = 0x00010000, FCFTR_RFD2 = 0x00000004,
477 FCFTR_RFD1 = 0x00000002, FCFTR_RFD0 = 0x00000001,
478};
479#define FIFO_F_D_RFF (FCFTR_RFF2|FCFTR_RFF1|FCFTR_RFF0)
480#define FIFO_F_D_RFD (FCFTR_RFD2|FCFTR_RFD1|FCFTR_RFD0)
481
482/* Transfer descriptor bit */
483enum TD_STS_BIT {
Nobuhiro Iwamatsu46288f42014-01-23 07:52:18 +0900484#if defined(SH_ETH_TYPE_GETHER) || defined(SH_ETH_TYPE_ETHER) || \
485 defined(SH_ETH_TYPE_RZ)
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +0900486 TD_TACT = 0x80000000,
487#else
488 TD_TACT = 0x7fffffff,
489#endif
490 TD_TDLE = 0x40000000, TD_TFP1 = 0x20000000,
491 TD_TFP0 = 0x10000000,
492};
493#define TDF1ST TD_TFP1
494#define TDFEND TD_TFP0
495#define TD_TFP (TD_TFP1|TD_TFP0)
496
497/* RMCR */
498enum RECV_RST_BIT { RMCR_RST = 0x01, };
499/* ECMR */
500enum FELIC_MODE_BIT {
Nobuhiro Iwamatsu46288f42014-01-23 07:52:18 +0900501#if defined(SH_ETH_TYPE_GETHER) || defined(SH_ETH_TYPE_RZ)
Nobuhiro Iwamatsu31e84df2014-01-23 07:52:19 +0900502 ECMR_TRCCM = 0x04000000, ECMR_RCSC = 0x00800000,
503 ECMR_DPAD = 0x00200000, ECMR_RZPF = 0x00100000,
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +0900504#endif
505 ECMR_ZPF = 0x00080000, ECMR_PFR = 0x00040000, ECMR_RXF = 0x00020000,
506 ECMR_TXF = 0x00010000, ECMR_MCT = 0x00002000, ECMR_PRCEF = 0x00001000,
507 ECMR_PMDE = 0x00000200, ECMR_RE = 0x00000040, ECMR_TE = 0x00000020,
508 ECMR_ILB = 0x00000008, ECMR_ELB = 0x00000004, ECMR_DM = 0x00000002,
509 ECMR_PRM = 0x00000001,
Nobuhiro Iwamatsu9dfac0a2011-11-14 16:56:59 +0900510#ifdef CONFIG_CPU_SH7724
511 ECMR_RTM = 0x00000010,
Marek Vasutee2f21b2018-01-22 01:42:32 +0100512#elif defined(CONFIG_RCAR_GEN2)
Nobuhiro Iwamatsu72befd32013-08-22 13:22:04 +0900513 ECMR_RTM = 0x00000004,
Nobuhiro Iwamatsu9dfac0a2011-11-14 16:56:59 +0900514#endif
515
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +0900516};
517
Nobuhiro Iwamatsu46288f42014-01-23 07:52:18 +0900518#if defined(SH_ETH_TYPE_GETHER) || defined(SH_ETH_TYPE_RZ)
Nobuhiro Iwamatsu31e84df2014-01-23 07:52:19 +0900519#define ECMR_CHG_DM (ECMR_TRCCM | ECMR_RZPF | ECMR_ZPF | ECMR_PFR | \
520 ECMR_RXF | ECMR_TXF | ECMR_MCT)
Yoshihiro Shimoda9d553032012-06-26 16:38:06 +0000521#elif defined(SH_ETH_TYPE_ETHER)
Nobuhiro Iwamatsu9dfac0a2011-11-14 16:56:59 +0900522#define ECMR_CHG_DM (ECMR_ZPF | ECMR_PFR | ECMR_RXF | ECMR_TXF)
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +0900523#else
Yoshihiro Shimoda34cca922011-01-18 17:53:45 +0900524#define ECMR_CHG_DM (ECMR_ZPF | ECMR_PFR | ECMR_RXF | ECMR_TXF | ECMR_MCT)
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +0900525#endif
526
527/* ECSR */
528enum ECSR_STATUS_BIT {
Yoshihiro Shimoda9d553032012-06-26 16:38:06 +0000529#if defined(SH_ETH_TYPE_ETHER)
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +0900530 ECSR_BRCRX = 0x20, ECSR_PSRTO = 0x10,
531#endif
532 ECSR_LCHNG = 0x04,
533 ECSR_MPD = 0x02, ECSR_ICD = 0x01,
534};
535
Nobuhiro Iwamatsu46288f42014-01-23 07:52:18 +0900536#if defined(SH_ETH_TYPE_GETHER) || defined(SH_ETH_TYPE_RZ)
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +0900537# define ECSR_INIT (ECSR_ICD | ECSIPR_MPDIP)
538#else
539# define ECSR_INIT (ECSR_BRCRX | ECSR_PSRTO | \
540 ECSR_LCHNG | ECSR_ICD | ECSIPR_MPDIP)
541#endif
542
543/* ECSIPR */
544enum ECSIPR_STATUS_MASK_BIT {
Yoshihiro Shimoda9d553032012-06-26 16:38:06 +0000545#if defined(SH_ETH_TYPE_ETHER)
Nobuhiro Iwamatsud8d74e82012-06-05 16:39:06 +0000546 ECSIPR_BRCRXIP = 0x20,
Nobuhiro Iwamatsu58802902012-02-02 21:28:49 +0000547 ECSIPR_PSRTOIP = 0x10,
Yoshihiro Shimoda9d553032012-06-26 16:38:06 +0000548#elif defined(SH_ETY_TYPE_GETHER)
Nobuhiro Iwamatsu58802902012-02-02 21:28:49 +0000549 ECSIPR_PSRTOIP = 0x10,
550 ECSIPR_PHYIP = 0x08,
Nobuhiro Iwamatsud8d74e82012-06-05 16:39:06 +0000551#endif
Nobuhiro Iwamatsu58802902012-02-02 21:28:49 +0000552 ECSIPR_LCHNGIP = 0x04,
553 ECSIPR_MPDIP = 0x02,
554 ECSIPR_ICDIP = 0x01,
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +0900555};
556
Nobuhiro Iwamatsu46288f42014-01-23 07:52:18 +0900557#if defined(SH_ETH_TYPE_GETHER) || defined(SH_ETH_TYPE_RZ)
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +0900558# define ECSIPR_INIT (ECSIPR_LCHNGIP | ECSIPR_ICDIP | ECSIPR_MPDIP)
559#else
560# define ECSIPR_INIT (ECSIPR_BRCRXIP | ECSIPR_PSRTOIP | ECSIPR_LCHNGIP | \
561 ECSIPR_ICDIP | ECSIPR_MPDIP)
562#endif
563
564/* APR */
565enum APR_BIT {
566 APR_AP = 0x00000004,
567};
568
569/* MPR */
570enum MPR_BIT {
571 MPR_MP = 0x00000006,
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +0900572};
573
574/* TRSCER */
575enum DESC_I_BIT {
576 DESC_I_TINT4 = 0x0800, DESC_I_TINT3 = 0x0400, DESC_I_TINT2 = 0x0200,
577 DESC_I_TINT1 = 0x0100, DESC_I_RINT8 = 0x0080, DESC_I_RINT5 = 0x0010,
578 DESC_I_RINT4 = 0x0008, DESC_I_RINT3 = 0x0004, DESC_I_RINT2 = 0x0002,
579 DESC_I_RINT1 = 0x0001,
580};
581
582/* RPADIR */
583enum RPADIR_BIT {
584 RPADIR_PADS1 = 0x20000, RPADIR_PADS0 = 0x10000,
585 RPADIR_PADR = 0x0003f,
586};
587
Nobuhiro Iwamatsu46288f42014-01-23 07:52:18 +0900588#if defined(SH_ETH_TYPE_GETHER) || defined(SH_ETH_TYPE_RZ)
Nobuhiro Iwamatsu240b7232008-06-11 21:05:00 +0900589# define RPADIR_INIT (0x00)
590#else
591# define RPADIR_INIT (RPADIR_PADS1)
592#endif
593
594/* FDR */
595enum FIFO_SIZE_BIT {
596 FIFO_SIZE_T = 0x00000700, FIFO_SIZE_R = 0x00000007,
597};
Yoshihiro Shimoda4c4aa6c2012-06-26 16:38:09 +0000598
Nobuhiro Iwamatsuec921f12017-12-01 08:10:32 +0900599static inline unsigned long sh_eth_reg_addr(struct sh_eth_info *port,
Yoshihiro Shimoda4c4aa6c2012-06-26 16:38:09 +0000600 int enum_index)
601{
Chris Brandta65a9292017-11-03 08:30:12 -0500602#if defined(SH_ETH_TYPE_GETHER) || defined(SH_ETH_TYPE_RZ)
Yoshihiro Shimoda4c4aa6c2012-06-26 16:38:09 +0000603 const u16 *reg_offset = sh_eth_offset_gigabit;
604#elif defined(SH_ETH_TYPE_ETHER)
605 const u16 *reg_offset = sh_eth_offset_fast_sh4;
606#else
607#error
608#endif
Nobuhiro Iwamatsuec921f12017-12-01 08:10:32 +0900609 return (unsigned long)port->iobase + reg_offset[enum_index];
Yoshihiro Shimoda4c4aa6c2012-06-26 16:38:09 +0000610}
611
Nobuhiro Iwamatsuec921f12017-12-01 08:10:32 +0900612static inline void sh_eth_write(struct sh_eth_info *port, unsigned long data,
Yoshihiro Shimoda4c4aa6c2012-06-26 16:38:09 +0000613 int enum_index)
614{
Nobuhiro Iwamatsuec921f12017-12-01 08:10:32 +0900615 outl(data, sh_eth_reg_addr(port, enum_index));
Yoshihiro Shimoda4c4aa6c2012-06-26 16:38:09 +0000616}
617
Nobuhiro Iwamatsuec921f12017-12-01 08:10:32 +0900618static inline unsigned long sh_eth_read(struct sh_eth_info *port,
Yoshihiro Shimoda4c4aa6c2012-06-26 16:38:09 +0000619 int enum_index)
620{
Nobuhiro Iwamatsuec921f12017-12-01 08:10:32 +0900621 return inl(sh_eth_reg_addr(port, enum_index));
Yoshihiro Shimoda4c4aa6c2012-06-26 16:38:09 +0000622}