blob: 8e35ccba6259fff1ca2123eb81ae733cf50752b9 [file] [log] [blame]
Sergei Shtylyov128296f2014-01-03 15:52:22 +03001/* SuperH Ethernet device driver
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002 *
Hisashi Nakamura966d6db2014-11-13 15:54:05 +09003 * Copyright (C) 2014 Renesas Electronics Corporation
Nobuhiro Iwamatsuf0e81fe2012-03-25 18:59:51 +00004 * Copyright (C) 2006-2012 Nobuhiro Iwamatsu
Sergei Shtylyovb356e972014-02-18 03:12:43 +03005 * Copyright (C) 2008-2014 Renesas Solutions Corp.
6 * Copyright (C) 2013-2014 Cogent Embedded, Inc.
Ben Dooks702eca02014-03-12 17:47:40 +00007 * Copyright (C) 2014 Codethink Limited
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07008 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms and conditions of the GNU General Public License,
11 * version 2, as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -070017 *
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 */
21
Yoshihiro Shimoda06540112011-09-29 17:16:57 +000022#include <linux/module.h>
23#include <linux/kernel.h>
24#include <linux/spinlock.h>
David S. Miller823dcd22011-08-20 10:39:12 -070025#include <linux/interrupt.h>
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -070026#include <linux/dma-mapping.h>
27#include <linux/etherdevice.h>
28#include <linux/delay.h>
29#include <linux/platform_device.h>
30#include <linux/mdio-bitbang.h>
31#include <linux/netdevice.h>
Sergei Shtylyovb356e972014-02-18 03:12:43 +030032#include <linux/of.h>
33#include <linux/of_device.h>
34#include <linux/of_irq.h>
35#include <linux/of_net.h>
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -070036#include <linux/phy.h>
37#include <linux/cache.h>
38#include <linux/io.h>
Magnus Dammbcd51492009-10-09 00:20:04 +000039#include <linux/pm_runtime.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090040#include <linux/slab.h>
Nobuhiro Iwamatsudc19e4e2011-02-15 21:17:32 +000041#include <linux/ethtool.h>
Yoshihiro Shimodafdb37a72012-02-06 23:55:15 +000042#include <linux/if_vlan.h>
Nobuhiro Iwamatsuf0e81fe2012-03-25 18:59:51 +000043#include <linux/clk.h>
Yoshihiro Shimodad4fa0e32011-09-27 21:49:12 +000044#include <linux/sh_eth.h>
Ben Dooks702eca02014-03-12 17:47:40 +000045#include <linux/of_mdio.h>
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -070046
47#include "sh_eth.h"
48
Nobuhiro Iwamatsudc19e4e2011-02-15 21:17:32 +000049#define SH_ETH_DEF_MSG_ENABLE \
50 (NETIF_MSG_LINK | \
51 NETIF_MSG_TIMER | \
52 NETIF_MSG_RX_ERR| \
53 NETIF_MSG_TX_ERR)
54
Sergei Shtylyovc0013f62013-03-28 11:48:26 +000055static const u16 sh_eth_offset_gigabit[SH_ETH_MAX_REGISTER_OFFSET] = {
56 [EDSR] = 0x0000,
57 [EDMR] = 0x0400,
58 [EDTRR] = 0x0408,
59 [EDRRR] = 0x0410,
60 [EESR] = 0x0428,
61 [EESIPR] = 0x0430,
62 [TDLAR] = 0x0010,
63 [TDFAR] = 0x0014,
64 [TDFXR] = 0x0018,
65 [TDFFR] = 0x001c,
66 [RDLAR] = 0x0030,
67 [RDFAR] = 0x0034,
68 [RDFXR] = 0x0038,
69 [RDFFR] = 0x003c,
70 [TRSCER] = 0x0438,
71 [RMFCR] = 0x0440,
72 [TFTR] = 0x0448,
73 [FDR] = 0x0450,
74 [RMCR] = 0x0458,
75 [RPADIR] = 0x0460,
76 [FCFTR] = 0x0468,
77 [CSMR] = 0x04E4,
78
79 [ECMR] = 0x0500,
80 [ECSR] = 0x0510,
81 [ECSIPR] = 0x0518,
82 [PIR] = 0x0520,
83 [PSR] = 0x0528,
84 [PIPR] = 0x052c,
85 [RFLR] = 0x0508,
86 [APR] = 0x0554,
87 [MPR] = 0x0558,
88 [PFTCR] = 0x055c,
89 [PFRCR] = 0x0560,
90 [TPAUSER] = 0x0564,
91 [GECMR] = 0x05b0,
92 [BCULR] = 0x05b4,
93 [MAHR] = 0x05c0,
94 [MALR] = 0x05c8,
95 [TROCR] = 0x0700,
96 [CDCR] = 0x0708,
97 [LCCR] = 0x0710,
98 [CEFCR] = 0x0740,
99 [FRECR] = 0x0748,
100 [TSFRCR] = 0x0750,
101 [TLFRCR] = 0x0758,
102 [RFCR] = 0x0760,
103 [CERCR] = 0x0768,
104 [CEECR] = 0x0770,
105 [MAFCR] = 0x0778,
106 [RMII_MII] = 0x0790,
107
108 [ARSTR] = 0x0000,
109 [TSU_CTRST] = 0x0004,
110 [TSU_FWEN0] = 0x0010,
111 [TSU_FWEN1] = 0x0014,
112 [TSU_FCM] = 0x0018,
113 [TSU_BSYSL0] = 0x0020,
114 [TSU_BSYSL1] = 0x0024,
115 [TSU_PRISL0] = 0x0028,
116 [TSU_PRISL1] = 0x002c,
117 [TSU_FWSL0] = 0x0030,
118 [TSU_FWSL1] = 0x0034,
119 [TSU_FWSLC] = 0x0038,
120 [TSU_QTAG0] = 0x0040,
121 [TSU_QTAG1] = 0x0044,
122 [TSU_FWSR] = 0x0050,
123 [TSU_FWINMK] = 0x0054,
124 [TSU_ADQT0] = 0x0048,
125 [TSU_ADQT1] = 0x004c,
126 [TSU_VTAG0] = 0x0058,
127 [TSU_VTAG1] = 0x005c,
128 [TSU_ADSBSY] = 0x0060,
129 [TSU_TEN] = 0x0064,
130 [TSU_POST1] = 0x0070,
131 [TSU_POST2] = 0x0074,
132 [TSU_POST3] = 0x0078,
133 [TSU_POST4] = 0x007c,
134 [TSU_ADRH0] = 0x0100,
135 [TSU_ADRL0] = 0x0104,
136 [TSU_ADRH31] = 0x01f8,
137 [TSU_ADRL31] = 0x01fc,
138
139 [TXNLCR0] = 0x0080,
140 [TXALCR0] = 0x0084,
141 [RXNLCR0] = 0x0088,
142 [RXALCR0] = 0x008c,
143 [FWNLCR0] = 0x0090,
144 [FWALCR0] = 0x0094,
145 [TXNLCR1] = 0x00a0,
146 [TXALCR1] = 0x00a0,
147 [RXNLCR1] = 0x00a8,
148 [RXALCR1] = 0x00ac,
149 [FWNLCR1] = 0x00b0,
150 [FWALCR1] = 0x00b4,
151};
152
Simon Hormandb893472014-01-17 09:22:28 +0900153static const u16 sh_eth_offset_fast_rz[SH_ETH_MAX_REGISTER_OFFSET] = {
154 [EDSR] = 0x0000,
155 [EDMR] = 0x0400,
156 [EDTRR] = 0x0408,
157 [EDRRR] = 0x0410,
158 [EESR] = 0x0428,
159 [EESIPR] = 0x0430,
160 [TDLAR] = 0x0010,
161 [TDFAR] = 0x0014,
162 [TDFXR] = 0x0018,
163 [TDFFR] = 0x001c,
164 [RDLAR] = 0x0030,
165 [RDFAR] = 0x0034,
166 [RDFXR] = 0x0038,
167 [RDFFR] = 0x003c,
168 [TRSCER] = 0x0438,
169 [RMFCR] = 0x0440,
170 [TFTR] = 0x0448,
171 [FDR] = 0x0450,
172 [RMCR] = 0x0458,
173 [RPADIR] = 0x0460,
174 [FCFTR] = 0x0468,
175 [CSMR] = 0x04E4,
176
177 [ECMR] = 0x0500,
178 [RFLR] = 0x0508,
179 [ECSR] = 0x0510,
180 [ECSIPR] = 0x0518,
181 [PIR] = 0x0520,
182 [APR] = 0x0554,
183 [MPR] = 0x0558,
184 [PFTCR] = 0x055c,
185 [PFRCR] = 0x0560,
186 [TPAUSER] = 0x0564,
187 [MAHR] = 0x05c0,
188 [MALR] = 0x05c8,
189 [CEFCR] = 0x0740,
190 [FRECR] = 0x0748,
191 [TSFRCR] = 0x0750,
192 [TLFRCR] = 0x0758,
193 [RFCR] = 0x0760,
194 [MAFCR] = 0x0778,
195
196 [ARSTR] = 0x0000,
197 [TSU_CTRST] = 0x0004,
198 [TSU_VTAG0] = 0x0058,
199 [TSU_ADSBSY] = 0x0060,
200 [TSU_TEN] = 0x0064,
201 [TSU_ADRH0] = 0x0100,
202 [TSU_ADRL0] = 0x0104,
203 [TSU_ADRH31] = 0x01f8,
204 [TSU_ADRL31] = 0x01fc,
205
206 [TXNLCR0] = 0x0080,
207 [TXALCR0] = 0x0084,
208 [RXNLCR0] = 0x0088,
209 [RXALCR0] = 0x008C,
210};
211
Sergei Shtylyova3f109b2013-03-28 11:51:31 +0000212static const u16 sh_eth_offset_fast_rcar[SH_ETH_MAX_REGISTER_OFFSET] = {
213 [ECMR] = 0x0300,
214 [RFLR] = 0x0308,
215 [ECSR] = 0x0310,
216 [ECSIPR] = 0x0318,
217 [PIR] = 0x0320,
218 [PSR] = 0x0328,
219 [RDMLR] = 0x0340,
220 [IPGR] = 0x0350,
221 [APR] = 0x0354,
222 [MPR] = 0x0358,
223 [RFCF] = 0x0360,
224 [TPAUSER] = 0x0364,
225 [TPAUSECR] = 0x0368,
226 [MAHR] = 0x03c0,
227 [MALR] = 0x03c8,
228 [TROCR] = 0x03d0,
229 [CDCR] = 0x03d4,
230 [LCCR] = 0x03d8,
231 [CNDCR] = 0x03dc,
232 [CEFCR] = 0x03e4,
233 [FRECR] = 0x03e8,
234 [TSFRCR] = 0x03ec,
235 [TLFRCR] = 0x03f0,
236 [RFCR] = 0x03f4,
237 [MAFCR] = 0x03f8,
238
239 [EDMR] = 0x0200,
240 [EDTRR] = 0x0208,
241 [EDRRR] = 0x0210,
242 [TDLAR] = 0x0218,
243 [RDLAR] = 0x0220,
244 [EESR] = 0x0228,
245 [EESIPR] = 0x0230,
246 [TRSCER] = 0x0238,
247 [RMFCR] = 0x0240,
248 [TFTR] = 0x0248,
249 [FDR] = 0x0250,
250 [RMCR] = 0x0258,
251 [TFUCR] = 0x0264,
252 [RFOCR] = 0x0268,
Simon Horman55754f12013-07-23 10:18:04 +0900253 [RMIIMODE] = 0x026c,
Sergei Shtylyova3f109b2013-03-28 11:51:31 +0000254 [FCFTR] = 0x0270,
255 [TRIMD] = 0x027c,
256};
257
Sergei Shtylyovc0013f62013-03-28 11:48:26 +0000258static const u16 sh_eth_offset_fast_sh4[SH_ETH_MAX_REGISTER_OFFSET] = {
259 [ECMR] = 0x0100,
260 [RFLR] = 0x0108,
261 [ECSR] = 0x0110,
262 [ECSIPR] = 0x0118,
263 [PIR] = 0x0120,
264 [PSR] = 0x0128,
265 [RDMLR] = 0x0140,
266 [IPGR] = 0x0150,
267 [APR] = 0x0154,
268 [MPR] = 0x0158,
269 [TPAUSER] = 0x0164,
270 [RFCF] = 0x0160,
271 [TPAUSECR] = 0x0168,
272 [BCFRR] = 0x016c,
273 [MAHR] = 0x01c0,
274 [MALR] = 0x01c8,
275 [TROCR] = 0x01d0,
276 [CDCR] = 0x01d4,
277 [LCCR] = 0x01d8,
278 [CNDCR] = 0x01dc,
279 [CEFCR] = 0x01e4,
280 [FRECR] = 0x01e8,
281 [TSFRCR] = 0x01ec,
282 [TLFRCR] = 0x01f0,
283 [RFCR] = 0x01f4,
284 [MAFCR] = 0x01f8,
285 [RTRATE] = 0x01fc,
286
287 [EDMR] = 0x0000,
288 [EDTRR] = 0x0008,
289 [EDRRR] = 0x0010,
290 [TDLAR] = 0x0018,
291 [RDLAR] = 0x0020,
292 [EESR] = 0x0028,
293 [EESIPR] = 0x0030,
294 [TRSCER] = 0x0038,
295 [RMFCR] = 0x0040,
296 [TFTR] = 0x0048,
297 [FDR] = 0x0050,
298 [RMCR] = 0x0058,
299 [TFUCR] = 0x0064,
300 [RFOCR] = 0x0068,
301 [FCFTR] = 0x0070,
302 [RPADIR] = 0x0078,
303 [TRIMD] = 0x007c,
304 [RBWAR] = 0x00c8,
305 [RDFAR] = 0x00cc,
306 [TBRAR] = 0x00d4,
307 [TDFAR] = 0x00d8,
308};
309
310static const u16 sh_eth_offset_fast_sh3_sh2[SH_ETH_MAX_REGISTER_OFFSET] = {
Sergei Shtylyovd8b04262014-06-03 23:42:26 +0400311 [EDMR] = 0x0000,
312 [EDTRR] = 0x0004,
313 [EDRRR] = 0x0008,
314 [TDLAR] = 0x000c,
315 [RDLAR] = 0x0010,
316 [EESR] = 0x0014,
317 [EESIPR] = 0x0018,
318 [TRSCER] = 0x001c,
319 [RMFCR] = 0x0020,
320 [TFTR] = 0x0024,
321 [FDR] = 0x0028,
322 [RMCR] = 0x002c,
323 [EDOCR] = 0x0030,
324 [FCFTR] = 0x0034,
325 [RPADIR] = 0x0038,
326 [TRIMD] = 0x003c,
327 [RBWAR] = 0x0040,
328 [RDFAR] = 0x0044,
329 [TBRAR] = 0x004c,
330 [TDFAR] = 0x0050,
331
Sergei Shtylyovc0013f62013-03-28 11:48:26 +0000332 [ECMR] = 0x0160,
333 [ECSR] = 0x0164,
334 [ECSIPR] = 0x0168,
335 [PIR] = 0x016c,
336 [MAHR] = 0x0170,
337 [MALR] = 0x0174,
338 [RFLR] = 0x0178,
339 [PSR] = 0x017c,
340 [TROCR] = 0x0180,
341 [CDCR] = 0x0184,
342 [LCCR] = 0x0188,
343 [CNDCR] = 0x018c,
344 [CEFCR] = 0x0194,
345 [FRECR] = 0x0198,
346 [TSFRCR] = 0x019c,
347 [TLFRCR] = 0x01a0,
348 [RFCR] = 0x01a4,
349 [MAFCR] = 0x01a8,
350 [IPGR] = 0x01b4,
351 [APR] = 0x01b8,
352 [MPR] = 0x01bc,
353 [TPAUSER] = 0x01c4,
354 [BCFR] = 0x01cc,
355
356 [ARSTR] = 0x0000,
357 [TSU_CTRST] = 0x0004,
358 [TSU_FWEN0] = 0x0010,
359 [TSU_FWEN1] = 0x0014,
360 [TSU_FCM] = 0x0018,
361 [TSU_BSYSL0] = 0x0020,
362 [TSU_BSYSL1] = 0x0024,
363 [TSU_PRISL0] = 0x0028,
364 [TSU_PRISL1] = 0x002c,
365 [TSU_FWSL0] = 0x0030,
366 [TSU_FWSL1] = 0x0034,
367 [TSU_FWSLC] = 0x0038,
368 [TSU_QTAGM0] = 0x0040,
369 [TSU_QTAGM1] = 0x0044,
370 [TSU_ADQT0] = 0x0048,
371 [TSU_ADQT1] = 0x004c,
372 [TSU_FWSR] = 0x0050,
373 [TSU_FWINMK] = 0x0054,
374 [TSU_ADSBSY] = 0x0060,
375 [TSU_TEN] = 0x0064,
376 [TSU_POST1] = 0x0070,
377 [TSU_POST2] = 0x0074,
378 [TSU_POST3] = 0x0078,
379 [TSU_POST4] = 0x007c,
380
381 [TXNLCR0] = 0x0080,
382 [TXALCR0] = 0x0084,
383 [RXNLCR0] = 0x0088,
384 [RXALCR0] = 0x008c,
385 [FWNLCR0] = 0x0090,
386 [FWALCR0] = 0x0094,
387 [TXNLCR1] = 0x00a0,
388 [TXALCR1] = 0x00a0,
389 [RXNLCR1] = 0x00a8,
390 [RXALCR1] = 0x00ac,
391 [FWNLCR1] = 0x00b0,
392 [FWALCR1] = 0x00b4,
393
394 [TSU_ADRH0] = 0x0100,
395 [TSU_ADRL0] = 0x0104,
396 [TSU_ADRL31] = 0x01fc,
397};
398
Ben Hutchings740c7f32015-01-27 00:49:32 +0000399static void sh_eth_rcv_snd_disable(struct net_device *ndev);
400static struct net_device_stats *sh_eth_get_stats(struct net_device *ndev);
401
Simon Horman504c8ca2014-01-17 09:22:27 +0900402static bool sh_eth_is_gether(struct sh_eth_private *mdp)
Nobuhiro Iwamatsudabdde92013-06-06 09:51:39 +0000403{
Simon Horman504c8ca2014-01-17 09:22:27 +0900404 return mdp->reg_offset == sh_eth_offset_gigabit;
Nobuhiro Iwamatsudabdde92013-06-06 09:51:39 +0000405}
406
Simon Hormandb893472014-01-17 09:22:28 +0900407static bool sh_eth_is_rz_fast_ether(struct sh_eth_private *mdp)
408{
409 return mdp->reg_offset == sh_eth_offset_fast_rz;
410}
411
Sergei Shtylyov8e994402013-06-12 03:07:29 +0400412static void sh_eth_select_mii(struct net_device *ndev)
Nobuhiro Iwamatsu5e7a76b2012-06-25 17:34:14 +0000413{
414 u32 value = 0x0;
415 struct sh_eth_private *mdp = netdev_priv(ndev);
416
417 switch (mdp->phy_interface) {
418 case PHY_INTERFACE_MODE_GMII:
419 value = 0x2;
420 break;
421 case PHY_INTERFACE_MODE_MII:
422 value = 0x1;
423 break;
424 case PHY_INTERFACE_MODE_RMII:
425 value = 0x0;
426 break;
427 default:
Sergei Shtylyovf75f14e2014-03-15 03:27:54 +0300428 netdev_warn(ndev,
429 "PHY interface mode was not setup. Set to MII.\n");
Nobuhiro Iwamatsu5e7a76b2012-06-25 17:34:14 +0000430 value = 0x1;
431 break;
432 }
433
434 sh_eth_write(ndev, value, RMII_MII);
435}
Nobuhiro Iwamatsu5e7a76b2012-06-25 17:34:14 +0000436
Sergei Shtylyov8e994402013-06-12 03:07:29 +0400437static void sh_eth_set_duplex(struct net_device *ndev)
Yoshihiro Shimoda65ac8852009-05-24 23:54:30 +0000438{
439 struct sh_eth_private *mdp = netdev_priv(ndev);
Yoshihiro Shimoda65ac8852009-05-24 23:54:30 +0000440
441 if (mdp->duplex) /* Full */
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +0000442 sh_eth_write(ndev, sh_eth_read(ndev, ECMR) | ECMR_DM, ECMR);
Yoshihiro Shimoda65ac8852009-05-24 23:54:30 +0000443 else /* Half */
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +0000444 sh_eth_write(ndev, sh_eth_read(ndev, ECMR) & ~ECMR_DM, ECMR);
Yoshihiro Shimoda65ac8852009-05-24 23:54:30 +0000445}
446
Nobuhiro Iwamatsu04b0ed22013-06-06 09:45:25 +0000447/* There is CPU dependent code */
Sergei Shtylyov589ebde2013-06-07 14:05:59 +0000448static void sh_eth_set_rate_r8a777x(struct net_device *ndev)
Yoshihiro Shimoda65ac8852009-05-24 23:54:30 +0000449{
450 struct sh_eth_private *mdp = netdev_priv(ndev);
Yoshihiro Shimoda65ac8852009-05-24 23:54:30 +0000451
452 switch (mdp->speed) {
453 case 10: /* 10BASE */
Sergei Shtylyova3f109b2013-03-28 11:51:31 +0000454 sh_eth_write(ndev, sh_eth_read(ndev, ECMR) & ~ECMR_ELB, ECMR);
Yoshihiro Shimoda65ac8852009-05-24 23:54:30 +0000455 break;
456 case 100:/* 100BASE */
Sergei Shtylyova3f109b2013-03-28 11:51:31 +0000457 sh_eth_write(ndev, sh_eth_read(ndev, ECMR) | ECMR_ELB, ECMR);
458 break;
459 default:
460 break;
461 }
462}
463
Sergei Shtylyov674853b2013-04-27 10:44:24 +0000464/* R8A7778/9 */
Sergei Shtylyov589ebde2013-06-07 14:05:59 +0000465static struct sh_eth_cpu_data r8a777x_data = {
Sergei Shtylyova3f109b2013-03-28 11:51:31 +0000466 .set_duplex = sh_eth_set_duplex,
Sergei Shtylyov589ebde2013-06-07 14:05:59 +0000467 .set_rate = sh_eth_set_rate_r8a777x,
Sergei Shtylyova3f109b2013-03-28 11:51:31 +0000468
Sergei Shtylyova3153d82013-08-18 03:11:28 +0400469 .register_type = SH_ETH_REG_FAST_RCAR,
470
Sergei Shtylyova3f109b2013-03-28 11:51:31 +0000471 .ecsr_value = ECSR_PSRTO | ECSR_LCHNG | ECSR_ICD,
472 .ecsipr_value = ECSIPR_PSRTOIP | ECSIPR_LCHNGIP | ECSIPR_ICDIP,
473 .eesipr_value = 0x01ff009f,
474
475 .tx_check = EESR_FTC | EESR_CND | EESR_DLC | EESR_CD | EESR_RTO,
Sergei Shtylyovca8c3582013-06-21 01:12:21 +0400476 .eesr_err_check = EESR_TWB | EESR_TABT | EESR_RABT | EESR_RFE |
477 EESR_RDE | EESR_RFRMER | EESR_TFE | EESR_TDE |
478 EESR_ECI,
Nobuhiro Iwamatsud407bc02015-01-07 14:40:15 +0900479 .fdr_value = 0x00000f0f,
Sergei Shtylyova3f109b2013-03-28 11:51:31 +0000480
481 .apr = 1,
482 .mpr = 1,
483 .tpauser = 1,
484 .hw_swap = 1,
485};
Sergei Shtylyova3f109b2013-03-28 11:51:31 +0000486
Sergei Shtylyov94a12b12013-12-08 02:59:18 +0300487/* R8A7790/1 */
488static struct sh_eth_cpu_data r8a779x_data = {
Simon Hormane18dbf72013-07-23 10:18:05 +0900489 .set_duplex = sh_eth_set_duplex,
490 .set_rate = sh_eth_set_rate_r8a777x,
491
Sergei Shtylyova3153d82013-08-18 03:11:28 +0400492 .register_type = SH_ETH_REG_FAST_RCAR,
493
Simon Hormane18dbf72013-07-23 10:18:05 +0900494 .ecsr_value = ECSR_PSRTO | ECSR_LCHNG | ECSR_ICD,
495 .ecsipr_value = ECSIPR_PSRTOIP | ECSIPR_LCHNGIP | ECSIPR_ICDIP,
496 .eesipr_value = 0x01ff009f,
497
498 .tx_check = EESR_FTC | EESR_CND | EESR_DLC | EESR_CD | EESR_RTO,
Laurent Pinchartba361cb2013-07-31 16:42:11 +0900499 .eesr_err_check = EESR_TWB | EESR_TABT | EESR_RABT | EESR_RFE |
500 EESR_RDE | EESR_RFRMER | EESR_TFE | EESR_TDE |
501 EESR_ECI,
Nobuhiro Iwamatsud407bc02015-01-07 14:40:15 +0900502 .fdr_value = 0x00000f0f,
Simon Hormane18dbf72013-07-23 10:18:05 +0900503
Geert Uytterhoeven01fbd3f2015-01-15 11:52:19 +0100504 .trscer_err_mask = DESC_I_RINT8,
505
Simon Hormane18dbf72013-07-23 10:18:05 +0900506 .apr = 1,
507 .mpr = 1,
508 .tpauser = 1,
509 .hw_swap = 1,
510 .rmiimode = 1,
511};
512
Sergei Shtylyov9c3beaa2013-06-07 14:03:37 +0000513static void sh_eth_set_rate_sh7724(struct net_device *ndev)
Sergei Shtylyova3f109b2013-03-28 11:51:31 +0000514{
515 struct sh_eth_private *mdp = netdev_priv(ndev);
516
517 switch (mdp->speed) {
518 case 10: /* 10BASE */
519 sh_eth_write(ndev, sh_eth_read(ndev, ECMR) & ~ECMR_RTM, ECMR);
520 break;
521 case 100:/* 100BASE */
522 sh_eth_write(ndev, sh_eth_read(ndev, ECMR) | ECMR_RTM, ECMR);
Yoshihiro Shimoda65ac8852009-05-24 23:54:30 +0000523 break;
524 default:
525 break;
526 }
527}
528
529/* SH7724 */
Sergei Shtylyov9c3beaa2013-06-07 14:03:37 +0000530static struct sh_eth_cpu_data sh7724_data = {
Yoshihiro Shimoda65ac8852009-05-24 23:54:30 +0000531 .set_duplex = sh_eth_set_duplex,
Sergei Shtylyov9c3beaa2013-06-07 14:03:37 +0000532 .set_rate = sh_eth_set_rate_sh7724,
Yoshihiro Shimoda65ac8852009-05-24 23:54:30 +0000533
Sergei Shtylyova3153d82013-08-18 03:11:28 +0400534 .register_type = SH_ETH_REG_FAST_SH4,
535
Yoshihiro Shimoda65ac8852009-05-24 23:54:30 +0000536 .ecsr_value = ECSR_PSRTO | ECSR_LCHNG | ECSR_ICD,
537 .ecsipr_value = ECSIPR_PSRTOIP | ECSIPR_LCHNGIP | ECSIPR_ICDIP,
Sergei Shtylyova80c3de2013-06-20 02:24:54 +0400538 .eesipr_value = 0x01ff009f,
Yoshihiro Shimoda65ac8852009-05-24 23:54:30 +0000539
540 .tx_check = EESR_FTC | EESR_CND | EESR_DLC | EESR_CD | EESR_RTO,
Sergei Shtylyovca8c3582013-06-21 01:12:21 +0400541 .eesr_err_check = EESR_TWB | EESR_TABT | EESR_RABT | EESR_RFE |
542 EESR_RDE | EESR_RFRMER | EESR_TFE | EESR_TDE |
543 EESR_ECI,
Yoshihiro Shimoda65ac8852009-05-24 23:54:30 +0000544
545 .apr = 1,
546 .mpr = 1,
547 .tpauser = 1,
548 .hw_swap = 1,
Magnus Damm503914c2009-12-15 21:16:55 -0800549 .rpadir = 1,
550 .rpadir_value = 0x00020000, /* NET_IP_ALIGN assumed to be 2 */
Yoshihiro Shimoda65ac8852009-05-24 23:54:30 +0000551};
Nobuhiro Iwamatsu5cee1d32012-06-25 17:35:12 +0000552
Sergei Shtylyov24549e22013-06-07 13:59:21 +0000553static void sh_eth_set_rate_sh7757(struct net_device *ndev)
Yoshihiro Shimodaf29a3d02010-07-05 18:32:50 +0000554{
555 struct sh_eth_private *mdp = netdev_priv(ndev);
Yoshihiro Shimodaf29a3d02010-07-05 18:32:50 +0000556
557 switch (mdp->speed) {
558 case 10: /* 10BASE */
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +0000559 sh_eth_write(ndev, 0, RTRATE);
Yoshihiro Shimodaf29a3d02010-07-05 18:32:50 +0000560 break;
561 case 100:/* 100BASE */
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +0000562 sh_eth_write(ndev, 1, RTRATE);
Yoshihiro Shimodaf29a3d02010-07-05 18:32:50 +0000563 break;
564 default:
565 break;
566 }
567}
568
569/* SH7757 */
Sergei Shtylyov24549e22013-06-07 13:59:21 +0000570static struct sh_eth_cpu_data sh7757_data = {
571 .set_duplex = sh_eth_set_duplex,
572 .set_rate = sh_eth_set_rate_sh7757,
Yoshihiro Shimodaf29a3d02010-07-05 18:32:50 +0000573
Sergei Shtylyova3153d82013-08-18 03:11:28 +0400574 .register_type = SH_ETH_REG_FAST_SH4,
575
Yoshihiro Shimodaf29a3d02010-07-05 18:32:50 +0000576 .eesipr_value = DMAC_M_RFRMER | DMAC_M_ECI | 0x003fffff,
Yoshihiro Shimodaf29a3d02010-07-05 18:32:50 +0000577
578 .tx_check = EESR_FTC | EESR_CND | EESR_DLC | EESR_CD | EESR_RTO,
Sergei Shtylyovca8c3582013-06-21 01:12:21 +0400579 .eesr_err_check = EESR_TWB | EESR_TABT | EESR_RABT | EESR_RFE |
580 EESR_RDE | EESR_RFRMER | EESR_TFE | EESR_TDE |
581 EESR_ECI,
Yoshihiro Shimodaf29a3d02010-07-05 18:32:50 +0000582
Nobuhiro Iwamatsu5b3dfd12013-06-06 09:49:30 +0000583 .irq_flags = IRQF_SHARED,
Yoshihiro Shimodaf29a3d02010-07-05 18:32:50 +0000584 .apr = 1,
585 .mpr = 1,
586 .tpauser = 1,
587 .hw_swap = 1,
588 .no_ade = 1,
Yoshihiro Shimoda2e98e792011-07-05 20:33:57 +0000589 .rpadir = 1,
590 .rpadir_value = 2 << 16,
Yoshihiro Shimodaf29a3d02010-07-05 18:32:50 +0000591};
Yoshihiro Shimoda65ac8852009-05-24 23:54:30 +0000592
David S. Millere403d292013-06-07 23:40:41 -0700593#define SH_GIGA_ETH_BASE 0xfee00000UL
Yoshihiro Shimoda8fcd4962011-03-07 21:59:49 +0000594#define GIGA_MALR(port) (SH_GIGA_ETH_BASE + 0x800 * (port) + 0x05c8)
595#define GIGA_MAHR(port) (SH_GIGA_ETH_BASE + 0x800 * (port) + 0x05c0)
596static void sh_eth_chip_reset_giga(struct net_device *ndev)
597{
598 int i;
Geert Uytterhoeven0799c2d2015-01-15 11:54:28 +0100599 u32 mahr[2], malr[2];
Yoshihiro Shimoda8fcd4962011-03-07 21:59:49 +0000600
601 /* save MAHR and MALR */
602 for (i = 0; i < 2; i++) {
Yoshihiro Shimodaae706442011-09-27 21:48:58 +0000603 malr[i] = ioread32((void *)GIGA_MALR(i));
604 mahr[i] = ioread32((void *)GIGA_MAHR(i));
Yoshihiro Shimoda8fcd4962011-03-07 21:59:49 +0000605 }
606
607 /* reset device */
Yoshihiro Shimodaae706442011-09-27 21:48:58 +0000608 iowrite32(ARSTR_ARSTR, (void *)(SH_GIGA_ETH_BASE + 0x1800));
Yoshihiro Shimoda8fcd4962011-03-07 21:59:49 +0000609 mdelay(1);
610
611 /* restore MAHR and MALR */
612 for (i = 0; i < 2; i++) {
Yoshihiro Shimodaae706442011-09-27 21:48:58 +0000613 iowrite32(malr[i], (void *)GIGA_MALR(i));
614 iowrite32(mahr[i], (void *)GIGA_MAHR(i));
Yoshihiro Shimoda8fcd4962011-03-07 21:59:49 +0000615 }
616}
617
Yoshihiro Shimoda8fcd4962011-03-07 21:59:49 +0000618static void sh_eth_set_rate_giga(struct net_device *ndev)
619{
620 struct sh_eth_private *mdp = netdev_priv(ndev);
621
622 switch (mdp->speed) {
623 case 10: /* 10BASE */
624 sh_eth_write(ndev, 0x00000000, GECMR);
625 break;
626 case 100:/* 100BASE */
627 sh_eth_write(ndev, 0x00000010, GECMR);
628 break;
629 case 1000: /* 1000BASE */
630 sh_eth_write(ndev, 0x00000020, GECMR);
631 break;
632 default:
633 break;
634 }
635}
636
637/* SH7757(GETHERC) */
Sergei Shtylyov24549e22013-06-07 13:59:21 +0000638static struct sh_eth_cpu_data sh7757_data_giga = {
Yoshihiro Shimoda8fcd4962011-03-07 21:59:49 +0000639 .chip_reset = sh_eth_chip_reset_giga,
Nobuhiro Iwamatsu04b0ed22013-06-06 09:45:25 +0000640 .set_duplex = sh_eth_set_duplex,
Yoshihiro Shimoda8fcd4962011-03-07 21:59:49 +0000641 .set_rate = sh_eth_set_rate_giga,
642
Sergei Shtylyova3153d82013-08-18 03:11:28 +0400643 .register_type = SH_ETH_REG_GIGABIT,
644
Yoshihiro Shimoda8fcd4962011-03-07 21:59:49 +0000645 .ecsr_value = ECSR_ICD | ECSR_MPD,
646 .ecsipr_value = ECSIPR_LCHNGIP | ECSIPR_ICDIP | ECSIPR_MPDIP,
647 .eesipr_value = DMAC_M_RFRMER | DMAC_M_ECI | 0x003fffff,
648
649 .tx_check = EESR_TC1 | EESR_FTC,
Sergei Shtylyovca8c3582013-06-21 01:12:21 +0400650 .eesr_err_check = EESR_TWB1 | EESR_TWB | EESR_TABT | EESR_RABT |
651 EESR_RFE | EESR_RDE | EESR_RFRMER | EESR_TFE |
652 EESR_TDE | EESR_ECI,
Yoshihiro Shimoda8fcd4962011-03-07 21:59:49 +0000653 .fdr_value = 0x0000072f,
Yoshihiro Shimoda8fcd4962011-03-07 21:59:49 +0000654
Nobuhiro Iwamatsu5b3dfd12013-06-06 09:49:30 +0000655 .irq_flags = IRQF_SHARED,
Yoshihiro Shimoda8fcd4962011-03-07 21:59:49 +0000656 .apr = 1,
657 .mpr = 1,
658 .tpauser = 1,
659 .bculr = 1,
660 .hw_swap = 1,
661 .rpadir = 1,
662 .rpadir_value = 2 << 16,
663 .no_trimd = 1,
664 .no_ade = 1,
Yoshihiro Shimoda3acbc972012-02-15 17:54:51 +0000665 .tsu = 1,
Yoshihiro Shimoda8fcd4962011-03-07 21:59:49 +0000666};
667
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +0000668static void sh_eth_chip_reset(struct net_device *ndev)
669{
Yoshihiro Shimoda4986b992011-03-07 21:59:34 +0000670 struct sh_eth_private *mdp = netdev_priv(ndev);
671
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +0000672 /* reset device */
Yoshihiro Shimoda4986b992011-03-07 21:59:34 +0000673 sh_eth_tsu_write(mdp, ARSTR_ARSTR, ARSTR);
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +0000674 mdelay(1);
675}
676
Sergei Shtylyovf5d12762013-06-07 13:58:18 +0000677static void sh_eth_set_rate_gether(struct net_device *ndev)
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +0000678{
679 struct sh_eth_private *mdp = netdev_priv(ndev);
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +0000680
681 switch (mdp->speed) {
682 case 10: /* 10BASE */
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +0000683 sh_eth_write(ndev, GECMR_10, GECMR);
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +0000684 break;
685 case 100:/* 100BASE */
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +0000686 sh_eth_write(ndev, GECMR_100, GECMR);
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +0000687 break;
688 case 1000: /* 1000BASE */
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +0000689 sh_eth_write(ndev, GECMR_1000, GECMR);
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +0000690 break;
691 default:
692 break;
693 }
694}
695
Sergei Shtylyovf5d12762013-06-07 13:58:18 +0000696/* SH7734 */
697static struct sh_eth_cpu_data sh7734_data = {
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +0000698 .chip_reset = sh_eth_chip_reset,
699 .set_duplex = sh_eth_set_duplex,
Sergei Shtylyovf5d12762013-06-07 13:58:18 +0000700 .set_rate = sh_eth_set_rate_gether,
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +0000701
Sergei Shtylyova3153d82013-08-18 03:11:28 +0400702 .register_type = SH_ETH_REG_GIGABIT,
703
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +0000704 .ecsr_value = ECSR_ICD | ECSR_MPD,
705 .ecsipr_value = ECSIPR_LCHNGIP | ECSIPR_ICDIP | ECSIPR_MPDIP,
706 .eesipr_value = DMAC_M_RFRMER | DMAC_M_ECI | 0x003fffff,
707
708 .tx_check = EESR_TC1 | EESR_FTC,
Sergei Shtylyovca8c3582013-06-21 01:12:21 +0400709 .eesr_err_check = EESR_TWB1 | EESR_TWB | EESR_TABT | EESR_RABT |
710 EESR_RFE | EESR_RDE | EESR_RFRMER | EESR_TFE |
711 EESR_TDE | EESR_ECI,
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +0000712
713 .apr = 1,
714 .mpr = 1,
715 .tpauser = 1,
716 .bculr = 1,
717 .hw_swap = 1,
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +0000718 .no_trimd = 1,
719 .no_ade = 1,
Yoshihiro Shimoda4986b992011-03-07 21:59:34 +0000720 .tsu = 1,
Sergei Shtylyovf5d12762013-06-07 13:58:18 +0000721 .hw_crc = 1,
722 .select_mii = 1,
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +0000723};
Sergei Shtylyovf5d12762013-06-07 13:58:18 +0000724
725/* SH7763 */
726static struct sh_eth_cpu_data sh7763_data = {
727 .chip_reset = sh_eth_chip_reset,
728 .set_duplex = sh_eth_set_duplex,
729 .set_rate = sh_eth_set_rate_gether,
730
Sergei Shtylyova3153d82013-08-18 03:11:28 +0400731 .register_type = SH_ETH_REG_GIGABIT,
732
Sergei Shtylyovf5d12762013-06-07 13:58:18 +0000733 .ecsr_value = ECSR_ICD | ECSR_MPD,
734 .ecsipr_value = ECSIPR_LCHNGIP | ECSIPR_ICDIP | ECSIPR_MPDIP,
735 .eesipr_value = DMAC_M_RFRMER | DMAC_M_ECI | 0x003fffff,
736
737 .tx_check = EESR_TC1 | EESR_FTC,
Sergei Shtylyov128296f2014-01-03 15:52:22 +0300738 .eesr_err_check = EESR_TWB1 | EESR_TWB | EESR_TABT | EESR_RABT |
739 EESR_RDE | EESR_RFRMER | EESR_TFE | EESR_TDE |
Sergei Shtylyovf5d12762013-06-07 13:58:18 +0000740 EESR_ECI,
Sergei Shtylyovf5d12762013-06-07 13:58:18 +0000741
742 .apr = 1,
743 .mpr = 1,
744 .tpauser = 1,
745 .bculr = 1,
746 .hw_swap = 1,
747 .no_trimd = 1,
748 .no_ade = 1,
749 .tsu = 1,
750 .irq_flags = IRQF_SHARED,
751};
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +0000752
Sergei Shtylyove5c9b4c2013-06-07 13:57:12 +0000753static void sh_eth_chip_reset_r8a7740(struct net_device *ndev)
Yoshihiro Shimoda73a0d902012-04-04 18:37:10 +0000754{
755 struct sh_eth_private *mdp = netdev_priv(ndev);
Yoshihiro Shimoda73a0d902012-04-04 18:37:10 +0000756
757 /* reset device */
758 sh_eth_tsu_write(mdp, ARSTR_ARSTR, ARSTR);
759 mdelay(1);
760
Nobuhiro Iwamatsu5e7a76b2012-06-25 17:34:14 +0000761 sh_eth_select_mii(ndev);
Yoshihiro Shimoda73a0d902012-04-04 18:37:10 +0000762}
763
Yoshihiro Shimoda73a0d902012-04-04 18:37:10 +0000764/* R8A7740 */
Sergei Shtylyove5c9b4c2013-06-07 13:57:12 +0000765static struct sh_eth_cpu_data r8a7740_data = {
766 .chip_reset = sh_eth_chip_reset_r8a7740,
Yoshihiro Shimoda73a0d902012-04-04 18:37:10 +0000767 .set_duplex = sh_eth_set_duplex,
Sergei Shtylyove5c9b4c2013-06-07 13:57:12 +0000768 .set_rate = sh_eth_set_rate_gether,
Yoshihiro Shimoda73a0d902012-04-04 18:37:10 +0000769
Sergei Shtylyova3153d82013-08-18 03:11:28 +0400770 .register_type = SH_ETH_REG_GIGABIT,
771
Yoshihiro Shimoda73a0d902012-04-04 18:37:10 +0000772 .ecsr_value = ECSR_ICD | ECSR_MPD,
773 .ecsipr_value = ECSIPR_LCHNGIP | ECSIPR_ICDIP | ECSIPR_MPDIP,
774 .eesipr_value = DMAC_M_RFRMER | DMAC_M_ECI | 0x003fffff,
775
776 .tx_check = EESR_TC1 | EESR_FTC,
Sergei Shtylyovca8c3582013-06-21 01:12:21 +0400777 .eesr_err_check = EESR_TWB1 | EESR_TWB | EESR_TABT | EESR_RABT |
778 EESR_RFE | EESR_RDE | EESR_RFRMER | EESR_TFE |
779 EESR_TDE | EESR_ECI,
Simon Hormancc235282013-10-10 14:51:16 +0900780 .fdr_value = 0x0000070f,
Yoshihiro Shimoda73a0d902012-04-04 18:37:10 +0000781
782 .apr = 1,
783 .mpr = 1,
784 .tpauser = 1,
785 .bculr = 1,
786 .hw_swap = 1,
Simon Hormancc235282013-10-10 14:51:16 +0900787 .rpadir = 1,
788 .rpadir_value = 2 << 16,
Yoshihiro Shimoda73a0d902012-04-04 18:37:10 +0000789 .no_trimd = 1,
790 .no_ade = 1,
791 .tsu = 1,
Nobuhiro Iwamatsu5e7a76b2012-06-25 17:34:14 +0000792 .select_mii = 1,
Sergei Shtylyovac8025a2013-06-13 22:12:45 +0400793 .shift_rd0 = 1,
Yoshihiro Shimoda73a0d902012-04-04 18:37:10 +0000794};
795
Simon Hormandb893472014-01-17 09:22:28 +0900796/* R7S72100 */
797static struct sh_eth_cpu_data r7s72100_data = {
798 .chip_reset = sh_eth_chip_reset,
799 .set_duplex = sh_eth_set_duplex,
800
801 .register_type = SH_ETH_REG_FAST_RZ,
802
803 .ecsr_value = ECSR_ICD,
804 .ecsipr_value = ECSIPR_ICDIP,
805 .eesipr_value = 0xff7f009f,
806
807 .tx_check = EESR_TC1 | EESR_FTC,
808 .eesr_err_check = EESR_TWB1 | EESR_TWB | EESR_TABT | EESR_RABT |
809 EESR_RFE | EESR_RDE | EESR_RFRMER | EESR_TFE |
810 EESR_TDE | EESR_ECI,
811 .fdr_value = 0x0000070f,
Simon Hormandb893472014-01-17 09:22:28 +0900812
813 .no_psr = 1,
814 .apr = 1,
815 .mpr = 1,
816 .tpauser = 1,
817 .hw_swap = 1,
818 .rpadir = 1,
819 .rpadir_value = 2 << 16,
820 .no_trimd = 1,
821 .no_ade = 1,
822 .hw_crc = 1,
823 .tsu = 1,
824 .shift_rd0 = 1,
825};
826
Sergei Shtylyovc18a79a2013-06-07 13:56:05 +0000827static struct sh_eth_cpu_data sh7619_data = {
Sergei Shtylyova3153d82013-08-18 03:11:28 +0400828 .register_type = SH_ETH_REG_FAST_SH3_SH2,
829
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +0000830 .eesipr_value = DMAC_M_RFRMER | DMAC_M_ECI | 0x003fffff,
831
832 .apr = 1,
833 .mpr = 1,
834 .tpauser = 1,
835 .hw_swap = 1,
836};
Sergei Shtylyov7bbe1502013-06-07 13:55:08 +0000837
838static struct sh_eth_cpu_data sh771x_data = {
Sergei Shtylyova3153d82013-08-18 03:11:28 +0400839 .register_type = SH_ETH_REG_FAST_SH3_SH2,
840
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +0000841 .eesipr_value = DMAC_M_RFRMER | DMAC_M_ECI | 0x003fffff,
Yoshihiro Shimoda4986b992011-03-07 21:59:34 +0000842 .tsu = 1,
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +0000843};
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +0000844
845static void sh_eth_set_default_cpu_data(struct sh_eth_cpu_data *cd)
846{
847 if (!cd->ecsr_value)
848 cd->ecsr_value = DEFAULT_ECSR_INIT;
849
850 if (!cd->ecsipr_value)
851 cd->ecsipr_value = DEFAULT_ECSIPR_INIT;
852
853 if (!cd->fcftr_value)
Sergei Shtylyov128296f2014-01-03 15:52:22 +0300854 cd->fcftr_value = DEFAULT_FIFO_F_D_RFF |
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +0000855 DEFAULT_FIFO_F_D_RFD;
856
857 if (!cd->fdr_value)
858 cd->fdr_value = DEFAULT_FDR_INIT;
859
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +0000860 if (!cd->tx_check)
861 cd->tx_check = DEFAULT_TX_CHECK;
862
863 if (!cd->eesr_err_check)
864 cd->eesr_err_check = DEFAULT_EESR_ERR_CHECK;
Nobuhiro Iwamatsub284fbe2015-01-08 15:25:07 +0900865
866 if (!cd->trscer_err_mask)
867 cd->trscer_err_mask = DEFAULT_TRSCER_ERR_MASK;
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +0000868}
869
Nobuhiro Iwamatsu5cee1d32012-06-25 17:35:12 +0000870static int sh_eth_check_reset(struct net_device *ndev)
871{
872 int ret = 0;
873 int cnt = 100;
874
875 while (cnt > 0) {
876 if (!(sh_eth_read(ndev, EDMR) & 0x3))
877 break;
878 mdelay(1);
879 cnt--;
880 }
Sergei Shtylyov9f8c4262013-06-05 23:54:01 +0400881 if (cnt <= 0) {
Sergei Shtylyovf75f14e2014-03-15 03:27:54 +0300882 netdev_err(ndev, "Device reset failed\n");
Nobuhiro Iwamatsu5cee1d32012-06-25 17:35:12 +0000883 ret = -ETIMEDOUT;
884 }
885 return ret;
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +0000886}
Nobuhiro Iwamatsudabdde92013-06-06 09:51:39 +0000887
888static int sh_eth_reset(struct net_device *ndev)
889{
890 struct sh_eth_private *mdp = netdev_priv(ndev);
891 int ret = 0;
892
Simon Hormandb893472014-01-17 09:22:28 +0900893 if (sh_eth_is_gether(mdp) || sh_eth_is_rz_fast_ether(mdp)) {
Nobuhiro Iwamatsudabdde92013-06-06 09:51:39 +0000894 sh_eth_write(ndev, EDSR_ENALL, EDSR);
895 sh_eth_write(ndev, sh_eth_read(ndev, EDMR) | EDMR_SRST_GETHER,
896 EDMR);
897
898 ret = sh_eth_check_reset(ndev);
899 if (ret)
Laurent Pinchartf738a132014-03-20 15:00:35 +0100900 return ret;
Nobuhiro Iwamatsudabdde92013-06-06 09:51:39 +0000901
902 /* Table Init */
903 sh_eth_write(ndev, 0x0, TDLAR);
904 sh_eth_write(ndev, 0x0, TDFAR);
905 sh_eth_write(ndev, 0x0, TDFXR);
906 sh_eth_write(ndev, 0x0, TDFFR);
907 sh_eth_write(ndev, 0x0, RDLAR);
908 sh_eth_write(ndev, 0x0, RDFAR);
909 sh_eth_write(ndev, 0x0, RDFXR);
910 sh_eth_write(ndev, 0x0, RDFFR);
911
912 /* Reset HW CRC register */
913 if (mdp->cd->hw_crc)
914 sh_eth_write(ndev, 0x0, CSMR);
915
916 /* Select MII mode */
917 if (mdp->cd->select_mii)
918 sh_eth_select_mii(ndev);
919 } else {
920 sh_eth_write(ndev, sh_eth_read(ndev, EDMR) | EDMR_SRST_ETHER,
921 EDMR);
922 mdelay(3);
923 sh_eth_write(ndev, sh_eth_read(ndev, EDMR) & ~EDMR_SRST_ETHER,
924 EDMR);
925 }
926
Nobuhiro Iwamatsudabdde92013-06-06 09:51:39 +0000927 return ret;
928}
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +0000929
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +0000930static void sh_eth_set_receive_align(struct sk_buff *skb)
931{
Mitsuhiro Kimura4d6a9492014-11-27 20:34:00 +0900932 uintptr_t reserve = (uintptr_t)skb->data & (SH_ETH_RX_ALIGN - 1);
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +0000933
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +0000934 if (reserve)
Mitsuhiro Kimura4d6a9492014-11-27 20:34:00 +0900935 skb_reserve(skb, SH_ETH_RX_ALIGN - reserve);
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +0000936}
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +0000937
938
Yoshinori Sato71557a32008-08-06 19:49:00 -0400939/* CPU <-> EDMAC endian convert */
940static inline __u32 cpu_to_edmac(struct sh_eth_private *mdp, u32 x)
941{
942 switch (mdp->edmac_endian) {
943 case EDMAC_LITTLE_ENDIAN:
944 return cpu_to_le32(x);
945 case EDMAC_BIG_ENDIAN:
946 return cpu_to_be32(x);
947 }
948 return x;
949}
950
951static inline __u32 edmac_to_cpu(struct sh_eth_private *mdp, u32 x)
952{
953 switch (mdp->edmac_endian) {
954 case EDMAC_LITTLE_ENDIAN:
955 return le32_to_cpu(x);
956 case EDMAC_BIG_ENDIAN:
957 return be32_to_cpu(x);
958 }
959 return x;
960}
961
Sergei Shtylyov128296f2014-01-03 15:52:22 +0300962/* Program the hardware MAC address from dev->dev_addr. */
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -0700963static void update_mac_address(struct net_device *ndev)
964{
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +0000965 sh_eth_write(ndev,
Sergei Shtylyov128296f2014-01-03 15:52:22 +0300966 (ndev->dev_addr[0] << 24) | (ndev->dev_addr[1] << 16) |
967 (ndev->dev_addr[2] << 8) | (ndev->dev_addr[3]), MAHR);
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +0000968 sh_eth_write(ndev,
Sergei Shtylyov128296f2014-01-03 15:52:22 +0300969 (ndev->dev_addr[4] << 8) | (ndev->dev_addr[5]), MALR);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -0700970}
971
Sergei Shtylyov128296f2014-01-03 15:52:22 +0300972/* Get MAC address from SuperH MAC address register
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -0700973 *
974 * SuperH's Ethernet device doesn't have 'ROM' to MAC address.
975 * This driver get MAC address that use by bootloader(U-boot or sh-ipl+g).
976 * When you want use this device, you must set MAC address in bootloader.
977 *
978 */
Magnus Damm748031f2009-10-09 00:17:14 +0000979static void read_mac_address(struct net_device *ndev, unsigned char *mac)
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -0700980{
Magnus Damm748031f2009-10-09 00:17:14 +0000981 if (mac[0] || mac[1] || mac[2] || mac[3] || mac[4] || mac[5]) {
Joe Perchesd458cdf2013-10-01 19:04:40 -0700982 memcpy(ndev->dev_addr, mac, ETH_ALEN);
Magnus Damm748031f2009-10-09 00:17:14 +0000983 } else {
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +0000984 ndev->dev_addr[0] = (sh_eth_read(ndev, MAHR) >> 24);
985 ndev->dev_addr[1] = (sh_eth_read(ndev, MAHR) >> 16) & 0xFF;
986 ndev->dev_addr[2] = (sh_eth_read(ndev, MAHR) >> 8) & 0xFF;
987 ndev->dev_addr[3] = (sh_eth_read(ndev, MAHR) & 0xFF);
988 ndev->dev_addr[4] = (sh_eth_read(ndev, MALR) >> 8) & 0xFF;
989 ndev->dev_addr[5] = (sh_eth_read(ndev, MALR) & 0xFF);
Magnus Damm748031f2009-10-09 00:17:14 +0000990 }
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -0700991}
992
Geert Uytterhoeven0799c2d2015-01-15 11:54:28 +0100993static u32 sh_eth_get_edtrr_trns(struct sh_eth_private *mdp)
Yoshihiro Shimodac5ed5362011-03-07 21:59:38 +0000994{
Simon Hormandb893472014-01-17 09:22:28 +0900995 if (sh_eth_is_gether(mdp) || sh_eth_is_rz_fast_ether(mdp))
Yoshihiro Shimodac5ed5362011-03-07 21:59:38 +0000996 return EDTRR_TRNS_GETHER;
997 else
998 return EDTRR_TRNS_ETHER;
999}
1000
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001001struct bb_info {
Yoshihiro Shimodaae706442011-09-27 21:48:58 +00001002 void (*set_gate)(void *addr);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001003 struct mdiobb_ctrl ctrl;
Yoshihiro Shimodaae706442011-09-27 21:48:58 +00001004 void *addr;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001005 u32 mmd_msk;/* MMD */
1006 u32 mdo_msk;
1007 u32 mdi_msk;
1008 u32 mdc_msk;
1009};
1010
1011/* PHY bit set */
Yoshihiro Shimodaae706442011-09-27 21:48:58 +00001012static void bb_set(void *addr, u32 msk)
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001013{
Yoshihiro Shimodaae706442011-09-27 21:48:58 +00001014 iowrite32(ioread32(addr) | msk, addr);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001015}
1016
1017/* PHY bit clear */
Yoshihiro Shimodaae706442011-09-27 21:48:58 +00001018static void bb_clr(void *addr, u32 msk)
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001019{
Yoshihiro Shimodaae706442011-09-27 21:48:58 +00001020 iowrite32((ioread32(addr) & ~msk), addr);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001021}
1022
1023/* PHY bit read */
Yoshihiro Shimodaae706442011-09-27 21:48:58 +00001024static int bb_read(void *addr, u32 msk)
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001025{
Yoshihiro Shimodaae706442011-09-27 21:48:58 +00001026 return (ioread32(addr) & msk) != 0;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001027}
1028
1029/* Data I/O pin control */
1030static void sh_mmd_ctrl(struct mdiobb_ctrl *ctrl, int bit)
1031{
1032 struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl);
Yoshihiro Shimodab3017e62011-03-07 21:59:55 +00001033
1034 if (bitbang->set_gate)
1035 bitbang->set_gate(bitbang->addr);
1036
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001037 if (bit)
1038 bb_set(bitbang->addr, bitbang->mmd_msk);
1039 else
1040 bb_clr(bitbang->addr, bitbang->mmd_msk);
1041}
1042
1043/* Set bit data*/
1044static void sh_set_mdio(struct mdiobb_ctrl *ctrl, int bit)
1045{
1046 struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl);
1047
Yoshihiro Shimodab3017e62011-03-07 21:59:55 +00001048 if (bitbang->set_gate)
1049 bitbang->set_gate(bitbang->addr);
1050
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001051 if (bit)
1052 bb_set(bitbang->addr, bitbang->mdo_msk);
1053 else
1054 bb_clr(bitbang->addr, bitbang->mdo_msk);
1055}
1056
1057/* Get bit data*/
1058static int sh_get_mdio(struct mdiobb_ctrl *ctrl)
1059{
1060 struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl);
Yoshihiro Shimodab3017e62011-03-07 21:59:55 +00001061
1062 if (bitbang->set_gate)
1063 bitbang->set_gate(bitbang->addr);
1064
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001065 return bb_read(bitbang->addr, bitbang->mdi_msk);
1066}
1067
1068/* MDC pin control */
1069static void sh_mdc_ctrl(struct mdiobb_ctrl *ctrl, int bit)
1070{
1071 struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl);
1072
Yoshihiro Shimodab3017e62011-03-07 21:59:55 +00001073 if (bitbang->set_gate)
1074 bitbang->set_gate(bitbang->addr);
1075
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001076 if (bit)
1077 bb_set(bitbang->addr, bitbang->mdc_msk);
1078 else
1079 bb_clr(bitbang->addr, bitbang->mdc_msk);
1080}
1081
1082/* mdio bus control struct */
1083static struct mdiobb_ops bb_ops = {
1084 .owner = THIS_MODULE,
1085 .set_mdc = sh_mdc_ctrl,
1086 .set_mdio_dir = sh_mmd_ctrl,
1087 .set_mdio_data = sh_set_mdio,
1088 .get_mdio_data = sh_get_mdio,
1089};
1090
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001091/* free skb and descriptor buffer */
1092static void sh_eth_ring_free(struct net_device *ndev)
1093{
1094 struct sh_eth_private *mdp = netdev_priv(ndev);
1095 int i;
1096
1097 /* Free Rx skb ringbuffer */
1098 if (mdp->rx_skbuff) {
Sergei Shtylyov179d80a2014-06-28 04:10:00 +04001099 for (i = 0; i < mdp->num_rx_ring; i++)
1100 dev_kfree_skb(mdp->rx_skbuff[i]);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001101 }
1102 kfree(mdp->rx_skbuff);
Yoshihiro Shimoda91c77552012-06-26 20:00:01 +00001103 mdp->rx_skbuff = NULL;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001104
1105 /* Free Tx skb ringbuffer */
1106 if (mdp->tx_skbuff) {
Sergei Shtylyov179d80a2014-06-28 04:10:00 +04001107 for (i = 0; i < mdp->num_tx_ring; i++)
1108 dev_kfree_skb(mdp->tx_skbuff[i]);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001109 }
1110 kfree(mdp->tx_skbuff);
Yoshihiro Shimoda91c77552012-06-26 20:00:01 +00001111 mdp->tx_skbuff = NULL;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001112}
1113
1114/* format skb and descriptor buffer */
1115static void sh_eth_ring_format(struct net_device *ndev)
1116{
1117 struct sh_eth_private *mdp = netdev_priv(ndev);
1118 int i;
1119 struct sk_buff *skb;
1120 struct sh_eth_rxdesc *rxdesc = NULL;
1121 struct sh_eth_txdesc *txdesc = NULL;
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00001122 int rx_ringsize = sizeof(*rxdesc) * mdp->num_rx_ring;
1123 int tx_ringsize = sizeof(*txdesc) * mdp->num_tx_ring;
Mitsuhiro Kimura4d6a9492014-11-27 20:34:00 +09001124 int skbuff_size = mdp->rx_buf_sz + SH_ETH_RX_ALIGN - 1;
Ben Hutchings52b9fa32015-01-27 00:50:24 +00001125 dma_addr_t dma_addr;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001126
Sergei Shtylyov128296f2014-01-03 15:52:22 +03001127 mdp->cur_rx = 0;
1128 mdp->cur_tx = 0;
1129 mdp->dirty_rx = 0;
1130 mdp->dirty_tx = 0;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001131
1132 memset(mdp->rx_ring, 0, rx_ringsize);
1133
1134 /* build Rx ring buffer */
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00001135 for (i = 0; i < mdp->num_rx_ring; i++) {
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001136 /* skb */
1137 mdp->rx_skbuff[i] = NULL;
Mitsuhiro Kimura4d6a9492014-11-27 20:34:00 +09001138 skb = netdev_alloc_skb(ndev, skbuff_size);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001139 if (skb == NULL)
1140 break;
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +00001141 sh_eth_set_receive_align(skb);
1142
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001143 /* RX descriptor */
1144 rxdesc = &mdp->rx_ring[i];
Mitsuhiro Kimura4d6a9492014-11-27 20:34:00 +09001145 /* The size of the buffer is a multiple of 16 bytes. */
1146 rxdesc->buffer_length = ALIGN(mdp->rx_buf_sz, 16);
Ben Hutchings52b9fa32015-01-27 00:50:24 +00001147 dma_addr = dma_map_single(&ndev->dev, skb->data,
1148 rxdesc->buffer_length,
1149 DMA_FROM_DEVICE);
1150 if (dma_mapping_error(&ndev->dev, dma_addr)) {
1151 kfree_skb(skb);
1152 break;
1153 }
1154 mdp->rx_skbuff[i] = skb;
1155 rxdesc->addr = dma_addr;
Yoshinori Sato71557a32008-08-06 19:49:00 -04001156 rxdesc->status = cpu_to_edmac(mdp, RD_RACT | RD_RFP);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001157
Nobuhiro Iwamatsub0ca2a22008-06-30 11:08:17 +09001158 /* Rx descriptor address set */
1159 if (i == 0) {
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001160 sh_eth_write(ndev, mdp->rx_desc_dma, RDLAR);
Simon Hormandb893472014-01-17 09:22:28 +09001161 if (sh_eth_is_gether(mdp) ||
1162 sh_eth_is_rz_fast_ether(mdp))
Yoshihiro Shimodac5ed5362011-03-07 21:59:38 +00001163 sh_eth_write(ndev, mdp->rx_desc_dma, RDFAR);
Nobuhiro Iwamatsub0ca2a22008-06-30 11:08:17 +09001164 }
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001165 }
1166
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00001167 mdp->dirty_rx = (u32) (i - mdp->num_rx_ring);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001168
1169 /* Mark the last entry as wrapping the ring. */
Yoshinori Sato71557a32008-08-06 19:49:00 -04001170 rxdesc->status |= cpu_to_edmac(mdp, RD_RDEL);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001171
1172 memset(mdp->tx_ring, 0, tx_ringsize);
1173
1174 /* build Tx ring buffer */
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00001175 for (i = 0; i < mdp->num_tx_ring; i++) {
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001176 mdp->tx_skbuff[i] = NULL;
1177 txdesc = &mdp->tx_ring[i];
Yoshinori Sato71557a32008-08-06 19:49:00 -04001178 txdesc->status = cpu_to_edmac(mdp, TD_TFP);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001179 txdesc->buffer_length = 0;
Nobuhiro Iwamatsub0ca2a22008-06-30 11:08:17 +09001180 if (i == 0) {
Yoshinori Sato71557a32008-08-06 19:49:00 -04001181 /* Tx descriptor address set */
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001182 sh_eth_write(ndev, mdp->tx_desc_dma, TDLAR);
Simon Hormandb893472014-01-17 09:22:28 +09001183 if (sh_eth_is_gether(mdp) ||
1184 sh_eth_is_rz_fast_ether(mdp))
Yoshihiro Shimodac5ed5362011-03-07 21:59:38 +00001185 sh_eth_write(ndev, mdp->tx_desc_dma, TDFAR);
Nobuhiro Iwamatsub0ca2a22008-06-30 11:08:17 +09001186 }
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001187 }
1188
Yoshinori Sato71557a32008-08-06 19:49:00 -04001189 txdesc->status |= cpu_to_edmac(mdp, TD_TDLE);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001190}
1191
1192/* Get skb and descriptor buffer */
1193static int sh_eth_ring_init(struct net_device *ndev)
1194{
1195 struct sh_eth_private *mdp = netdev_priv(ndev);
1196 int rx_ringsize, tx_ringsize, ret = 0;
1197
Sergei Shtylyov128296f2014-01-03 15:52:22 +03001198 /* +26 gets the maximum ethernet encapsulation, +7 & ~7 because the
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001199 * card needs room to do 8 byte alignment, +2 so we can reserve
1200 * the first 2 bytes, and +16 gets room for the status word from the
1201 * card.
1202 */
1203 mdp->rx_buf_sz = (ndev->mtu <= 1492 ? PKT_BUF_SZ :
1204 (((ndev->mtu + 26 + 7) & ~7) + 2 + 16));
Magnus Damm503914c2009-12-15 21:16:55 -08001205 if (mdp->cd->rpadir)
1206 mdp->rx_buf_sz += NET_IP_ALIGN;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001207
1208 /* Allocate RX and TX skb rings */
Joe Perchesb2adaca2013-02-03 17:43:58 +00001209 mdp->rx_skbuff = kmalloc_array(mdp->num_rx_ring,
1210 sizeof(*mdp->rx_skbuff), GFP_KERNEL);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001211 if (!mdp->rx_skbuff) {
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001212 ret = -ENOMEM;
1213 return ret;
1214 }
1215
Joe Perchesb2adaca2013-02-03 17:43:58 +00001216 mdp->tx_skbuff = kmalloc_array(mdp->num_tx_ring,
1217 sizeof(*mdp->tx_skbuff), GFP_KERNEL);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001218 if (!mdp->tx_skbuff) {
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001219 ret = -ENOMEM;
1220 goto skb_ring_free;
1221 }
1222
1223 /* Allocate all Rx descriptors. */
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00001224 rx_ringsize = sizeof(struct sh_eth_rxdesc) * mdp->num_rx_ring;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001225 mdp->rx_ring = dma_alloc_coherent(NULL, rx_ringsize, &mdp->rx_desc_dma,
Joe Perchesd0320f72013-03-14 13:07:21 +00001226 GFP_KERNEL);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001227 if (!mdp->rx_ring) {
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001228 ret = -ENOMEM;
1229 goto desc_ring_free;
1230 }
1231
1232 mdp->dirty_rx = 0;
1233
1234 /* Allocate all Tx descriptors. */
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00001235 tx_ringsize = sizeof(struct sh_eth_txdesc) * mdp->num_tx_ring;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001236 mdp->tx_ring = dma_alloc_coherent(NULL, tx_ringsize, &mdp->tx_desc_dma,
Joe Perchesd0320f72013-03-14 13:07:21 +00001237 GFP_KERNEL);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001238 if (!mdp->tx_ring) {
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001239 ret = -ENOMEM;
1240 goto desc_ring_free;
1241 }
1242 return ret;
1243
1244desc_ring_free:
1245 /* free DMA buffer */
1246 dma_free_coherent(NULL, rx_ringsize, mdp->rx_ring, mdp->rx_desc_dma);
1247
1248skb_ring_free:
1249 /* Free Rx and Tx skb ring buffer */
1250 sh_eth_ring_free(ndev);
Yoshihiro Shimoda91c77552012-06-26 20:00:01 +00001251 mdp->tx_ring = NULL;
1252 mdp->rx_ring = NULL;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001253
1254 return ret;
1255}
1256
Yoshihiro Shimoda91c77552012-06-26 20:00:01 +00001257static void sh_eth_free_dma_buffer(struct sh_eth_private *mdp)
1258{
1259 int ringsize;
1260
1261 if (mdp->rx_ring) {
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00001262 ringsize = sizeof(struct sh_eth_rxdesc) * mdp->num_rx_ring;
Yoshihiro Shimoda91c77552012-06-26 20:00:01 +00001263 dma_free_coherent(NULL, ringsize, mdp->rx_ring,
1264 mdp->rx_desc_dma);
1265 mdp->rx_ring = NULL;
1266 }
1267
1268 if (mdp->tx_ring) {
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00001269 ringsize = sizeof(struct sh_eth_txdesc) * mdp->num_tx_ring;
Yoshihiro Shimoda91c77552012-06-26 20:00:01 +00001270 dma_free_coherent(NULL, ringsize, mdp->tx_ring,
1271 mdp->tx_desc_dma);
1272 mdp->tx_ring = NULL;
1273 }
1274}
1275
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00001276static int sh_eth_dev_init(struct net_device *ndev, bool start)
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001277{
1278 int ret = 0;
1279 struct sh_eth_private *mdp = netdev_priv(ndev);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001280 u32 val;
1281
1282 /* Soft Reset */
Nobuhiro Iwamatsu5cee1d32012-06-25 17:35:12 +00001283 ret = sh_eth_reset(ndev);
1284 if (ret)
Laurent Pinchartf738a132014-03-20 15:00:35 +01001285 return ret;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001286
Simon Horman55754f12013-07-23 10:18:04 +09001287 if (mdp->cd->rmiimode)
1288 sh_eth_write(ndev, 0x1, RMIIMODE);
1289
Nobuhiro Iwamatsub0ca2a22008-06-30 11:08:17 +09001290 /* Descriptor format */
1291 sh_eth_ring_format(ndev);
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +00001292 if (mdp->cd->rpadir)
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001293 sh_eth_write(ndev, mdp->cd->rpadir_value, RPADIR);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001294
1295 /* all sh_eth int mask */
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001296 sh_eth_write(ndev, 0, EESIPR);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001297
Yoshihiro Shimoda10b91942012-03-29 19:32:08 +00001298#if defined(__LITTLE_ENDIAN)
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +00001299 if (mdp->cd->hw_swap)
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001300 sh_eth_write(ndev, EDMR_EL, EDMR);
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +00001301 else
Nobuhiro Iwamatsub0ca2a22008-06-30 11:08:17 +09001302#endif
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001303 sh_eth_write(ndev, 0, EDMR);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001304
Nobuhiro Iwamatsub0ca2a22008-06-30 11:08:17 +09001305 /* FIFO size set */
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001306 sh_eth_write(ndev, mdp->cd->fdr_value, FDR);
1307 sh_eth_write(ndev, 0, TFTR);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001308
Ben Dooks530aa2d2014-06-03 12:21:13 +01001309 /* Frame recv control (enable multiple-packets per rx irq) */
1310 sh_eth_write(ndev, RMCR_RNC, RMCR);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001311
Nobuhiro Iwamatsub284fbe2015-01-08 15:25:07 +09001312 sh_eth_write(ndev, mdp->cd->trscer_err_mask, TRSCER);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001313
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +00001314 if (mdp->cd->bculr)
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001315 sh_eth_write(ndev, 0x800, BCULR); /* Burst sycle set */
Nobuhiro Iwamatsub0ca2a22008-06-30 11:08:17 +09001316
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001317 sh_eth_write(ndev, mdp->cd->fcftr_value, FCFTR);
Nobuhiro Iwamatsub0ca2a22008-06-30 11:08:17 +09001318
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +00001319 if (!mdp->cd->no_trimd)
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001320 sh_eth_write(ndev, 0, TRIMD);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001321
Nobuhiro Iwamatsub0ca2a22008-06-30 11:08:17 +09001322 /* Recv frame limit set register */
Yoshihiro Shimodafdb37a72012-02-06 23:55:15 +00001323 sh_eth_write(ndev, ndev->mtu + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN,
1324 RFLR);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001325
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001326 sh_eth_write(ndev, sh_eth_read(ndev, EESR), EESR);
Ben Hutchings283e38d2015-01-22 12:44:08 +00001327 if (start) {
1328 mdp->irq_enabled = true;
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00001329 sh_eth_write(ndev, mdp->cd->eesipr_value, EESIPR);
Ben Hutchings283e38d2015-01-22 12:44:08 +00001330 }
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001331
1332 /* PAUSE Prohibition */
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001333 val = (sh_eth_read(ndev, ECMR) & ECMR_DM) |
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001334 ECMR_ZPF | (mdp->duplex ? ECMR_DM : 0) | ECMR_TE | ECMR_RE;
1335
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001336 sh_eth_write(ndev, val, ECMR);
Nobuhiro Iwamatsub0ca2a22008-06-30 11:08:17 +09001337
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +00001338 if (mdp->cd->set_rate)
1339 mdp->cd->set_rate(ndev);
1340
Nobuhiro Iwamatsub0ca2a22008-06-30 11:08:17 +09001341 /* E-MAC Status Register clear */
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001342 sh_eth_write(ndev, mdp->cd->ecsr_value, ECSR);
Nobuhiro Iwamatsub0ca2a22008-06-30 11:08:17 +09001343
1344 /* E-MAC Interrupt Enable register */
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00001345 if (start)
1346 sh_eth_write(ndev, mdp->cd->ecsipr_value, ECSIPR);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001347
1348 /* Set MAC address */
1349 update_mac_address(ndev);
1350
1351 /* mask reset */
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +00001352 if (mdp->cd->apr)
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001353 sh_eth_write(ndev, APR_AP, APR);
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +00001354 if (mdp->cd->mpr)
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001355 sh_eth_write(ndev, MPR_MP, MPR);
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +00001356 if (mdp->cd->tpauser)
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001357 sh_eth_write(ndev, TPAUSER_UNLIMITED, TPAUSER);
Nobuhiro Iwamatsub0ca2a22008-06-30 11:08:17 +09001358
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00001359 if (start) {
1360 /* Setting the Rx mode will start the Rx process. */
1361 sh_eth_write(ndev, EDRRR_R, EDRRR);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001362
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00001363 netif_start_queue(ndev);
1364 }
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001365
1366 return ret;
1367}
1368
Ben Hutchings740c7f32015-01-27 00:49:32 +00001369static void sh_eth_dev_exit(struct net_device *ndev)
1370{
1371 struct sh_eth_private *mdp = netdev_priv(ndev);
1372 int i;
1373
1374 /* Deactivate all TX descriptors, so DMA should stop at next
1375 * packet boundary if it's currently running
1376 */
1377 for (i = 0; i < mdp->num_tx_ring; i++)
1378 mdp->tx_ring[i].status &= ~cpu_to_edmac(mdp, TD_TACT);
1379
1380 /* Disable TX FIFO egress to MAC */
1381 sh_eth_rcv_snd_disable(ndev);
1382
1383 /* Stop RX DMA at next packet boundary */
1384 sh_eth_write(ndev, 0, EDRRR);
1385
1386 /* Aside from TX DMA, we can't tell when the hardware is
1387 * really stopped, so we need to reset to make sure.
1388 * Before doing that, wait for long enough to *probably*
1389 * finish transmitting the last packet and poll stats.
1390 */
1391 msleep(2); /* max frame time at 10 Mbps < 1250 us */
1392 sh_eth_get_stats(ndev);
1393 sh_eth_reset(ndev);
Geert Uytterhoevena14c7d12015-02-27 17:16:26 +01001394
1395 /* Set MAC address again */
1396 update_mac_address(ndev);
Ben Hutchings740c7f32015-01-27 00:49:32 +00001397}
1398
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001399/* free Tx skb function */
1400static int sh_eth_txfree(struct net_device *ndev)
1401{
1402 struct sh_eth_private *mdp = netdev_priv(ndev);
1403 struct sh_eth_txdesc *txdesc;
Sergei Shtylyov128296f2014-01-03 15:52:22 +03001404 int free_num = 0;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001405 int entry = 0;
1406
1407 for (; mdp->cur_tx - mdp->dirty_tx > 0; mdp->dirty_tx++) {
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00001408 entry = mdp->dirty_tx % mdp->num_tx_ring;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001409 txdesc = &mdp->tx_ring[entry];
Yoshinori Sato71557a32008-08-06 19:49:00 -04001410 if (txdesc->status & cpu_to_edmac(mdp, TD_TACT))
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001411 break;
Ben Hutchings7d7355f2015-03-03 00:52:00 +00001412 /* TACT bit must be checked before all the following reads */
1413 rmb();
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001414 /* Free the original skb. */
1415 if (mdp->tx_skbuff[entry]) {
Yoshihiro Shimoda31fcb992011-06-30 22:52:13 +00001416 dma_unmap_single(&ndev->dev, txdesc->addr,
1417 txdesc->buffer_length, DMA_TO_DEVICE);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001418 dev_kfree_skb_irq(mdp->tx_skbuff[entry]);
1419 mdp->tx_skbuff[entry] = NULL;
Sergei Shtylyov128296f2014-01-03 15:52:22 +03001420 free_num++;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001421 }
Yoshinori Sato71557a32008-08-06 19:49:00 -04001422 txdesc->status = cpu_to_edmac(mdp, TD_TFP);
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00001423 if (entry >= mdp->num_tx_ring - 1)
Yoshinori Sato71557a32008-08-06 19:49:00 -04001424 txdesc->status |= cpu_to_edmac(mdp, TD_TDLE);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001425
Eric Dumazetbb7d92e2012-02-06 22:17:21 +00001426 ndev->stats.tx_packets++;
1427 ndev->stats.tx_bytes += txdesc->buffer_length;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001428 }
Sergei Shtylyov128296f2014-01-03 15:52:22 +03001429 return free_num;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001430}
1431
1432/* Packet receive function */
Sergei Shtylyov37191092013-06-19 23:30:23 +04001433static int sh_eth_rx(struct net_device *ndev, u32 intr_status, int *quota)
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001434{
1435 struct sh_eth_private *mdp = netdev_priv(ndev);
1436 struct sh_eth_rxdesc *rxdesc;
1437
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00001438 int entry = mdp->cur_rx % mdp->num_rx_ring;
1439 int boguscnt = (mdp->dirty_rx + mdp->num_rx_ring) - mdp->cur_rx;
Mitsuhiro Kimura319cd522014-12-09 21:23:42 +09001440 int limit;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001441 struct sk_buff *skb;
1442 u16 pkt_len = 0;
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +00001443 u32 desc_status;
Mitsuhiro Kimura4d6a9492014-11-27 20:34:00 +09001444 int skbuff_size = mdp->rx_buf_sz + SH_ETH_RX_ALIGN - 1;
Ben Hutchings52b9fa32015-01-27 00:50:24 +00001445 dma_addr_t dma_addr;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001446
Mitsuhiro Kimura319cd522014-12-09 21:23:42 +09001447 boguscnt = min(boguscnt, *quota);
1448 limit = boguscnt;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001449 rxdesc = &mdp->rx_ring[entry];
Yoshinori Sato71557a32008-08-06 19:49:00 -04001450 while (!(rxdesc->status & cpu_to_edmac(mdp, RD_RACT))) {
Ben Hutchings7d7355f2015-03-03 00:52:00 +00001451 /* RACT bit must be checked before all the following reads */
1452 rmb();
Yoshinori Sato71557a32008-08-06 19:49:00 -04001453 desc_status = edmac_to_cpu(mdp, rxdesc->status);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001454 pkt_len = rxdesc->frame_length;
1455
1456 if (--boguscnt < 0)
1457 break;
1458
1459 if (!(desc_status & RDFEND))
Eric Dumazetbb7d92e2012-02-06 22:17:21 +00001460 ndev->stats.rx_length_errors++;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001461
Sergei Shtylyov128296f2014-01-03 15:52:22 +03001462 /* In case of almost all GETHER/ETHERs, the Receive Frame State
Yoshihiro Shimodadd019892013-06-13 10:15:45 +09001463 * (RFS) bits in the Receive Descriptor 0 are from bit 9 to
Ben Hutchings9b4a6362015-03-03 00:52:39 +00001464 * bit 0. However, in case of the R8A7740 and R7S72100
1465 * the RFS bits are from bit 25 to bit 16. So, the
Simon Hormandb893472014-01-17 09:22:28 +09001466 * driver needs right shifting by 16.
Yoshihiro Shimodadd019892013-06-13 10:15:45 +09001467 */
Sergei Shtylyovac8025a2013-06-13 22:12:45 +04001468 if (mdp->cd->shift_rd0)
1469 desc_status >>= 16;
Yoshihiro Shimodadd019892013-06-13 10:15:45 +09001470
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001471 if (desc_status & (RD_RFS1 | RD_RFS2 | RD_RFS3 | RD_RFS4 |
1472 RD_RFS5 | RD_RFS6 | RD_RFS10)) {
Eric Dumazetbb7d92e2012-02-06 22:17:21 +00001473 ndev->stats.rx_errors++;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001474 if (desc_status & RD_RFS1)
Eric Dumazetbb7d92e2012-02-06 22:17:21 +00001475 ndev->stats.rx_crc_errors++;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001476 if (desc_status & RD_RFS2)
Eric Dumazetbb7d92e2012-02-06 22:17:21 +00001477 ndev->stats.rx_frame_errors++;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001478 if (desc_status & RD_RFS3)
Eric Dumazetbb7d92e2012-02-06 22:17:21 +00001479 ndev->stats.rx_length_errors++;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001480 if (desc_status & RD_RFS4)
Eric Dumazetbb7d92e2012-02-06 22:17:21 +00001481 ndev->stats.rx_length_errors++;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001482 if (desc_status & RD_RFS6)
Eric Dumazetbb7d92e2012-02-06 22:17:21 +00001483 ndev->stats.rx_missed_errors++;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001484 if (desc_status & RD_RFS10)
Eric Dumazetbb7d92e2012-02-06 22:17:21 +00001485 ndev->stats.rx_over_errors++;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001486 } else {
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +00001487 if (!mdp->cd->hw_swap)
1488 sh_eth_soft_swap(
1489 phys_to_virt(ALIGN(rxdesc->addr, 4)),
1490 pkt_len + 2);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001491 skb = mdp->rx_skbuff[entry];
1492 mdp->rx_skbuff[entry] = NULL;
Magnus Damm503914c2009-12-15 21:16:55 -08001493 if (mdp->cd->rpadir)
1494 skb_reserve(skb, NET_IP_ALIGN);
Ben Hutchings52b9fa32015-01-27 00:50:24 +00001495 dma_unmap_single(&ndev->dev, rxdesc->addr,
1496 ALIGN(mdp->rx_buf_sz, 16),
1497 DMA_FROM_DEVICE);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001498 skb_put(skb, pkt_len);
1499 skb->protocol = eth_type_trans(skb, ndev);
Sergei Shtylyova8e9fd02013-09-03 03:03:10 +04001500 netif_receive_skb(skb);
Eric Dumazetbb7d92e2012-02-06 22:17:21 +00001501 ndev->stats.rx_packets++;
1502 ndev->stats.rx_bytes += pkt_len;
Ben Hutchings25b77ad2015-02-26 20:33:30 +00001503 if (desc_status & RD_RFS8)
1504 ndev->stats.multicast++;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001505 }
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00001506 entry = (++mdp->cur_rx) % mdp->num_rx_ring;
Yoshihiro Shimoda862df492009-05-24 23:53:40 +00001507 rxdesc = &mdp->rx_ring[entry];
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001508 }
1509
1510 /* Refill the Rx ring buffers. */
1511 for (; mdp->cur_rx - mdp->dirty_rx > 0; mdp->dirty_rx++) {
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00001512 entry = mdp->dirty_rx % mdp->num_rx_ring;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001513 rxdesc = &mdp->rx_ring[entry];
Nobuhiro Iwamatsub0ca2a22008-06-30 11:08:17 +09001514 /* The size of the buffer is 16 byte boundary. */
Yoshihiro Shimoda0029d642009-05-24 23:53:20 +00001515 rxdesc->buffer_length = ALIGN(mdp->rx_buf_sz, 16);
Nobuhiro Iwamatsub0ca2a22008-06-30 11:08:17 +09001516
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001517 if (mdp->rx_skbuff[entry] == NULL) {
Mitsuhiro Kimura4d6a9492014-11-27 20:34:00 +09001518 skb = netdev_alloc_skb(ndev, skbuff_size);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001519 if (skb == NULL)
1520 break; /* Better luck next round. */
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +00001521 sh_eth_set_receive_align(skb);
Ben Hutchings52b9fa32015-01-27 00:50:24 +00001522 dma_addr = dma_map_single(&ndev->dev, skb->data,
1523 rxdesc->buffer_length,
1524 DMA_FROM_DEVICE);
1525 if (dma_mapping_error(&ndev->dev, dma_addr)) {
1526 kfree_skb(skb);
1527 break;
1528 }
1529 mdp->rx_skbuff[entry] = skb;
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +00001530
Eric Dumazetbc8acf22010-09-02 13:07:41 -07001531 skb_checksum_none_assert(skb);
Ben Hutchings52b9fa32015-01-27 00:50:24 +00001532 rxdesc->addr = dma_addr;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001533 }
Ben Hutchings7d7355f2015-03-03 00:52:00 +00001534 wmb(); /* RACT bit must be set after all the above writes */
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00001535 if (entry >= mdp->num_rx_ring - 1)
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001536 rxdesc->status |=
Yoshinori Sato71557a32008-08-06 19:49:00 -04001537 cpu_to_edmac(mdp, RD_RACT | RD_RFP | RD_RDEL);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001538 else
1539 rxdesc->status |=
Yoshinori Sato71557a32008-08-06 19:49:00 -04001540 cpu_to_edmac(mdp, RD_RACT | RD_RFP);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001541 }
1542
1543 /* Restart Rx engine if stopped. */
1544 /* If we don't need to check status, don't. -KDU */
Yoshihiro Shimoda79fba9f2012-05-28 23:07:55 +00001545 if (!(sh_eth_read(ndev, EDRRR) & EDRRR_R)) {
Yoshihiro Shimodaa18e08b2012-06-20 15:26:34 +00001546 /* fix the values for the next receiving if RDE is set */
Ben Hutchings6ded2862015-03-03 00:52:08 +00001547 if (intr_status & EESR_RDE && mdp->reg_offset[RDFAR] != 0) {
Sergei Shtylyov128296f2014-01-03 15:52:22 +03001548 u32 count = (sh_eth_read(ndev, RDFAR) -
1549 sh_eth_read(ndev, RDLAR)) >> 4;
1550
1551 mdp->cur_rx = count;
1552 mdp->dirty_rx = count;
1553 }
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001554 sh_eth_write(ndev, EDRRR_R, EDRRR);
Yoshihiro Shimoda79fba9f2012-05-28 23:07:55 +00001555 }
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001556
Mitsuhiro Kimura319cd522014-12-09 21:23:42 +09001557 *quota -= limit - boguscnt - 1;
1558
Yoshihiro Shimoda4f809ce2014-06-10 09:40:14 +09001559 return *quota <= 0;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001560}
1561
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001562static void sh_eth_rcv_snd_disable(struct net_device *ndev)
Nobuhiro Iwamatsudc19e4e2011-02-15 21:17:32 +00001563{
1564 /* disable tx and rx */
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001565 sh_eth_write(ndev, sh_eth_read(ndev, ECMR) &
1566 ~(ECMR_RE | ECMR_TE), ECMR);
Nobuhiro Iwamatsudc19e4e2011-02-15 21:17:32 +00001567}
1568
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001569static void sh_eth_rcv_snd_enable(struct net_device *ndev)
Nobuhiro Iwamatsudc19e4e2011-02-15 21:17:32 +00001570{
1571 /* enable tx and rx */
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001572 sh_eth_write(ndev, sh_eth_read(ndev, ECMR) |
1573 (ECMR_RE | ECMR_TE), ECMR);
Nobuhiro Iwamatsudc19e4e2011-02-15 21:17:32 +00001574}
1575
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001576/* error control function */
Geert Uytterhoeven0799c2d2015-01-15 11:54:28 +01001577static void sh_eth_error(struct net_device *ndev, u32 intr_status)
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001578{
1579 struct sh_eth_private *mdp = netdev_priv(ndev);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001580 u32 felic_stat;
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +00001581 u32 link_stat;
1582 u32 mask;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001583
1584 if (intr_status & EESR_ECI) {
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001585 felic_stat = sh_eth_read(ndev, ECSR);
1586 sh_eth_write(ndev, felic_stat, ECSR); /* clear int */
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001587 if (felic_stat & ECSR_ICD)
Eric Dumazetbb7d92e2012-02-06 22:17:21 +00001588 ndev->stats.tx_carrier_errors++;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001589 if (felic_stat & ECSR_LCHNG) {
1590 /* Link Changed */
Yoshihiro Shimoda49235762009-08-27 23:25:03 +00001591 if (mdp->cd->no_psr || mdp->no_ether_link) {
Sergei Shtylyov1e1b8122013-03-31 09:50:07 +00001592 goto ignore_link;
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +00001593 } else {
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001594 link_stat = (sh_eth_read(ndev, PSR));
Yoshihiro Shimoda49235762009-08-27 23:25:03 +00001595 if (mdp->ether_link_active_low)
1596 link_stat = ~link_stat;
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +00001597 }
Sergei Shtylyov128296f2014-01-03 15:52:22 +03001598 if (!(link_stat & PHY_ST_LINK)) {
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001599 sh_eth_rcv_snd_disable(ndev);
Sergei Shtylyov128296f2014-01-03 15:52:22 +03001600 } else {
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001601 /* Link Up */
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001602 sh_eth_write(ndev, sh_eth_read(ndev, EESIPR) &
Sergei Shtylyov128296f2014-01-03 15:52:22 +03001603 ~DMAC_M_ECI, EESIPR);
1604 /* clear int */
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001605 sh_eth_write(ndev, sh_eth_read(ndev, ECSR),
Sergei Shtylyov128296f2014-01-03 15:52:22 +03001606 ECSR);
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001607 sh_eth_write(ndev, sh_eth_read(ndev, EESIPR) |
Sergei Shtylyov128296f2014-01-03 15:52:22 +03001608 DMAC_M_ECI, EESIPR);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001609 /* enable tx and rx */
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001610 sh_eth_rcv_snd_enable(ndev);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001611 }
1612 }
1613 }
1614
Sergei Shtylyov1e1b8122013-03-31 09:50:07 +00001615ignore_link:
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001616 if (intr_status & EESR_TWB) {
Sergei Shtylyov4eb313a2013-06-21 01:13:42 +04001617 /* Unused write back interrupt */
1618 if (intr_status & EESR_TABT) { /* Transmit Abort int */
Eric Dumazetbb7d92e2012-02-06 22:17:21 +00001619 ndev->stats.tx_aborted_errors++;
Sergei Shtylyov8d5009f2014-03-15 03:30:59 +03001620 netif_err(mdp, tx_err, ndev, "Transmit Abort\n");
Sergei Shtylyov4eb313a2013-06-21 01:13:42 +04001621 }
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001622 }
1623
1624 if (intr_status & EESR_RABT) {
1625 /* Receive Abort int */
1626 if (intr_status & EESR_RFRMER) {
1627 /* Receive Frame Overflow int */
Eric Dumazetbb7d92e2012-02-06 22:17:21 +00001628 ndev->stats.rx_frame_errors++;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001629 }
1630 }
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +00001631
Nobuhiro Iwamatsudc19e4e2011-02-15 21:17:32 +00001632 if (intr_status & EESR_TDE) {
1633 /* Transmit Descriptor Empty int */
Eric Dumazetbb7d92e2012-02-06 22:17:21 +00001634 ndev->stats.tx_fifo_errors++;
Sergei Shtylyov8d5009f2014-03-15 03:30:59 +03001635 netif_err(mdp, tx_err, ndev, "Transmit Descriptor Empty\n");
Nobuhiro Iwamatsudc19e4e2011-02-15 21:17:32 +00001636 }
1637
1638 if (intr_status & EESR_TFE) {
1639 /* FIFO under flow */
Eric Dumazetbb7d92e2012-02-06 22:17:21 +00001640 ndev->stats.tx_fifo_errors++;
Sergei Shtylyov8d5009f2014-03-15 03:30:59 +03001641 netif_err(mdp, tx_err, ndev, "Transmit FIFO Under flow\n");
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001642 }
1643
1644 if (intr_status & EESR_RDE) {
1645 /* Receive Descriptor Empty int */
Eric Dumazetbb7d92e2012-02-06 22:17:21 +00001646 ndev->stats.rx_over_errors++;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001647 }
Nobuhiro Iwamatsudc19e4e2011-02-15 21:17:32 +00001648
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001649 if (intr_status & EESR_RFE) {
1650 /* Receive FIFO Overflow int */
Eric Dumazetbb7d92e2012-02-06 22:17:21 +00001651 ndev->stats.rx_fifo_errors++;
Nobuhiro Iwamatsudc19e4e2011-02-15 21:17:32 +00001652 }
1653
1654 if (!mdp->cd->no_ade && (intr_status & EESR_ADE)) {
1655 /* Address Error */
Eric Dumazetbb7d92e2012-02-06 22:17:21 +00001656 ndev->stats.tx_fifo_errors++;
Sergei Shtylyov8d5009f2014-03-15 03:30:59 +03001657 netif_err(mdp, tx_err, ndev, "Address Error\n");
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001658 }
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +00001659
1660 mask = EESR_TWB | EESR_TABT | EESR_ADE | EESR_TDE | EESR_TFE;
1661 if (mdp->cd->no_ade)
1662 mask &= ~EESR_ADE;
1663 if (intr_status & mask) {
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001664 /* Tx error */
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001665 u32 edtrr = sh_eth_read(ndev, EDTRR);
Sergei Shtylyov090d5602014-01-11 02:41:49 +03001666
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001667 /* dmesg */
Sergei Shtylyovda246852014-03-15 03:29:14 +03001668 netdev_err(ndev, "TX error. status=%8.8x cur_tx=%8.8x dirty_tx=%8.8x state=%8.8x EDTRR=%8.8x.\n",
1669 intr_status, mdp->cur_tx, mdp->dirty_tx,
1670 (u32)ndev->state, edtrr);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001671 /* dirty buffer free */
1672 sh_eth_txfree(ndev);
1673
1674 /* SH7712 BUG */
Yoshihiro Shimodac5ed5362011-03-07 21:59:38 +00001675 if (edtrr ^ sh_eth_get_edtrr_trns(mdp)) {
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001676 /* tx dma start */
Yoshihiro Shimodac5ed5362011-03-07 21:59:38 +00001677 sh_eth_write(ndev, sh_eth_get_edtrr_trns(mdp), EDTRR);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001678 }
1679 /* wakeup */
1680 netif_wake_queue(ndev);
1681 }
1682}
1683
1684static irqreturn_t sh_eth_interrupt(int irq, void *netdev)
1685{
1686 struct net_device *ndev = netdev;
1687 struct sh_eth_private *mdp = netdev_priv(ndev);
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +00001688 struct sh_eth_cpu_data *cd = mdp->cd;
Nobuhiro Iwamatsu0e0fde32009-03-16 19:50:57 +00001689 irqreturn_t ret = IRQ_NONE;
Geert Uytterhoeven0799c2d2015-01-15 11:54:28 +01001690 u32 intr_status, intr_enable;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001691
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001692 spin_lock(&mdp->lock);
1693
Sergei Shtylyov3893b273452013-03-31 09:54:20 +00001694 /* Get interrupt status */
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001695 intr_status = sh_eth_read(ndev, EESR);
Sergei Shtylyov3893b273452013-03-31 09:54:20 +00001696 /* Mask it with the interrupt mask, forcing ECI interrupt to be always
1697 * enabled since it's the one that comes thru regardless of the mask,
1698 * and we need to fully handle it in sh_eth_error() in order to quench
1699 * it as it doesn't get cleared by just writing 1 to the ECI bit...
1700 */
Sergei Shtylyov37191092013-06-19 23:30:23 +04001701 intr_enable = sh_eth_read(ndev, EESIPR);
1702 intr_status &= intr_enable | DMAC_M_ECI;
1703 if (intr_status & (EESR_RX_CHECK | cd->tx_check | cd->eesr_err_check))
Nobuhiro Iwamatsu0e0fde32009-03-16 19:50:57 +00001704 ret = IRQ_HANDLED;
Sergei Shtylyov37191092013-06-19 23:30:23 +04001705 else
Ben Hutchings283e38d2015-01-22 12:44:08 +00001706 goto out;
1707
1708 if (!likely(mdp->irq_enabled)) {
1709 sh_eth_write(ndev, 0, EESIPR);
1710 goto out;
1711 }
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001712
Sergei Shtylyov37191092013-06-19 23:30:23 +04001713 if (intr_status & EESR_RX_CHECK) {
1714 if (napi_schedule_prep(&mdp->napi)) {
1715 /* Mask Rx interrupts */
1716 sh_eth_write(ndev, intr_enable & ~EESR_RX_CHECK,
1717 EESIPR);
1718 __napi_schedule(&mdp->napi);
1719 } else {
Sergei Shtylyovda246852014-03-15 03:29:14 +03001720 netdev_warn(ndev,
Geert Uytterhoeven0799c2d2015-01-15 11:54:28 +01001721 "ignoring interrupt, status 0x%08x, mask 0x%08x.\n",
Sergei Shtylyovda246852014-03-15 03:29:14 +03001722 intr_status, intr_enable);
Sergei Shtylyov37191092013-06-19 23:30:23 +04001723 }
1724 }
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001725
Nobuhiro Iwamatsub0ca2a22008-06-30 11:08:17 +09001726 /* Tx Check */
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +00001727 if (intr_status & cd->tx_check) {
Sergei Shtylyov37191092013-06-19 23:30:23 +04001728 /* Clear Tx interrupts */
1729 sh_eth_write(ndev, intr_status & cd->tx_check, EESR);
1730
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001731 sh_eth_txfree(ndev);
1732 netif_wake_queue(ndev);
1733 }
1734
Sergei Shtylyov37191092013-06-19 23:30:23 +04001735 if (intr_status & cd->eesr_err_check) {
1736 /* Clear error interrupts */
1737 sh_eth_write(ndev, intr_status & cd->eesr_err_check, EESR);
1738
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001739 sh_eth_error(ndev, intr_status);
Sergei Shtylyov37191092013-06-19 23:30:23 +04001740 }
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001741
Ben Hutchings283e38d2015-01-22 12:44:08 +00001742out:
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001743 spin_unlock(&mdp->lock);
1744
Nobuhiro Iwamatsu0e0fde32009-03-16 19:50:57 +00001745 return ret;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001746}
1747
Sergei Shtylyov37191092013-06-19 23:30:23 +04001748static int sh_eth_poll(struct napi_struct *napi, int budget)
1749{
1750 struct sh_eth_private *mdp = container_of(napi, struct sh_eth_private,
1751 napi);
1752 struct net_device *ndev = napi->dev;
1753 int quota = budget;
Geert Uytterhoeven0799c2d2015-01-15 11:54:28 +01001754 u32 intr_status;
Sergei Shtylyov37191092013-06-19 23:30:23 +04001755
1756 for (;;) {
1757 intr_status = sh_eth_read(ndev, EESR);
1758 if (!(intr_status & EESR_RX_CHECK))
1759 break;
1760 /* Clear Rx interrupts */
1761 sh_eth_write(ndev, intr_status & EESR_RX_CHECK, EESR);
1762
1763 if (sh_eth_rx(ndev, intr_status, &quota))
1764 goto out;
1765 }
1766
1767 napi_complete(napi);
1768
1769 /* Reenable Rx interrupts */
Ben Hutchings283e38d2015-01-22 12:44:08 +00001770 if (mdp->irq_enabled)
1771 sh_eth_write(ndev, mdp->cd->eesipr_value, EESIPR);
Sergei Shtylyov37191092013-06-19 23:30:23 +04001772out:
1773 return budget - quota;
1774}
1775
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001776/* PHY state control function */
1777static void sh_eth_adjust_link(struct net_device *ndev)
1778{
1779 struct sh_eth_private *mdp = netdev_priv(ndev);
1780 struct phy_device *phydev = mdp->phydev;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001781 int new_state = 0;
1782
Sergei Shtylyov3340d2a2013-03-31 10:11:04 +00001783 if (phydev->link) {
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001784 if (phydev->duplex != mdp->duplex) {
1785 new_state = 1;
1786 mdp->duplex = phydev->duplex;
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +00001787 if (mdp->cd->set_duplex)
1788 mdp->cd->set_duplex(ndev);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001789 }
1790
1791 if (phydev->speed != mdp->speed) {
1792 new_state = 1;
1793 mdp->speed = phydev->speed;
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +00001794 if (mdp->cd->set_rate)
1795 mdp->cd->set_rate(ndev);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001796 }
Sergei Shtylyov3340d2a2013-03-31 10:11:04 +00001797 if (!mdp->link) {
Yoshihiro Shimoda91a56152011-07-05 20:33:51 +00001798 sh_eth_write(ndev,
Sergei Shtylyov128296f2014-01-03 15:52:22 +03001799 sh_eth_read(ndev, ECMR) & ~ECMR_TXF,
1800 ECMR);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001801 new_state = 1;
1802 mdp->link = phydev->link;
Sergei Shtylyov1e1b8122013-03-31 09:50:07 +00001803 if (mdp->cd->no_psr || mdp->no_ether_link)
1804 sh_eth_rcv_snd_enable(ndev);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001805 }
1806 } else if (mdp->link) {
1807 new_state = 1;
Sergei Shtylyov3340d2a2013-03-31 10:11:04 +00001808 mdp->link = 0;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001809 mdp->speed = 0;
1810 mdp->duplex = -1;
Sergei Shtylyov1e1b8122013-03-31 09:50:07 +00001811 if (mdp->cd->no_psr || mdp->no_ether_link)
1812 sh_eth_rcv_snd_disable(ndev);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001813 }
1814
Nobuhiro Iwamatsudc19e4e2011-02-15 21:17:32 +00001815 if (new_state && netif_msg_link(mdp))
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001816 phy_print_status(phydev);
1817}
1818
1819/* PHY init function */
1820static int sh_eth_phy_init(struct net_device *ndev)
1821{
Ben Dooks702eca02014-03-12 17:47:40 +00001822 struct device_node *np = ndev->dev.parent->of_node;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001823 struct sh_eth_private *mdp = netdev_priv(ndev);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001824 struct phy_device *phydev = NULL;
1825
Sergei Shtylyov3340d2a2013-03-31 10:11:04 +00001826 mdp->link = 0;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001827 mdp->speed = 0;
1828 mdp->duplex = -1;
1829
1830 /* Try connect to PHY */
Ben Dooks702eca02014-03-12 17:47:40 +00001831 if (np) {
1832 struct device_node *pn;
1833
1834 pn = of_parse_phandle(np, "phy-handle", 0);
1835 phydev = of_phy_connect(ndev, pn,
1836 sh_eth_adjust_link, 0,
1837 mdp->phy_interface);
1838
1839 if (!phydev)
1840 phydev = ERR_PTR(-ENOENT);
1841 } else {
1842 char phy_id[MII_BUS_ID_SIZE + 3];
1843
1844 snprintf(phy_id, sizeof(phy_id), PHY_ID_FMT,
1845 mdp->mii_bus->id, mdp->phy_id);
1846
1847 phydev = phy_connect(ndev, phy_id, sh_eth_adjust_link,
1848 mdp->phy_interface);
1849 }
1850
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001851 if (IS_ERR(phydev)) {
Sergei Shtylyovda246852014-03-15 03:29:14 +03001852 netdev_err(ndev, "failed to connect PHY\n");
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001853 return PTR_ERR(phydev);
1854 }
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +00001855
Sergei Shtylyovda246852014-03-15 03:29:14 +03001856 netdev_info(ndev, "attached PHY %d (IRQ %d) to driver %s\n",
1857 phydev->addr, phydev->irq, phydev->drv->name);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001858
1859 mdp->phydev = phydev;
1860
1861 return 0;
1862}
1863
1864/* PHY control start function */
1865static int sh_eth_phy_start(struct net_device *ndev)
1866{
1867 struct sh_eth_private *mdp = netdev_priv(ndev);
1868 int ret;
1869
1870 ret = sh_eth_phy_init(ndev);
1871 if (ret)
1872 return ret;
1873
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07001874 phy_start(mdp->phydev);
1875
1876 return 0;
1877}
1878
Nobuhiro Iwamatsudc19e4e2011-02-15 21:17:32 +00001879static int sh_eth_get_settings(struct net_device *ndev,
Sergei Shtylyov128296f2014-01-03 15:52:22 +03001880 struct ethtool_cmd *ecmd)
Nobuhiro Iwamatsudc19e4e2011-02-15 21:17:32 +00001881{
1882 struct sh_eth_private *mdp = netdev_priv(ndev);
1883 unsigned long flags;
1884 int ret;
1885
Ben Hutchings4f9dce232015-01-16 17:51:25 +00001886 if (!mdp->phydev)
1887 return -ENODEV;
1888
Nobuhiro Iwamatsudc19e4e2011-02-15 21:17:32 +00001889 spin_lock_irqsave(&mdp->lock, flags);
1890 ret = phy_ethtool_gset(mdp->phydev, ecmd);
1891 spin_unlock_irqrestore(&mdp->lock, flags);
1892
1893 return ret;
1894}
1895
1896static int sh_eth_set_settings(struct net_device *ndev,
Sergei Shtylyov128296f2014-01-03 15:52:22 +03001897 struct ethtool_cmd *ecmd)
Nobuhiro Iwamatsudc19e4e2011-02-15 21:17:32 +00001898{
1899 struct sh_eth_private *mdp = netdev_priv(ndev);
1900 unsigned long flags;
1901 int ret;
Nobuhiro Iwamatsudc19e4e2011-02-15 21:17:32 +00001902
Ben Hutchings4f9dce232015-01-16 17:51:25 +00001903 if (!mdp->phydev)
1904 return -ENODEV;
1905
Nobuhiro Iwamatsudc19e4e2011-02-15 21:17:32 +00001906 spin_lock_irqsave(&mdp->lock, flags);
1907
1908 /* disable tx and rx */
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001909 sh_eth_rcv_snd_disable(ndev);
Nobuhiro Iwamatsudc19e4e2011-02-15 21:17:32 +00001910
1911 ret = phy_ethtool_sset(mdp->phydev, ecmd);
1912 if (ret)
1913 goto error_exit;
1914
1915 if (ecmd->duplex == DUPLEX_FULL)
1916 mdp->duplex = 1;
1917 else
1918 mdp->duplex = 0;
1919
1920 if (mdp->cd->set_duplex)
1921 mdp->cd->set_duplex(ndev);
1922
1923error_exit:
1924 mdelay(1);
1925
1926 /* enable tx and rx */
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00001927 sh_eth_rcv_snd_enable(ndev);
Nobuhiro Iwamatsudc19e4e2011-02-15 21:17:32 +00001928
1929 spin_unlock_irqrestore(&mdp->lock, flags);
1930
1931 return ret;
1932}
1933
1934static int sh_eth_nway_reset(struct net_device *ndev)
1935{
1936 struct sh_eth_private *mdp = netdev_priv(ndev);
1937 unsigned long flags;
1938 int ret;
1939
Ben Hutchings4f9dce232015-01-16 17:51:25 +00001940 if (!mdp->phydev)
1941 return -ENODEV;
1942
Nobuhiro Iwamatsudc19e4e2011-02-15 21:17:32 +00001943 spin_lock_irqsave(&mdp->lock, flags);
1944 ret = phy_start_aneg(mdp->phydev);
1945 spin_unlock_irqrestore(&mdp->lock, flags);
1946
1947 return ret;
1948}
1949
1950static u32 sh_eth_get_msglevel(struct net_device *ndev)
1951{
1952 struct sh_eth_private *mdp = netdev_priv(ndev);
1953 return mdp->msg_enable;
1954}
1955
1956static void sh_eth_set_msglevel(struct net_device *ndev, u32 value)
1957{
1958 struct sh_eth_private *mdp = netdev_priv(ndev);
1959 mdp->msg_enable = value;
1960}
1961
1962static const char sh_eth_gstrings_stats[][ETH_GSTRING_LEN] = {
1963 "rx_current", "tx_current",
1964 "rx_dirty", "tx_dirty",
1965};
1966#define SH_ETH_STATS_LEN ARRAY_SIZE(sh_eth_gstrings_stats)
1967
1968static int sh_eth_get_sset_count(struct net_device *netdev, int sset)
1969{
1970 switch (sset) {
1971 case ETH_SS_STATS:
1972 return SH_ETH_STATS_LEN;
1973 default:
1974 return -EOPNOTSUPP;
1975 }
1976}
1977
1978static void sh_eth_get_ethtool_stats(struct net_device *ndev,
Sergei Shtylyov128296f2014-01-03 15:52:22 +03001979 struct ethtool_stats *stats, u64 *data)
Nobuhiro Iwamatsudc19e4e2011-02-15 21:17:32 +00001980{
1981 struct sh_eth_private *mdp = netdev_priv(ndev);
1982 int i = 0;
1983
1984 /* device-specific stats */
1985 data[i++] = mdp->cur_rx;
1986 data[i++] = mdp->cur_tx;
1987 data[i++] = mdp->dirty_rx;
1988 data[i++] = mdp->dirty_tx;
1989}
1990
1991static void sh_eth_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
1992{
1993 switch (stringset) {
1994 case ETH_SS_STATS:
1995 memcpy(data, *sh_eth_gstrings_stats,
Sergei Shtylyov128296f2014-01-03 15:52:22 +03001996 sizeof(sh_eth_gstrings_stats));
Nobuhiro Iwamatsudc19e4e2011-02-15 21:17:32 +00001997 break;
1998 }
1999}
2000
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00002001static void sh_eth_get_ringparam(struct net_device *ndev,
2002 struct ethtool_ringparam *ring)
2003{
2004 struct sh_eth_private *mdp = netdev_priv(ndev);
2005
2006 ring->rx_max_pending = RX_RING_MAX;
2007 ring->tx_max_pending = TX_RING_MAX;
2008 ring->rx_pending = mdp->num_rx_ring;
2009 ring->tx_pending = mdp->num_tx_ring;
2010}
2011
2012static int sh_eth_set_ringparam(struct net_device *ndev,
2013 struct ethtool_ringparam *ring)
2014{
2015 struct sh_eth_private *mdp = netdev_priv(ndev);
2016 int ret;
2017
2018 if (ring->tx_pending > TX_RING_MAX ||
2019 ring->rx_pending > RX_RING_MAX ||
2020 ring->tx_pending < TX_RING_MIN ||
2021 ring->rx_pending < RX_RING_MIN)
2022 return -EINVAL;
2023 if (ring->rx_mini_pending || ring->rx_jumbo_pending)
2024 return -EINVAL;
2025
2026 if (netif_running(ndev)) {
Ben Hutchingsbd888912015-01-22 12:40:25 +00002027 netif_device_detach(ndev);
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00002028 netif_tx_disable(ndev);
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00002029
Ben Hutchings283e38d2015-01-22 12:44:08 +00002030 /* Serialise with the interrupt handler and NAPI, then
2031 * disable interrupts. We have to clear the
2032 * irq_enabled flag first to ensure that interrupts
2033 * won't be re-enabled.
2034 */
2035 mdp->irq_enabled = false;
2036 synchronize_irq(ndev->irq);
2037 napi_synchronize(&mdp->napi);
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00002038 sh_eth_write(ndev, 0x0000, EESIPR);
Ben Hutchings283e38d2015-01-22 12:44:08 +00002039
Ben Hutchings740c7f32015-01-27 00:49:32 +00002040 sh_eth_dev_exit(ndev);
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00002041
Ben Hutchings084236d2015-01-22 12:41:34 +00002042 /* Free all the skbuffs in the Rx queue. */
2043 sh_eth_ring_free(ndev);
2044 /* Free DMA buffer */
2045 sh_eth_free_dma_buffer(mdp);
2046 }
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00002047
2048 /* Set new parameters */
2049 mdp->num_rx_ring = ring->rx_pending;
2050 mdp->num_tx_ring = ring->tx_pending;
2051
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00002052 if (netif_running(ndev)) {
Ben Hutchings084236d2015-01-22 12:41:34 +00002053 ret = sh_eth_ring_init(ndev);
2054 if (ret < 0) {
2055 netdev_err(ndev, "%s: sh_eth_ring_init failed.\n",
2056 __func__);
2057 return ret;
2058 }
2059 ret = sh_eth_dev_init(ndev, false);
2060 if (ret < 0) {
2061 netdev_err(ndev, "%s: sh_eth_dev_init failed.\n",
2062 __func__);
2063 return ret;
2064 }
2065
Ben Hutchings283e38d2015-01-22 12:44:08 +00002066 mdp->irq_enabled = true;
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00002067 sh_eth_write(ndev, mdp->cd->eesipr_value, EESIPR);
2068 /* Setting the Rx mode will start the Rx process. */
2069 sh_eth_write(ndev, EDRRR_R, EDRRR);
Ben Hutchingsbd888912015-01-22 12:40:25 +00002070 netif_device_attach(ndev);
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00002071 }
2072
2073 return 0;
2074}
2075
stephen hemminger9b07be42012-01-04 12:59:49 +00002076static const struct ethtool_ops sh_eth_ethtool_ops = {
Nobuhiro Iwamatsudc19e4e2011-02-15 21:17:32 +00002077 .get_settings = sh_eth_get_settings,
2078 .set_settings = sh_eth_set_settings,
stephen hemminger9b07be42012-01-04 12:59:49 +00002079 .nway_reset = sh_eth_nway_reset,
Nobuhiro Iwamatsudc19e4e2011-02-15 21:17:32 +00002080 .get_msglevel = sh_eth_get_msglevel,
2081 .set_msglevel = sh_eth_set_msglevel,
stephen hemminger9b07be42012-01-04 12:59:49 +00002082 .get_link = ethtool_op_get_link,
Nobuhiro Iwamatsudc19e4e2011-02-15 21:17:32 +00002083 .get_strings = sh_eth_get_strings,
2084 .get_ethtool_stats = sh_eth_get_ethtool_stats,
2085 .get_sset_count = sh_eth_get_sset_count,
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00002086 .get_ringparam = sh_eth_get_ringparam,
2087 .set_ringparam = sh_eth_set_ringparam,
Nobuhiro Iwamatsudc19e4e2011-02-15 21:17:32 +00002088};
2089
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002090/* network device open function */
2091static int sh_eth_open(struct net_device *ndev)
2092{
2093 int ret = 0;
2094 struct sh_eth_private *mdp = netdev_priv(ndev);
2095
Magnus Dammbcd51492009-10-09 00:20:04 +00002096 pm_runtime_get_sync(&mdp->pdev->dev);
2097
Sergei Shtylyovd2779e92013-09-04 02:41:27 +04002098 napi_enable(&mdp->napi);
2099
Joe Perchesa0607fd2009-11-18 23:29:17 -08002100 ret = request_irq(ndev->irq, sh_eth_interrupt,
Nobuhiro Iwamatsu5b3dfd12013-06-06 09:49:30 +00002101 mdp->cd->irq_flags, ndev->name, ndev);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002102 if (ret) {
Sergei Shtylyovda246852014-03-15 03:29:14 +03002103 netdev_err(ndev, "Can not assign IRQ number\n");
Sergei Shtylyovd2779e92013-09-04 02:41:27 +04002104 goto out_napi_off;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002105 }
2106
2107 /* Descriptor set */
2108 ret = sh_eth_ring_init(ndev);
2109 if (ret)
2110 goto out_free_irq;
2111
2112 /* device init */
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00002113 ret = sh_eth_dev_init(ndev, true);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002114 if (ret)
2115 goto out_free_irq;
2116
2117 /* PHY control start*/
2118 ret = sh_eth_phy_start(ndev);
2119 if (ret)
2120 goto out_free_irq;
2121
Mitsuhiro Kimura7fa29552014-11-28 10:04:15 +09002122 mdp->is_opened = 1;
2123
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002124 return ret;
2125
2126out_free_irq:
2127 free_irq(ndev->irq, ndev);
Sergei Shtylyovd2779e92013-09-04 02:41:27 +04002128out_napi_off:
2129 napi_disable(&mdp->napi);
Magnus Dammbcd51492009-10-09 00:20:04 +00002130 pm_runtime_put_sync(&mdp->pdev->dev);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002131 return ret;
2132}
2133
2134/* Timeout function */
2135static void sh_eth_tx_timeout(struct net_device *ndev)
2136{
2137 struct sh_eth_private *mdp = netdev_priv(ndev);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002138 struct sh_eth_rxdesc *rxdesc;
2139 int i;
2140
2141 netif_stop_queue(ndev);
2142
Sergei Shtylyov8d5009f2014-03-15 03:30:59 +03002143 netif_err(mdp, timer, ndev,
2144 "transmit timed out, status %8.8x, resetting...\n",
Geert Uytterhoeven0799c2d2015-01-15 11:54:28 +01002145 sh_eth_read(ndev, EESR));
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002146
2147 /* tx_errors count up */
Eric Dumazetbb7d92e2012-02-06 22:17:21 +00002148 ndev->stats.tx_errors++;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002149
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002150 /* Free all the skbuffs in the Rx queue. */
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00002151 for (i = 0; i < mdp->num_rx_ring; i++) {
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002152 rxdesc = &mdp->rx_ring[i];
2153 rxdesc->status = 0;
2154 rxdesc->addr = 0xBADF00D0;
Sergei Shtylyov179d80a2014-06-28 04:10:00 +04002155 dev_kfree_skb(mdp->rx_skbuff[i]);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002156 mdp->rx_skbuff[i] = NULL;
2157 }
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00002158 for (i = 0; i < mdp->num_tx_ring; i++) {
Sergei Shtylyov179d80a2014-06-28 04:10:00 +04002159 dev_kfree_skb(mdp->tx_skbuff[i]);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002160 mdp->tx_skbuff[i] = NULL;
2161 }
2162
2163 /* device init */
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00002164 sh_eth_dev_init(ndev, true);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002165}
2166
2167/* Packet transmit function */
2168static int sh_eth_start_xmit(struct sk_buff *skb, struct net_device *ndev)
2169{
2170 struct sh_eth_private *mdp = netdev_priv(ndev);
2171 struct sh_eth_txdesc *txdesc;
2172 u32 entry;
Nobuhiro Iwamatsufb5e2f92008-11-17 20:29:58 +00002173 unsigned long flags;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002174
2175 spin_lock_irqsave(&mdp->lock, flags);
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00002176 if ((mdp->cur_tx - mdp->dirty_tx) >= (mdp->num_tx_ring - 4)) {
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002177 if (!sh_eth_txfree(ndev)) {
Sergei Shtylyov8d5009f2014-03-15 03:30:59 +03002178 netif_warn(mdp, tx_queued, ndev, "TxFD exhausted.\n");
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002179 netif_stop_queue(ndev);
2180 spin_unlock_irqrestore(&mdp->lock, flags);
Patrick McHardy5b548142009-06-12 06:22:29 +00002181 return NETDEV_TX_BUSY;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002182 }
2183 }
2184 spin_unlock_irqrestore(&mdp->lock, flags);
2185
Ben Hutchingsdacc73e2015-03-03 00:53:08 +00002186 if (skb_put_padto(skb, ETH_ZLEN))
Ben Hutchingseebfb642015-01-22 12:40:13 +00002187 return NETDEV_TX_OK;
2188
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00002189 entry = mdp->cur_tx % mdp->num_tx_ring;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002190 mdp->tx_skbuff[entry] = skb;
2191 txdesc = &mdp->tx_ring[entry];
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002192 /* soft swap. */
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +00002193 if (!mdp->cd->hw_swap)
2194 sh_eth_soft_swap(phys_to_virt(ALIGN(txdesc->addr, 4)),
2195 skb->len + 2);
Yoshihiro Shimoda31fcb992011-06-30 22:52:13 +00002196 txdesc->addr = dma_map_single(&ndev->dev, skb->data, skb->len,
2197 DMA_TO_DEVICE);
Ben Hutchingsaa3933b2015-01-27 00:49:47 +00002198 if (dma_mapping_error(&ndev->dev, txdesc->addr)) {
2199 kfree_skb(skb);
2200 return NETDEV_TX_OK;
2201 }
Ben Hutchingseebfb642015-01-22 12:40:13 +00002202 txdesc->buffer_length = skb->len;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002203
Ben Hutchings7d7355f2015-03-03 00:52:00 +00002204 wmb(); /* TACT bit must be set after all the above writes */
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00002205 if (entry >= mdp->num_tx_ring - 1)
Yoshinori Sato71557a32008-08-06 19:49:00 -04002206 txdesc->status |= cpu_to_edmac(mdp, TD_TACT | TD_TDLE);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002207 else
Yoshinori Sato71557a32008-08-06 19:49:00 -04002208 txdesc->status |= cpu_to_edmac(mdp, TD_TACT);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002209
2210 mdp->cur_tx++;
2211
Yoshihiro Shimodac5ed5362011-03-07 21:59:38 +00002212 if (!(sh_eth_read(ndev, EDTRR) & sh_eth_get_edtrr_trns(mdp)))
2213 sh_eth_write(ndev, sh_eth_get_edtrr_trns(mdp), EDTRR);
Nobuhiro Iwamatsub0ca2a22008-06-30 11:08:17 +09002214
Patrick McHardy6ed10652009-06-23 06:03:08 +00002215 return NETDEV_TX_OK;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002216}
2217
Mitsuhiro Kimura7fa29552014-11-28 10:04:15 +09002218static struct net_device_stats *sh_eth_get_stats(struct net_device *ndev)
2219{
2220 struct sh_eth_private *mdp = netdev_priv(ndev);
2221
2222 if (sh_eth_is_rz_fast_ether(mdp))
2223 return &ndev->stats;
2224
2225 if (!mdp->is_opened)
2226 return &ndev->stats;
2227
2228 ndev->stats.tx_dropped += sh_eth_read(ndev, TROCR);
2229 sh_eth_write(ndev, 0, TROCR); /* (write clear) */
2230 ndev->stats.collisions += sh_eth_read(ndev, CDCR);
2231 sh_eth_write(ndev, 0, CDCR); /* (write clear) */
2232 ndev->stats.tx_carrier_errors += sh_eth_read(ndev, LCCR);
2233 sh_eth_write(ndev, 0, LCCR); /* (write clear) */
2234
2235 if (sh_eth_is_gether(mdp)) {
2236 ndev->stats.tx_carrier_errors += sh_eth_read(ndev, CERCR);
2237 sh_eth_write(ndev, 0, CERCR); /* (write clear) */
2238 ndev->stats.tx_carrier_errors += sh_eth_read(ndev, CEECR);
2239 sh_eth_write(ndev, 0, CEECR); /* (write clear) */
2240 } else {
2241 ndev->stats.tx_carrier_errors += sh_eth_read(ndev, CNDCR);
2242 sh_eth_write(ndev, 0, CNDCR); /* (write clear) */
2243 }
2244
2245 return &ndev->stats;
2246}
2247
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002248/* device close function */
2249static int sh_eth_close(struct net_device *ndev)
2250{
2251 struct sh_eth_private *mdp = netdev_priv(ndev);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002252
2253 netif_stop_queue(ndev);
2254
Ben Hutchings283e38d2015-01-22 12:44:08 +00002255 /* Serialise with the interrupt handler and NAPI, then disable
2256 * interrupts. We have to clear the irq_enabled flag first to
2257 * ensure that interrupts won't be re-enabled.
2258 */
2259 mdp->irq_enabled = false;
2260 synchronize_irq(ndev->irq);
2261 napi_disable(&mdp->napi);
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00002262 sh_eth_write(ndev, 0x0000, EESIPR);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002263
Ben Hutchings740c7f32015-01-27 00:49:32 +00002264 sh_eth_dev_exit(ndev);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002265
2266 /* PHY Disconnect */
2267 if (mdp->phydev) {
2268 phy_stop(mdp->phydev);
2269 phy_disconnect(mdp->phydev);
Ben Hutchings4f9dce232015-01-16 17:51:25 +00002270 mdp->phydev = NULL;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002271 }
2272
2273 free_irq(ndev->irq, ndev);
2274
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002275 /* Free all the skbuffs in the Rx queue. */
2276 sh_eth_ring_free(ndev);
2277
2278 /* free DMA buffer */
Yoshihiro Shimoda91c77552012-06-26 20:00:01 +00002279 sh_eth_free_dma_buffer(mdp);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002280
Magnus Dammbcd51492009-10-09 00:20:04 +00002281 pm_runtime_put_sync(&mdp->pdev->dev);
2282
Mitsuhiro Kimura7fa29552014-11-28 10:04:15 +09002283 mdp->is_opened = 0;
2284
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002285 return 0;
2286}
2287
Eric Dumazetbb7d92e2012-02-06 22:17:21 +00002288/* ioctl to device function */
Sergei Shtylyov128296f2014-01-03 15:52:22 +03002289static int sh_eth_do_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002290{
2291 struct sh_eth_private *mdp = netdev_priv(ndev);
2292 struct phy_device *phydev = mdp->phydev;
2293
2294 if (!netif_running(ndev))
2295 return -EINVAL;
2296
2297 if (!phydev)
2298 return -ENODEV;
2299
Richard Cochran28b04112010-07-17 08:48:55 +00002300 return phy_mii_ioctl(phydev, rq, cmd);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002301}
2302
Yoshihiro Shimoda6743fe62012-02-15 17:55:03 +00002303/* For TSU_POSTn. Please refer to the manual about this (strange) bitfields */
2304static void *sh_eth_tsu_get_post_reg_offset(struct sh_eth_private *mdp,
2305 int entry)
2306{
2307 return sh_eth_tsu_get_offset(mdp, TSU_POST1) + (entry / 8 * 4);
2308}
2309
2310static u32 sh_eth_tsu_get_post_mask(int entry)
2311{
2312 return 0x0f << (28 - ((entry % 8) * 4));
2313}
2314
2315static u32 sh_eth_tsu_get_post_bit(struct sh_eth_private *mdp, int entry)
2316{
2317 return (0x08 >> (mdp->port << 1)) << (28 - ((entry % 8) * 4));
2318}
2319
2320static void sh_eth_tsu_enable_cam_entry_post(struct net_device *ndev,
2321 int entry)
2322{
2323 struct sh_eth_private *mdp = netdev_priv(ndev);
2324 u32 tmp;
2325 void *reg_offset;
2326
2327 reg_offset = sh_eth_tsu_get_post_reg_offset(mdp, entry);
2328 tmp = ioread32(reg_offset);
2329 iowrite32(tmp | sh_eth_tsu_get_post_bit(mdp, entry), reg_offset);
2330}
2331
2332static bool sh_eth_tsu_disable_cam_entry_post(struct net_device *ndev,
2333 int entry)
2334{
2335 struct sh_eth_private *mdp = netdev_priv(ndev);
2336 u32 post_mask, ref_mask, tmp;
2337 void *reg_offset;
2338
2339 reg_offset = sh_eth_tsu_get_post_reg_offset(mdp, entry);
2340 post_mask = sh_eth_tsu_get_post_mask(entry);
2341 ref_mask = sh_eth_tsu_get_post_bit(mdp, entry) & ~post_mask;
2342
2343 tmp = ioread32(reg_offset);
2344 iowrite32(tmp & ~post_mask, reg_offset);
2345
2346 /* If other port enables, the function returns "true" */
2347 return tmp & ref_mask;
2348}
2349
2350static int sh_eth_tsu_busy(struct net_device *ndev)
2351{
2352 int timeout = SH_ETH_TSU_TIMEOUT_MS * 100;
2353 struct sh_eth_private *mdp = netdev_priv(ndev);
2354
2355 while ((sh_eth_tsu_read(mdp, TSU_ADSBSY) & TSU_ADSBSY_0)) {
2356 udelay(10);
2357 timeout--;
2358 if (timeout <= 0) {
Sergei Shtylyovda246852014-03-15 03:29:14 +03002359 netdev_err(ndev, "%s: timeout\n", __func__);
Yoshihiro Shimoda6743fe62012-02-15 17:55:03 +00002360 return -ETIMEDOUT;
2361 }
2362 }
2363
2364 return 0;
2365}
2366
2367static int sh_eth_tsu_write_entry(struct net_device *ndev, void *reg,
2368 const u8 *addr)
2369{
2370 u32 val;
2371
2372 val = addr[0] << 24 | addr[1] << 16 | addr[2] << 8 | addr[3];
2373 iowrite32(val, reg);
2374 if (sh_eth_tsu_busy(ndev) < 0)
2375 return -EBUSY;
2376
2377 val = addr[4] << 8 | addr[5];
2378 iowrite32(val, reg + 4);
2379 if (sh_eth_tsu_busy(ndev) < 0)
2380 return -EBUSY;
2381
2382 return 0;
2383}
2384
2385static void sh_eth_tsu_read_entry(void *reg, u8 *addr)
2386{
2387 u32 val;
2388
2389 val = ioread32(reg);
2390 addr[0] = (val >> 24) & 0xff;
2391 addr[1] = (val >> 16) & 0xff;
2392 addr[2] = (val >> 8) & 0xff;
2393 addr[3] = val & 0xff;
2394 val = ioread32(reg + 4);
2395 addr[4] = (val >> 8) & 0xff;
2396 addr[5] = val & 0xff;
2397}
2398
2399
2400static int sh_eth_tsu_find_entry(struct net_device *ndev, const u8 *addr)
2401{
2402 struct sh_eth_private *mdp = netdev_priv(ndev);
2403 void *reg_offset = sh_eth_tsu_get_offset(mdp, TSU_ADRH0);
2404 int i;
2405 u8 c_addr[ETH_ALEN];
2406
2407 for (i = 0; i < SH_ETH_TSU_CAM_ENTRIES; i++, reg_offset += 8) {
2408 sh_eth_tsu_read_entry(reg_offset, c_addr);
dingtianhongc4bde292013-12-30 15:41:17 +08002409 if (ether_addr_equal(addr, c_addr))
Yoshihiro Shimoda6743fe62012-02-15 17:55:03 +00002410 return i;
2411 }
2412
2413 return -ENOENT;
2414}
2415
2416static int sh_eth_tsu_find_empty(struct net_device *ndev)
2417{
2418 u8 blank[ETH_ALEN];
2419 int entry;
2420
2421 memset(blank, 0, sizeof(blank));
2422 entry = sh_eth_tsu_find_entry(ndev, blank);
2423 return (entry < 0) ? -ENOMEM : entry;
2424}
2425
2426static int sh_eth_tsu_disable_cam_entry_table(struct net_device *ndev,
2427 int entry)
2428{
2429 struct sh_eth_private *mdp = netdev_priv(ndev);
2430 void *reg_offset = sh_eth_tsu_get_offset(mdp, TSU_ADRH0);
2431 int ret;
2432 u8 blank[ETH_ALEN];
2433
2434 sh_eth_tsu_write(mdp, sh_eth_tsu_read(mdp, TSU_TEN) &
2435 ~(1 << (31 - entry)), TSU_TEN);
2436
2437 memset(blank, 0, sizeof(blank));
2438 ret = sh_eth_tsu_write_entry(ndev, reg_offset + entry * 8, blank);
2439 if (ret < 0)
2440 return ret;
2441 return 0;
2442}
2443
2444static int sh_eth_tsu_add_entry(struct net_device *ndev, const u8 *addr)
2445{
2446 struct sh_eth_private *mdp = netdev_priv(ndev);
2447 void *reg_offset = sh_eth_tsu_get_offset(mdp, TSU_ADRH0);
2448 int i, ret;
2449
2450 if (!mdp->cd->tsu)
2451 return 0;
2452
2453 i = sh_eth_tsu_find_entry(ndev, addr);
2454 if (i < 0) {
2455 /* No entry found, create one */
2456 i = sh_eth_tsu_find_empty(ndev);
2457 if (i < 0)
2458 return -ENOMEM;
2459 ret = sh_eth_tsu_write_entry(ndev, reg_offset + i * 8, addr);
2460 if (ret < 0)
2461 return ret;
2462
2463 /* Enable the entry */
2464 sh_eth_tsu_write(mdp, sh_eth_tsu_read(mdp, TSU_TEN) |
2465 (1 << (31 - i)), TSU_TEN);
2466 }
2467
2468 /* Entry found or created, enable POST */
2469 sh_eth_tsu_enable_cam_entry_post(ndev, i);
2470
2471 return 0;
2472}
2473
2474static int sh_eth_tsu_del_entry(struct net_device *ndev, const u8 *addr)
2475{
2476 struct sh_eth_private *mdp = netdev_priv(ndev);
2477 int i, ret;
2478
2479 if (!mdp->cd->tsu)
2480 return 0;
2481
2482 i = sh_eth_tsu_find_entry(ndev, addr);
2483 if (i) {
2484 /* Entry found */
2485 if (sh_eth_tsu_disable_cam_entry_post(ndev, i))
2486 goto done;
2487
2488 /* Disable the entry if both ports was disabled */
2489 ret = sh_eth_tsu_disable_cam_entry_table(ndev, i);
2490 if (ret < 0)
2491 return ret;
2492 }
2493done:
2494 return 0;
2495}
2496
2497static int sh_eth_tsu_purge_all(struct net_device *ndev)
2498{
2499 struct sh_eth_private *mdp = netdev_priv(ndev);
2500 int i, ret;
2501
Ben Hutchingsb37feed2015-01-16 17:51:12 +00002502 if (!mdp->cd->tsu)
Yoshihiro Shimoda6743fe62012-02-15 17:55:03 +00002503 return 0;
2504
2505 for (i = 0; i < SH_ETH_TSU_CAM_ENTRIES; i++) {
2506 if (sh_eth_tsu_disable_cam_entry_post(ndev, i))
2507 continue;
2508
2509 /* Disable the entry if both ports was disabled */
2510 ret = sh_eth_tsu_disable_cam_entry_table(ndev, i);
2511 if (ret < 0)
2512 return ret;
2513 }
2514
2515 return 0;
2516}
2517
2518static void sh_eth_tsu_purge_mcast(struct net_device *ndev)
2519{
2520 struct sh_eth_private *mdp = netdev_priv(ndev);
2521 u8 addr[ETH_ALEN];
2522 void *reg_offset = sh_eth_tsu_get_offset(mdp, TSU_ADRH0);
2523 int i;
2524
Ben Hutchingsb37feed2015-01-16 17:51:12 +00002525 if (!mdp->cd->tsu)
Yoshihiro Shimoda6743fe62012-02-15 17:55:03 +00002526 return;
2527
2528 for (i = 0; i < SH_ETH_TSU_CAM_ENTRIES; i++, reg_offset += 8) {
2529 sh_eth_tsu_read_entry(reg_offset, addr);
2530 if (is_multicast_ether_addr(addr))
2531 sh_eth_tsu_del_entry(ndev, addr);
2532 }
2533}
2534
Ben Hutchingsb37feed2015-01-16 17:51:12 +00002535/* Update promiscuous flag and multicast filter */
2536static void sh_eth_set_rx_mode(struct net_device *ndev)
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002537{
Yoshihiro Shimoda6743fe62012-02-15 17:55:03 +00002538 struct sh_eth_private *mdp = netdev_priv(ndev);
2539 u32 ecmr_bits;
2540 int mcast_all = 0;
2541 unsigned long flags;
2542
2543 spin_lock_irqsave(&mdp->lock, flags);
Sergei Shtylyov128296f2014-01-03 15:52:22 +03002544 /* Initial condition is MCT = 1, PRM = 0.
Yoshihiro Shimoda6743fe62012-02-15 17:55:03 +00002545 * Depending on ndev->flags, set PRM or clear MCT
2546 */
Ben Hutchingsb37feed2015-01-16 17:51:12 +00002547 ecmr_bits = sh_eth_read(ndev, ECMR) & ~ECMR_PRM;
2548 if (mdp->cd->tsu)
2549 ecmr_bits |= ECMR_MCT;
Yoshihiro Shimoda6743fe62012-02-15 17:55:03 +00002550
2551 if (!(ndev->flags & IFF_MULTICAST)) {
2552 sh_eth_tsu_purge_mcast(ndev);
2553 mcast_all = 1;
2554 }
2555 if (ndev->flags & IFF_ALLMULTI) {
2556 sh_eth_tsu_purge_mcast(ndev);
2557 ecmr_bits &= ~ECMR_MCT;
2558 mcast_all = 1;
2559 }
2560
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002561 if (ndev->flags & IFF_PROMISC) {
Yoshihiro Shimoda6743fe62012-02-15 17:55:03 +00002562 sh_eth_tsu_purge_all(ndev);
2563 ecmr_bits = (ecmr_bits & ~ECMR_MCT) | ECMR_PRM;
2564 } else if (mdp->cd->tsu) {
2565 struct netdev_hw_addr *ha;
2566 netdev_for_each_mc_addr(ha, ndev) {
2567 if (mcast_all && is_multicast_ether_addr(ha->addr))
2568 continue;
2569
2570 if (sh_eth_tsu_add_entry(ndev, ha->addr) < 0) {
2571 if (!mcast_all) {
2572 sh_eth_tsu_purge_mcast(ndev);
2573 ecmr_bits &= ~ECMR_MCT;
2574 mcast_all = 1;
2575 }
2576 }
2577 }
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002578 }
Yoshihiro Shimoda6743fe62012-02-15 17:55:03 +00002579
2580 /* update the ethernet mode */
2581 sh_eth_write(ndev, ecmr_bits, ECMR);
2582
2583 spin_unlock_irqrestore(&mdp->lock, flags);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002584}
Yoshihiro Shimoda71cc7c32012-02-15 17:55:06 +00002585
2586static int sh_eth_get_vtag_index(struct sh_eth_private *mdp)
2587{
2588 if (!mdp->port)
2589 return TSU_VTAG0;
2590 else
2591 return TSU_VTAG1;
2592}
2593
Patrick McHardy80d5c362013-04-19 02:04:28 +00002594static int sh_eth_vlan_rx_add_vid(struct net_device *ndev,
2595 __be16 proto, u16 vid)
Yoshihiro Shimoda71cc7c32012-02-15 17:55:06 +00002596{
2597 struct sh_eth_private *mdp = netdev_priv(ndev);
2598 int vtag_reg_index = sh_eth_get_vtag_index(mdp);
2599
2600 if (unlikely(!mdp->cd->tsu))
2601 return -EPERM;
2602
2603 /* No filtering if vid = 0 */
2604 if (!vid)
2605 return 0;
2606
2607 mdp->vlan_num_ids++;
2608
Sergei Shtylyov128296f2014-01-03 15:52:22 +03002609 /* The controller has one VLAN tag HW filter. So, if the filter is
Yoshihiro Shimoda71cc7c32012-02-15 17:55:06 +00002610 * already enabled, the driver disables it and the filte
2611 */
2612 if (mdp->vlan_num_ids > 1) {
2613 /* disable VLAN filter */
2614 sh_eth_tsu_write(mdp, 0, vtag_reg_index);
2615 return 0;
2616 }
2617
2618 sh_eth_tsu_write(mdp, TSU_VTAG_ENABLE | (vid & TSU_VTAG_VID_MASK),
2619 vtag_reg_index);
2620
2621 return 0;
2622}
2623
Patrick McHardy80d5c362013-04-19 02:04:28 +00002624static int sh_eth_vlan_rx_kill_vid(struct net_device *ndev,
2625 __be16 proto, u16 vid)
Yoshihiro Shimoda71cc7c32012-02-15 17:55:06 +00002626{
2627 struct sh_eth_private *mdp = netdev_priv(ndev);
2628 int vtag_reg_index = sh_eth_get_vtag_index(mdp);
2629
2630 if (unlikely(!mdp->cd->tsu))
2631 return -EPERM;
2632
2633 /* No filtering if vid = 0 */
2634 if (!vid)
2635 return 0;
2636
2637 mdp->vlan_num_ids--;
2638 sh_eth_tsu_write(mdp, 0, vtag_reg_index);
2639
2640 return 0;
2641}
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002642
2643/* SuperH's TSU register init function */
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00002644static void sh_eth_tsu_init(struct sh_eth_private *mdp)
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002645{
Simon Hormandb893472014-01-17 09:22:28 +09002646 if (sh_eth_is_rz_fast_ether(mdp)) {
2647 sh_eth_tsu_write(mdp, 0, TSU_TEN); /* Disable all CAM entry */
2648 return;
2649 }
2650
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00002651 sh_eth_tsu_write(mdp, 0, TSU_FWEN0); /* Disable forward(0->1) */
2652 sh_eth_tsu_write(mdp, 0, TSU_FWEN1); /* Disable forward(1->0) */
2653 sh_eth_tsu_write(mdp, 0, TSU_FCM); /* forward fifo 3k-3k */
2654 sh_eth_tsu_write(mdp, 0xc, TSU_BSYSL0);
2655 sh_eth_tsu_write(mdp, 0xc, TSU_BSYSL1);
2656 sh_eth_tsu_write(mdp, 0, TSU_PRISL0);
2657 sh_eth_tsu_write(mdp, 0, TSU_PRISL1);
2658 sh_eth_tsu_write(mdp, 0, TSU_FWSL0);
2659 sh_eth_tsu_write(mdp, 0, TSU_FWSL1);
2660 sh_eth_tsu_write(mdp, TSU_FWSLC_POSTENU | TSU_FWSLC_POSTENL, TSU_FWSLC);
Yoshihiro Shimodac5ed5362011-03-07 21:59:38 +00002661 if (sh_eth_is_gether(mdp)) {
2662 sh_eth_tsu_write(mdp, 0, TSU_QTAG0); /* Disable QTAG(0->1) */
2663 sh_eth_tsu_write(mdp, 0, TSU_QTAG1); /* Disable QTAG(1->0) */
2664 } else {
2665 sh_eth_tsu_write(mdp, 0, TSU_QTAGM0); /* Disable QTAG(0->1) */
2666 sh_eth_tsu_write(mdp, 0, TSU_QTAGM1); /* Disable QTAG(1->0) */
2667 }
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00002668 sh_eth_tsu_write(mdp, 0, TSU_FWSR); /* all interrupt status clear */
2669 sh_eth_tsu_write(mdp, 0, TSU_FWINMK); /* Disable all interrupt */
2670 sh_eth_tsu_write(mdp, 0, TSU_TEN); /* Disable all CAM entry */
2671 sh_eth_tsu_write(mdp, 0, TSU_POST1); /* Disable CAM entry [ 0- 7] */
2672 sh_eth_tsu_write(mdp, 0, TSU_POST2); /* Disable CAM entry [ 8-15] */
2673 sh_eth_tsu_write(mdp, 0, TSU_POST3); /* Disable CAM entry [16-23] */
2674 sh_eth_tsu_write(mdp, 0, TSU_POST4); /* Disable CAM entry [24-31] */
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002675}
2676
2677/* MDIO bus release function */
Laurent Pinchartbd920ff2014-03-20 15:00:33 +01002678static int sh_mdio_release(struct sh_eth_private *mdp)
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002679{
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002680 /* unregister mdio bus */
Laurent Pinchartbd920ff2014-03-20 15:00:33 +01002681 mdiobus_unregister(mdp->mii_bus);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002682
2683 /* free bitbang info */
Laurent Pinchartbd920ff2014-03-20 15:00:33 +01002684 free_mdio_bitbang(mdp->mii_bus);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002685
2686 return 0;
2687}
2688
2689/* MDIO bus init function */
Laurent Pinchartbd920ff2014-03-20 15:00:33 +01002690static int sh_mdio_init(struct sh_eth_private *mdp,
Yoshihiro Shimodab3017e62011-03-07 21:59:55 +00002691 struct sh_eth_plat_data *pd)
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002692{
2693 int ret, i;
2694 struct bb_info *bitbang;
Laurent Pinchartbd920ff2014-03-20 15:00:33 +01002695 struct platform_device *pdev = mdp->pdev;
Laurent Pinchartaa8d4222014-03-20 15:00:31 +01002696 struct device *dev = &mdp->pdev->dev;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002697
2698 /* create bit control struct for PHY */
Laurent Pinchartaa8d4222014-03-20 15:00:31 +01002699 bitbang = devm_kzalloc(dev, sizeof(struct bb_info), GFP_KERNEL);
Laurent Pinchartf738a132014-03-20 15:00:35 +01002700 if (!bitbang)
2701 return -ENOMEM;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002702
2703 /* bitbang init */
Yoshihiro Shimodaae706442011-09-27 21:48:58 +00002704 bitbang->addr = mdp->addr + mdp->reg_offset[PIR];
Yoshihiro Shimodab3017e62011-03-07 21:59:55 +00002705 bitbang->set_gate = pd->set_mdio_gate;
Sergei Shtylyovdfed5e72013-03-21 10:37:54 +00002706 bitbang->mdi_msk = PIR_MDI;
2707 bitbang->mdo_msk = PIR_MDO;
2708 bitbang->mmd_msk = PIR_MMD;
2709 bitbang->mdc_msk = PIR_MDC;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002710 bitbang->ctrl.ops = &bb_ops;
2711
Stefan Weilc2e07b32010-08-03 19:44:52 +02002712 /* MII controller setting */
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002713 mdp->mii_bus = alloc_mdio_bitbang(&bitbang->ctrl);
Laurent Pinchartf738a132014-03-20 15:00:35 +01002714 if (!mdp->mii_bus)
2715 return -ENOMEM;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002716
2717 /* Hook up MII support for ethtool */
2718 mdp->mii_bus->name = "sh_mii";
Laurent Pincharta5bd60602014-03-20 15:00:32 +01002719 mdp->mii_bus->parent = dev;
Florian Fainelli5278fb52012-01-09 23:59:17 +00002720 snprintf(mdp->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
Laurent Pinchartbd920ff2014-03-20 15:00:33 +01002721 pdev->name, pdev->id);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002722
2723 /* PHY IRQ */
Sergei Shtylyov86b5d252014-05-13 02:30:14 +04002724 mdp->mii_bus->irq = devm_kmalloc_array(dev, PHY_MAX_ADDR, sizeof(int),
2725 GFP_KERNEL);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002726 if (!mdp->mii_bus->irq) {
2727 ret = -ENOMEM;
2728 goto out_free_bus;
2729 }
2730
Laurent Pinchartbd920ff2014-03-20 15:00:33 +01002731 /* register MDIO bus */
2732 if (dev->of_node) {
2733 ret = of_mdiobus_register(mdp->mii_bus, dev->of_node);
Ben Dooks702eca02014-03-12 17:47:40 +00002734 } else {
2735 for (i = 0; i < PHY_MAX_ADDR; i++)
2736 mdp->mii_bus->irq[i] = PHY_POLL;
2737 if (pd->phy_irq > 0)
2738 mdp->mii_bus->irq[pd->phy] = pd->phy_irq;
2739
2740 ret = mdiobus_register(mdp->mii_bus);
2741 }
2742
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002743 if (ret)
Sergei Shtylyovd5e07e62013-03-21 10:41:11 +00002744 goto out_free_bus;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002745
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002746 return 0;
2747
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002748out_free_bus:
Lennert Buytenhek298cf9be2008-10-08 16:29:57 -07002749 free_mdio_bitbang(mdp->mii_bus);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002750 return ret;
2751}
2752
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00002753static const u16 *sh_eth_get_register_offset(int register_type)
2754{
2755 const u16 *reg_offset = NULL;
2756
2757 switch (register_type) {
2758 case SH_ETH_REG_GIGABIT:
2759 reg_offset = sh_eth_offset_gigabit;
2760 break;
Simon Hormandb893472014-01-17 09:22:28 +09002761 case SH_ETH_REG_FAST_RZ:
2762 reg_offset = sh_eth_offset_fast_rz;
2763 break;
Sergei Shtylyova3f109b2013-03-28 11:51:31 +00002764 case SH_ETH_REG_FAST_RCAR:
2765 reg_offset = sh_eth_offset_fast_rcar;
2766 break;
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00002767 case SH_ETH_REG_FAST_SH4:
2768 reg_offset = sh_eth_offset_fast_sh4;
2769 break;
2770 case SH_ETH_REG_FAST_SH3_SH2:
2771 reg_offset = sh_eth_offset_fast_sh3_sh2;
2772 break;
2773 default:
Yoshihiro Shimoda4a555302011-03-07 21:59:26 +00002774 break;
2775 }
2776
2777 return reg_offset;
2778}
2779
Sergei Shtylyov8f728d72013-06-13 00:55:34 +04002780static const struct net_device_ops sh_eth_netdev_ops = {
Alexander Beregalovebf84ea2009-04-11 07:40:49 +00002781 .ndo_open = sh_eth_open,
2782 .ndo_stop = sh_eth_close,
2783 .ndo_start_xmit = sh_eth_start_xmit,
2784 .ndo_get_stats = sh_eth_get_stats,
Ben Hutchingsb37feed2015-01-16 17:51:12 +00002785 .ndo_set_rx_mode = sh_eth_set_rx_mode,
Alexander Beregalovebf84ea2009-04-11 07:40:49 +00002786 .ndo_tx_timeout = sh_eth_tx_timeout,
2787 .ndo_do_ioctl = sh_eth_do_ioctl,
2788 .ndo_validate_addr = eth_validate_addr,
2789 .ndo_set_mac_address = eth_mac_addr,
2790 .ndo_change_mtu = eth_change_mtu,
2791};
2792
Sergei Shtylyov8f728d72013-06-13 00:55:34 +04002793static const struct net_device_ops sh_eth_netdev_ops_tsu = {
2794 .ndo_open = sh_eth_open,
2795 .ndo_stop = sh_eth_close,
2796 .ndo_start_xmit = sh_eth_start_xmit,
2797 .ndo_get_stats = sh_eth_get_stats,
Ben Hutchingsb37feed2015-01-16 17:51:12 +00002798 .ndo_set_rx_mode = sh_eth_set_rx_mode,
Sergei Shtylyov8f728d72013-06-13 00:55:34 +04002799 .ndo_vlan_rx_add_vid = sh_eth_vlan_rx_add_vid,
2800 .ndo_vlan_rx_kill_vid = sh_eth_vlan_rx_kill_vid,
2801 .ndo_tx_timeout = sh_eth_tx_timeout,
2802 .ndo_do_ioctl = sh_eth_do_ioctl,
2803 .ndo_validate_addr = eth_validate_addr,
2804 .ndo_set_mac_address = eth_mac_addr,
2805 .ndo_change_mtu = eth_change_mtu,
2806};
2807
Sergei Shtylyovb356e972014-02-18 03:12:43 +03002808#ifdef CONFIG_OF
2809static struct sh_eth_plat_data *sh_eth_parse_dt(struct device *dev)
2810{
2811 struct device_node *np = dev->of_node;
2812 struct sh_eth_plat_data *pdata;
Sergei Shtylyovb356e972014-02-18 03:12:43 +03002813 const char *mac_addr;
2814
2815 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
2816 if (!pdata)
2817 return NULL;
2818
2819 pdata->phy_interface = of_get_phy_mode(np);
2820
Sergei Shtylyovb356e972014-02-18 03:12:43 +03002821 mac_addr = of_get_mac_address(np);
2822 if (mac_addr)
2823 memcpy(pdata->mac_addr, mac_addr, ETH_ALEN);
2824
2825 pdata->no_ether_link =
2826 of_property_read_bool(np, "renesas,no-ether-link");
2827 pdata->ether_link_active_low =
2828 of_property_read_bool(np, "renesas,ether-link-active-low");
2829
2830 return pdata;
2831}
2832
2833static const struct of_device_id sh_eth_match_table[] = {
2834 { .compatible = "renesas,gether-r8a7740", .data = &r8a7740_data },
2835 { .compatible = "renesas,ether-r8a7778", .data = &r8a777x_data },
2836 { .compatible = "renesas,ether-r8a7779", .data = &r8a777x_data },
2837 { .compatible = "renesas,ether-r8a7790", .data = &r8a779x_data },
2838 { .compatible = "renesas,ether-r8a7791", .data = &r8a779x_data },
Hisashi Nakamura9488e1e2014-11-13 15:59:07 +09002839 { .compatible = "renesas,ether-r8a7793", .data = &r8a779x_data },
Hisashi Nakamura0f76b9d2014-08-01 17:03:00 +02002840 { .compatible = "renesas,ether-r8a7794", .data = &r8a779x_data },
Sergei Shtylyovb356e972014-02-18 03:12:43 +03002841 { .compatible = "renesas,ether-r7s72100", .data = &r7s72100_data },
2842 { }
2843};
2844MODULE_DEVICE_TABLE(of, sh_eth_match_table);
2845#else
2846static inline struct sh_eth_plat_data *sh_eth_parse_dt(struct device *dev)
2847{
2848 return NULL;
2849}
2850#endif
2851
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002852static int sh_eth_drv_probe(struct platform_device *pdev)
2853{
Kuninori Morimoto9c386572010-08-19 00:39:45 -07002854 int ret, devno = 0;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002855 struct resource *res;
2856 struct net_device *ndev = NULL;
Kuninori Morimotoec0d7552011-06-23 16:02:38 +00002857 struct sh_eth_private *mdp = NULL;
Jingoo Han0b76b862013-08-30 14:00:11 +09002858 struct sh_eth_plat_data *pd = dev_get_platdata(&pdev->dev);
Sergei Shtylyovafe391a2013-06-07 13:54:02 +00002859 const struct platform_device_id *id = platform_get_device_id(pdev);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002860
2861 /* get base addr */
2862 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002863
2864 ndev = alloc_etherdev(sizeof(struct sh_eth_private));
Laurent Pinchartf738a132014-03-20 15:00:35 +01002865 if (!ndev)
2866 return -ENOMEM;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002867
Ben Dooksb5893a02014-03-21 12:09:14 +01002868 pm_runtime_enable(&pdev->dev);
2869 pm_runtime_get_sync(&pdev->dev);
2870
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002871 devno = pdev->id;
2872 if (devno < 0)
2873 devno = 0;
2874
2875 ndev->dma = -1;
roel kluincc3c0802008-09-10 19:22:44 +02002876 ret = platform_get_irq(pdev, 0);
2877 if (ret < 0) {
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002878 ret = -ENODEV;
2879 goto out_release;
2880 }
roel kluincc3c0802008-09-10 19:22:44 +02002881 ndev->irq = ret;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002882
2883 SET_NETDEV_DEV(ndev, &pdev->dev);
2884
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002885 mdp = netdev_priv(ndev);
Yoshihiro Shimoda525b8072012-06-26 20:00:03 +00002886 mdp->num_tx_ring = TX_RING_SIZE;
2887 mdp->num_rx_ring = RX_RING_SIZE;
Sergei Shtylyovd5e07e62013-03-21 10:41:11 +00002888 mdp->addr = devm_ioremap_resource(&pdev->dev, res);
2889 if (IS_ERR(mdp->addr)) {
2890 ret = PTR_ERR(mdp->addr);
Yoshihiro Shimodaae706442011-09-27 21:48:58 +00002891 goto out_release;
2892 }
2893
Varka Bhadramc9608042014-10-24 07:42:09 +05302894 ndev->base_addr = res->start;
2895
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002896 spin_lock_init(&mdp->lock);
Magnus Dammbcd51492009-10-09 00:20:04 +00002897 mdp->pdev = pdev;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002898
Sergei Shtylyovb356e972014-02-18 03:12:43 +03002899 if (pdev->dev.of_node)
2900 pd = sh_eth_parse_dt(&pdev->dev);
Sergei Shtylyov3b4c5cb2013-10-30 23:30:19 +03002901 if (!pd) {
2902 dev_err(&pdev->dev, "no platform data\n");
2903 ret = -EINVAL;
2904 goto out_release;
2905 }
2906
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002907 /* get PHY ID */
Yoshinori Sato71557a32008-08-06 19:49:00 -04002908 mdp->phy_id = pd->phy;
Yoshihiro Shimodae47c9052011-03-07 21:59:45 +00002909 mdp->phy_interface = pd->phy_interface;
Yoshinori Sato71557a32008-08-06 19:49:00 -04002910 /* EDMAC endian */
2911 mdp->edmac_endian = pd->edmac_endian;
Yoshihiro Shimoda49235762009-08-27 23:25:03 +00002912 mdp->no_ether_link = pd->no_ether_link;
2913 mdp->ether_link_active_low = pd->ether_link_active_low;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002914
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +00002915 /* set cpu data */
Sergei Shtylyovb356e972014-02-18 03:12:43 +03002916 if (id) {
2917 mdp->cd = (struct sh_eth_cpu_data *)id->driver_data;
2918 } else {
2919 const struct of_device_id *match;
2920
2921 match = of_match_device(of_match_ptr(sh_eth_match_table),
2922 &pdev->dev);
2923 mdp->cd = (struct sh_eth_cpu_data *)match->data;
2924 }
Sergei Shtylyova3153d82013-08-18 03:11:28 +04002925 mdp->reg_offset = sh_eth_get_register_offset(mdp->cd->register_type);
Sergei Shtylyov264be2f2014-03-15 03:11:24 +03002926 if (!mdp->reg_offset) {
2927 dev_err(&pdev->dev, "Unknown register type (%d)\n",
2928 mdp->cd->register_type);
2929 ret = -EINVAL;
2930 goto out_release;
2931 }
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +00002932 sh_eth_set_default_cpu_data(mdp->cd);
2933
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002934 /* set function */
Sergei Shtylyov8f728d72013-06-13 00:55:34 +04002935 if (mdp->cd->tsu)
2936 ndev->netdev_ops = &sh_eth_netdev_ops_tsu;
2937 else
2938 ndev->netdev_ops = &sh_eth_netdev_ops;
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002939 ndev->ethtool_ops = &sh_eth_ethtool_ops;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002940 ndev->watchdog_timeo = TX_TIMEOUT;
2941
Nobuhiro Iwamatsudc19e4e2011-02-15 21:17:32 +00002942 /* debug message level */
2943 mdp->msg_enable = SH_ETH_DEF_MSG_ENABLE;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002944
2945 /* read and set MAC address */
Magnus Damm748031f2009-10-09 00:17:14 +00002946 read_mac_address(ndev, pd->mac_addr);
Sergei Shtylyovff6e7222013-04-29 09:49:42 +00002947 if (!is_valid_ether_addr(ndev->dev_addr)) {
2948 dev_warn(&pdev->dev,
2949 "no valid MAC address supplied, using a random one.\n");
2950 eth_hw_addr_random(ndev);
2951 }
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002952
Yoshihiro Shimoda6ba88022012-02-15 17:55:01 +00002953 /* ioremap the TSU registers */
2954 if (mdp->cd->tsu) {
2955 struct resource *rtsu;
2956 rtsu = platform_get_resource(pdev, IORESOURCE_MEM, 1);
Sergei Shtylyovd5e07e62013-03-21 10:41:11 +00002957 mdp->tsu_addr = devm_ioremap_resource(&pdev->dev, rtsu);
2958 if (IS_ERR(mdp->tsu_addr)) {
2959 ret = PTR_ERR(mdp->tsu_addr);
Sergei Shtylyovfc0c0902013-03-19 13:41:32 +00002960 goto out_release;
2961 }
Yoshihiro Shimoda6743fe62012-02-15 17:55:03 +00002962 mdp->port = devno % 2;
Patrick McHardyf6469682013-04-19 02:04:27 +00002963 ndev->features = NETIF_F_HW_VLAN_CTAG_FILTER;
Yoshihiro Shimoda6ba88022012-02-15 17:55:01 +00002964 }
2965
Yoshihiro Shimoda150647f2012-02-15 17:54:56 +00002966 /* initialize first or needed device */
2967 if (!devno || pd->needs_init) {
Yoshihiro Shimoda380af9e2009-05-24 23:54:21 +00002968 if (mdp->cd->chip_reset)
2969 mdp->cd->chip_reset(ndev);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002970
Yoshihiro Shimoda4986b992011-03-07 21:59:34 +00002971 if (mdp->cd->tsu) {
2972 /* TSU init (Init only)*/
2973 sh_eth_tsu_init(mdp);
2974 }
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002975 }
2976
Hisashi Nakamura966d6db2014-11-13 15:54:05 +09002977 if (mdp->cd->rmiimode)
2978 sh_eth_write(ndev, 0x1, RMIIMODE);
2979
Laurent Pinchartdaacf032014-03-20 15:00:34 +01002980 /* MDIO bus init */
2981 ret = sh_mdio_init(mdp, pd);
2982 if (ret) {
2983 dev_err(&ndev->dev, "failed to initialise MDIO\n");
2984 goto out_release;
2985 }
2986
Sergei Shtylyov37191092013-06-19 23:30:23 +04002987 netif_napi_add(ndev, &mdp->napi, sh_eth_poll, 64);
2988
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002989 /* network device register */
2990 ret = register_netdev(ndev);
2991 if (ret)
Sergei Shtylyov37191092013-06-19 23:30:23 +04002992 goto out_napi_del;
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002993
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002994 /* print device information */
Sergei Shtylyovf75f14e2014-03-15 03:27:54 +03002995 netdev_info(ndev, "Base address at 0x%x, %pM, IRQ %d.\n",
2996 (u32)ndev->base_addr, ndev->dev_addr, ndev->irq);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002997
Ben Dooksb5893a02014-03-21 12:09:14 +01002998 pm_runtime_put(&pdev->dev);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07002999 platform_set_drvdata(pdev, ndev);
3000
3001 return ret;
3002
Sergei Shtylyov37191092013-06-19 23:30:23 +04003003out_napi_del:
3004 netif_napi_del(&mdp->napi);
Laurent Pinchartdaacf032014-03-20 15:00:34 +01003005 sh_mdio_release(mdp);
Sergei Shtylyov37191092013-06-19 23:30:23 +04003006
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07003007out_release:
3008 /* net_dev free */
3009 if (ndev)
3010 free_netdev(ndev);
3011
Ben Dooksb5893a02014-03-21 12:09:14 +01003012 pm_runtime_put(&pdev->dev);
3013 pm_runtime_disable(&pdev->dev);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07003014 return ret;
3015}
3016
3017static int sh_eth_drv_remove(struct platform_device *pdev)
3018{
3019 struct net_device *ndev = platform_get_drvdata(pdev);
Sergei Shtylyov37191092013-06-19 23:30:23 +04003020 struct sh_eth_private *mdp = netdev_priv(ndev);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07003021
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07003022 unregister_netdev(ndev);
Sergei Shtylyov37191092013-06-19 23:30:23 +04003023 netif_napi_del(&mdp->napi);
Laurent Pinchartdaacf032014-03-20 15:00:34 +01003024 sh_mdio_release(mdp);
Magnus Dammbcd51492009-10-09 00:20:04 +00003025 pm_runtime_disable(&pdev->dev);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07003026 free_netdev(ndev);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07003027
3028 return 0;
3029}
3030
Nobuhiro Iwamatsu540ad1b2013-06-06 09:52:37 +00003031#ifdef CONFIG_PM
Mikhail Ulyanovb71af042015-01-22 01:19:48 +03003032#ifdef CONFIG_PM_SLEEP
3033static int sh_eth_suspend(struct device *dev)
3034{
3035 struct net_device *ndev = dev_get_drvdata(dev);
3036 int ret = 0;
3037
3038 if (netif_running(ndev)) {
3039 netif_device_detach(ndev);
3040 ret = sh_eth_close(ndev);
3041 }
3042
3043 return ret;
3044}
3045
3046static int sh_eth_resume(struct device *dev)
3047{
3048 struct net_device *ndev = dev_get_drvdata(dev);
3049 int ret = 0;
3050
3051 if (netif_running(ndev)) {
3052 ret = sh_eth_open(ndev);
3053 if (ret < 0)
3054 return ret;
3055 netif_device_attach(ndev);
3056 }
3057
3058 return ret;
3059}
3060#endif
3061
Magnus Dammbcd51492009-10-09 00:20:04 +00003062static int sh_eth_runtime_nop(struct device *dev)
3063{
Sergei Shtylyov128296f2014-01-03 15:52:22 +03003064 /* Runtime PM callback shared between ->runtime_suspend()
Magnus Dammbcd51492009-10-09 00:20:04 +00003065 * and ->runtime_resume(). Simply returns success.
3066 *
3067 * This driver re-initializes all registers after
3068 * pm_runtime_get_sync() anyway so there is no need
3069 * to save and restore registers here.
3070 */
3071 return 0;
3072}
3073
Nobuhiro Iwamatsu540ad1b2013-06-06 09:52:37 +00003074static const struct dev_pm_ops sh_eth_dev_pm_ops = {
Mikhail Ulyanovb71af042015-01-22 01:19:48 +03003075 SET_SYSTEM_SLEEP_PM_OPS(sh_eth_suspend, sh_eth_resume)
Mikhail Ulyanove7d7e892015-01-22 01:18:44 +03003076 SET_RUNTIME_PM_OPS(sh_eth_runtime_nop, sh_eth_runtime_nop, NULL)
Magnus Dammbcd51492009-10-09 00:20:04 +00003077};
Nobuhiro Iwamatsu540ad1b2013-06-06 09:52:37 +00003078#define SH_ETH_PM_OPS (&sh_eth_dev_pm_ops)
3079#else
3080#define SH_ETH_PM_OPS NULL
3081#endif
Magnus Dammbcd51492009-10-09 00:20:04 +00003082
Sergei Shtylyovafe391a2013-06-07 13:54:02 +00003083static struct platform_device_id sh_eth_id_table[] = {
Sergei Shtylyovc18a79a2013-06-07 13:56:05 +00003084 { "sh7619-ether", (kernel_ulong_t)&sh7619_data },
Sergei Shtylyov7bbe1502013-06-07 13:55:08 +00003085 { "sh771x-ether", (kernel_ulong_t)&sh771x_data },
Sergei Shtylyov9c3beaa2013-06-07 14:03:37 +00003086 { "sh7724-ether", (kernel_ulong_t)&sh7724_data },
Sergei Shtylyovf5d12762013-06-07 13:58:18 +00003087 { "sh7734-gether", (kernel_ulong_t)&sh7734_data },
Sergei Shtylyov24549e22013-06-07 13:59:21 +00003088 { "sh7757-ether", (kernel_ulong_t)&sh7757_data },
3089 { "sh7757-gether", (kernel_ulong_t)&sh7757_data_giga },
Sergei Shtylyovf5d12762013-06-07 13:58:18 +00003090 { "sh7763-gether", (kernel_ulong_t)&sh7763_data },
Simon Hormandb893472014-01-17 09:22:28 +09003091 { "r7s72100-ether", (kernel_ulong_t)&r7s72100_data },
Sergei Shtylyove5c9b4c2013-06-07 13:57:12 +00003092 { "r8a7740-gether", (kernel_ulong_t)&r8a7740_data },
Sergei Shtylyov589ebde2013-06-07 14:05:59 +00003093 { "r8a777x-ether", (kernel_ulong_t)&r8a777x_data },
Sergei Shtylyov94a12b12013-12-08 02:59:18 +03003094 { "r8a7790-ether", (kernel_ulong_t)&r8a779x_data },
3095 { "r8a7791-ether", (kernel_ulong_t)&r8a779x_data },
Hisashi Nakamura9488e1e2014-11-13 15:59:07 +09003096 { "r8a7793-ether", (kernel_ulong_t)&r8a779x_data },
Hisashi Nakamura0f76b9d2014-08-01 17:03:00 +02003097 { "r8a7794-ether", (kernel_ulong_t)&r8a779x_data },
Sergei Shtylyovafe391a2013-06-07 13:54:02 +00003098 { }
3099};
3100MODULE_DEVICE_TABLE(platform, sh_eth_id_table);
3101
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07003102static struct platform_driver sh_eth_driver = {
3103 .probe = sh_eth_drv_probe,
3104 .remove = sh_eth_drv_remove,
Sergei Shtylyovafe391a2013-06-07 13:54:02 +00003105 .id_table = sh_eth_id_table,
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07003106 .driver = {
3107 .name = CARDNAME,
Nobuhiro Iwamatsu540ad1b2013-06-06 09:52:37 +00003108 .pm = SH_ETH_PM_OPS,
Sergei Shtylyovb356e972014-02-18 03:12:43 +03003109 .of_match_table = of_match_ptr(sh_eth_match_table),
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07003110 },
3111};
3112
Axel Lindb62f682011-11-27 16:44:17 +00003113module_platform_driver(sh_eth_driver);
Nobuhiro Iwamatsu86a74ff2008-06-09 16:33:56 -07003114
3115MODULE_AUTHOR("Nobuhiro Iwamatsu, Yoshihiro Shimoda");
3116MODULE_DESCRIPTION("Renesas SuperH Ethernet driver");
3117MODULE_LICENSE("GPL v2");