blob: a8339ebf332d0405ec11f49095b0db34be241bdc [file] [log] [blame]
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +09001/*
Robert P. J. Day1cc0a9f2016-05-04 04:47:31 -04002 * sh_eth.h - Driver for Renesas SuperH ethernet controller.
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +09003 *
Nobuhiro Iwamatsudcd5a592012-08-02 22:08:40 +00004 * Copyright (C) 2008 - 2012 Renesas Solutions Corp.
5 * Copyright (c) 2008 - 2012 Nobuhiro Iwamatsu
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +09006 * Copyright (c) 2007 Carlos Munoz <carlos@kenati.com>
7 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +09009 */
10
Nobuhiro Iwamatsubd3980c2008-11-21 12:04:18 +090011#include <netdev.h>
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +090012#include <asm/types.h>
13
14#define SHETHER_NAME "sh_eth"
15
Nobuhiro Iwamatsudcd5a592012-08-02 22:08:40 +000016#if defined(CONFIG_SH)
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +090017/* Malloc returns addresses in the P1 area (cacheable). However we need to
18 use area P2 (non-cacheable) */
19#define ADDR_TO_P2(addr) ((((int)(addr) & ~0xe0000000) | 0xa0000000))
20
21/* The ethernet controller needs to use physical addresses */
Yoshihiro Shimoda903de462011-01-18 17:53:45 +090022#if defined(CONFIG_SH_32BIT)
23#define ADDR_TO_PHY(addr) ((((int)(addr) & ~0xe0000000) | 0x40000000))
24#else
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +090025#define ADDR_TO_PHY(addr) ((int)(addr) & ~0xe0000000)
Yoshihiro Shimoda903de462011-01-18 17:53:45 +090026#endif
Nobuhiro Iwamatsudcd5a592012-08-02 22:08:40 +000027#elif defined(CONFIG_ARM)
Chris Brandt5ad565b2017-11-03 08:30:11 -050028#ifndef inl
29#define inl readl
Nobuhiro Iwamatsudcd5a592012-08-02 22:08:40 +000030#define outl writel
Chris Brandt5ad565b2017-11-03 08:30:11 -050031#endif
Nobuhiro Iwamatsudcd5a592012-08-02 22:08:40 +000032#define ADDR_TO_PHY(addr) ((int)(addr))
33#define ADDR_TO_P2(addr) (addr)
34#endif /* defined(CONFIG_SH) */
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +090035
Nobuhiro Iwamatsuf8b75072013-08-22 13:22:02 +090036/* base padding size is 16 */
37#ifndef CONFIG_SH_ETHER_ALIGNE_SIZE
38#define CONFIG_SH_ETHER_ALIGNE_SIZE 16
39#endif
40
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +090041/* Number of supported ports */
42#define MAX_PORT_NUM 2
43
44/* Buffers must be big enough to hold the largest ethernet frame. Also, rx
45 buffers must be a multiple of 32 bytes */
46#define MAX_BUF_SIZE (48 * 32)
47
48/* The number of tx descriptors must be large enough to point to 5 or more
49 frames. If each frame uses 2 descriptors, at least 10 descriptors are needed.
50 We use one descriptor per frame */
51#define NUM_TX_DESC 8
52
53/* The size of the tx descriptor is determined by how much padding is used.
54 4, 20, or 52 bytes of padding can be used */
Nobuhiro Iwamatsuf8b75072013-08-22 13:22:02 +090055#define TX_DESC_PADDING (CONFIG_SH_ETHER_ALIGNE_SIZE - 12)
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +090056
Nobuhiro Iwamatsubd3980c2008-11-21 12:04:18 +090057/* Tx descriptor. We always use 3 bytes of padding */
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +090058struct tx_desc_s {
59 volatile u32 td0;
60 u32 td1;
61 u32 td2; /* Buffer start */
Nobuhiro Iwamatsuf8b75072013-08-22 13:22:02 +090062 u8 padding[TX_DESC_PADDING]; /* aligned cache line size */
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +090063};
64
65/* There is no limitation in the number of rx descriptors */
66#define NUM_RX_DESC 8
67
68/* The size of the rx descriptor is determined by how much padding is used.
69 4, 20, or 52 bytes of padding can be used */
Nobuhiro Iwamatsuf8b75072013-08-22 13:22:02 +090070#define RX_DESC_PADDING (CONFIG_SH_ETHER_ALIGNE_SIZE - 12)
Nobuhiro Iwamatsuf8b75072013-08-22 13:22:02 +090071/* aligned cache line size */
72#define RX_BUF_ALIGNE_SIZE (CONFIG_SH_ETHER_ALIGNE_SIZE > 32 ? 64 : 32)
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +090073
74/* Rx descriptor. We always use 4 bytes of padding */
75struct rx_desc_s {
76 volatile u32 rd0;
77 volatile u32 rd1;
78 u32 rd2; /* Buffer start */
Nobuhiro Iwamatsuf8b75072013-08-22 13:22:02 +090079 u8 padding[TX_DESC_PADDING]; /* aligned cache line size */
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +090080};
81
Nobuhiro Iwamatsubd3980c2008-11-21 12:04:18 +090082struct sh_eth_info {
Nobuhiro Iwamatsu000889c2014-11-04 09:15:47 +090083 struct tx_desc_s *tx_desc_alloc;
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +090084 struct tx_desc_s *tx_desc_base;
85 struct tx_desc_s *tx_desc_cur;
Nobuhiro Iwamatsu000889c2014-11-04 09:15:47 +090086 struct rx_desc_s *rx_desc_alloc;
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +090087 struct rx_desc_s *rx_desc_base;
88 struct rx_desc_s *rx_desc_cur;
Nobuhiro Iwamatsu000889c2014-11-04 09:15:47 +090089 u8 *rx_buf_alloc;
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +090090 u8 *rx_buf_base;
91 u8 mac_addr[6];
92 u8 phy_addr;
Nobuhiro Iwamatsubd3980c2008-11-21 12:04:18 +090093 struct eth_device *dev;
Yoshihiro Shimodabd1024b2011-10-11 18:10:14 +090094 struct phy_device *phydev;
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +090095};
96
Nobuhiro Iwamatsubd3980c2008-11-21 12:04:18 +090097struct sh_eth_dev {
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +090098 int port;
Nobuhiro Iwamatsubd3980c2008-11-21 12:04:18 +090099 struct sh_eth_info port_info[MAX_PORT_NUM];
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +0900100};
101
Yoshihiro Shimoda49afb8c2012-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 Iwamatsu87076782013-08-22 13:22:04 +0900167 RMIIMR, /* R8A7790 */
Yoshihiro Shimoda49afb8c2012-06-26 16:38:09 +0000168 MAFCR,
169 RTRATE,
170 CSMR,
171 RMII_MII,
172
173 /* 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,
200
201 [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};
230
231static 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,
259
260 [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 Iwamatsu87076782013-08-22 13:22:04 +0900274 [RMIIMR] = 0x006C,
Yoshihiro Shimoda49afb8c2012-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};
283
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +0900284/* Register Address */
Yoshihiro Shimoda49afb8c2012-06-26 16:38:09 +0000285#if defined(CONFIG_CPU_SH7763) || defined(CONFIG_CPU_SH7734)
Yoshihiro Shimoda26235092012-06-26 16:38:06 +0000286#define SH_ETH_TYPE_GETHER
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +0900287#define BASE_IO_ADDR 0xfee00000
Yoshihiro Shimoda3067f812013-12-18 16:04:04 +0900288#elif defined(CONFIG_CPU_SH7757) || \
289 defined(CONFIG_CPU_SH7752) || \
290 defined(CONFIG_CPU_SH7753)
Yoshihiro Shimoda631fea82012-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 Shimoda26235092012-06-26 16:38:06 +0000295#define SH_ETH_TYPE_ETHER
Yoshihiro Shimoda903de462011-01-18 17:53:45 +0900296#define BASE_IO_ADDR 0xfef00000
Yoshihiro Shimoda631fea82012-06-26 16:38:11 +0000297#endif
Nobuhiro Iwamatsu3bb4cc32011-11-14 16:56:59 +0900298#elif defined(CONFIG_CPU_SH7724)
Yoshihiro Shimoda26235092012-06-26 16:38:06 +0000299#define SH_ETH_TYPE_ETHER
Nobuhiro Iwamatsu3bb4cc32011-11-14 16:56:59 +0900300#define BASE_IO_ADDR 0xA4600000
Nobuhiro Iwamatsudcd5a592012-08-02 22:08:40 +0000301#elif defined(CONFIG_R8A7740)
302#define SH_ETH_TYPE_GETHER
303#define BASE_IO_ADDR 0xE9A00000
Nobuhiro Iwamatsu17243742014-06-24 17:01:08 +0900304#elif defined(CONFIG_R8A7790) || defined(CONFIG_R8A7791) || \
Nobuhiro Iwamatsua341b7e2014-11-04 09:13:40 +0900305 defined(CONFIG_R8A7793) || defined(CONFIG_R8A7794)
Nobuhiro Iwamatsu87076782013-08-22 13:22:04 +0900306#define SH_ETH_TYPE_ETHER
307#define BASE_IO_ADDR 0xEE700200
Nobuhiro Iwamatsu62cbddc2014-01-23 07:52:18 +0900308#elif defined(CONFIG_R7S72100)
309#define SH_ETH_TYPE_RZ
310#define BASE_IO_ADDR 0xE8203000
Yoshihiro Shimoda903de462011-01-18 17:53:45 +0900311#endif
312
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +0900313/*
314 * Register's bits
315 * Copy from Linux driver source code
316 */
Nobuhiro Iwamatsu62cbddc2014-01-23 07:52:18 +0900317#if defined(SH_ETH_TYPE_GETHER) || defined(SH_ETH_TYPE_RZ)
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +0900318/* EDSR */
319enum EDSR_BIT {
320 EDSR_ENT = 0x01, EDSR_ENR = 0x02,
321};
322#define EDSR_ENALL (EDSR_ENT|EDSR_ENR)
323#endif
324
325/* EDMR */
326enum DMAC_M_BIT {
327 EDMR_DL1 = 0x20, EDMR_DL0 = 0x10,
Nobuhiro Iwamatsu62cbddc2014-01-23 07:52:18 +0900328#if defined(SH_ETH_TYPE_GETHER) || defined(SH_ETH_TYPE_RZ)
Nobuhiro Iwamatsuee6ec5d2012-02-02 21:28:49 +0000329 EDMR_SRST = 0x03, /* Receive/Send reset */
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +0900330 EMDR_DESC_R = 0x30, /* Descriptor reserve size */
331 EDMR_EL = 0x40, /* Litte endian */
Yoshihiro Shimoda26235092012-06-26 16:38:06 +0000332#elif defined(SH_ETH_TYPE_ETHER)
Yoshihiro Shimoda903de462011-01-18 17:53:45 +0900333 EDMR_SRST = 0x01,
334 EMDR_DESC_R = 0x30, /* Descriptor reserve size */
335 EDMR_EL = 0x40, /* Litte endian */
Yoshihiro Shimoda26235092012-06-26 16:38:06 +0000336#else
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +0900337 EDMR_SRST = 0x01,
338#endif
339};
340
Nobuhiro Iwamatsuf8b75072013-08-22 13:22:02 +0900341#if CONFIG_SH_ETHER_ALIGNE_SIZE == 64
342# define EMDR_DESC EDMR_DL1
343#elif CONFIG_SH_ETHER_ALIGNE_SIZE == 32
344# define EMDR_DESC EDMR_DL0
345#elif CONFIG_SH_ETHER_ALIGNE_SIZE == 16 /* Default */
346# define EMDR_DESC 0
347#endif
348
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +0900349/* RFLR */
350#define RFLR_RFL_MIN 0x05EE /* Recv Frame length 1518 byte */
351
352/* EDTRR */
353enum DMAC_T_BIT {
Nobuhiro Iwamatsu62cbddc2014-01-23 07:52:18 +0900354#if defined(SH_ETH_TYPE_GETHER) || defined(SH_ETH_TYPE_RZ)
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +0900355 EDTRR_TRNS = 0x03,
356#else
357 EDTRR_TRNS = 0x01,
358#endif
359};
360
361/* GECMR */
362enum GECMR_BIT {
Yoshihiro Shimoda3067f812013-12-18 16:04:04 +0900363#if defined(CONFIG_CPU_SH7757) || \
364 defined(CONFIG_CPU_SH7752) || \
365 defined(CONFIG_CPU_SH7753)
Yoshihiro Shimoda631fea82012-06-26 16:38:11 +0000366 GECMR_1000B = 0x20, GECMR_100B = 0x01, GECMR_10B = 0x00,
367#else
Simon Munton09fcc8b2009-02-02 09:44:08 +0000368 GECMR_1000B = 0x01, GECMR_100B = 0x04, GECMR_10B = 0x00,
Yoshihiro Shimoda631fea82012-06-26 16:38:11 +0000369#endif
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +0900370};
371
372/* EDRRR*/
373enum EDRRR_R_BIT {
374 EDRRR_R = 0x01,
375};
376
377/* TPAUSER */
378enum TPAUSER_BIT {
379 TPAUSER_TPAUSE = 0x0000ffff,
380 TPAUSER_UNLIMITED = 0,
381};
382
383/* BCFR */
384enum BCFR_BIT {
385 BCFR_RPAUSE = 0x0000ffff,
386 BCFR_UNLIMITED = 0,
387};
388
389/* PIR */
390enum PIR_BIT {
391 PIR_MDI = 0x08, PIR_MDO = 0x04, PIR_MMD = 0x02, PIR_MDC = 0x01,
392};
393
394/* PSR */
395enum PHY_STATUS_BIT { PHY_ST_LINK = 0x01, };
396
397/* EESR */
398enum EESR_BIT {
Yoshihiro Shimoda26235092012-06-26 16:38:06 +0000399#if defined(SH_ETH_TYPE_ETHER)
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +0900400 EESR_TWB = 0x40000000,
401#else
402 EESR_TWB = 0xC0000000,
403 EESR_TC1 = 0x20000000,
404 EESR_TUC = 0x10000000,
405 EESR_ROC = 0x80000000,
406#endif
407 EESR_TABT = 0x04000000,
408 EESR_RABT = 0x02000000, EESR_RFRMER = 0x01000000,
Yoshihiro Shimoda26235092012-06-26 16:38:06 +0000409#if defined(SH_ETH_TYPE_ETHER)
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +0900410 EESR_ADE = 0x00800000,
411#endif
412 EESR_ECI = 0x00400000,
413 EESR_FTC = 0x00200000, EESR_TDE = 0x00100000,
414 EESR_TFE = 0x00080000, EESR_FRC = 0x00040000,
415 EESR_RDE = 0x00020000, EESR_RFE = 0x00010000,
Yoshihiro Shimoda26235092012-06-26 16:38:06 +0000416#if defined(SH_ETH_TYPE_ETHER)
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +0900417 EESR_CND = 0x00000800,
418#endif
419 EESR_DLC = 0x00000400,
420 EESR_CD = 0x00000200, EESR_RTO = 0x00000100,
421 EESR_RMAF = 0x00000080, EESR_CEEF = 0x00000040,
422 EESR_CELF = 0x00000020, EESR_RRF = 0x00000010,
Nobuhiro Iwamatsu1dbd7282014-01-23 07:52:20 +0900423 EESR_RTLF = 0x00000008, EESR_RTSF = 0x00000004,
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +0900424 EESR_PRE = 0x00000002, EESR_CERF = 0x00000001,
425};
426
427
Nobuhiro Iwamatsu62cbddc2014-01-23 07:52:18 +0900428#if defined(SH_ETH_TYPE_GETHER) || defined(SH_ETH_TYPE_RZ)
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +0900429# define TX_CHECK (EESR_TC1 | EESR_FTC)
430# define EESR_ERR_CHECK (EESR_TWB | EESR_TABT | EESR_RABT | EESR_RDE \
431 | EESR_RFRMER | EESR_TFE | EESR_TDE | EESR_ECI)
432# define TX_ERROR_CEHCK (EESR_TWB | EESR_TABT | EESR_TDE | EESR_TFE)
433
434#else
435# define TX_CHECK (EESR_FTC | EESR_CND | EESR_DLC | EESR_CD | EESR_RTO)
436# define EESR_ERR_CHECK (EESR_TWB | EESR_TABT | EESR_RABT | EESR_RDE \
437 | EESR_RFRMER | EESR_ADE | EESR_TFE | EESR_TDE | EESR_ECI)
438# define TX_ERROR_CEHCK (EESR_TWB | EESR_TABT | EESR_ADE | EESR_TDE | EESR_TFE)
439#endif
440
441/* EESIPR */
442enum DMAC_IM_BIT {
443 DMAC_M_TWB = 0x40000000, DMAC_M_TABT = 0x04000000,
444 DMAC_M_RABT = 0x02000000,
445 DMAC_M_RFRMER = 0x01000000, DMAC_M_ADF = 0x00800000,
446 DMAC_M_ECI = 0x00400000, DMAC_M_FTC = 0x00200000,
447 DMAC_M_TDE = 0x00100000, DMAC_M_TFE = 0x00080000,
448 DMAC_M_FRC = 0x00040000, DMAC_M_RDE = 0x00020000,
449 DMAC_M_RFE = 0x00010000, DMAC_M_TINT4 = 0x00000800,
450 DMAC_M_TINT3 = 0x00000400, DMAC_M_TINT2 = 0x00000200,
451 DMAC_M_TINT1 = 0x00000100, DMAC_M_RINT8 = 0x00000080,
452 DMAC_M_RINT5 = 0x00000010, DMAC_M_RINT4 = 0x00000008,
453 DMAC_M_RINT3 = 0x00000004, DMAC_M_RINT2 = 0x00000002,
454 DMAC_M_RINT1 = 0x00000001,
455};
456
457/* Receive descriptor bit */
458enum RD_STS_BIT {
459 RD_RACT = 0x80000000, RD_RDLE = 0x40000000,
460 RD_RFP1 = 0x20000000, RD_RFP0 = 0x10000000,
461 RD_RFE = 0x08000000, RD_RFS10 = 0x00000200,
462 RD_RFS9 = 0x00000100, RD_RFS8 = 0x00000080,
463 RD_RFS7 = 0x00000040, RD_RFS6 = 0x00000020,
464 RD_RFS5 = 0x00000010, RD_RFS4 = 0x00000008,
465 RD_RFS3 = 0x00000004, RD_RFS2 = 0x00000002,
466 RD_RFS1 = 0x00000001,
467};
468#define RDF1ST RD_RFP1
469#define RDFEND RD_RFP0
470#define RD_RFP (RD_RFP1|RD_RFP0)
471
472/* RDFFR*/
473enum RDFFR_BIT {
474 RDFFR_RDLF = 0x01,
475};
476
477/* FCFTR */
478enum FCFTR_BIT {
479 FCFTR_RFF2 = 0x00040000, FCFTR_RFF1 = 0x00020000,
480 FCFTR_RFF0 = 0x00010000, FCFTR_RFD2 = 0x00000004,
481 FCFTR_RFD1 = 0x00000002, FCFTR_RFD0 = 0x00000001,
482};
483#define FIFO_F_D_RFF (FCFTR_RFF2|FCFTR_RFF1|FCFTR_RFF0)
484#define FIFO_F_D_RFD (FCFTR_RFD2|FCFTR_RFD1|FCFTR_RFD0)
485
486/* Transfer descriptor bit */
487enum TD_STS_BIT {
Nobuhiro Iwamatsu62cbddc2014-01-23 07:52:18 +0900488#if defined(SH_ETH_TYPE_GETHER) || defined(SH_ETH_TYPE_ETHER) || \
489 defined(SH_ETH_TYPE_RZ)
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +0900490 TD_TACT = 0x80000000,
491#else
492 TD_TACT = 0x7fffffff,
493#endif
494 TD_TDLE = 0x40000000, TD_TFP1 = 0x20000000,
495 TD_TFP0 = 0x10000000,
496};
497#define TDF1ST TD_TFP1
498#define TDFEND TD_TFP0
499#define TD_TFP (TD_TFP1|TD_TFP0)
500
501/* RMCR */
502enum RECV_RST_BIT { RMCR_RST = 0x01, };
503/* ECMR */
504enum FELIC_MODE_BIT {
Nobuhiro Iwamatsu62cbddc2014-01-23 07:52:18 +0900505#if defined(SH_ETH_TYPE_GETHER) || defined(SH_ETH_TYPE_RZ)
Nobuhiro Iwamatsue2752db2014-01-23 07:52:19 +0900506 ECMR_TRCCM = 0x04000000, ECMR_RCSC = 0x00800000,
507 ECMR_DPAD = 0x00200000, ECMR_RZPF = 0x00100000,
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +0900508#endif
509 ECMR_ZPF = 0x00080000, ECMR_PFR = 0x00040000, ECMR_RXF = 0x00020000,
510 ECMR_TXF = 0x00010000, ECMR_MCT = 0x00002000, ECMR_PRCEF = 0x00001000,
511 ECMR_PMDE = 0x00000200, ECMR_RE = 0x00000040, ECMR_TE = 0x00000020,
512 ECMR_ILB = 0x00000008, ECMR_ELB = 0x00000004, ECMR_DM = 0x00000002,
513 ECMR_PRM = 0x00000001,
Nobuhiro Iwamatsu3bb4cc32011-11-14 16:56:59 +0900514#ifdef CONFIG_CPU_SH7724
515 ECMR_RTM = 0x00000010,
Nobuhiro Iwamatsu17243742014-06-24 17:01:08 +0900516#elif defined(CONFIG_R8A7790) || defined(CONFIG_R8A7791) || \
Nobuhiro Iwamatsua341b7e2014-11-04 09:13:40 +0900517 defined(CONFIG_R8A7793) || defined(CONFIG_R8A7794)
Nobuhiro Iwamatsu87076782013-08-22 13:22:04 +0900518 ECMR_RTM = 0x00000004,
Nobuhiro Iwamatsu3bb4cc32011-11-14 16:56:59 +0900519#endif
520
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +0900521};
522
Nobuhiro Iwamatsu62cbddc2014-01-23 07:52:18 +0900523#if defined(SH_ETH_TYPE_GETHER) || defined(SH_ETH_TYPE_RZ)
Nobuhiro Iwamatsue2752db2014-01-23 07:52:19 +0900524#define ECMR_CHG_DM (ECMR_TRCCM | ECMR_RZPF | ECMR_ZPF | ECMR_PFR | \
525 ECMR_RXF | ECMR_TXF | ECMR_MCT)
Yoshihiro Shimoda26235092012-06-26 16:38:06 +0000526#elif defined(SH_ETH_TYPE_ETHER)
Nobuhiro Iwamatsu3bb4cc32011-11-14 16:56:59 +0900527#define ECMR_CHG_DM (ECMR_ZPF | ECMR_PFR | ECMR_RXF | ECMR_TXF)
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +0900528#else
Yoshihiro Shimoda903de462011-01-18 17:53:45 +0900529#define ECMR_CHG_DM (ECMR_ZPF | ECMR_PFR | ECMR_RXF | ECMR_TXF | ECMR_MCT)
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +0900530#endif
531
532/* ECSR */
533enum ECSR_STATUS_BIT {
Yoshihiro Shimoda26235092012-06-26 16:38:06 +0000534#if defined(SH_ETH_TYPE_ETHER)
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +0900535 ECSR_BRCRX = 0x20, ECSR_PSRTO = 0x10,
536#endif
537 ECSR_LCHNG = 0x04,
538 ECSR_MPD = 0x02, ECSR_ICD = 0x01,
539};
540
Nobuhiro Iwamatsu62cbddc2014-01-23 07:52:18 +0900541#if defined(SH_ETH_TYPE_GETHER) || defined(SH_ETH_TYPE_RZ)
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +0900542# define ECSR_INIT (ECSR_ICD | ECSIPR_MPDIP)
543#else
544# define ECSR_INIT (ECSR_BRCRX | ECSR_PSRTO | \
545 ECSR_LCHNG | ECSR_ICD | ECSIPR_MPDIP)
546#endif
547
548/* ECSIPR */
549enum ECSIPR_STATUS_MASK_BIT {
Yoshihiro Shimoda26235092012-06-26 16:38:06 +0000550#if defined(SH_ETH_TYPE_ETHER)
Nobuhiro Iwamatsua6616ef2012-06-05 16:39:06 +0000551 ECSIPR_BRCRXIP = 0x20,
Nobuhiro Iwamatsuee6ec5d2012-02-02 21:28:49 +0000552 ECSIPR_PSRTOIP = 0x10,
Yoshihiro Shimoda26235092012-06-26 16:38:06 +0000553#elif defined(SH_ETY_TYPE_GETHER)
Nobuhiro Iwamatsuee6ec5d2012-02-02 21:28:49 +0000554 ECSIPR_PSRTOIP = 0x10,
555 ECSIPR_PHYIP = 0x08,
Nobuhiro Iwamatsua6616ef2012-06-05 16:39:06 +0000556#endif
Nobuhiro Iwamatsuee6ec5d2012-02-02 21:28:49 +0000557 ECSIPR_LCHNGIP = 0x04,
558 ECSIPR_MPDIP = 0x02,
559 ECSIPR_ICDIP = 0x01,
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +0900560};
561
Nobuhiro Iwamatsu62cbddc2014-01-23 07:52:18 +0900562#if defined(SH_ETH_TYPE_GETHER) || defined(SH_ETH_TYPE_RZ)
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +0900563# define ECSIPR_INIT (ECSIPR_LCHNGIP | ECSIPR_ICDIP | ECSIPR_MPDIP)
564#else
565# define ECSIPR_INIT (ECSIPR_BRCRXIP | ECSIPR_PSRTOIP | ECSIPR_LCHNGIP | \
566 ECSIPR_ICDIP | ECSIPR_MPDIP)
567#endif
568
569/* APR */
570enum APR_BIT {
571 APR_AP = 0x00000004,
572};
573
574/* MPR */
575enum MPR_BIT {
576 MPR_MP = 0x00000006,
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +0900577};
578
579/* TRSCER */
580enum DESC_I_BIT {
581 DESC_I_TINT4 = 0x0800, DESC_I_TINT3 = 0x0400, DESC_I_TINT2 = 0x0200,
582 DESC_I_TINT1 = 0x0100, DESC_I_RINT8 = 0x0080, DESC_I_RINT5 = 0x0010,
583 DESC_I_RINT4 = 0x0008, DESC_I_RINT3 = 0x0004, DESC_I_RINT2 = 0x0002,
584 DESC_I_RINT1 = 0x0001,
585};
586
587/* RPADIR */
588enum RPADIR_BIT {
589 RPADIR_PADS1 = 0x20000, RPADIR_PADS0 = 0x10000,
590 RPADIR_PADR = 0x0003f,
591};
592
Nobuhiro Iwamatsu62cbddc2014-01-23 07:52:18 +0900593#if defined(SH_ETH_TYPE_GETHER) || defined(SH_ETH_TYPE_RZ)
Nobuhiro Iwamatsu9751ee02008-06-11 21:05:00 +0900594# define RPADIR_INIT (0x00)
595#else
596# define RPADIR_INIT (RPADIR_PADS1)
597#endif
598
599/* FDR */
600enum FIFO_SIZE_BIT {
601 FIFO_SIZE_T = 0x00000700, FIFO_SIZE_R = 0x00000007,
602};
Yoshihiro Shimoda49afb8c2012-06-26 16:38:09 +0000603
604static inline unsigned long sh_eth_reg_addr(struct sh_eth_dev *eth,
605 int enum_index)
606{
Chris Brandtf6ac6262017-11-03 08:30:12 -0500607#if defined(SH_ETH_TYPE_GETHER) || defined(SH_ETH_TYPE_RZ)
Yoshihiro Shimoda49afb8c2012-06-26 16:38:09 +0000608 const u16 *reg_offset = sh_eth_offset_gigabit;
609#elif defined(SH_ETH_TYPE_ETHER)
610 const u16 *reg_offset = sh_eth_offset_fast_sh4;
611#else
612#error
613#endif
614 return BASE_IO_ADDR + reg_offset[enum_index] + 0x800 * eth->port;
615}
616
617static inline void sh_eth_write(struct sh_eth_dev *eth, unsigned long data,
618 int enum_index)
619{
620 outl(data, sh_eth_reg_addr(eth, enum_index));
621}
622
623static inline unsigned long sh_eth_read(struct sh_eth_dev *eth,
624 int enum_index)
625{
626 return inl(sh_eth_reg_addr(eth, enum_index));
627}