blob: e5784f0eac3df57c520d6cae91cb206a7d84f7bd [file] [log] [blame]
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001/* Renesas Ethernet AVB device driver
2 *
3 * Copyright (C) 2014-2015 Renesas Electronics Corporation
4 * Copyright (C) 2015 Renesas Solutions Corp.
Sergei Shtylyov568b3ce2016-02-10 01:37:44 +03005 * Copyright (C) 2015-2016 Cogent Embedded, Inc. <source@cogentembedded.com>
Sergei Shtylyovc1566332015-06-11 01:01:43 +03006 *
7 * Based on the SuperH Ethernet driver
8 *
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 version 2,
11 * as published by the Free Software Foundation.
12 */
13
14#include <linux/cache.h>
15#include <linux/clk.h>
16#include <linux/delay.h>
17#include <linux/dma-mapping.h>
18#include <linux/err.h>
19#include <linux/etherdevice.h>
20#include <linux/ethtool.h>
21#include <linux/if_vlan.h>
22#include <linux/kernel.h>
23#include <linux/list.h>
24#include <linux/module.h>
25#include <linux/net_tstamp.h>
26#include <linux/of.h>
27#include <linux/of_device.h>
28#include <linux/of_irq.h>
29#include <linux/of_mdio.h>
30#include <linux/of_net.h>
Sergei Shtylyovc1566332015-06-11 01:01:43 +030031#include <linux/pm_runtime.h>
32#include <linux/slab.h>
33#include <linux/spinlock.h>
Geert Uytterhoeven0e98f9d2017-01-27 20:46:27 +010034#include <linux/sys_soc.h>
Sergei Shtylyovc1566332015-06-11 01:01:43 +030035
Simon Hormanb3d39a82015-11-20 11:29:39 -080036#include <asm/div64.h>
37
Sergei Shtylyovc1566332015-06-11 01:01:43 +030038#include "ravb.h"
39
40#define RAVB_DEF_MSG_ENABLE \
41 (NETIF_MSG_LINK | \
42 NETIF_MSG_TIMER | \
43 NETIF_MSG_RX_ERR | \
44 NETIF_MSG_TX_ERR)
45
Kazuya Mizuguchif51bdc22016-04-03 23:54:38 +090046static const char *ravb_rx_irqs[NUM_RX_QUEUE] = {
47 "ch0", /* RAVB_BE */
48 "ch1", /* RAVB_NC */
49};
50
51static const char *ravb_tx_irqs[NUM_TX_QUEUE] = {
52 "ch18", /* RAVB_BE */
53 "ch19", /* RAVB_NC */
54};
55
Sergei Shtylyov568b3ce2016-02-10 01:37:44 +030056void ravb_modify(struct net_device *ndev, enum ravb_reg reg, u32 clear,
57 u32 set)
58{
59 ravb_write(ndev, (ravb_read(ndev, reg) & ~clear) | set, reg);
60}
61
Sergei Shtylyova0d2f202015-06-11 01:02:30 +030062int ravb_wait(struct net_device *ndev, enum ravb_reg reg, u32 mask, u32 value)
Sergei Shtylyovc1566332015-06-11 01:01:43 +030063{
64 int i;
65
66 for (i = 0; i < 10000; i++) {
67 if ((ravb_read(ndev, reg) & mask) == value)
68 return 0;
69 udelay(10);
70 }
71 return -ETIMEDOUT;
72}
73
74static int ravb_config(struct net_device *ndev)
75{
76 int error;
77
78 /* Set config mode */
Sergei Shtylyov568b3ce2016-02-10 01:37:44 +030079 ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_CONFIG);
Sergei Shtylyovc1566332015-06-11 01:01:43 +030080 /* Check if the operating mode is changed to the config mode */
81 error = ravb_wait(ndev, CSR, CSR_OPS, CSR_OPS_CONFIG);
82 if (error)
83 netdev_err(ndev, "failed to switch device to config mode\n");
84
85 return error;
86}
87
88static void ravb_set_duplex(struct net_device *ndev)
89{
90 struct ravb_private *priv = netdev_priv(ndev);
Sergei Shtylyovc1566332015-06-11 01:01:43 +030091
Sergei Shtylyov568b3ce2016-02-10 01:37:44 +030092 ravb_modify(ndev, ECMR, ECMR_DM, priv->duplex ? ECMR_DM : 0);
Sergei Shtylyovc1566332015-06-11 01:01:43 +030093}
94
95static void ravb_set_rate(struct net_device *ndev)
96{
97 struct ravb_private *priv = netdev_priv(ndev);
98
99 switch (priv->speed) {
100 case 100: /* 100BASE */
101 ravb_write(ndev, GECMR_SPEED_100, GECMR);
102 break;
103 case 1000: /* 1000BASE */
104 ravb_write(ndev, GECMR_SPEED_1000, GECMR);
105 break;
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300106 }
107}
108
109static void ravb_set_buffer_align(struct sk_buff *skb)
110{
111 u32 reserve = (unsigned long)skb->data & (RAVB_ALIGN - 1);
112
113 if (reserve)
114 skb_reserve(skb, RAVB_ALIGN - reserve);
115}
116
117/* Get MAC address from the MAC address registers
118 *
119 * Ethernet AVB device doesn't have ROM for MAC address.
120 * This function gets the MAC address that was used by a bootloader.
121 */
122static void ravb_read_mac_address(struct net_device *ndev, const u8 *mac)
123{
124 if (mac) {
125 ether_addr_copy(ndev->dev_addr, mac);
126 } else {
Sergei Shtylyovd9660632015-12-05 00:58:07 +0300127 u32 mahr = ravb_read(ndev, MAHR);
128 u32 malr = ravb_read(ndev, MALR);
129
130 ndev->dev_addr[0] = (mahr >> 24) & 0xFF;
131 ndev->dev_addr[1] = (mahr >> 16) & 0xFF;
132 ndev->dev_addr[2] = (mahr >> 8) & 0xFF;
133 ndev->dev_addr[3] = (mahr >> 0) & 0xFF;
134 ndev->dev_addr[4] = (malr >> 8) & 0xFF;
135 ndev->dev_addr[5] = (malr >> 0) & 0xFF;
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300136 }
137}
138
139static void ravb_mdio_ctrl(struct mdiobb_ctrl *ctrl, u32 mask, int set)
140{
141 struct ravb_private *priv = container_of(ctrl, struct ravb_private,
142 mdiobb);
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300143
Sergei Shtylyov568b3ce2016-02-10 01:37:44 +0300144 ravb_modify(priv->ndev, PIR, mask, set ? mask : 0);
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300145}
146
147/* MDC pin control */
148static void ravb_set_mdc(struct mdiobb_ctrl *ctrl, int level)
149{
150 ravb_mdio_ctrl(ctrl, PIR_MDC, level);
151}
152
153/* Data I/O pin control */
154static void ravb_set_mdio_dir(struct mdiobb_ctrl *ctrl, int output)
155{
156 ravb_mdio_ctrl(ctrl, PIR_MMD, output);
157}
158
159/* Set data bit */
160static void ravb_set_mdio_data(struct mdiobb_ctrl *ctrl, int value)
161{
162 ravb_mdio_ctrl(ctrl, PIR_MDO, value);
163}
164
165/* Get data bit */
166static int ravb_get_mdio_data(struct mdiobb_ctrl *ctrl)
167{
168 struct ravb_private *priv = container_of(ctrl, struct ravb_private,
169 mdiobb);
170
171 return (ravb_read(priv->ndev, PIR) & PIR_MDI) != 0;
172}
173
174/* MDIO bus control struct */
175static struct mdiobb_ops bb_ops = {
176 .owner = THIS_MODULE,
177 .set_mdc = ravb_set_mdc,
178 .set_mdio_dir = ravb_set_mdio_dir,
179 .set_mdio_data = ravb_set_mdio_data,
180 .get_mdio_data = ravb_get_mdio_data,
181};
182
Kazuya Mizuguchia47b70e2017-01-26 14:29:27 +0100183/* Free TX skb function for AVB-IP */
184static int ravb_tx_free(struct net_device *ndev, int q, bool free_txed_only)
185{
186 struct ravb_private *priv = netdev_priv(ndev);
187 struct net_device_stats *stats = &priv->stats[q];
188 struct ravb_tx_desc *desc;
189 int free_num = 0;
190 int entry;
191 u32 size;
192
193 for (; priv->cur_tx[q] - priv->dirty_tx[q] > 0; priv->dirty_tx[q]++) {
194 bool txed;
195
196 entry = priv->dirty_tx[q] % (priv->num_tx_ring[q] *
197 NUM_TX_DESC);
198 desc = &priv->tx_ring[q][entry];
199 txed = desc->die_dt == DT_FEMPTY;
200 if (free_txed_only && !txed)
201 break;
202 /* Descriptor type must be checked before all other reads */
203 dma_rmb();
204 size = le16_to_cpu(desc->ds_tagl) & TX_DS;
205 /* Free the original skb. */
206 if (priv->tx_skb[q][entry / NUM_TX_DESC]) {
207 dma_unmap_single(ndev->dev.parent, le32_to_cpu(desc->dptr),
208 size, DMA_TO_DEVICE);
209 /* Last packet descriptor? */
210 if (entry % NUM_TX_DESC == NUM_TX_DESC - 1) {
211 entry /= NUM_TX_DESC;
212 dev_kfree_skb_any(priv->tx_skb[q][entry]);
213 priv->tx_skb[q][entry] = NULL;
214 if (txed)
215 stats->tx_packets++;
216 }
217 free_num++;
218 }
219 if (txed)
220 stats->tx_bytes += size;
221 desc->die_dt = DT_EEMPTY;
222 }
223 return free_num;
224}
225
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300226/* Free skb's and DMA buffers for Ethernet AVB */
227static void ravb_ring_free(struct net_device *ndev, int q)
228{
229 struct ravb_private *priv = netdev_priv(ndev);
230 int ring_size;
231 int i;
232
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300233 if (priv->rx_ring[q]) {
Kazuya Mizuguchia47b70e2017-01-26 14:29:27 +0100234 for (i = 0; i < priv->num_rx_ring[q]; i++) {
235 struct ravb_ex_rx_desc *desc = &priv->rx_ring[q][i];
236
237 if (!dma_mapping_error(ndev->dev.parent,
238 le32_to_cpu(desc->dptr)))
239 dma_unmap_single(ndev->dev.parent,
240 le32_to_cpu(desc->dptr),
Niklas Söderlund75efa062018-02-16 17:10:08 +0100241 priv->rx_buf_sz,
Kazuya Mizuguchia47b70e2017-01-26 14:29:27 +0100242 DMA_FROM_DEVICE);
243 }
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300244 ring_size = sizeof(struct ravb_ex_rx_desc) *
245 (priv->num_rx_ring[q] + 1);
Kazuya Mizuguchie2dbb332015-09-30 15:15:53 +0900246 dma_free_coherent(ndev->dev.parent, ring_size, priv->rx_ring[q],
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300247 priv->rx_desc_dma[q]);
248 priv->rx_ring[q] = NULL;
249 }
250
251 if (priv->tx_ring[q]) {
Kazuya Mizuguchia47b70e2017-01-26 14:29:27 +0100252 ravb_tx_free(ndev, q, false);
253
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300254 ring_size = sizeof(struct ravb_tx_desc) *
Sergei Shtylyov2f45d192015-07-25 23:42:01 +0300255 (priv->num_tx_ring[q] * NUM_TX_DESC + 1);
Kazuya Mizuguchie2dbb332015-09-30 15:15:53 +0900256 dma_free_coherent(ndev->dev.parent, ring_size, priv->tx_ring[q],
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300257 priv->tx_desc_dma[q]);
258 priv->tx_ring[q] = NULL;
259 }
Kazuya Mizuguchia47b70e2017-01-26 14:29:27 +0100260
Eugeniu Rosca79514ef2017-06-06 00:08:10 +0200261 /* Free RX skb ringbuffer */
262 if (priv->rx_skb[q]) {
263 for (i = 0; i < priv->num_rx_ring[q]; i++)
264 dev_kfree_skb(priv->rx_skb[q][i]);
265 }
266 kfree(priv->rx_skb[q]);
267 priv->rx_skb[q] = NULL;
268
269 /* Free aligned TX buffers */
270 kfree(priv->tx_align[q]);
271 priv->tx_align[q] = NULL;
272
Kazuya Mizuguchia47b70e2017-01-26 14:29:27 +0100273 /* Free TX skb ringbuffer.
274 * SKBs are freed by ravb_tx_free() call above.
275 */
276 kfree(priv->tx_skb[q]);
277 priv->tx_skb[q] = NULL;
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300278}
279
280/* Format skb and descriptor buffer for Ethernet AVB */
281static void ravb_ring_format(struct net_device *ndev, int q)
282{
283 struct ravb_private *priv = netdev_priv(ndev);
Sergei Shtylyovaad0d512015-07-10 21:10:10 +0300284 struct ravb_ex_rx_desc *rx_desc;
285 struct ravb_tx_desc *tx_desc;
286 struct ravb_desc *desc;
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300287 int rx_ring_size = sizeof(*rx_desc) * priv->num_rx_ring[q];
Sergei Shtylyov2f45d192015-07-25 23:42:01 +0300288 int tx_ring_size = sizeof(*tx_desc) * priv->num_tx_ring[q] *
289 NUM_TX_DESC;
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300290 dma_addr_t dma_addr;
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300291 int i;
292
293 priv->cur_rx[q] = 0;
294 priv->cur_tx[q] = 0;
295 priv->dirty_rx[q] = 0;
296 priv->dirty_tx[q] = 0;
297
298 memset(priv->rx_ring[q], 0, rx_ring_size);
299 /* Build RX ring buffer */
300 for (i = 0; i < priv->num_rx_ring[q]; i++) {
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300301 /* RX descriptor */
302 rx_desc = &priv->rx_ring[q][i];
Niklas Söderlund75efa062018-02-16 17:10:08 +0100303 rx_desc->ds_cc = cpu_to_le16(priv->rx_buf_sz);
Kazuya Mizuguchie2dbb332015-09-30 15:15:53 +0900304 dma_addr = dma_map_single(ndev->dev.parent, priv->rx_skb[q][i]->data,
Niklas Söderlund75efa062018-02-16 17:10:08 +0100305 priv->rx_buf_sz,
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300306 DMA_FROM_DEVICE);
Sergei Shtylyovd8b48912015-07-22 01:31:59 +0300307 /* We just set the data size to 0 for a failed mapping which
308 * should prevent DMA from happening...
309 */
Kazuya Mizuguchie2dbb332015-09-30 15:15:53 +0900310 if (dma_mapping_error(ndev->dev.parent, dma_addr))
Sergei Shtylyovd8b48912015-07-22 01:31:59 +0300311 rx_desc->ds_cc = cpu_to_le16(0);
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300312 rx_desc->dptr = cpu_to_le32(dma_addr);
313 rx_desc->die_dt = DT_FEMPTY;
314 }
315 rx_desc = &priv->rx_ring[q][i];
316 rx_desc->dptr = cpu_to_le32((u32)priv->rx_desc_dma[q]);
317 rx_desc->die_dt = DT_LINKFIX; /* type */
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300318
319 memset(priv->tx_ring[q], 0, tx_ring_size);
320 /* Build TX ring buffer */
Sergei Shtylyov2f45d192015-07-25 23:42:01 +0300321 for (i = 0, tx_desc = priv->tx_ring[q]; i < priv->num_tx_ring[q];
322 i++, tx_desc++) {
323 tx_desc->die_dt = DT_EEMPTY;
324 tx_desc++;
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300325 tx_desc->die_dt = DT_EEMPTY;
326 }
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300327 tx_desc->dptr = cpu_to_le32((u32)priv->tx_desc_dma[q]);
328 tx_desc->die_dt = DT_LINKFIX; /* type */
329
330 /* RX descriptor base address for best effort */
331 desc = &priv->desc_bat[RX_QUEUE_OFFSET + q];
332 desc->die_dt = DT_LINKFIX; /* type */
333 desc->dptr = cpu_to_le32((u32)priv->rx_desc_dma[q]);
334
335 /* TX descriptor base address for best effort */
336 desc = &priv->desc_bat[q];
337 desc->die_dt = DT_LINKFIX; /* type */
338 desc->dptr = cpu_to_le32((u32)priv->tx_desc_dma[q]);
339}
340
341/* Init skb and descriptor buffer for Ethernet AVB */
342static int ravb_ring_init(struct net_device *ndev, int q)
343{
344 struct ravb_private *priv = netdev_priv(ndev);
Sergei Shtylyovd8b48912015-07-22 01:31:59 +0300345 struct sk_buff *skb;
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300346 int ring_size;
Sergei Shtylyovd8b48912015-07-22 01:31:59 +0300347 int i;
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300348
Niklas Söderlund75efa062018-02-16 17:10:08 +0100349 priv->rx_buf_sz = (ndev->mtu <= 1492 ? PKT_BUF_SZ : ndev->mtu) +
350 ETH_HLEN + VLAN_HLEN;
351
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300352 /* Allocate RX and TX skb rings */
353 priv->rx_skb[q] = kcalloc(priv->num_rx_ring[q],
354 sizeof(*priv->rx_skb[q]), GFP_KERNEL);
355 priv->tx_skb[q] = kcalloc(priv->num_tx_ring[q],
356 sizeof(*priv->tx_skb[q]), GFP_KERNEL);
357 if (!priv->rx_skb[q] || !priv->tx_skb[q])
358 goto error;
359
Sergei Shtylyovd8b48912015-07-22 01:31:59 +0300360 for (i = 0; i < priv->num_rx_ring[q]; i++) {
Niklas Söderlund75efa062018-02-16 17:10:08 +0100361 skb = netdev_alloc_skb(ndev, priv->rx_buf_sz + RAVB_ALIGN - 1);
Sergei Shtylyovd8b48912015-07-22 01:31:59 +0300362 if (!skb)
363 goto error;
364 ravb_set_buffer_align(skb);
365 priv->rx_skb[q][i] = skb;
366 }
367
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300368 /* Allocate rings for the aligned buffers */
Sergei Shtylyov2f45d192015-07-25 23:42:01 +0300369 priv->tx_align[q] = kmalloc(DPTR_ALIGN * priv->num_tx_ring[q] +
370 DPTR_ALIGN - 1, GFP_KERNEL);
371 if (!priv->tx_align[q])
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300372 goto error;
373
374 /* Allocate all RX descriptors. */
375 ring_size = sizeof(struct ravb_ex_rx_desc) * (priv->num_rx_ring[q] + 1);
Kazuya Mizuguchie2dbb332015-09-30 15:15:53 +0900376 priv->rx_ring[q] = dma_alloc_coherent(ndev->dev.parent, ring_size,
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300377 &priv->rx_desc_dma[q],
378 GFP_KERNEL);
379 if (!priv->rx_ring[q])
380 goto error;
381
382 priv->dirty_rx[q] = 0;
383
384 /* Allocate all TX descriptors. */
Sergei Shtylyov2f45d192015-07-25 23:42:01 +0300385 ring_size = sizeof(struct ravb_tx_desc) *
386 (priv->num_tx_ring[q] * NUM_TX_DESC + 1);
Kazuya Mizuguchie2dbb332015-09-30 15:15:53 +0900387 priv->tx_ring[q] = dma_alloc_coherent(ndev->dev.parent, ring_size,
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300388 &priv->tx_desc_dma[q],
389 GFP_KERNEL);
390 if (!priv->tx_ring[q])
391 goto error;
392
393 return 0;
394
395error:
396 ravb_ring_free(ndev, q);
397
398 return -ENOMEM;
399}
400
401/* E-MAC init function */
402static void ravb_emac_init(struct net_device *ndev)
403{
404 struct ravb_private *priv = netdev_priv(ndev);
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300405
406 /* Receive frame limit set register */
407 ravb_write(ndev, ndev->mtu + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN, RFLR);
408
Simon Horman4d86d382017-10-04 09:54:27 +0200409 /* EMAC Mode: PAUSE prohibition; Duplex; RX Checksum; TX; RX */
Sergei Shtylyov1c1fa822016-01-11 00:27:38 +0300410 ravb_write(ndev, ECMR_ZPF | (priv->duplex ? ECMR_DM : 0) |
Simon Horman4d86d382017-10-04 09:54:27 +0200411 (ndev->features & NETIF_F_RXCSUM ? ECMR_RCSC : 0) |
Sergei Shtylyov1c1fa822016-01-11 00:27:38 +0300412 ECMR_TE | ECMR_RE, ECMR);
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300413
414 ravb_set_rate(ndev);
415
416 /* Set MAC address */
417 ravb_write(ndev,
418 (ndev->dev_addr[0] << 24) | (ndev->dev_addr[1] << 16) |
419 (ndev->dev_addr[2] << 8) | (ndev->dev_addr[3]), MAHR);
420 ravb_write(ndev,
421 (ndev->dev_addr[4] << 8) | (ndev->dev_addr[5]), MALR);
422
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300423 /* E-MAC status register clear */
424 ravb_write(ndev, ECSR_ICD | ECSR_MPD, ECSR);
425
426 /* E-MAC interrupt enable register */
427 ravb_write(ndev, ECSIPR_ICDIP | ECSIPR_MPDIP | ECSIPR_LCHNGIP, ECSIPR);
428}
429
430/* Device init function for Ethernet AVB */
431static int ravb_dmac_init(struct net_device *ndev)
432{
Kazuya Mizuguchif51bdc22016-04-03 23:54:38 +0900433 struct ravb_private *priv = netdev_priv(ndev);
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300434 int error;
435
436 /* Set CONFIG mode */
437 error = ravb_config(ndev);
438 if (error)
439 return error;
440
441 error = ravb_ring_init(ndev, RAVB_BE);
442 if (error)
443 return error;
444 error = ravb_ring_init(ndev, RAVB_NC);
445 if (error) {
446 ravb_ring_free(ndev, RAVB_BE);
447 return error;
448 }
449
450 /* Descriptor format */
451 ravb_ring_format(ndev, RAVB_BE);
452 ravb_ring_format(ndev, RAVB_NC);
453
454#if defined(__LITTLE_ENDIAN)
Sergei Shtylyov568b3ce2016-02-10 01:37:44 +0300455 ravb_modify(ndev, CCC, CCC_BOC, 0);
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300456#else
Sergei Shtylyov568b3ce2016-02-10 01:37:44 +0300457 ravb_modify(ndev, CCC, CCC_BOC, CCC_BOC);
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300458#endif
459
460 /* Set AVB RX */
Masaru Nagai8d9c4182016-06-01 03:01:28 +0900461 ravb_write(ndev,
462 RCR_EFFS | RCR_ENCF | RCR_ETS0 | RCR_ESF | 0x18000000, RCR);
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300463
464 /* Set FIFO size */
465 ravb_write(ndev, TGC_TQP_AVBMODE1 | 0x00222200, TGC);
466
467 /* Timestamp enable */
468 ravb_write(ndev, TCCR_TFEN, TCCR);
469
Kazuya Mizuguchi6474de52015-12-15 01:24:58 +0900470 /* Interrupt init: */
Kazuya Mizuguchif51bdc22016-04-03 23:54:38 +0900471 if (priv->chip_id == RCAR_GEN3) {
472 /* Clear DIL.DPLx */
473 ravb_write(ndev, 0, DIL);
474 /* Set queue specific interrupt */
475 ravb_write(ndev, CIE_CRIE | CIE_CTIE | CIE_CL0M, CIE);
476 }
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300477 /* Frame receive */
478 ravb_write(ndev, RIC0_FRE0 | RIC0_FRE1, RIC0);
Kazuya Mizuguchi6474de52015-12-15 01:24:58 +0900479 /* Disable FIFO full warning */
480 ravb_write(ndev, 0, RIC1);
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300481 /* Receive FIFO full error, descriptor empty */
482 ravb_write(ndev, RIC2_QFE0 | RIC2_QFE1 | RIC2_RFFE, RIC2);
483 /* Frame transmitted, timestamp FIFO updated */
484 ravb_write(ndev, TIC_FTE0 | TIC_FTE1 | TIC_TFUE, TIC);
485
486 /* Setting the control will start the AVB-DMAC process. */
Sergei Shtylyov568b3ce2016-02-10 01:37:44 +0300487 ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_OPERATION);
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300488
489 return 0;
490}
491
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300492static void ravb_get_tx_tstamp(struct net_device *ndev)
493{
494 struct ravb_private *priv = netdev_priv(ndev);
495 struct ravb_tstamp_skb *ts_skb, *ts_skb2;
496 struct skb_shared_hwtstamps shhwtstamps;
497 struct sk_buff *skb;
498 struct timespec64 ts;
499 u16 tag, tfa_tag;
500 int count;
501 u32 tfa2;
502
503 count = (ravb_read(ndev, TSR) & TSR_TFFL) >> 8;
504 while (count--) {
505 tfa2 = ravb_read(ndev, TFA2);
506 tfa_tag = (tfa2 & TFA2_TST) >> 16;
507 ts.tv_nsec = (u64)ravb_read(ndev, TFA0);
508 ts.tv_sec = ((u64)(tfa2 & TFA2_TSV) << 32) |
509 ravb_read(ndev, TFA1);
510 memset(&shhwtstamps, 0, sizeof(shhwtstamps));
511 shhwtstamps.hwtstamp = timespec64_to_ktime(ts);
512 list_for_each_entry_safe(ts_skb, ts_skb2, &priv->ts_skb_list,
513 list) {
514 skb = ts_skb->skb;
515 tag = ts_skb->tag;
516 list_del(&ts_skb->list);
517 kfree(ts_skb);
518 if (tag == tfa_tag) {
519 skb_tstamp_tx(skb, &shhwtstamps);
520 break;
521 }
522 }
Sergei Shtylyov568b3ce2016-02-10 01:37:44 +0300523 ravb_modify(ndev, TCCR, TCCR_TFR, TCCR_TFR);
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300524 }
525}
526
Simon Horman4d86d382017-10-04 09:54:27 +0200527static void ravb_rx_csum(struct sk_buff *skb)
528{
529 u8 *hw_csum;
530
531 /* The hardware checksum is 2 bytes appended to packet data */
532 if (unlikely(skb->len < 2))
533 return;
534 hw_csum = skb_tail_pointer(skb) - 2;
535 skb->csum = csum_unfold((__force __sum16)get_unaligned_le16(hw_csum));
536 skb->ip_summed = CHECKSUM_COMPLETE;
537 skb_trim(skb, skb->len - 2);
538}
539
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300540/* Packet receive function for Ethernet AVB */
541static bool ravb_rx(struct net_device *ndev, int *quota, int q)
542{
543 struct ravb_private *priv = netdev_priv(ndev);
544 int entry = priv->cur_rx[q] % priv->num_rx_ring[q];
545 int boguscnt = (priv->dirty_rx[q] + priv->num_rx_ring[q]) -
546 priv->cur_rx[q];
547 struct net_device_stats *stats = &priv->stats[q];
548 struct ravb_ex_rx_desc *desc;
549 struct sk_buff *skb;
550 dma_addr_t dma_addr;
551 struct timespec64 ts;
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300552 u8 desc_status;
Sergei Shtylyovaad0d512015-07-10 21:10:10 +0300553 u16 pkt_len;
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300554 int limit;
555
556 boguscnt = min(boguscnt, *quota);
557 limit = boguscnt;
558 desc = &priv->rx_ring[q][entry];
559 while (desc->die_dt != DT_FEMPTY) {
560 /* Descriptor type must be checked before all other reads */
561 dma_rmb();
562 desc_status = desc->msc;
563 pkt_len = le16_to_cpu(desc->ds_cc) & RX_DS;
564
565 if (--boguscnt < 0)
566 break;
567
Sergei Shtylyovd8b48912015-07-22 01:31:59 +0300568 /* We use 0-byte descriptors to mark the DMA mapping errors */
569 if (!pkt_len)
570 continue;
571
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300572 if (desc_status & MSC_MC)
573 stats->multicast++;
574
575 if (desc_status & (MSC_CRC | MSC_RFE | MSC_RTSF | MSC_RTLF |
576 MSC_CEEF)) {
577 stats->rx_errors++;
578 if (desc_status & MSC_CRC)
579 stats->rx_crc_errors++;
580 if (desc_status & MSC_RFE)
581 stats->rx_frame_errors++;
582 if (desc_status & (MSC_RTLF | MSC_RTSF))
583 stats->rx_length_errors++;
584 if (desc_status & MSC_CEEF)
585 stats->rx_missed_errors++;
586 } else {
587 u32 get_ts = priv->tstamp_rx_ctrl & RAVB_RXTSTAMP_TYPE;
588
589 skb = priv->rx_skb[q][entry];
590 priv->rx_skb[q][entry] = NULL;
Kazuya Mizuguchie2dbb332015-09-30 15:15:53 +0900591 dma_unmap_single(ndev->dev.parent, le32_to_cpu(desc->dptr),
Niklas Söderlund75efa062018-02-16 17:10:08 +0100592 priv->rx_buf_sz,
Sergei Shtylyove2370f02015-07-15 00:56:52 +0300593 DMA_FROM_DEVICE);
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300594 get_ts &= (q == RAVB_NC) ?
595 RAVB_RXTSTAMP_TYPE_V2_L2_EVENT :
596 ~RAVB_RXTSTAMP_TYPE_V2_L2_EVENT;
597 if (get_ts) {
598 struct skb_shared_hwtstamps *shhwtstamps;
599
600 shhwtstamps = skb_hwtstamps(skb);
601 memset(shhwtstamps, 0, sizeof(*shhwtstamps));
602 ts.tv_sec = ((u64) le16_to_cpu(desc->ts_sh) <<
603 32) | le32_to_cpu(desc->ts_sl);
604 ts.tv_nsec = le32_to_cpu(desc->ts_n);
605 shhwtstamps->hwtstamp = timespec64_to_ktime(ts);
606 }
Simon Horman4d86d382017-10-04 09:54:27 +0200607
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300608 skb_put(skb, pkt_len);
609 skb->protocol = eth_type_trans(skb, ndev);
Simon Horman4d86d382017-10-04 09:54:27 +0200610 if (ndev->features & NETIF_F_RXCSUM)
611 ravb_rx_csum(skb);
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300612 napi_gro_receive(&priv->napi[q], skb);
613 stats->rx_packets++;
614 stats->rx_bytes += pkt_len;
615 }
616
617 entry = (++priv->cur_rx[q]) % priv->num_rx_ring[q];
618 desc = &priv->rx_ring[q][entry];
619 }
620
621 /* Refill the RX ring buffers. */
622 for (; priv->cur_rx[q] - priv->dirty_rx[q] > 0; priv->dirty_rx[q]++) {
623 entry = priv->dirty_rx[q] % priv->num_rx_ring[q];
624 desc = &priv->rx_ring[q][entry];
Niklas Söderlund75efa062018-02-16 17:10:08 +0100625 desc->ds_cc = cpu_to_le16(priv->rx_buf_sz);
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300626
627 if (!priv->rx_skb[q][entry]) {
628 skb = netdev_alloc_skb(ndev,
Niklas Söderlund75efa062018-02-16 17:10:08 +0100629 priv->rx_buf_sz +
630 RAVB_ALIGN - 1);
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300631 if (!skb)
632 break; /* Better luck next round. */
633 ravb_set_buffer_align(skb);
Kazuya Mizuguchie2dbb332015-09-30 15:15:53 +0900634 dma_addr = dma_map_single(ndev->dev.parent, skb->data,
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300635 le16_to_cpu(desc->ds_cc),
636 DMA_FROM_DEVICE);
637 skb_checksum_none_assert(skb);
Sergei Shtylyovd8b48912015-07-22 01:31:59 +0300638 /* We just set the data size to 0 for a failed mapping
639 * which should prevent DMA from happening...
640 */
Kazuya Mizuguchie2dbb332015-09-30 15:15:53 +0900641 if (dma_mapping_error(ndev->dev.parent, dma_addr))
Sergei Shtylyovd8b48912015-07-22 01:31:59 +0300642 desc->ds_cc = cpu_to_le16(0);
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300643 desc->dptr = cpu_to_le32(dma_addr);
644 priv->rx_skb[q][entry] = skb;
645 }
646 /* Descriptor type must be set after all the above writes */
647 dma_wmb();
648 desc->die_dt = DT_FEMPTY;
649 }
650
651 *quota -= limit - (++boguscnt);
652
653 return boguscnt <= 0;
654}
655
656static void ravb_rcv_snd_disable(struct net_device *ndev)
657{
658 /* Disable TX and RX */
Sergei Shtylyov568b3ce2016-02-10 01:37:44 +0300659 ravb_modify(ndev, ECMR, ECMR_RE | ECMR_TE, 0);
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300660}
661
662static void ravb_rcv_snd_enable(struct net_device *ndev)
663{
664 /* Enable TX and RX */
Sergei Shtylyov568b3ce2016-02-10 01:37:44 +0300665 ravb_modify(ndev, ECMR, ECMR_RE | ECMR_TE, ECMR_RE | ECMR_TE);
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300666}
667
668/* function for waiting dma process finished */
669static int ravb_stop_dma(struct net_device *ndev)
670{
671 int error;
672
673 /* Wait for stopping the hardware TX process */
674 error = ravb_wait(ndev, TCCR,
675 TCCR_TSRQ0 | TCCR_TSRQ1 | TCCR_TSRQ2 | TCCR_TSRQ3, 0);
676 if (error)
677 return error;
678
679 error = ravb_wait(ndev, CSR, CSR_TPO0 | CSR_TPO1 | CSR_TPO2 | CSR_TPO3,
680 0);
681 if (error)
682 return error;
683
684 /* Stop the E-MAC's RX/TX processes. */
685 ravb_rcv_snd_disable(ndev);
686
687 /* Wait for stopping the RX DMA process */
688 error = ravb_wait(ndev, CSR, CSR_RPO, 0);
689 if (error)
690 return error;
691
692 /* Stop AVB-DMAC process */
693 return ravb_config(ndev);
694}
695
696/* E-MAC interrupt handler */
Kazuya Mizuguchif51bdc22016-04-03 23:54:38 +0900697static void ravb_emac_interrupt_unlocked(struct net_device *ndev)
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300698{
699 struct ravb_private *priv = netdev_priv(ndev);
700 u32 ecsr, psr;
701
702 ecsr = ravb_read(ndev, ECSR);
703 ravb_write(ndev, ecsr, ECSR); /* clear interrupt */
Niklas Söderlund3e3d6472017-08-01 12:14:36 +0200704
705 if (ecsr & ECSR_MPD)
706 pm_wakeup_event(&priv->pdev->dev, 0);
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300707 if (ecsr & ECSR_ICD)
708 ndev->stats.tx_carrier_errors++;
709 if (ecsr & ECSR_LCHNG) {
710 /* Link changed */
711 if (priv->no_avb_link)
712 return;
713 psr = ravb_read(ndev, PSR);
714 if (priv->avb_link_active_low)
715 psr ^= PSR_LMON;
716 if (!(psr & PSR_LMON)) {
717 /* DIsable RX and TX */
718 ravb_rcv_snd_disable(ndev);
719 } else {
720 /* Enable RX and TX */
721 ravb_rcv_snd_enable(ndev);
722 }
723 }
724}
725
Kazuya Mizuguchif51bdc22016-04-03 23:54:38 +0900726static irqreturn_t ravb_emac_interrupt(int irq, void *dev_id)
727{
728 struct net_device *ndev = dev_id;
729 struct ravb_private *priv = netdev_priv(ndev);
730
731 spin_lock(&priv->lock);
732 ravb_emac_interrupt_unlocked(ndev);
733 mmiowb();
734 spin_unlock(&priv->lock);
735 return IRQ_HANDLED;
736}
737
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300738/* Error interrupt handler */
739static void ravb_error_interrupt(struct net_device *ndev)
740{
741 struct ravb_private *priv = netdev_priv(ndev);
742 u32 eis, ris2;
743
744 eis = ravb_read(ndev, EIS);
745 ravb_write(ndev, ~EIS_QFS, EIS);
746 if (eis & EIS_QFS) {
747 ris2 = ravb_read(ndev, RIS2);
748 ravb_write(ndev, ~(RIS2_QFF0 | RIS2_RFFF), RIS2);
749
750 /* Receive Descriptor Empty int */
751 if (ris2 & RIS2_QFF0)
752 priv->stats[RAVB_BE].rx_over_errors++;
753
754 /* Receive Descriptor Empty int */
755 if (ris2 & RIS2_QFF1)
756 priv->stats[RAVB_NC].rx_over_errors++;
757
758 /* Receive FIFO Overflow int */
759 if (ris2 & RIS2_RFFF)
760 priv->rx_fifo_errors++;
761 }
762}
763
Kazuya Mizuguchif51bdc22016-04-03 23:54:38 +0900764static bool ravb_queue_interrupt(struct net_device *ndev, int q)
765{
766 struct ravb_private *priv = netdev_priv(ndev);
767 u32 ris0 = ravb_read(ndev, RIS0);
768 u32 ric0 = ravb_read(ndev, RIC0);
769 u32 tis = ravb_read(ndev, TIS);
770 u32 tic = ravb_read(ndev, TIC);
771
772 if (((ris0 & ric0) & BIT(q)) || ((tis & tic) & BIT(q))) {
773 if (napi_schedule_prep(&priv->napi[q])) {
774 /* Mask RX and TX interrupts */
775 if (priv->chip_id == RCAR_GEN2) {
776 ravb_write(ndev, ric0 & ~BIT(q), RIC0);
777 ravb_write(ndev, tic & ~BIT(q), TIC);
778 } else {
779 ravb_write(ndev, BIT(q), RID0);
780 ravb_write(ndev, BIT(q), TID);
781 }
782 __napi_schedule(&priv->napi[q]);
783 } else {
784 netdev_warn(ndev,
785 "ignoring interrupt, rx status 0x%08x, rx mask 0x%08x,\n",
786 ris0, ric0);
787 netdev_warn(ndev,
788 " tx status 0x%08x, tx mask 0x%08x.\n",
789 tis, tic);
790 }
791 return true;
792 }
793 return false;
794}
795
796static bool ravb_timestamp_interrupt(struct net_device *ndev)
797{
798 u32 tis = ravb_read(ndev, TIS);
799
800 if (tis & TIS_TFUF) {
801 ravb_write(ndev, ~TIS_TFUF, TIS);
802 ravb_get_tx_tstamp(ndev);
803 return true;
804 }
805 return false;
806}
807
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300808static irqreturn_t ravb_interrupt(int irq, void *dev_id)
809{
810 struct net_device *ndev = dev_id;
811 struct ravb_private *priv = netdev_priv(ndev);
812 irqreturn_t result = IRQ_NONE;
813 u32 iss;
814
815 spin_lock(&priv->lock);
816 /* Get interrupt status */
817 iss = ravb_read(ndev, ISS);
818
819 /* Received and transmitted interrupts */
820 if (iss & (ISS_FRS | ISS_FTS | ISS_TFUS)) {
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300821 int q;
822
823 /* Timestamp updated */
Kazuya Mizuguchif51bdc22016-04-03 23:54:38 +0900824 if (ravb_timestamp_interrupt(ndev))
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300825 result = IRQ_HANDLED;
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300826
827 /* Network control and best effort queue RX/TX */
828 for (q = RAVB_NC; q >= RAVB_BE; q--) {
Kazuya Mizuguchif51bdc22016-04-03 23:54:38 +0900829 if (ravb_queue_interrupt(ndev, q))
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300830 result = IRQ_HANDLED;
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300831 }
832 }
833
834 /* E-MAC status summary */
835 if (iss & ISS_MS) {
Kazuya Mizuguchif51bdc22016-04-03 23:54:38 +0900836 ravb_emac_interrupt_unlocked(ndev);
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300837 result = IRQ_HANDLED;
838 }
839
840 /* Error status summary */
841 if (iss & ISS_ES) {
842 ravb_error_interrupt(ndev);
843 result = IRQ_HANDLED;
844 }
845
Kazuya Mizuguchif51bdc22016-04-03 23:54:38 +0900846 /* gPTP interrupt status summary */
Sergei Shtylyovd0988a52016-04-10 23:55:15 +0300847 if (iss & ISS_CGIS) {
848 ravb_ptp_interrupt(ndev);
Yoshihiro Kaneko38c848c2016-03-16 00:52:16 +0900849 result = IRQ_HANDLED;
Sergei Shtylyovd0988a52016-04-10 23:55:15 +0300850 }
Sergei Shtylyova0d2f202015-06-11 01:02:30 +0300851
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300852 mmiowb();
853 spin_unlock(&priv->lock);
854 return result;
855}
856
Kazuya Mizuguchif51bdc22016-04-03 23:54:38 +0900857/* Timestamp/Error/gPTP interrupt handler */
858static irqreturn_t ravb_multi_interrupt(int irq, void *dev_id)
859{
860 struct net_device *ndev = dev_id;
861 struct ravb_private *priv = netdev_priv(ndev);
862 irqreturn_t result = IRQ_NONE;
863 u32 iss;
864
865 spin_lock(&priv->lock);
866 /* Get interrupt status */
867 iss = ravb_read(ndev, ISS);
868
869 /* Timestamp updated */
870 if ((iss & ISS_TFUS) && ravb_timestamp_interrupt(ndev))
871 result = IRQ_HANDLED;
872
873 /* Error status summary */
874 if (iss & ISS_ES) {
875 ravb_error_interrupt(ndev);
876 result = IRQ_HANDLED;
877 }
878
879 /* gPTP interrupt status summary */
Sergei Shtylyovd0988a52016-04-10 23:55:15 +0300880 if (iss & ISS_CGIS) {
881 ravb_ptp_interrupt(ndev);
Kazuya Mizuguchif51bdc22016-04-03 23:54:38 +0900882 result = IRQ_HANDLED;
Sergei Shtylyovd0988a52016-04-10 23:55:15 +0300883 }
Kazuya Mizuguchif51bdc22016-04-03 23:54:38 +0900884
885 mmiowb();
886 spin_unlock(&priv->lock);
887 return result;
888}
889
890static irqreturn_t ravb_dma_interrupt(int irq, void *dev_id, int q)
891{
892 struct net_device *ndev = dev_id;
893 struct ravb_private *priv = netdev_priv(ndev);
894 irqreturn_t result = IRQ_NONE;
895
896 spin_lock(&priv->lock);
897
898 /* Network control/Best effort queue RX/TX */
899 if (ravb_queue_interrupt(ndev, q))
900 result = IRQ_HANDLED;
901
902 mmiowb();
903 spin_unlock(&priv->lock);
904 return result;
905}
906
907static irqreturn_t ravb_be_interrupt(int irq, void *dev_id)
908{
909 return ravb_dma_interrupt(irq, dev_id, RAVB_BE);
910}
911
912static irqreturn_t ravb_nc_interrupt(int irq, void *dev_id)
913{
914 return ravb_dma_interrupt(irq, dev_id, RAVB_NC);
915}
916
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300917static int ravb_poll(struct napi_struct *napi, int budget)
918{
919 struct net_device *ndev = napi->dev;
920 struct ravb_private *priv = netdev_priv(ndev);
921 unsigned long flags;
922 int q = napi - priv->napi;
923 int mask = BIT(q);
924 int quota = budget;
925 u32 ris0, tis;
926
927 for (;;) {
928 tis = ravb_read(ndev, TIS);
929 ris0 = ravb_read(ndev, RIS0);
930 if (!((ris0 & mask) || (tis & mask)))
931 break;
932
933 /* Processing RX Descriptor Ring */
934 if (ris0 & mask) {
935 /* Clear RX interrupt */
936 ravb_write(ndev, ~mask, RIS0);
937 if (ravb_rx(ndev, &quota, q))
938 goto out;
939 }
940 /* Processing TX Descriptor Ring */
941 if (tis & mask) {
942 spin_lock_irqsave(&priv->lock, flags);
943 /* Clear TX interrupt */
944 ravb_write(ndev, ~mask, TIS);
Kazuya Mizuguchia47b70e2017-01-26 14:29:27 +0100945 ravb_tx_free(ndev, q, true);
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300946 netif_wake_subqueue(ndev, q);
947 mmiowb();
948 spin_unlock_irqrestore(&priv->lock, flags);
949 }
950 }
951
952 napi_complete(napi);
953
954 /* Re-enable RX/TX interrupts */
955 spin_lock_irqsave(&priv->lock, flags);
Kazuya Mizuguchif51bdc22016-04-03 23:54:38 +0900956 if (priv->chip_id == RCAR_GEN2) {
957 ravb_modify(ndev, RIC0, mask, mask);
958 ravb_modify(ndev, TIC, mask, mask);
959 } else {
960 ravb_write(ndev, mask, RIE0);
961 ravb_write(ndev, mask, TIE);
962 }
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300963 mmiowb();
964 spin_unlock_irqrestore(&priv->lock, flags);
965
966 /* Receive error message handling */
967 priv->rx_over_errors = priv->stats[RAVB_BE].rx_over_errors;
968 priv->rx_over_errors += priv->stats[RAVB_NC].rx_over_errors;
Kazuya Mizuguchi18a3ed52017-01-12 13:21:06 +0100969 if (priv->rx_over_errors != ndev->stats.rx_over_errors)
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300970 ndev->stats.rx_over_errors = priv->rx_over_errors;
Kazuya Mizuguchi18a3ed52017-01-12 13:21:06 +0100971 if (priv->rx_fifo_errors != ndev->stats.rx_fifo_errors)
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300972 ndev->stats.rx_fifo_errors = priv->rx_fifo_errors;
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300973out:
974 return budget - quota;
975}
976
977/* PHY state control function */
978static void ravb_adjust_link(struct net_device *ndev)
979{
980 struct ravb_private *priv = netdev_priv(ndev);
Philippe Reynes0f635172016-08-20 00:52:18 +0200981 struct phy_device *phydev = ndev->phydev;
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300982 bool new_state = false;
983
984 if (phydev->link) {
985 if (phydev->duplex != priv->duplex) {
986 new_state = true;
987 priv->duplex = phydev->duplex;
988 ravb_set_duplex(ndev);
989 }
990
991 if (phydev->speed != priv->speed) {
992 new_state = true;
993 priv->speed = phydev->speed;
994 ravb_set_rate(ndev);
995 }
996 if (!priv->link) {
Sergei Shtylyov568b3ce2016-02-10 01:37:44 +0300997 ravb_modify(ndev, ECMR, ECMR_TXF, 0);
Sergei Shtylyovc1566332015-06-11 01:01:43 +0300998 new_state = true;
999 priv->link = phydev->link;
1000 if (priv->no_avb_link)
1001 ravb_rcv_snd_enable(ndev);
1002 }
1003 } else if (priv->link) {
1004 new_state = true;
1005 priv->link = 0;
1006 priv->speed = 0;
1007 priv->duplex = -1;
1008 if (priv->no_avb_link)
1009 ravb_rcv_snd_disable(ndev);
1010 }
1011
1012 if (new_state && netif_msg_link(priv))
1013 phy_print_status(phydev);
1014}
1015
Geert Uytterhoeven0e98f9d2017-01-27 20:46:27 +01001016static const struct soc_device_attribute r8a7795es10[] = {
1017 { .soc_id = "r8a7795", .revision = "ES1.0", },
1018 { /* sentinel */ }
1019};
1020
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001021/* PHY init function */
1022static int ravb_phy_init(struct net_device *ndev)
1023{
1024 struct device_node *np = ndev->dev.parent->of_node;
1025 struct ravb_private *priv = netdev_priv(ndev);
1026 struct phy_device *phydev;
1027 struct device_node *pn;
Kazuya Mizuguchib4bc88a2015-12-15 19:44:13 +09001028 int err;
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001029
1030 priv->link = 0;
1031 priv->speed = 0;
1032 priv->duplex = -1;
1033
1034 /* Try connecting to PHY */
1035 pn = of_parse_phandle(np, "phy-handle", 0);
Kazuya Mizuguchib4bc88a2015-12-15 19:44:13 +09001036 if (!pn) {
1037 /* In the case of a fixed PHY, the DT node associated
1038 * to the PHY is the Ethernet MAC DT node.
1039 */
1040 if (of_phy_is_fixed_link(np)) {
1041 err = of_phy_register_fixed_link(np);
1042 if (err)
1043 return err;
1044 }
1045 pn = of_node_get(np);
1046 }
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001047 phydev = of_phy_connect(ndev, pn, ravb_adjust_link, 0,
1048 priv->phy_interface);
Peter Chenc9b1eb82016-08-01 15:02:39 +08001049 of_node_put(pn);
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001050 if (!phydev) {
1051 netdev_err(ndev, "failed to connect PHY\n");
Johan Hovold9f70eb32016-11-28 19:25:06 +01001052 err = -ENOENT;
1053 goto err_deregister_fixed_link;
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001054 }
1055
Geert Uytterhoeven0e98f9d2017-01-27 20:46:27 +01001056 /* This driver only support 10/100Mbit speeds on R-Car H3 ES1.0
Kazuya Mizuguchi22d4df82015-09-30 15:15:55 +09001057 * at this time.
1058 */
Geert Uytterhoeven0e98f9d2017-01-27 20:46:27 +01001059 if (soc_device_match(r8a7795es10)) {
Kazuya Mizuguchi22d4df82015-09-30 15:15:55 +09001060 err = phy_set_max_speed(phydev, SPEED_100);
1061 if (err) {
1062 netdev_err(ndev, "failed to limit PHY to 100Mbit/s\n");
Johan Hovold9f70eb32016-11-28 19:25:06 +01001063 goto err_phy_disconnect;
Kazuya Mizuguchi22d4df82015-09-30 15:15:55 +09001064 }
1065
1066 netdev_info(ndev, "limited PHY to 100Mbit/s\n");
1067 }
1068
Kazuya Mizuguchi54499962015-12-14 00:15:58 +09001069 /* 10BASE is not supported */
1070 phydev->supported &= ~PHY_10BT_FEATURES;
1071
Andrew Lunn22209432016-01-06 20:11:13 +01001072 phy_attached_info(phydev);
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001073
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001074 return 0;
Johan Hovold9f70eb32016-11-28 19:25:06 +01001075
1076err_phy_disconnect:
1077 phy_disconnect(phydev);
1078err_deregister_fixed_link:
1079 if (of_phy_is_fixed_link(np))
1080 of_phy_deregister_fixed_link(np);
1081
1082 return err;
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001083}
1084
1085/* PHY control start function */
1086static int ravb_phy_start(struct net_device *ndev)
1087{
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001088 int error;
1089
1090 error = ravb_phy_init(ndev);
1091 if (error)
1092 return error;
1093
Philippe Reynes0f635172016-08-20 00:52:18 +02001094 phy_start(ndev->phydev);
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001095
1096 return 0;
1097}
1098
Philippe Reynes04462f22016-08-20 00:52:19 +02001099static int ravb_get_link_ksettings(struct net_device *ndev,
1100 struct ethtool_link_ksettings *cmd)
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001101{
1102 struct ravb_private *priv = netdev_priv(ndev);
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001103 unsigned long flags;
1104
yuval.shaia@oracle.com55141742017-06-13 10:09:46 +03001105 if (!ndev->phydev)
1106 return -ENODEV;
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001107
yuval.shaia@oracle.com55141742017-06-13 10:09:46 +03001108 spin_lock_irqsave(&priv->lock, flags);
1109 phy_ethtool_ksettings_get(ndev->phydev, cmd);
1110 spin_unlock_irqrestore(&priv->lock, flags);
1111
1112 return 0;
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001113}
1114
Philippe Reynes04462f22016-08-20 00:52:19 +02001115static int ravb_set_link_ksettings(struct net_device *ndev,
1116 const struct ethtool_link_ksettings *cmd)
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001117{
1118 struct ravb_private *priv = netdev_priv(ndev);
1119 unsigned long flags;
1120 int error;
1121
Philippe Reynes0f635172016-08-20 00:52:18 +02001122 if (!ndev->phydev)
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001123 return -ENODEV;
1124
1125 spin_lock_irqsave(&priv->lock, flags);
1126
1127 /* Disable TX and RX */
1128 ravb_rcv_snd_disable(ndev);
1129
Philippe Reynes04462f22016-08-20 00:52:19 +02001130 error = phy_ethtool_ksettings_set(ndev->phydev, cmd);
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001131 if (error)
1132 goto error_exit;
1133
Philippe Reynes04462f22016-08-20 00:52:19 +02001134 if (cmd->base.duplex == DUPLEX_FULL)
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001135 priv->duplex = 1;
1136 else
1137 priv->duplex = 0;
1138
1139 ravb_set_duplex(ndev);
1140
1141error_exit:
1142 mdelay(1);
1143
1144 /* Enable TX and RX */
1145 ravb_rcv_snd_enable(ndev);
1146
1147 mmiowb();
1148 spin_unlock_irqrestore(&priv->lock, flags);
1149
1150 return error;
1151}
1152
1153static int ravb_nway_reset(struct net_device *ndev)
1154{
1155 struct ravb_private *priv = netdev_priv(ndev);
1156 int error = -ENODEV;
1157 unsigned long flags;
1158
Philippe Reynes0f635172016-08-20 00:52:18 +02001159 if (ndev->phydev) {
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001160 spin_lock_irqsave(&priv->lock, flags);
Philippe Reynes0f635172016-08-20 00:52:18 +02001161 error = phy_start_aneg(ndev->phydev);
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001162 spin_unlock_irqrestore(&priv->lock, flags);
1163 }
1164
1165 return error;
1166}
1167
1168static u32 ravb_get_msglevel(struct net_device *ndev)
1169{
1170 struct ravb_private *priv = netdev_priv(ndev);
1171
1172 return priv->msg_enable;
1173}
1174
1175static void ravb_set_msglevel(struct net_device *ndev, u32 value)
1176{
1177 struct ravb_private *priv = netdev_priv(ndev);
1178
1179 priv->msg_enable = value;
1180}
1181
1182static const char ravb_gstrings_stats[][ETH_GSTRING_LEN] = {
1183 "rx_queue_0_current",
1184 "tx_queue_0_current",
1185 "rx_queue_0_dirty",
1186 "tx_queue_0_dirty",
1187 "rx_queue_0_packets",
1188 "tx_queue_0_packets",
1189 "rx_queue_0_bytes",
1190 "tx_queue_0_bytes",
1191 "rx_queue_0_mcast_packets",
1192 "rx_queue_0_errors",
1193 "rx_queue_0_crc_errors",
1194 "rx_queue_0_frame_errors",
1195 "rx_queue_0_length_errors",
1196 "rx_queue_0_missed_errors",
1197 "rx_queue_0_over_errors",
1198
1199 "rx_queue_1_current",
1200 "tx_queue_1_current",
1201 "rx_queue_1_dirty",
1202 "tx_queue_1_dirty",
1203 "rx_queue_1_packets",
1204 "tx_queue_1_packets",
1205 "rx_queue_1_bytes",
1206 "tx_queue_1_bytes",
1207 "rx_queue_1_mcast_packets",
1208 "rx_queue_1_errors",
1209 "rx_queue_1_crc_errors",
Sergei Shtylyovb17c1d92015-12-04 01:51:10 +03001210 "rx_queue_1_frame_errors",
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001211 "rx_queue_1_length_errors",
1212 "rx_queue_1_missed_errors",
1213 "rx_queue_1_over_errors",
1214};
1215
1216#define RAVB_STATS_LEN ARRAY_SIZE(ravb_gstrings_stats)
1217
1218static int ravb_get_sset_count(struct net_device *netdev, int sset)
1219{
1220 switch (sset) {
1221 case ETH_SS_STATS:
1222 return RAVB_STATS_LEN;
1223 default:
1224 return -EOPNOTSUPP;
1225 }
1226}
1227
1228static void ravb_get_ethtool_stats(struct net_device *ndev,
Niklas Söderlundc94f2fc2018-07-16 14:19:25 +02001229 struct ethtool_stats *estats, u64 *data)
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001230{
1231 struct ravb_private *priv = netdev_priv(ndev);
1232 int i = 0;
1233 int q;
1234
1235 /* Device-specific stats */
1236 for (q = RAVB_BE; q < NUM_RX_QUEUE; q++) {
1237 struct net_device_stats *stats = &priv->stats[q];
1238
1239 data[i++] = priv->cur_rx[q];
1240 data[i++] = priv->cur_tx[q];
1241 data[i++] = priv->dirty_rx[q];
1242 data[i++] = priv->dirty_tx[q];
1243 data[i++] = stats->rx_packets;
1244 data[i++] = stats->tx_packets;
1245 data[i++] = stats->rx_bytes;
1246 data[i++] = stats->tx_bytes;
1247 data[i++] = stats->multicast;
1248 data[i++] = stats->rx_errors;
1249 data[i++] = stats->rx_crc_errors;
1250 data[i++] = stats->rx_frame_errors;
1251 data[i++] = stats->rx_length_errors;
1252 data[i++] = stats->rx_missed_errors;
1253 data[i++] = stats->rx_over_errors;
1254 }
1255}
1256
1257static void ravb_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
1258{
1259 switch (stringset) {
1260 case ETH_SS_STATS:
1261 memcpy(data, *ravb_gstrings_stats, sizeof(ravb_gstrings_stats));
1262 break;
1263 }
1264}
1265
1266static void ravb_get_ringparam(struct net_device *ndev,
1267 struct ethtool_ringparam *ring)
1268{
1269 struct ravb_private *priv = netdev_priv(ndev);
1270
1271 ring->rx_max_pending = BE_RX_RING_MAX;
1272 ring->tx_max_pending = BE_TX_RING_MAX;
1273 ring->rx_pending = priv->num_rx_ring[RAVB_BE];
1274 ring->tx_pending = priv->num_tx_ring[RAVB_BE];
1275}
1276
1277static int ravb_set_ringparam(struct net_device *ndev,
1278 struct ethtool_ringparam *ring)
1279{
1280 struct ravb_private *priv = netdev_priv(ndev);
1281 int error;
1282
1283 if (ring->tx_pending > BE_TX_RING_MAX ||
1284 ring->rx_pending > BE_RX_RING_MAX ||
1285 ring->tx_pending < BE_TX_RING_MIN ||
1286 ring->rx_pending < BE_RX_RING_MIN)
1287 return -EINVAL;
1288 if (ring->rx_mini_pending || ring->rx_jumbo_pending)
1289 return -EINVAL;
1290
1291 if (netif_running(ndev)) {
1292 netif_device_detach(ndev);
Sergei Shtylyova0d2f202015-06-11 01:02:30 +03001293 /* Stop PTP Clock driver */
Sergei Shtylyov50bfd832016-02-06 17:47:22 +03001294 if (priv->chip_id == RCAR_GEN2)
1295 ravb_ptp_stop(ndev);
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001296 /* Wait for DMA stopping */
1297 error = ravb_stop_dma(ndev);
1298 if (error) {
1299 netdev_err(ndev,
1300 "cannot set ringparam! Any AVB processes are still running?\n");
1301 return error;
1302 }
1303 synchronize_irq(ndev->irq);
1304
1305 /* Free all the skb's in the RX queue and the DMA buffers. */
1306 ravb_ring_free(ndev, RAVB_BE);
1307 ravb_ring_free(ndev, RAVB_NC);
1308 }
1309
1310 /* Set new parameters */
1311 priv->num_rx_ring[RAVB_BE] = ring->rx_pending;
1312 priv->num_tx_ring[RAVB_BE] = ring->tx_pending;
1313
1314 if (netif_running(ndev)) {
1315 error = ravb_dmac_init(ndev);
1316 if (error) {
1317 netdev_err(ndev,
1318 "%s: ravb_dmac_init() failed, error %d\n",
1319 __func__, error);
1320 return error;
1321 }
1322
1323 ravb_emac_init(ndev);
1324
Sergei Shtylyova0d2f202015-06-11 01:02:30 +03001325 /* Initialise PTP Clock driver */
Sergei Shtylyov50bfd832016-02-06 17:47:22 +03001326 if (priv->chip_id == RCAR_GEN2)
1327 ravb_ptp_init(ndev, priv->pdev);
Sergei Shtylyova0d2f202015-06-11 01:02:30 +03001328
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001329 netif_device_attach(ndev);
1330 }
1331
1332 return 0;
1333}
1334
1335static int ravb_get_ts_info(struct net_device *ndev,
1336 struct ethtool_ts_info *info)
1337{
Sergei Shtylyova0d2f202015-06-11 01:02:30 +03001338 struct ravb_private *priv = netdev_priv(ndev);
1339
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001340 info->so_timestamping =
1341 SOF_TIMESTAMPING_TX_SOFTWARE |
1342 SOF_TIMESTAMPING_RX_SOFTWARE |
1343 SOF_TIMESTAMPING_SOFTWARE |
1344 SOF_TIMESTAMPING_TX_HARDWARE |
1345 SOF_TIMESTAMPING_RX_HARDWARE |
1346 SOF_TIMESTAMPING_RAW_HARDWARE;
1347 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
1348 info->rx_filters =
1349 (1 << HWTSTAMP_FILTER_NONE) |
1350 (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1351 (1 << HWTSTAMP_FILTER_ALL);
Sergei Shtylyova0d2f202015-06-11 01:02:30 +03001352 info->phc_index = ptp_clock_index(priv->ptp.clock);
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001353
1354 return 0;
1355}
1356
Niklas Söderlund3e3d6472017-08-01 12:14:36 +02001357static void ravb_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
1358{
1359 struct ravb_private *priv = netdev_priv(ndev);
1360
Geert Uytterhoevenab104612017-10-12 10:24:53 +02001361 wol->supported = WAKE_MAGIC;
1362 wol->wolopts = priv->wol_enabled ? WAKE_MAGIC : 0;
Niklas Söderlund3e3d6472017-08-01 12:14:36 +02001363}
1364
1365static int ravb_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
1366{
1367 struct ravb_private *priv = netdev_priv(ndev);
1368
Geert Uytterhoevenab104612017-10-12 10:24:53 +02001369 if (wol->wolopts & ~WAKE_MAGIC)
Niklas Söderlund3e3d6472017-08-01 12:14:36 +02001370 return -EOPNOTSUPP;
1371
1372 priv->wol_enabled = !!(wol->wolopts & WAKE_MAGIC);
1373
1374 device_set_wakeup_enable(&priv->pdev->dev, priv->wol_enabled);
1375
1376 return 0;
1377}
1378
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001379static const struct ethtool_ops ravb_ethtool_ops = {
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001380 .nway_reset = ravb_nway_reset,
1381 .get_msglevel = ravb_get_msglevel,
1382 .set_msglevel = ravb_set_msglevel,
1383 .get_link = ethtool_op_get_link,
1384 .get_strings = ravb_get_strings,
1385 .get_ethtool_stats = ravb_get_ethtool_stats,
1386 .get_sset_count = ravb_get_sset_count,
1387 .get_ringparam = ravb_get_ringparam,
1388 .set_ringparam = ravb_set_ringparam,
1389 .get_ts_info = ravb_get_ts_info,
Philippe Reynes04462f22016-08-20 00:52:19 +02001390 .get_link_ksettings = ravb_get_link_ksettings,
1391 .set_link_ksettings = ravb_set_link_ksettings,
Niklas Söderlund3e3d6472017-08-01 12:14:36 +02001392 .get_wol = ravb_get_wol,
1393 .set_wol = ravb_set_wol,
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001394};
1395
Kazuya Mizuguchif51bdc22016-04-03 23:54:38 +09001396static inline int ravb_hook_irq(unsigned int irq, irq_handler_t handler,
1397 struct net_device *ndev, struct device *dev,
1398 const char *ch)
1399{
1400 char *name;
1401 int error;
1402
1403 name = devm_kasprintf(dev, GFP_KERNEL, "%s:%s", ndev->name, ch);
1404 if (!name)
1405 return -ENOMEM;
1406 error = request_irq(irq, handler, 0, name, ndev);
1407 if (error)
1408 netdev_err(ndev, "cannot request IRQ %s\n", name);
1409
1410 return error;
1411}
1412
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001413/* Network device open function for Ethernet AVB */
1414static int ravb_open(struct net_device *ndev)
1415{
1416 struct ravb_private *priv = netdev_priv(ndev);
Kazuya Mizuguchif51bdc22016-04-03 23:54:38 +09001417 struct platform_device *pdev = priv->pdev;
1418 struct device *dev = &pdev->dev;
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001419 int error;
1420
1421 napi_enable(&priv->napi[RAVB_BE]);
1422 napi_enable(&priv->napi[RAVB_NC]);
1423
Kazuya Mizuguchif51bdc22016-04-03 23:54:38 +09001424 if (priv->chip_id == RCAR_GEN2) {
1425 error = request_irq(ndev->irq, ravb_interrupt, IRQF_SHARED,
1426 ndev->name, ndev);
Kazuya Mizuguchi22d4df82015-09-30 15:15:55 +09001427 if (error) {
1428 netdev_err(ndev, "cannot request IRQ\n");
Kazuya Mizuguchif51bdc22016-04-03 23:54:38 +09001429 goto out_napi_off;
Kazuya Mizuguchi22d4df82015-09-30 15:15:55 +09001430 }
Kazuya Mizuguchif51bdc22016-04-03 23:54:38 +09001431 } else {
1432 error = ravb_hook_irq(ndev->irq, ravb_multi_interrupt, ndev,
1433 dev, "ch22:multi");
1434 if (error)
1435 goto out_napi_off;
1436 error = ravb_hook_irq(priv->emac_irq, ravb_emac_interrupt, ndev,
1437 dev, "ch24:emac");
1438 if (error)
1439 goto out_free_irq;
1440 error = ravb_hook_irq(priv->rx_irqs[RAVB_BE], ravb_be_interrupt,
1441 ndev, dev, "ch0:rx_be");
1442 if (error)
1443 goto out_free_irq_emac;
1444 error = ravb_hook_irq(priv->tx_irqs[RAVB_BE], ravb_be_interrupt,
1445 ndev, dev, "ch18:tx_be");
1446 if (error)
1447 goto out_free_irq_be_rx;
1448 error = ravb_hook_irq(priv->rx_irqs[RAVB_NC], ravb_nc_interrupt,
1449 ndev, dev, "ch1:rx_nc");
1450 if (error)
1451 goto out_free_irq_be_tx;
1452 error = ravb_hook_irq(priv->tx_irqs[RAVB_NC], ravb_nc_interrupt,
1453 ndev, dev, "ch19:tx_nc");
1454 if (error)
1455 goto out_free_irq_nc_rx;
Kazuya Mizuguchi22d4df82015-09-30 15:15:55 +09001456 }
1457
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001458 /* Device init */
1459 error = ravb_dmac_init(ndev);
1460 if (error)
Kazuya Mizuguchif51bdc22016-04-03 23:54:38 +09001461 goto out_free_irq_nc_tx;
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001462 ravb_emac_init(ndev);
1463
Sergei Shtylyova0d2f202015-06-11 01:02:30 +03001464 /* Initialise PTP Clock driver */
Kazuya Mizuguchif5d78372015-12-02 02:04:39 +09001465 if (priv->chip_id == RCAR_GEN2)
1466 ravb_ptp_init(ndev, priv->pdev);
Sergei Shtylyova0d2f202015-06-11 01:02:30 +03001467
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001468 netif_tx_start_all_queues(ndev);
1469
1470 /* PHY control start */
1471 error = ravb_phy_start(ndev);
1472 if (error)
Sergei Shtylyova0d2f202015-06-11 01:02:30 +03001473 goto out_ptp_stop;
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001474
1475 return 0;
1476
Sergei Shtylyova0d2f202015-06-11 01:02:30 +03001477out_ptp_stop:
1478 /* Stop PTP Clock driver */
Kazuya Mizuguchif5d78372015-12-02 02:04:39 +09001479 if (priv->chip_id == RCAR_GEN2)
1480 ravb_ptp_stop(ndev);
Kazuya Mizuguchif51bdc22016-04-03 23:54:38 +09001481out_free_irq_nc_tx:
1482 if (priv->chip_id == RCAR_GEN2)
1483 goto out_free_irq;
1484 free_irq(priv->tx_irqs[RAVB_NC], ndev);
1485out_free_irq_nc_rx:
1486 free_irq(priv->rx_irqs[RAVB_NC], ndev);
1487out_free_irq_be_tx:
1488 free_irq(priv->tx_irqs[RAVB_BE], ndev);
1489out_free_irq_be_rx:
1490 free_irq(priv->rx_irqs[RAVB_BE], ndev);
1491out_free_irq_emac:
1492 free_irq(priv->emac_irq, ndev);
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001493out_free_irq:
1494 free_irq(ndev->irq, ndev);
1495out_napi_off:
1496 napi_disable(&priv->napi[RAVB_NC]);
1497 napi_disable(&priv->napi[RAVB_BE]);
1498 return error;
1499}
1500
1501/* Timeout function for Ethernet AVB */
1502static void ravb_tx_timeout(struct net_device *ndev)
1503{
1504 struct ravb_private *priv = netdev_priv(ndev);
1505
1506 netif_err(priv, tx_err, ndev,
1507 "transmit timed out, status %08x, resetting...\n",
1508 ravb_read(ndev, ISS));
1509
1510 /* tx_errors count up */
1511 ndev->stats.tx_errors++;
1512
1513 schedule_work(&priv->work);
1514}
1515
1516static void ravb_tx_timeout_work(struct work_struct *work)
1517{
1518 struct ravb_private *priv = container_of(work, struct ravb_private,
1519 work);
1520 struct net_device *ndev = priv->ndev;
1521
1522 netif_tx_stop_all_queues(ndev);
1523
Sergei Shtylyova0d2f202015-06-11 01:02:30 +03001524 /* Stop PTP Clock driver */
Sergei Shtylyov50bfd832016-02-06 17:47:22 +03001525 if (priv->chip_id == RCAR_GEN2)
1526 ravb_ptp_stop(ndev);
Sergei Shtylyova0d2f202015-06-11 01:02:30 +03001527
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001528 /* Wait for DMA stopping */
1529 ravb_stop_dma(ndev);
1530
1531 ravb_ring_free(ndev, RAVB_BE);
1532 ravb_ring_free(ndev, RAVB_NC);
1533
1534 /* Device init */
1535 ravb_dmac_init(ndev);
1536 ravb_emac_init(ndev);
1537
Sergei Shtylyova0d2f202015-06-11 01:02:30 +03001538 /* Initialise PTP Clock driver */
Sergei Shtylyov50bfd832016-02-06 17:47:22 +03001539 if (priv->chip_id == RCAR_GEN2)
1540 ravb_ptp_init(ndev, priv->pdev);
Sergei Shtylyova0d2f202015-06-11 01:02:30 +03001541
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001542 netif_tx_start_all_queues(ndev);
1543}
1544
1545/* Packet transmit function for Ethernet AVB */
1546static netdev_tx_t ravb_start_xmit(struct sk_buff *skb, struct net_device *ndev)
1547{
1548 struct ravb_private *priv = netdev_priv(ndev);
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001549 u16 q = skb_get_queue_mapping(skb);
Sergei Shtylyovaad0d512015-07-10 21:10:10 +03001550 struct ravb_tstamp_skb *ts_skb;
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001551 struct ravb_tx_desc *desc;
1552 unsigned long flags;
1553 u32 dma_addr;
1554 void *buffer;
1555 u32 entry;
Sergei Shtylyov2f45d192015-07-25 23:42:01 +03001556 u32 len;
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001557
1558 spin_lock_irqsave(&priv->lock, flags);
Sergei Shtylyov2f45d192015-07-25 23:42:01 +03001559 if (priv->cur_tx[q] - priv->dirty_tx[q] > (priv->num_tx_ring[q] - 1) *
1560 NUM_TX_DESC) {
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001561 netif_err(priv, tx_queued, ndev,
1562 "still transmitting with the full ring!\n");
1563 netif_stop_subqueue(ndev, q);
1564 spin_unlock_irqrestore(&priv->lock, flags);
1565 return NETDEV_TX_BUSY;
1566 }
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001567
1568 if (skb_put_padto(skb, ETH_ZLEN))
Dan Carpenter9199cb72017-04-22 13:46:56 +03001569 goto exit;
1570
1571 entry = priv->cur_tx[q] % (priv->num_tx_ring[q] * NUM_TX_DESC);
1572 priv->tx_skb[q][entry / NUM_TX_DESC] = skb;
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001573
Sergei Shtylyov2f45d192015-07-25 23:42:01 +03001574 buffer = PTR_ALIGN(priv->tx_align[q], DPTR_ALIGN) +
1575 entry / NUM_TX_DESC * DPTR_ALIGN;
1576 len = PTR_ALIGN(skb->data, DPTR_ALIGN) - skb->data;
Masaru Nagai8ec3e8a2017-01-16 11:45:21 +01001577 /* Zero length DMA descriptors are problematic as they seem to
1578 * terminate DMA transfers. Avoid them by simply using a length of
1579 * DPTR_ALIGN (4) when skb data is aligned to DPTR_ALIGN.
1580 *
1581 * As skb is guaranteed to have at least ETH_ZLEN (60) bytes of
1582 * data by the call to skb_put_padto() above this is safe with
1583 * respect to both the length of the first DMA descriptor (len)
1584 * overflowing the available data and the length of the second DMA
1585 * descriptor (skb->len - len) being negative.
1586 */
1587 if (len == 0)
1588 len = DPTR_ALIGN;
1589
Sergei Shtylyov2f45d192015-07-25 23:42:01 +03001590 memcpy(buffer, skb->data, len);
Kazuya Mizuguchie2dbb332015-09-30 15:15:53 +09001591 dma_addr = dma_map_single(ndev->dev.parent, buffer, len, DMA_TO_DEVICE);
1592 if (dma_mapping_error(ndev->dev.parent, dma_addr))
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001593 goto drop;
Sergei Shtylyov2f45d192015-07-25 23:42:01 +03001594
1595 desc = &priv->tx_ring[q][entry];
1596 desc->ds_tagl = cpu_to_le16(len);
1597 desc->dptr = cpu_to_le32(dma_addr);
1598
1599 buffer = skb->data + len;
1600 len = skb->len - len;
Kazuya Mizuguchie2dbb332015-09-30 15:15:53 +09001601 dma_addr = dma_map_single(ndev->dev.parent, buffer, len, DMA_TO_DEVICE);
1602 if (dma_mapping_error(ndev->dev.parent, dma_addr))
Sergei Shtylyov2f45d192015-07-25 23:42:01 +03001603 goto unmap;
1604
1605 desc++;
1606 desc->ds_tagl = cpu_to_le16(len);
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001607 desc->dptr = cpu_to_le32(dma_addr);
1608
1609 /* TX timestamp required */
1610 if (q == RAVB_NC) {
1611 ts_skb = kmalloc(sizeof(*ts_skb), GFP_ATOMIC);
1612 if (!ts_skb) {
Sergei Shtylyov2f45d192015-07-25 23:42:01 +03001613 desc--;
Kazuya Mizuguchie2dbb332015-09-30 15:15:53 +09001614 dma_unmap_single(ndev->dev.parent, dma_addr, len,
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001615 DMA_TO_DEVICE);
Sergei Shtylyov2f45d192015-07-25 23:42:01 +03001616 goto unmap;
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001617 }
1618 ts_skb->skb = skb;
1619 ts_skb->tag = priv->ts_skb_tag++;
1620 priv->ts_skb_tag &= 0x3ff;
1621 list_add_tail(&ts_skb->list, &priv->ts_skb_list);
1622
1623 /* TAG and timestamp required flag */
1624 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001625 desc->tagh_tsr = (ts_skb->tag >> 4) | TX_TSR;
1626 desc->ds_tagl |= le16_to_cpu(ts_skb->tag << 12);
1627 }
1628
Lino Sanfilippod7be81a2016-03-27 12:22:02 +02001629 skb_tx_timestamp(skb);
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001630 /* Descriptor type must be set after all the above writes */
1631 dma_wmb();
Sergei Shtylyov2f45d192015-07-25 23:42:01 +03001632 desc->die_dt = DT_FEND;
1633 desc--;
1634 desc->die_dt = DT_FSTART;
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001635
Sergei Shtylyov568b3ce2016-02-10 01:37:44 +03001636 ravb_modify(ndev, TCCR, TCCR_TSRQ0 << q, TCCR_TSRQ0 << q);
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001637
Sergei Shtylyov2f45d192015-07-25 23:42:01 +03001638 priv->cur_tx[q] += NUM_TX_DESC;
1639 if (priv->cur_tx[q] - priv->dirty_tx[q] >
Kazuya Mizuguchia47b70e2017-01-26 14:29:27 +01001640 (priv->num_tx_ring[q] - 1) * NUM_TX_DESC &&
1641 !ravb_tx_free(ndev, q, true))
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001642 netif_stop_subqueue(ndev, q);
1643
1644exit:
1645 mmiowb();
1646 spin_unlock_irqrestore(&priv->lock, flags);
1647 return NETDEV_TX_OK;
1648
Sergei Shtylyov2f45d192015-07-25 23:42:01 +03001649unmap:
Kazuya Mizuguchie2dbb332015-09-30 15:15:53 +09001650 dma_unmap_single(ndev->dev.parent, le32_to_cpu(desc->dptr),
Sergei Shtylyov2f45d192015-07-25 23:42:01 +03001651 le16_to_cpu(desc->ds_tagl), DMA_TO_DEVICE);
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001652drop:
1653 dev_kfree_skb_any(skb);
Sergei Shtylyov2f45d192015-07-25 23:42:01 +03001654 priv->tx_skb[q][entry / NUM_TX_DESC] = NULL;
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001655 goto exit;
1656}
1657
1658static u16 ravb_select_queue(struct net_device *ndev, struct sk_buff *skb,
Alexander Duyck4f49dec2018-07-09 12:19:59 -04001659 struct net_device *sb_dev,
1660 select_queue_fallback_t fallback)
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001661{
1662 /* If skb needs TX timestamp, it is handled in network control queue */
1663 return (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) ? RAVB_NC :
1664 RAVB_BE;
1665
1666}
1667
1668static struct net_device_stats *ravb_get_stats(struct net_device *ndev)
1669{
1670 struct ravb_private *priv = netdev_priv(ndev);
1671 struct net_device_stats *nstats, *stats0, *stats1;
1672
1673 nstats = &ndev->stats;
1674 stats0 = &priv->stats[RAVB_BE];
1675 stats1 = &priv->stats[RAVB_NC];
1676
1677 nstats->tx_dropped += ravb_read(ndev, TROCR);
1678 ravb_write(ndev, 0, TROCR); /* (write clear) */
1679 nstats->collisions += ravb_read(ndev, CDCR);
1680 ravb_write(ndev, 0, CDCR); /* (write clear) */
1681 nstats->tx_carrier_errors += ravb_read(ndev, LCCR);
1682 ravb_write(ndev, 0, LCCR); /* (write clear) */
1683
1684 nstats->tx_carrier_errors += ravb_read(ndev, CERCR);
1685 ravb_write(ndev, 0, CERCR); /* (write clear) */
1686 nstats->tx_carrier_errors += ravb_read(ndev, CEECR);
1687 ravb_write(ndev, 0, CEECR); /* (write clear) */
1688
1689 nstats->rx_packets = stats0->rx_packets + stats1->rx_packets;
1690 nstats->tx_packets = stats0->tx_packets + stats1->tx_packets;
1691 nstats->rx_bytes = stats0->rx_bytes + stats1->rx_bytes;
1692 nstats->tx_bytes = stats0->tx_bytes + stats1->tx_bytes;
1693 nstats->multicast = stats0->multicast + stats1->multicast;
1694 nstats->rx_errors = stats0->rx_errors + stats1->rx_errors;
1695 nstats->rx_crc_errors = stats0->rx_crc_errors + stats1->rx_crc_errors;
1696 nstats->rx_frame_errors =
1697 stats0->rx_frame_errors + stats1->rx_frame_errors;
1698 nstats->rx_length_errors =
1699 stats0->rx_length_errors + stats1->rx_length_errors;
1700 nstats->rx_missed_errors =
1701 stats0->rx_missed_errors + stats1->rx_missed_errors;
1702 nstats->rx_over_errors =
1703 stats0->rx_over_errors + stats1->rx_over_errors;
1704
1705 return nstats;
1706}
1707
1708/* Update promiscuous bit */
1709static void ravb_set_rx_mode(struct net_device *ndev)
1710{
1711 struct ravb_private *priv = netdev_priv(ndev);
1712 unsigned long flags;
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001713
1714 spin_lock_irqsave(&priv->lock, flags);
Sergei Shtylyov568b3ce2016-02-10 01:37:44 +03001715 ravb_modify(ndev, ECMR, ECMR_PRM,
1716 ndev->flags & IFF_PROMISC ? ECMR_PRM : 0);
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001717 mmiowb();
1718 spin_unlock_irqrestore(&priv->lock, flags);
1719}
1720
1721/* Device close function for Ethernet AVB */
1722static int ravb_close(struct net_device *ndev)
1723{
Johan Hovold9f70eb32016-11-28 19:25:06 +01001724 struct device_node *np = ndev->dev.parent->of_node;
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001725 struct ravb_private *priv = netdev_priv(ndev);
1726 struct ravb_tstamp_skb *ts_skb, *ts_skb2;
1727
1728 netif_tx_stop_all_queues(ndev);
1729
1730 /* Disable interrupts by clearing the interrupt masks. */
1731 ravb_write(ndev, 0, RIC0);
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001732 ravb_write(ndev, 0, RIC2);
1733 ravb_write(ndev, 0, TIC);
1734
Sergei Shtylyova0d2f202015-06-11 01:02:30 +03001735 /* Stop PTP Clock driver */
Kazuya Mizuguchif5d78372015-12-02 02:04:39 +09001736 if (priv->chip_id == RCAR_GEN2)
1737 ravb_ptp_stop(ndev);
Sergei Shtylyova0d2f202015-06-11 01:02:30 +03001738
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001739 /* Set the config mode to stop the AVB-DMAC's processes */
1740 if (ravb_stop_dma(ndev) < 0)
1741 netdev_err(ndev,
1742 "device will be stopped after h/w processes are done.\n");
1743
1744 /* Clear the timestamp list */
1745 list_for_each_entry_safe(ts_skb, ts_skb2, &priv->ts_skb_list, list) {
1746 list_del(&ts_skb->list);
1747 kfree(ts_skb);
1748 }
1749
1750 /* PHY disconnect */
Philippe Reynes0f635172016-08-20 00:52:18 +02001751 if (ndev->phydev) {
1752 phy_stop(ndev->phydev);
1753 phy_disconnect(ndev->phydev);
Johan Hovold9f70eb32016-11-28 19:25:06 +01001754 if (of_phy_is_fixed_link(np))
1755 of_phy_deregister_fixed_link(np);
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001756 }
1757
Geert Uytterhoevenccf92822016-05-17 11:05:34 +02001758 if (priv->chip_id != RCAR_GEN2) {
1759 free_irq(priv->tx_irqs[RAVB_NC], ndev);
1760 free_irq(priv->rx_irqs[RAVB_NC], ndev);
1761 free_irq(priv->tx_irqs[RAVB_BE], ndev);
1762 free_irq(priv->rx_irqs[RAVB_BE], ndev);
Geert Uytterhoeven7fa816b2016-05-07 13:17:11 +02001763 free_irq(priv->emac_irq, ndev);
Geert Uytterhoevenccf92822016-05-17 11:05:34 +02001764 }
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001765 free_irq(ndev->irq, ndev);
1766
1767 napi_disable(&priv->napi[RAVB_NC]);
1768 napi_disable(&priv->napi[RAVB_BE]);
1769
1770 /* Free all the skb's in the RX queue and the DMA buffers. */
1771 ravb_ring_free(ndev, RAVB_BE);
1772 ravb_ring_free(ndev, RAVB_NC);
1773
1774 return 0;
1775}
1776
1777static int ravb_hwtstamp_get(struct net_device *ndev, struct ifreq *req)
1778{
1779 struct ravb_private *priv = netdev_priv(ndev);
1780 struct hwtstamp_config config;
1781
1782 config.flags = 0;
1783 config.tx_type = priv->tstamp_tx_ctrl ? HWTSTAMP_TX_ON :
1784 HWTSTAMP_TX_OFF;
1785 if (priv->tstamp_rx_ctrl & RAVB_RXTSTAMP_TYPE_V2_L2_EVENT)
1786 config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT;
1787 else if (priv->tstamp_rx_ctrl & RAVB_RXTSTAMP_TYPE_ALL)
1788 config.rx_filter = HWTSTAMP_FILTER_ALL;
1789 else
1790 config.rx_filter = HWTSTAMP_FILTER_NONE;
1791
1792 return copy_to_user(req->ifr_data, &config, sizeof(config)) ?
1793 -EFAULT : 0;
1794}
1795
1796/* Control hardware time stamping */
1797static int ravb_hwtstamp_set(struct net_device *ndev, struct ifreq *req)
1798{
1799 struct ravb_private *priv = netdev_priv(ndev);
1800 struct hwtstamp_config config;
1801 u32 tstamp_rx_ctrl = RAVB_RXTSTAMP_ENABLED;
1802 u32 tstamp_tx_ctrl;
1803
1804 if (copy_from_user(&config, req->ifr_data, sizeof(config)))
1805 return -EFAULT;
1806
1807 /* Reserved for future extensions */
1808 if (config.flags)
1809 return -EINVAL;
1810
1811 switch (config.tx_type) {
1812 case HWTSTAMP_TX_OFF:
1813 tstamp_tx_ctrl = 0;
1814 break;
1815 case HWTSTAMP_TX_ON:
1816 tstamp_tx_ctrl = RAVB_TXTSTAMP_ENABLED;
1817 break;
1818 default:
1819 return -ERANGE;
1820 }
1821
1822 switch (config.rx_filter) {
1823 case HWTSTAMP_FILTER_NONE:
1824 tstamp_rx_ctrl = 0;
1825 break;
1826 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
1827 tstamp_rx_ctrl |= RAVB_RXTSTAMP_TYPE_V2_L2_EVENT;
1828 break;
1829 default:
1830 config.rx_filter = HWTSTAMP_FILTER_ALL;
1831 tstamp_rx_ctrl |= RAVB_RXTSTAMP_TYPE_ALL;
1832 }
1833
1834 priv->tstamp_tx_ctrl = tstamp_tx_ctrl;
1835 priv->tstamp_rx_ctrl = tstamp_rx_ctrl;
1836
1837 return copy_to_user(req->ifr_data, &config, sizeof(config)) ?
1838 -EFAULT : 0;
1839}
1840
1841/* ioctl to device function */
1842static int ravb_do_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
1843{
Philippe Reynes0f635172016-08-20 00:52:18 +02001844 struct phy_device *phydev = ndev->phydev;
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001845
1846 if (!netif_running(ndev))
1847 return -EINVAL;
1848
1849 if (!phydev)
1850 return -ENODEV;
1851
1852 switch (cmd) {
1853 case SIOCGHWTSTAMP:
1854 return ravb_hwtstamp_get(ndev, req);
1855 case SIOCSHWTSTAMP:
1856 return ravb_hwtstamp_set(ndev, req);
1857 }
1858
1859 return phy_mii_ioctl(phydev, req, cmd);
1860}
1861
Niklas Söderlund75efa062018-02-16 17:10:08 +01001862static int ravb_change_mtu(struct net_device *ndev, int new_mtu)
1863{
1864 if (netif_running(ndev))
1865 return -EBUSY;
1866
1867 ndev->mtu = new_mtu;
1868 netdev_update_features(ndev);
1869
1870 return 0;
1871}
1872
Simon Horman4d86d382017-10-04 09:54:27 +02001873static void ravb_set_rx_csum(struct net_device *ndev, bool enable)
1874{
1875 struct ravb_private *priv = netdev_priv(ndev);
1876 unsigned long flags;
1877
1878 spin_lock_irqsave(&priv->lock, flags);
1879
1880 /* Disable TX and RX */
1881 ravb_rcv_snd_disable(ndev);
1882
1883 /* Modify RX Checksum setting */
1884 ravb_modify(ndev, ECMR, ECMR_RCSC, enable ? ECMR_RCSC : 0);
1885
1886 /* Enable TX and RX */
1887 ravb_rcv_snd_enable(ndev);
1888
1889 spin_unlock_irqrestore(&priv->lock, flags);
1890}
1891
1892static int ravb_set_features(struct net_device *ndev,
1893 netdev_features_t features)
1894{
1895 netdev_features_t changed = ndev->features ^ features;
1896
1897 if (changed & NETIF_F_RXCSUM)
1898 ravb_set_rx_csum(ndev, features & NETIF_F_RXCSUM);
1899
1900 ndev->features = features;
1901
1902 return 0;
1903}
1904
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001905static const struct net_device_ops ravb_netdev_ops = {
1906 .ndo_open = ravb_open,
1907 .ndo_stop = ravb_close,
1908 .ndo_start_xmit = ravb_start_xmit,
1909 .ndo_select_queue = ravb_select_queue,
1910 .ndo_get_stats = ravb_get_stats,
1911 .ndo_set_rx_mode = ravb_set_rx_mode,
1912 .ndo_tx_timeout = ravb_tx_timeout,
1913 .ndo_do_ioctl = ravb_do_ioctl,
Niklas Söderlund75efa062018-02-16 17:10:08 +01001914 .ndo_change_mtu = ravb_change_mtu,
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001915 .ndo_validate_addr = eth_validate_addr,
1916 .ndo_set_mac_address = eth_mac_addr,
Simon Horman4d86d382017-10-04 09:54:27 +02001917 .ndo_set_features = ravb_set_features,
Sergei Shtylyovc1566332015-06-11 01:01:43 +03001918};
1919
1920/* MDIO bus init function */
1921static int ravb_mdio_init(struct ravb_private *priv)
1922{
1923 struct platform_device *pdev = priv->pdev;
1924 struct device *dev = &pdev->dev;
1925 int error;
1926
1927 /* Bitbang init */
1928 priv->mdiobb.ops = &bb_ops;
1929
1930 /* MII controller setting */
1931 priv->mii_bus = alloc_mdio_bitbang(&priv->mdiobb);
1932 if (!priv->mii_bus)
1933 return -ENOMEM;
1934
1935 /* Hook up MII support for ethtool */
1936 priv->mii_bus->name = "ravb_mii";
1937 priv->mii_bus->parent = dev;
1938 snprintf(priv->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
1939 pdev->name, pdev->id);
1940
1941 /* Register MDIO bus */
1942 error = of_mdiobus_register(priv->mii_bus, dev->of_node);
1943 if (error)
1944 goto out_free_bus;
1945
1946 return 0;
1947
1948out_free_bus:
1949 free_mdio_bitbang(priv->mii_bus);
1950 return error;
1951}
1952
1953/* MDIO bus release function */
1954static int ravb_mdio_release(struct ravb_private *priv)
1955{
1956 /* Unregister mdio bus */
1957 mdiobus_unregister(priv->mii_bus);
1958
1959 /* Free bitbang info */
1960 free_mdio_bitbang(priv->mii_bus);
1961
1962 return 0;
1963}
1964
Kazuya Mizuguchi22d4df82015-09-30 15:15:55 +09001965static const struct of_device_id ravb_match_table[] = {
1966 { .compatible = "renesas,etheravb-r8a7790", .data = (void *)RCAR_GEN2 },
1967 { .compatible = "renesas,etheravb-r8a7794", .data = (void *)RCAR_GEN2 },
Simon Horman0e874362015-12-02 14:58:32 +09001968 { .compatible = "renesas,etheravb-rcar-gen2", .data = (void *)RCAR_GEN2 },
Kazuya Mizuguchi22d4df82015-09-30 15:15:55 +09001969 { .compatible = "renesas,etheravb-r8a7795", .data = (void *)RCAR_GEN3 },
Simon Horman0e874362015-12-02 14:58:32 +09001970 { .compatible = "renesas,etheravb-rcar-gen3", .data = (void *)RCAR_GEN3 },
Kazuya Mizuguchi22d4df82015-09-30 15:15:55 +09001971 { }
1972};
1973MODULE_DEVICE_TABLE(of, ravb_match_table);
1974
Simon Hormanb3d39a82015-11-20 11:29:39 -08001975static int ravb_set_gti(struct net_device *ndev)
1976{
Geert Uytterhoevenab104612017-10-12 10:24:53 +02001977 struct ravb_private *priv = netdev_priv(ndev);
Simon Hormanb3d39a82015-11-20 11:29:39 -08001978 struct device *dev = ndev->dev.parent;
Simon Hormanb3d39a82015-11-20 11:29:39 -08001979 unsigned long rate;
Simon Hormanb3d39a82015-11-20 11:29:39 -08001980 uint64_t inc;
1981
Geert Uytterhoevenab104612017-10-12 10:24:53 +02001982 rate = clk_get_rate(priv->clk);
Wolfram Sanga6d37132016-04-08 13:28:42 +02001983 if (!rate)
1984 return -EINVAL;
1985
Simon Hormanb3d39a82015-11-20 11:29:39 -08001986 inc = 1000000000ULL << 20;
1987 do_div(inc, rate);
1988
1989 if (inc < GTI_TIV_MIN || inc > GTI_TIV_MAX) {
1990 dev_err(dev, "gti.tiv increment 0x%llx is outside the range 0x%x - 0x%x\n",
1991 inc, GTI_TIV_MIN, GTI_TIV_MAX);
1992 return -EINVAL;
1993 }
1994
1995 ravb_write(ndev, inc, GTI);
1996
1997 return 0;
1998}
1999
Niklas Söderlund01841652016-08-03 15:56:47 +02002000static void ravb_set_config_mode(struct net_device *ndev)
2001{
2002 struct ravb_private *priv = netdev_priv(ndev);
2003
2004 if (priv->chip_id == RCAR_GEN2) {
2005 ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_CONFIG);
2006 /* Set CSEL value */
2007 ravb_modify(ndev, CCC, CCC_CSEL, CCC_CSEL_HPB);
2008 } else {
2009 ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_CONFIG |
2010 CCC_GAC | CCC_CSEL_HPB);
2011 }
2012}
2013
Kazuya Mizuguchi61fccb22017-01-27 20:46:26 +01002014/* Set tx and rx clock internal delay modes */
2015static void ravb_set_delay_mode(struct net_device *ndev)
2016{
2017 struct ravb_private *priv = netdev_priv(ndev);
2018 int set = 0;
2019
2020 if (priv->phy_interface == PHY_INTERFACE_MODE_RGMII_ID ||
2021 priv->phy_interface == PHY_INTERFACE_MODE_RGMII_RXID)
2022 set |= APSR_DM_RDM;
2023
2024 if (priv->phy_interface == PHY_INTERFACE_MODE_RGMII_ID ||
2025 priv->phy_interface == PHY_INTERFACE_MODE_RGMII_TXID)
2026 set |= APSR_DM_TDM;
2027
2028 ravb_modify(ndev, APSR, APSR_DM, set);
2029}
2030
Sergei Shtylyovc1566332015-06-11 01:01:43 +03002031static int ravb_probe(struct platform_device *pdev)
2032{
2033 struct device_node *np = pdev->dev.of_node;
2034 struct ravb_private *priv;
Kazuya Mizuguchi22d4df82015-09-30 15:15:55 +09002035 enum ravb_chip_id chip_id;
Sergei Shtylyovc1566332015-06-11 01:01:43 +03002036 struct net_device *ndev;
2037 int error, irq, q;
2038 struct resource *res;
Kazuya Mizuguchif51bdc22016-04-03 23:54:38 +09002039 int i;
Sergei Shtylyovc1566332015-06-11 01:01:43 +03002040
2041 if (!np) {
2042 dev_err(&pdev->dev,
2043 "this driver is required to be instantiated from device tree\n");
2044 return -EINVAL;
2045 }
2046
2047 /* Get base address */
2048 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2049 if (!res) {
2050 dev_err(&pdev->dev, "invalid resource\n");
2051 return -EINVAL;
2052 }
2053
2054 ndev = alloc_etherdev_mqs(sizeof(struct ravb_private),
2055 NUM_TX_QUEUE, NUM_RX_QUEUE);
2056 if (!ndev)
2057 return -ENOMEM;
2058
Simon Horman4d86d382017-10-04 09:54:27 +02002059 ndev->features = NETIF_F_RXCSUM;
2060 ndev->hw_features = NETIF_F_RXCSUM;
2061
Sergei Shtylyovc1566332015-06-11 01:01:43 +03002062 pm_runtime_enable(&pdev->dev);
2063 pm_runtime_get_sync(&pdev->dev);
2064
2065 /* The Ether-specific entries in the device structure. */
2066 ndev->base_addr = res->start;
Kazuya Mizuguchi22d4df82015-09-30 15:15:55 +09002067
Wolfram Sange8668632016-03-01 17:37:58 +01002068 chip_id = (enum ravb_chip_id)of_device_get_match_data(&pdev->dev);
Kazuya Mizuguchi22d4df82015-09-30 15:15:55 +09002069
2070 if (chip_id == RCAR_GEN3)
2071 irq = platform_get_irq_byname(pdev, "ch22");
2072 else
2073 irq = platform_get_irq(pdev, 0);
Sergei Shtylyovc1566332015-06-11 01:01:43 +03002074 if (irq < 0) {
Sergei Shtylyovf3753392015-08-28 16:55:10 +03002075 error = irq;
Sergei Shtylyovc1566332015-06-11 01:01:43 +03002076 goto out_release;
2077 }
2078 ndev->irq = irq;
2079
2080 SET_NETDEV_DEV(ndev, &pdev->dev);
2081
2082 priv = netdev_priv(ndev);
2083 priv->ndev = ndev;
2084 priv->pdev = pdev;
2085 priv->num_tx_ring[RAVB_BE] = BE_TX_RING_SIZE;
2086 priv->num_rx_ring[RAVB_BE] = BE_RX_RING_SIZE;
2087 priv->num_tx_ring[RAVB_NC] = NC_TX_RING_SIZE;
2088 priv->num_rx_ring[RAVB_NC] = NC_RX_RING_SIZE;
2089 priv->addr = devm_ioremap_resource(&pdev->dev, res);
2090 if (IS_ERR(priv->addr)) {
2091 error = PTR_ERR(priv->addr);
2092 goto out_release;
2093 }
2094
2095 spin_lock_init(&priv->lock);
2096 INIT_WORK(&priv->work, ravb_tx_timeout_work);
2097
2098 priv->phy_interface = of_get_phy_mode(np);
2099
2100 priv->no_avb_link = of_property_read_bool(np, "renesas,no-ether-link");
2101 priv->avb_link_active_low =
2102 of_property_read_bool(np, "renesas,ether-link-active-low");
2103
Kazuya Mizuguchi22d4df82015-09-30 15:15:55 +09002104 if (chip_id == RCAR_GEN3) {
2105 irq = platform_get_irq_byname(pdev, "ch24");
2106 if (irq < 0) {
2107 error = irq;
2108 goto out_release;
2109 }
2110 priv->emac_irq = irq;
Kazuya Mizuguchif51bdc22016-04-03 23:54:38 +09002111 for (i = 0; i < NUM_RX_QUEUE; i++) {
2112 irq = platform_get_irq_byname(pdev, ravb_rx_irqs[i]);
2113 if (irq < 0) {
2114 error = irq;
2115 goto out_release;
2116 }
2117 priv->rx_irqs[i] = irq;
2118 }
2119 for (i = 0; i < NUM_TX_QUEUE; i++) {
2120 irq = platform_get_irq_byname(pdev, ravb_tx_irqs[i]);
2121 if (irq < 0) {
2122 error = irq;
2123 goto out_release;
2124 }
2125 priv->tx_irqs[i] = irq;
2126 }
Kazuya Mizuguchi22d4df82015-09-30 15:15:55 +09002127 }
2128
2129 priv->chip_id = chip_id;
2130
Niklas Söderlund3e3d6472017-08-01 12:14:36 +02002131 priv->clk = devm_clk_get(&pdev->dev, NULL);
Geert Uytterhoevenab104612017-10-12 10:24:53 +02002132 if (IS_ERR(priv->clk)) {
2133 error = PTR_ERR(priv->clk);
2134 goto out_release;
2135 }
Niklas Söderlund3e3d6472017-08-01 12:14:36 +02002136
Niklas Söderlund75efa062018-02-16 17:10:08 +01002137 ndev->max_mtu = 2048 - (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN);
2138 ndev->min_mtu = ETH_MIN_MTU;
2139
Sergei Shtylyovc1566332015-06-11 01:01:43 +03002140 /* Set function */
2141 ndev->netdev_ops = &ravb_netdev_ops;
2142 ndev->ethtool_ops = &ravb_ethtool_ops;
2143
2144 /* Set AVB config mode */
Niklas Söderlund01841652016-08-03 15:56:47 +02002145 ravb_set_config_mode(ndev);
Sergei Shtylyovc1566332015-06-11 01:01:43 +03002146
Sergei Shtylyovc1566332015-06-11 01:01:43 +03002147 /* Set GTI value */
Simon Hormanb3d39a82015-11-20 11:29:39 -08002148 error = ravb_set_gti(ndev);
2149 if (error)
2150 goto out_release;
Sergei Shtylyovc1566332015-06-11 01:01:43 +03002151
2152 /* Request GTI loading */
Sergei Shtylyov568b3ce2016-02-10 01:37:44 +03002153 ravb_modify(ndev, GCCR, GCCR_LTI, GCCR_LTI);
Sergei Shtylyovc1566332015-06-11 01:01:43 +03002154
Kazuya Mizuguchi61fccb22017-01-27 20:46:26 +01002155 if (priv->chip_id != RCAR_GEN2)
2156 ravb_set_delay_mode(ndev);
2157
Sergei Shtylyovc1566332015-06-11 01:01:43 +03002158 /* Allocate descriptor base address table */
2159 priv->desc_bat_size = sizeof(struct ravb_desc) * DBAT_ENTRY_NUM;
Kazuya Mizuguchie2dbb332015-09-30 15:15:53 +09002160 priv->desc_bat = dma_alloc_coherent(ndev->dev.parent, priv->desc_bat_size,
Sergei Shtylyovc1566332015-06-11 01:01:43 +03002161 &priv->desc_bat_dma, GFP_KERNEL);
2162 if (!priv->desc_bat) {
Simon Hormanc4511132015-11-02 10:40:17 +09002163 dev_err(&pdev->dev,
Sergei Shtylyovc1566332015-06-11 01:01:43 +03002164 "Cannot allocate desc base address table (size %d bytes)\n",
2165 priv->desc_bat_size);
2166 error = -ENOMEM;
2167 goto out_release;
2168 }
2169 for (q = RAVB_BE; q < DBAT_ENTRY_NUM; q++)
2170 priv->desc_bat[q].die_dt = DT_EOS;
2171 ravb_write(ndev, priv->desc_bat_dma, DBAT);
2172
2173 /* Initialise HW timestamp list */
2174 INIT_LIST_HEAD(&priv->ts_skb_list);
2175
Kazuya Mizuguchif5d78372015-12-02 02:04:39 +09002176 /* Initialise PTP Clock driver */
2177 if (chip_id != RCAR_GEN2)
2178 ravb_ptp_init(ndev, pdev);
2179
Sergei Shtylyovc1566332015-06-11 01:01:43 +03002180 /* Debug message level */
2181 priv->msg_enable = RAVB_DEF_MSG_ENABLE;
2182
2183 /* Read and set MAC address */
2184 ravb_read_mac_address(ndev, of_get_mac_address(np));
2185 if (!is_valid_ether_addr(ndev->dev_addr)) {
2186 dev_warn(&pdev->dev,
2187 "no valid MAC address supplied, using a random one\n");
2188 eth_hw_addr_random(ndev);
2189 }
2190
2191 /* MDIO bus init */
2192 error = ravb_mdio_init(priv);
2193 if (error) {
Simon Hormanc4511132015-11-02 10:40:17 +09002194 dev_err(&pdev->dev, "failed to initialize MDIO\n");
Sergei Shtylyovc1566332015-06-11 01:01:43 +03002195 goto out_dma_free;
2196 }
2197
2198 netif_napi_add(ndev, &priv->napi[RAVB_BE], ravb_poll, 64);
2199 netif_napi_add(ndev, &priv->napi[RAVB_NC], ravb_poll, 64);
2200
2201 /* Network device register */
2202 error = register_netdev(ndev);
2203 if (error)
2204 goto out_napi_del;
2205
Geert Uytterhoevenab104612017-10-12 10:24:53 +02002206 device_set_wakeup_capable(&pdev->dev, 1);
Niklas Söderlund3e3d6472017-08-01 12:14:36 +02002207
Sergei Shtylyovc1566332015-06-11 01:01:43 +03002208 /* Print device information */
2209 netdev_info(ndev, "Base address at %#x, %pM, IRQ %d.\n",
2210 (u32)ndev->base_addr, ndev->dev_addr, ndev->irq);
2211
2212 platform_set_drvdata(pdev, ndev);
2213
2214 return 0;
2215
2216out_napi_del:
2217 netif_napi_del(&priv->napi[RAVB_NC]);
2218 netif_napi_del(&priv->napi[RAVB_BE]);
2219 ravb_mdio_release(priv);
2220out_dma_free:
Kazuya Mizuguchie2dbb332015-09-30 15:15:53 +09002221 dma_free_coherent(ndev->dev.parent, priv->desc_bat_size, priv->desc_bat,
Sergei Shtylyovc1566332015-06-11 01:01:43 +03002222 priv->desc_bat_dma);
Kazuya Mizuguchif5d78372015-12-02 02:04:39 +09002223
2224 /* Stop PTP Clock driver */
2225 if (chip_id != RCAR_GEN2)
2226 ravb_ptp_stop(ndev);
Sergei Shtylyovc1566332015-06-11 01:01:43 +03002227out_release:
Sergei Shtylyov5d0c1002017-12-31 21:41:35 +03002228 free_netdev(ndev);
Sergei Shtylyovc1566332015-06-11 01:01:43 +03002229
2230 pm_runtime_put(&pdev->dev);
2231 pm_runtime_disable(&pdev->dev);
2232 return error;
2233}
2234
2235static int ravb_remove(struct platform_device *pdev)
2236{
2237 struct net_device *ndev = platform_get_drvdata(pdev);
2238 struct ravb_private *priv = netdev_priv(ndev);
2239
Kazuya Mizuguchif5d78372015-12-02 02:04:39 +09002240 /* Stop PTP Clock driver */
2241 if (priv->chip_id != RCAR_GEN2)
2242 ravb_ptp_stop(ndev);
2243
Kazuya Mizuguchie2dbb332015-09-30 15:15:53 +09002244 dma_free_coherent(ndev->dev.parent, priv->desc_bat_size, priv->desc_bat,
Sergei Shtylyovc1566332015-06-11 01:01:43 +03002245 priv->desc_bat_dma);
2246 /* Set reset mode */
2247 ravb_write(ndev, CCC_OPC_RESET, CCC);
2248 pm_runtime_put_sync(&pdev->dev);
2249 unregister_netdev(ndev);
2250 netif_napi_del(&priv->napi[RAVB_NC]);
2251 netif_napi_del(&priv->napi[RAVB_BE]);
2252 ravb_mdio_release(priv);
2253 pm_runtime_disable(&pdev->dev);
2254 free_netdev(ndev);
2255 platform_set_drvdata(pdev, NULL);
2256
2257 return 0;
2258}
2259
Niklas Söderlund3e3d6472017-08-01 12:14:36 +02002260static int ravb_wol_setup(struct net_device *ndev)
2261{
2262 struct ravb_private *priv = netdev_priv(ndev);
2263
2264 /* Disable interrupts by clearing the interrupt masks. */
2265 ravb_write(ndev, 0, RIC0);
2266 ravb_write(ndev, 0, RIC2);
2267 ravb_write(ndev, 0, TIC);
2268
2269 /* Only allow ECI interrupts */
2270 synchronize_irq(priv->emac_irq);
2271 napi_disable(&priv->napi[RAVB_NC]);
2272 napi_disable(&priv->napi[RAVB_BE]);
2273 ravb_write(ndev, ECSIPR_MPDIP, ECSIPR);
2274
2275 /* Enable MagicPacket */
2276 ravb_modify(ndev, ECMR, ECMR_MPDE, ECMR_MPDE);
2277
Niklas Söderlund3e3d6472017-08-01 12:14:36 +02002278 return enable_irq_wake(priv->emac_irq);
2279}
2280
2281static int ravb_wol_restore(struct net_device *ndev)
2282{
2283 struct ravb_private *priv = netdev_priv(ndev);
2284 int ret;
2285
2286 napi_enable(&priv->napi[RAVB_NC]);
2287 napi_enable(&priv->napi[RAVB_BE]);
2288
2289 /* Disable MagicPacket */
2290 ravb_modify(ndev, ECMR, ECMR_MPDE, 0);
2291
2292 ret = ravb_close(ndev);
2293 if (ret < 0)
2294 return ret;
2295
Niklas Söderlund3e3d6472017-08-01 12:14:36 +02002296 return disable_irq_wake(priv->emac_irq);
2297}
2298
Arnd Bergmann1ddcf412016-08-26 17:30:29 +02002299static int __maybe_unused ravb_suspend(struct device *dev)
Niklas Söderlund01841652016-08-03 15:56:47 +02002300{
2301 struct net_device *ndev = dev_get_drvdata(dev);
Niklas Söderlund3e3d6472017-08-01 12:14:36 +02002302 struct ravb_private *priv = netdev_priv(ndev);
2303 int ret;
Niklas Söderlund01841652016-08-03 15:56:47 +02002304
Niklas Söderlund3e3d6472017-08-01 12:14:36 +02002305 if (!netif_running(ndev))
2306 return 0;
2307
2308 netif_device_detach(ndev);
2309
2310 if (priv->wol_enabled)
2311 ret = ravb_wol_setup(ndev);
2312 else
Niklas Söderlund01841652016-08-03 15:56:47 +02002313 ret = ravb_close(ndev);
Niklas Söderlund01841652016-08-03 15:56:47 +02002314
2315 return ret;
2316}
2317
Arnd Bergmann1ddcf412016-08-26 17:30:29 +02002318static int __maybe_unused ravb_resume(struct device *dev)
Niklas Söderlund01841652016-08-03 15:56:47 +02002319{
2320 struct net_device *ndev = dev_get_drvdata(dev);
2321 struct ravb_private *priv = netdev_priv(ndev);
2322 int ret = 0;
2323
Geert Uytterhoeven6b782f42017-12-11 09:54:09 +01002324 /* If WoL is enabled set reset mode to rearm the WoL logic */
2325 if (priv->wol_enabled)
Niklas Söderlund3e3d6472017-08-01 12:14:36 +02002326 ravb_write(ndev, CCC_OPC_RESET, CCC);
2327
Niklas Söderlund01841652016-08-03 15:56:47 +02002328 /* All register have been reset to default values.
2329 * Restore all registers which where setup at probe time and
2330 * reopen device if it was running before system suspended.
2331 */
2332
2333 /* Set AVB config mode */
2334 ravb_set_config_mode(ndev);
2335
2336 /* Set GTI value */
2337 ret = ravb_set_gti(ndev);
2338 if (ret)
2339 return ret;
2340
2341 /* Request GTI loading */
2342 ravb_modify(ndev, GCCR, GCCR_LTI, GCCR_LTI);
2343
Kazuya Mizuguchi61fccb22017-01-27 20:46:26 +01002344 if (priv->chip_id != RCAR_GEN2)
2345 ravb_set_delay_mode(ndev);
2346
Niklas Söderlund01841652016-08-03 15:56:47 +02002347 /* Restore descriptor base address table */
2348 ravb_write(ndev, priv->desc_bat_dma, DBAT);
2349
2350 if (netif_running(ndev)) {
Niklas Söderlund3e3d6472017-08-01 12:14:36 +02002351 if (priv->wol_enabled) {
2352 ret = ravb_wol_restore(ndev);
2353 if (ret)
2354 return ret;
2355 }
Niklas Söderlund01841652016-08-03 15:56:47 +02002356 ret = ravb_open(ndev);
2357 if (ret < 0)
2358 return ret;
2359 netif_device_attach(ndev);
2360 }
2361
2362 return ret;
2363}
2364
Arnd Bergmann1ddcf412016-08-26 17:30:29 +02002365static int __maybe_unused ravb_runtime_nop(struct device *dev)
Sergei Shtylyovc1566332015-06-11 01:01:43 +03002366{
2367 /* Runtime PM callback shared between ->runtime_suspend()
2368 * and ->runtime_resume(). Simply returns success.
2369 *
2370 * This driver re-initializes all registers after
2371 * pm_runtime_get_sync() anyway so there is no need
2372 * to save and restore registers here.
2373 */
2374 return 0;
2375}
2376
2377static const struct dev_pm_ops ravb_dev_pm_ops = {
Niklas Söderlundb89b8152016-08-10 13:09:49 +02002378 SET_SYSTEM_SLEEP_PM_OPS(ravb_suspend, ravb_resume)
Kazuya Mizuguchi524c6f62016-05-30 05:25:43 +09002379 SET_RUNTIME_PM_OPS(ravb_runtime_nop, ravb_runtime_nop, NULL)
Sergei Shtylyovc1566332015-06-11 01:01:43 +03002380};
2381
Sergei Shtylyovc1566332015-06-11 01:01:43 +03002382static struct platform_driver ravb_driver = {
2383 .probe = ravb_probe,
2384 .remove = ravb_remove,
2385 .driver = {
2386 .name = "ravb",
Arnd Bergmann1ddcf412016-08-26 17:30:29 +02002387 .pm = &ravb_dev_pm_ops,
Sergei Shtylyovc1566332015-06-11 01:01:43 +03002388 .of_match_table = ravb_match_table,
2389 },
2390};
2391
2392module_platform_driver(ravb_driver);
2393
2394MODULE_AUTHOR("Mitsuhiro Kimura, Masaru Nagai");
2395MODULE_DESCRIPTION("Renesas Ethernet AVB driver");
2396MODULE_LICENSE("GPL v2");