1 // SPDX-License-Identifier: GPL-2.0
2 /* Renesas Ethernet AVB device driver
4 * Copyright (C) 2014-2019 Renesas Electronics Corporation
5 * Copyright (C) 2015 Renesas Solutions Corp.
8 * Based on the SuperH Ethernet driver
11 #include <linux/cache.h>
12 #include <linux/clk.h>
13 #include <linux/delay.h>
14 #include <linux/dma-mapping.h>
15 #include <linux/err.h>
16 #include <linux/etherdevice.h>
17 #include <linux/ethtool.h>
18 #include <linux/if_vlan.h>
19 #include <linux/kernel.h>
20 #include <linux/list.h>
21 #include <linux/module.h>
22 #include <linux/net_tstamp.h>
24 #include <linux/of_device.h>
25 #include <linux/of_irq.h>
26 #include <linux/of_mdio.h>
27 #include <linux/of_net.h>
28 #include <linux/pm_runtime.h>
29 #include <linux/slab.h>
30 #include <linux/spinlock.h>
31 #include <linux/sys_soc.h>
32 #include <linux/reset.h>
34 #include <asm/div64.h>
38 #define RAVB_DEF_MSG_ENABLE \
44 static const char *ravb_rx_irqs[NUM_RX_QUEUE] = {
49 static const char *ravb_tx_irqs[NUM_TX_QUEUE] = {
54 void ravb_modify(struct net_device *ndev, enum ravb_reg reg, u32 clear,
57 ravb_write(ndev, (ravb_read(ndev, reg) & ~clear) | set, reg);
60 int ravb_wait(struct net_device *ndev, enum ravb_reg reg, u32 mask, u32 value)
64 for (i = 0; i < 10000; i++) {
65 if ((ravb_read(ndev, reg) & mask) == value)
72 static int ravb_config(struct net_device *ndev)
77 ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_CONFIG);
78 /* Check if the operating mode is changed to the config mode */
79 error = ravb_wait(ndev, CSR, CSR_OPS, CSR_OPS_CONFIG);
81 netdev_err(ndev, "failed to switch device to config mode\n");
86 static void ravb_set_rate_gbeth(struct net_device *ndev)
88 struct ravb_private *priv = netdev_priv(ndev);
90 switch (priv->speed) {
92 ravb_write(ndev, GBETH_GECMR_SPEED_10, GECMR);
94 case 100: /* 100BASE */
95 ravb_write(ndev, GBETH_GECMR_SPEED_100, GECMR);
97 case 1000: /* 1000BASE */
98 ravb_write(ndev, GBETH_GECMR_SPEED_1000, GECMR);
103 static void ravb_set_rate_rcar(struct net_device *ndev)
105 struct ravb_private *priv = netdev_priv(ndev);
107 switch (priv->speed) {
108 case 100: /* 100BASE */
109 ravb_write(ndev, GECMR_SPEED_100, GECMR);
111 case 1000: /* 1000BASE */
112 ravb_write(ndev, GECMR_SPEED_1000, GECMR);
117 static void ravb_set_buffer_align(struct sk_buff *skb)
119 u32 reserve = (unsigned long)skb->data & (RAVB_ALIGN - 1);
122 skb_reserve(skb, RAVB_ALIGN - reserve);
125 /* Get MAC address from the MAC address registers
127 * Ethernet AVB device doesn't have ROM for MAC address.
128 * This function gets the MAC address that was used by a bootloader.
130 static void ravb_read_mac_address(struct device_node *np,
131 struct net_device *ndev)
135 ret = of_get_ethdev_address(np, ndev);
137 u32 mahr = ravb_read(ndev, MAHR);
138 u32 malr = ravb_read(ndev, MALR);
141 addr[0] = (mahr >> 24) & 0xFF;
142 addr[1] = (mahr >> 16) & 0xFF;
143 addr[2] = (mahr >> 8) & 0xFF;
144 addr[3] = (mahr >> 0) & 0xFF;
145 addr[4] = (malr >> 8) & 0xFF;
146 addr[5] = (malr >> 0) & 0xFF;
147 eth_hw_addr_set(ndev, addr);
151 static void ravb_mdio_ctrl(struct mdiobb_ctrl *ctrl, u32 mask, int set)
153 struct ravb_private *priv = container_of(ctrl, struct ravb_private,
156 ravb_modify(priv->ndev, PIR, mask, set ? mask : 0);
159 /* MDC pin control */
160 static void ravb_set_mdc(struct mdiobb_ctrl *ctrl, int level)
162 ravb_mdio_ctrl(ctrl, PIR_MDC, level);
165 /* Data I/O pin control */
166 static void ravb_set_mdio_dir(struct mdiobb_ctrl *ctrl, int output)
168 ravb_mdio_ctrl(ctrl, PIR_MMD, output);
172 static void ravb_set_mdio_data(struct mdiobb_ctrl *ctrl, int value)
174 ravb_mdio_ctrl(ctrl, PIR_MDO, value);
178 static int ravb_get_mdio_data(struct mdiobb_ctrl *ctrl)
180 struct ravb_private *priv = container_of(ctrl, struct ravb_private,
183 return (ravb_read(priv->ndev, PIR) & PIR_MDI) != 0;
186 /* MDIO bus control struct */
187 static const struct mdiobb_ops bb_ops = {
188 .owner = THIS_MODULE,
189 .set_mdc = ravb_set_mdc,
190 .set_mdio_dir = ravb_set_mdio_dir,
191 .set_mdio_data = ravb_set_mdio_data,
192 .get_mdio_data = ravb_get_mdio_data,
195 /* Free TX skb function for AVB-IP */
196 static int ravb_tx_free(struct net_device *ndev, int q, bool free_txed_only)
198 struct ravb_private *priv = netdev_priv(ndev);
199 struct net_device_stats *stats = &priv->stats[q];
200 unsigned int num_tx_desc = priv->num_tx_desc;
201 struct ravb_tx_desc *desc;
206 for (; priv->cur_tx[q] - priv->dirty_tx[q] > 0; priv->dirty_tx[q]++) {
209 entry = priv->dirty_tx[q] % (priv->num_tx_ring[q] *
211 desc = &priv->tx_ring[q][entry];
212 txed = desc->die_dt == DT_FEMPTY;
213 if (free_txed_only && !txed)
215 /* Descriptor type must be checked before all other reads */
217 size = le16_to_cpu(desc->ds_tagl) & TX_DS;
218 /* Free the original skb. */
219 if (priv->tx_skb[q][entry / num_tx_desc]) {
220 dma_unmap_single(ndev->dev.parent, le32_to_cpu(desc->dptr),
221 size, DMA_TO_DEVICE);
222 /* Last packet descriptor? */
223 if (entry % num_tx_desc == num_tx_desc - 1) {
224 entry /= num_tx_desc;
225 dev_kfree_skb_any(priv->tx_skb[q][entry]);
226 priv->tx_skb[q][entry] = NULL;
233 stats->tx_bytes += size;
234 desc->die_dt = DT_EEMPTY;
239 static void ravb_rx_ring_free_gbeth(struct net_device *ndev, int q)
241 struct ravb_private *priv = netdev_priv(ndev);
242 unsigned int ring_size;
245 if (!priv->gbeth_rx_ring)
248 for (i = 0; i < priv->num_rx_ring[q]; i++) {
249 struct ravb_rx_desc *desc = &priv->gbeth_rx_ring[i];
251 if (!dma_mapping_error(ndev->dev.parent,
252 le32_to_cpu(desc->dptr)))
253 dma_unmap_single(ndev->dev.parent,
254 le32_to_cpu(desc->dptr),
258 ring_size = sizeof(struct ravb_rx_desc) * (priv->num_rx_ring[q] + 1);
259 dma_free_coherent(ndev->dev.parent, ring_size, priv->gbeth_rx_ring,
260 priv->rx_desc_dma[q]);
261 priv->gbeth_rx_ring = NULL;
264 static void ravb_rx_ring_free_rcar(struct net_device *ndev, int q)
266 struct ravb_private *priv = netdev_priv(ndev);
267 unsigned int ring_size;
270 if (!priv->rx_ring[q])
273 for (i = 0; i < priv->num_rx_ring[q]; i++) {
274 struct ravb_ex_rx_desc *desc = &priv->rx_ring[q][i];
276 if (!dma_mapping_error(ndev->dev.parent,
277 le32_to_cpu(desc->dptr)))
278 dma_unmap_single(ndev->dev.parent,
279 le32_to_cpu(desc->dptr),
283 ring_size = sizeof(struct ravb_ex_rx_desc) *
284 (priv->num_rx_ring[q] + 1);
285 dma_free_coherent(ndev->dev.parent, ring_size, priv->rx_ring[q],
286 priv->rx_desc_dma[q]);
287 priv->rx_ring[q] = NULL;
290 /* Free skb's and DMA buffers for Ethernet AVB */
291 static void ravb_ring_free(struct net_device *ndev, int q)
293 struct ravb_private *priv = netdev_priv(ndev);
294 const struct ravb_hw_info *info = priv->info;
295 unsigned int num_tx_desc = priv->num_tx_desc;
296 unsigned int ring_size;
299 info->rx_ring_free(ndev, q);
301 if (priv->tx_ring[q]) {
302 ravb_tx_free(ndev, q, false);
304 ring_size = sizeof(struct ravb_tx_desc) *
305 (priv->num_tx_ring[q] * num_tx_desc + 1);
306 dma_free_coherent(ndev->dev.parent, ring_size, priv->tx_ring[q],
307 priv->tx_desc_dma[q]);
308 priv->tx_ring[q] = NULL;
311 /* Free RX skb ringbuffer */
312 if (priv->rx_skb[q]) {
313 for (i = 0; i < priv->num_rx_ring[q]; i++)
314 dev_kfree_skb(priv->rx_skb[q][i]);
316 kfree(priv->rx_skb[q]);
317 priv->rx_skb[q] = NULL;
319 /* Free aligned TX buffers */
320 kfree(priv->tx_align[q]);
321 priv->tx_align[q] = NULL;
323 /* Free TX skb ringbuffer.
324 * SKBs are freed by ravb_tx_free() call above.
326 kfree(priv->tx_skb[q]);
327 priv->tx_skb[q] = NULL;
330 static void ravb_rx_ring_format_gbeth(struct net_device *ndev, int q)
332 struct ravb_private *priv = netdev_priv(ndev);
333 struct ravb_rx_desc *rx_desc;
334 unsigned int rx_ring_size;
338 rx_ring_size = sizeof(*rx_desc) * priv->num_rx_ring[q];
339 memset(priv->gbeth_rx_ring, 0, rx_ring_size);
340 /* Build RX ring buffer */
341 for (i = 0; i < priv->num_rx_ring[q]; i++) {
343 rx_desc = &priv->gbeth_rx_ring[i];
344 rx_desc->ds_cc = cpu_to_le16(GBETH_RX_DESC_DATA_SIZE);
345 dma_addr = dma_map_single(ndev->dev.parent, priv->rx_skb[q][i]->data,
348 /* We just set the data size to 0 for a failed mapping which
349 * should prevent DMA from happening...
351 if (dma_mapping_error(ndev->dev.parent, dma_addr))
352 rx_desc->ds_cc = cpu_to_le16(0);
353 rx_desc->dptr = cpu_to_le32(dma_addr);
354 rx_desc->die_dt = DT_FEMPTY;
356 rx_desc = &priv->gbeth_rx_ring[i];
357 rx_desc->dptr = cpu_to_le32((u32)priv->rx_desc_dma[q]);
358 rx_desc->die_dt = DT_LINKFIX; /* type */
361 static void ravb_rx_ring_format_rcar(struct net_device *ndev, int q)
363 struct ravb_private *priv = netdev_priv(ndev);
364 struct ravb_ex_rx_desc *rx_desc;
365 unsigned int rx_ring_size = sizeof(*rx_desc) * priv->num_rx_ring[q];
369 memset(priv->rx_ring[q], 0, rx_ring_size);
370 /* Build RX ring buffer */
371 for (i = 0; i < priv->num_rx_ring[q]; i++) {
373 rx_desc = &priv->rx_ring[q][i];
374 rx_desc->ds_cc = cpu_to_le16(RX_BUF_SZ);
375 dma_addr = dma_map_single(ndev->dev.parent, priv->rx_skb[q][i]->data,
378 /* We just set the data size to 0 for a failed mapping which
379 * should prevent DMA from happening...
381 if (dma_mapping_error(ndev->dev.parent, dma_addr))
382 rx_desc->ds_cc = cpu_to_le16(0);
383 rx_desc->dptr = cpu_to_le32(dma_addr);
384 rx_desc->die_dt = DT_FEMPTY;
386 rx_desc = &priv->rx_ring[q][i];
387 rx_desc->dptr = cpu_to_le32((u32)priv->rx_desc_dma[q]);
388 rx_desc->die_dt = DT_LINKFIX; /* type */
391 /* Format skb and descriptor buffer for Ethernet AVB */
392 static void ravb_ring_format(struct net_device *ndev, int q)
394 struct ravb_private *priv = netdev_priv(ndev);
395 const struct ravb_hw_info *info = priv->info;
396 unsigned int num_tx_desc = priv->num_tx_desc;
397 struct ravb_tx_desc *tx_desc;
398 struct ravb_desc *desc;
399 unsigned int tx_ring_size = sizeof(*tx_desc) * priv->num_tx_ring[q] *
405 priv->dirty_rx[q] = 0;
406 priv->dirty_tx[q] = 0;
408 info->rx_ring_format(ndev, q);
410 memset(priv->tx_ring[q], 0, tx_ring_size);
411 /* Build TX ring buffer */
412 for (i = 0, tx_desc = priv->tx_ring[q]; i < priv->num_tx_ring[q];
414 tx_desc->die_dt = DT_EEMPTY;
415 if (num_tx_desc > 1) {
417 tx_desc->die_dt = DT_EEMPTY;
420 tx_desc->dptr = cpu_to_le32((u32)priv->tx_desc_dma[q]);
421 tx_desc->die_dt = DT_LINKFIX; /* type */
423 /* RX descriptor base address for best effort */
424 desc = &priv->desc_bat[RX_QUEUE_OFFSET + q];
425 desc->die_dt = DT_LINKFIX; /* type */
426 desc->dptr = cpu_to_le32((u32)priv->rx_desc_dma[q]);
428 /* TX descriptor base address for best effort */
429 desc = &priv->desc_bat[q];
430 desc->die_dt = DT_LINKFIX; /* type */
431 desc->dptr = cpu_to_le32((u32)priv->tx_desc_dma[q]);
434 static void *ravb_alloc_rx_desc_gbeth(struct net_device *ndev, int q)
436 struct ravb_private *priv = netdev_priv(ndev);
437 unsigned int ring_size;
439 ring_size = sizeof(struct ravb_rx_desc) * (priv->num_rx_ring[q] + 1);
441 priv->gbeth_rx_ring = dma_alloc_coherent(ndev->dev.parent, ring_size,
442 &priv->rx_desc_dma[q],
444 return priv->gbeth_rx_ring;
447 static void *ravb_alloc_rx_desc_rcar(struct net_device *ndev, int q)
449 struct ravb_private *priv = netdev_priv(ndev);
450 unsigned int ring_size;
452 ring_size = sizeof(struct ravb_ex_rx_desc) * (priv->num_rx_ring[q] + 1);
454 priv->rx_ring[q] = dma_alloc_coherent(ndev->dev.parent, ring_size,
455 &priv->rx_desc_dma[q],
457 return priv->rx_ring[q];
460 /* Init skb and descriptor buffer for Ethernet AVB */
461 static int ravb_ring_init(struct net_device *ndev, int q)
463 struct ravb_private *priv = netdev_priv(ndev);
464 const struct ravb_hw_info *info = priv->info;
465 unsigned int num_tx_desc = priv->num_tx_desc;
466 unsigned int ring_size;
470 /* Allocate RX and TX skb rings */
471 priv->rx_skb[q] = kcalloc(priv->num_rx_ring[q],
472 sizeof(*priv->rx_skb[q]), GFP_KERNEL);
473 priv->tx_skb[q] = kcalloc(priv->num_tx_ring[q],
474 sizeof(*priv->tx_skb[q]), GFP_KERNEL);
475 if (!priv->rx_skb[q] || !priv->tx_skb[q])
478 for (i = 0; i < priv->num_rx_ring[q]; i++) {
479 skb = netdev_alloc_skb(ndev, info->max_rx_len);
482 ravb_set_buffer_align(skb);
483 priv->rx_skb[q][i] = skb;
486 if (num_tx_desc > 1) {
487 /* Allocate rings for the aligned buffers */
488 priv->tx_align[q] = kmalloc(DPTR_ALIGN * priv->num_tx_ring[q] +
489 DPTR_ALIGN - 1, GFP_KERNEL);
490 if (!priv->tx_align[q])
494 /* Allocate all RX descriptors. */
495 if (!info->alloc_rx_desc(ndev, q))
498 priv->dirty_rx[q] = 0;
500 /* Allocate all TX descriptors. */
501 ring_size = sizeof(struct ravb_tx_desc) *
502 (priv->num_tx_ring[q] * num_tx_desc + 1);
503 priv->tx_ring[q] = dma_alloc_coherent(ndev->dev.parent, ring_size,
504 &priv->tx_desc_dma[q],
506 if (!priv->tx_ring[q])
512 ravb_ring_free(ndev, q);
517 static void ravb_emac_init_gbeth(struct net_device *ndev)
519 struct ravb_private *priv = netdev_priv(ndev);
521 /* Receive frame limit set register */
522 ravb_write(ndev, GBETH_RX_BUFF_MAX + ETH_FCS_LEN, RFLR);
524 /* EMAC Mode: PAUSE prohibition; Duplex; TX; RX; CRC Pass Through */
525 ravb_write(ndev, ECMR_ZPF | ((priv->duplex > 0) ? ECMR_DM : 0) |
526 ECMR_TE | ECMR_RE | ECMR_RCPT |
527 ECMR_TXF | ECMR_RXF, ECMR);
529 ravb_set_rate_gbeth(ndev);
531 /* Set MAC address */
533 (ndev->dev_addr[0] << 24) | (ndev->dev_addr[1] << 16) |
534 (ndev->dev_addr[2] << 8) | (ndev->dev_addr[3]), MAHR);
535 ravb_write(ndev, (ndev->dev_addr[4] << 8) | (ndev->dev_addr[5]), MALR);
537 /* E-MAC status register clear */
538 ravb_write(ndev, ECSR_ICD | ECSR_LCHNG | ECSR_PFRI, ECSR);
539 ravb_write(ndev, CSR0_TPE | CSR0_RPE, CSR0);
541 /* E-MAC interrupt enable register */
542 ravb_write(ndev, ECSIPR_ICDIP, ECSIPR);
544 ravb_modify(ndev, CXR31, CXR31_SEL_LINK0 | CXR31_SEL_LINK1, CXR31_SEL_LINK0);
547 static void ravb_emac_init_rcar(struct net_device *ndev)
549 /* Receive frame limit set register */
550 ravb_write(ndev, ndev->mtu + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN, RFLR);
552 /* EMAC Mode: PAUSE prohibition; Duplex; RX Checksum; TX; RX */
553 ravb_write(ndev, ECMR_ZPF | ECMR_DM |
554 (ndev->features & NETIF_F_RXCSUM ? ECMR_RCSC : 0) |
555 ECMR_TE | ECMR_RE, ECMR);
557 ravb_set_rate_rcar(ndev);
559 /* Set MAC address */
561 (ndev->dev_addr[0] << 24) | (ndev->dev_addr[1] << 16) |
562 (ndev->dev_addr[2] << 8) | (ndev->dev_addr[3]), MAHR);
564 (ndev->dev_addr[4] << 8) | (ndev->dev_addr[5]), MALR);
566 /* E-MAC status register clear */
567 ravb_write(ndev, ECSR_ICD | ECSR_MPD, ECSR);
569 /* E-MAC interrupt enable register */
570 ravb_write(ndev, ECSIPR_ICDIP | ECSIPR_MPDIP | ECSIPR_LCHNGIP, ECSIPR);
573 /* E-MAC init function */
574 static void ravb_emac_init(struct net_device *ndev)
576 struct ravb_private *priv = netdev_priv(ndev);
577 const struct ravb_hw_info *info = priv->info;
579 info->emac_init(ndev);
582 static int ravb_dmac_init_gbeth(struct net_device *ndev)
586 error = ravb_ring_init(ndev, RAVB_BE);
590 /* Descriptor format */
591 ravb_ring_format(ndev, RAVB_BE);
594 ravb_write(ndev, 0x60000000, RCR);
596 /* Set Max Frame Length (RTC) */
597 ravb_write(ndev, 0x7ffc0000 | GBETH_RX_BUFF_MAX, RTC);
600 ravb_write(ndev, 0x00222200, TGC);
602 ravb_write(ndev, 0, TCCR);
605 ravb_write(ndev, RIC0_FRE0, RIC0);
606 /* Disable FIFO full warning */
607 ravb_write(ndev, 0x0, RIC1);
608 /* Receive FIFO full error, descriptor empty */
609 ravb_write(ndev, RIC2_QFE0 | RIC2_RFFE, RIC2);
611 ravb_write(ndev, TIC_FTE0, TIC);
616 static int ravb_dmac_init_rcar(struct net_device *ndev)
618 struct ravb_private *priv = netdev_priv(ndev);
619 const struct ravb_hw_info *info = priv->info;
622 error = ravb_ring_init(ndev, RAVB_BE);
625 error = ravb_ring_init(ndev, RAVB_NC);
627 ravb_ring_free(ndev, RAVB_BE);
631 /* Descriptor format */
632 ravb_ring_format(ndev, RAVB_BE);
633 ravb_ring_format(ndev, RAVB_NC);
637 RCR_EFFS | RCR_ENCF | RCR_ETS0 | RCR_ESF | 0x18000000, RCR);
640 ravb_write(ndev, TGC_TQP_AVBMODE1 | 0x00112200, TGC);
642 /* Timestamp enable */
643 ravb_write(ndev, TCCR_TFEN, TCCR);
645 /* Interrupt init: */
646 if (info->multi_irqs) {
648 ravb_write(ndev, 0, DIL);
649 /* Set queue specific interrupt */
650 ravb_write(ndev, CIE_CRIE | CIE_CTIE | CIE_CL0M, CIE);
653 ravb_write(ndev, RIC0_FRE0 | RIC0_FRE1, RIC0);
654 /* Disable FIFO full warning */
655 ravb_write(ndev, 0, RIC1);
656 /* Receive FIFO full error, descriptor empty */
657 ravb_write(ndev, RIC2_QFE0 | RIC2_QFE1 | RIC2_RFFE, RIC2);
658 /* Frame transmitted, timestamp FIFO updated */
659 ravb_write(ndev, TIC_FTE0 | TIC_FTE1 | TIC_TFUE, TIC);
664 /* Device init function for Ethernet AVB */
665 static int ravb_dmac_init(struct net_device *ndev)
667 struct ravb_private *priv = netdev_priv(ndev);
668 const struct ravb_hw_info *info = priv->info;
671 /* Set CONFIG mode */
672 error = ravb_config(ndev);
676 error = info->dmac_init(ndev);
680 /* Setting the control will start the AVB-DMAC process. */
681 ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_OPERATION);
686 static void ravb_get_tx_tstamp(struct net_device *ndev)
688 struct ravb_private *priv = netdev_priv(ndev);
689 struct ravb_tstamp_skb *ts_skb, *ts_skb2;
690 struct skb_shared_hwtstamps shhwtstamps;
692 struct timespec64 ts;
697 count = (ravb_read(ndev, TSR) & TSR_TFFL) >> 8;
699 tfa2 = ravb_read(ndev, TFA2);
700 tfa_tag = (tfa2 & TFA2_TST) >> 16;
701 ts.tv_nsec = (u64)ravb_read(ndev, TFA0);
702 ts.tv_sec = ((u64)(tfa2 & TFA2_TSV) << 32) |
703 ravb_read(ndev, TFA1);
704 memset(&shhwtstamps, 0, sizeof(shhwtstamps));
705 shhwtstamps.hwtstamp = timespec64_to_ktime(ts);
706 list_for_each_entry_safe(ts_skb, ts_skb2, &priv->ts_skb_list,
710 list_del(&ts_skb->list);
712 if (tag == tfa_tag) {
713 skb_tstamp_tx(skb, &shhwtstamps);
714 dev_consume_skb_any(skb);
717 dev_kfree_skb_any(skb);
720 ravb_modify(ndev, TCCR, TCCR_TFR, TCCR_TFR);
724 static void ravb_rx_csum(struct sk_buff *skb)
728 /* The hardware checksum is contained in sizeof(__sum16) (2) bytes
729 * appended to packet data
731 if (unlikely(skb->len < sizeof(__sum16)))
733 hw_csum = skb_tail_pointer(skb) - sizeof(__sum16);
734 skb->csum = csum_unfold((__force __sum16)get_unaligned_le16(hw_csum));
735 skb->ip_summed = CHECKSUM_COMPLETE;
736 skb_trim(skb, skb->len - sizeof(__sum16));
739 static struct sk_buff *ravb_get_skb_gbeth(struct net_device *ndev, int entry,
740 struct ravb_rx_desc *desc)
742 struct ravb_private *priv = netdev_priv(ndev);
745 skb = priv->rx_skb[RAVB_BE][entry];
746 priv->rx_skb[RAVB_BE][entry] = NULL;
747 dma_unmap_single(ndev->dev.parent, le32_to_cpu(desc->dptr),
748 ALIGN(GBETH_RX_BUFF_MAX, 16), DMA_FROM_DEVICE);
753 /* Packet receive function for Gigabit Ethernet */
754 static bool ravb_rx_gbeth(struct net_device *ndev, int *quota, int q)
756 struct ravb_private *priv = netdev_priv(ndev);
757 const struct ravb_hw_info *info = priv->info;
758 struct net_device_stats *stats;
759 struct ravb_rx_desc *desc;
769 entry = priv->cur_rx[q] % priv->num_rx_ring[q];
770 boguscnt = priv->dirty_rx[q] + priv->num_rx_ring[q] - priv->cur_rx[q];
771 stats = &priv->stats[q];
773 boguscnt = min(boguscnt, *quota);
775 desc = &priv->gbeth_rx_ring[entry];
776 while (desc->die_dt != DT_FEMPTY) {
777 /* Descriptor type must be checked before all other reads */
779 desc_status = desc->msc;
780 pkt_len = le16_to_cpu(desc->ds_cc) & RX_DS;
785 /* We use 0-byte descriptors to mark the DMA mapping errors */
789 if (desc_status & MSC_MC)
792 if (desc_status & (MSC_CRC | MSC_RFE | MSC_RTSF | MSC_RTLF | MSC_CEEF)) {
794 if (desc_status & MSC_CRC)
795 stats->rx_crc_errors++;
796 if (desc_status & MSC_RFE)
797 stats->rx_frame_errors++;
798 if (desc_status & (MSC_RTLF | MSC_RTSF))
799 stats->rx_length_errors++;
800 if (desc_status & MSC_CEEF)
801 stats->rx_missed_errors++;
803 die_dt = desc->die_dt & 0xF0;
806 skb = ravb_get_skb_gbeth(ndev, entry, desc);
807 skb_put(skb, pkt_len);
808 skb->protocol = eth_type_trans(skb, ndev);
809 napi_gro_receive(&priv->napi[q], skb);
811 stats->rx_bytes += pkt_len;
814 priv->rx_1st_skb = ravb_get_skb_gbeth(ndev, entry, desc);
815 skb_put(priv->rx_1st_skb, pkt_len);
818 skb = ravb_get_skb_gbeth(ndev, entry, desc);
819 skb_copy_to_linear_data_offset(priv->rx_1st_skb,
820 priv->rx_1st_skb->len,
823 skb_put(priv->rx_1st_skb, pkt_len);
827 skb = ravb_get_skb_gbeth(ndev, entry, desc);
828 skb_copy_to_linear_data_offset(priv->rx_1st_skb,
829 priv->rx_1st_skb->len,
832 skb_put(priv->rx_1st_skb, pkt_len);
834 priv->rx_1st_skb->protocol =
835 eth_type_trans(priv->rx_1st_skb, ndev);
836 napi_gro_receive(&priv->napi[q],
839 stats->rx_bytes += priv->rx_1st_skb->len;
844 entry = (++priv->cur_rx[q]) % priv->num_rx_ring[q];
845 desc = &priv->gbeth_rx_ring[entry];
848 /* Refill the RX ring buffers. */
849 for (; priv->cur_rx[q] - priv->dirty_rx[q] > 0; priv->dirty_rx[q]++) {
850 entry = priv->dirty_rx[q] % priv->num_rx_ring[q];
851 desc = &priv->gbeth_rx_ring[entry];
852 desc->ds_cc = cpu_to_le16(GBETH_RX_DESC_DATA_SIZE);
854 if (!priv->rx_skb[q][entry]) {
855 skb = netdev_alloc_skb(ndev, info->max_rx_len);
858 ravb_set_buffer_align(skb);
859 dma_addr = dma_map_single(ndev->dev.parent,
863 skb_checksum_none_assert(skb);
864 /* We just set the data size to 0 for a failed mapping
865 * which should prevent DMA from happening...
867 if (dma_mapping_error(ndev->dev.parent, dma_addr))
868 desc->ds_cc = cpu_to_le16(0);
869 desc->dptr = cpu_to_le32(dma_addr);
870 priv->rx_skb[q][entry] = skb;
872 /* Descriptor type must be set after all the above writes */
874 desc->die_dt = DT_FEMPTY;
877 *quota -= limit - (++boguscnt);
879 return boguscnt <= 0;
882 /* Packet receive function for Ethernet AVB */
883 static bool ravb_rx_rcar(struct net_device *ndev, int *quota, int q)
885 struct ravb_private *priv = netdev_priv(ndev);
886 const struct ravb_hw_info *info = priv->info;
887 int entry = priv->cur_rx[q] % priv->num_rx_ring[q];
888 int boguscnt = (priv->dirty_rx[q] + priv->num_rx_ring[q]) -
890 struct net_device_stats *stats = &priv->stats[q];
891 struct ravb_ex_rx_desc *desc;
894 struct timespec64 ts;
899 boguscnt = min(boguscnt, *quota);
901 desc = &priv->rx_ring[q][entry];
902 while (desc->die_dt != DT_FEMPTY) {
903 /* Descriptor type must be checked before all other reads */
905 desc_status = desc->msc;
906 pkt_len = le16_to_cpu(desc->ds_cc) & RX_DS;
911 /* We use 0-byte descriptors to mark the DMA mapping errors */
915 if (desc_status & MSC_MC)
918 if (desc_status & (MSC_CRC | MSC_RFE | MSC_RTSF | MSC_RTLF |
921 if (desc_status & MSC_CRC)
922 stats->rx_crc_errors++;
923 if (desc_status & MSC_RFE)
924 stats->rx_frame_errors++;
925 if (desc_status & (MSC_RTLF | MSC_RTSF))
926 stats->rx_length_errors++;
927 if (desc_status & MSC_CEEF)
928 stats->rx_missed_errors++;
930 u32 get_ts = priv->tstamp_rx_ctrl & RAVB_RXTSTAMP_TYPE;
932 skb = priv->rx_skb[q][entry];
933 priv->rx_skb[q][entry] = NULL;
934 dma_unmap_single(ndev->dev.parent, le32_to_cpu(desc->dptr),
937 get_ts &= (q == RAVB_NC) ?
938 RAVB_RXTSTAMP_TYPE_V2_L2_EVENT :
939 ~RAVB_RXTSTAMP_TYPE_V2_L2_EVENT;
941 struct skb_shared_hwtstamps *shhwtstamps;
943 shhwtstamps = skb_hwtstamps(skb);
944 memset(shhwtstamps, 0, sizeof(*shhwtstamps));
945 ts.tv_sec = ((u64) le16_to_cpu(desc->ts_sh) <<
946 32) | le32_to_cpu(desc->ts_sl);
947 ts.tv_nsec = le32_to_cpu(desc->ts_n);
948 shhwtstamps->hwtstamp = timespec64_to_ktime(ts);
951 skb_put(skb, pkt_len);
952 skb->protocol = eth_type_trans(skb, ndev);
953 if (ndev->features & NETIF_F_RXCSUM)
955 napi_gro_receive(&priv->napi[q], skb);
957 stats->rx_bytes += pkt_len;
960 entry = (++priv->cur_rx[q]) % priv->num_rx_ring[q];
961 desc = &priv->rx_ring[q][entry];
964 /* Refill the RX ring buffers. */
965 for (; priv->cur_rx[q] - priv->dirty_rx[q] > 0; priv->dirty_rx[q]++) {
966 entry = priv->dirty_rx[q] % priv->num_rx_ring[q];
967 desc = &priv->rx_ring[q][entry];
968 desc->ds_cc = cpu_to_le16(RX_BUF_SZ);
970 if (!priv->rx_skb[q][entry]) {
971 skb = netdev_alloc_skb(ndev, info->max_rx_len);
973 break; /* Better luck next round. */
974 ravb_set_buffer_align(skb);
975 dma_addr = dma_map_single(ndev->dev.parent, skb->data,
976 le16_to_cpu(desc->ds_cc),
978 skb_checksum_none_assert(skb);
979 /* We just set the data size to 0 for a failed mapping
980 * which should prevent DMA from happening...
982 if (dma_mapping_error(ndev->dev.parent, dma_addr))
983 desc->ds_cc = cpu_to_le16(0);
984 desc->dptr = cpu_to_le32(dma_addr);
985 priv->rx_skb[q][entry] = skb;
987 /* Descriptor type must be set after all the above writes */
989 desc->die_dt = DT_FEMPTY;
992 *quota -= limit - (++boguscnt);
994 return boguscnt <= 0;
997 /* Packet receive function for Ethernet AVB */
998 static bool ravb_rx(struct net_device *ndev, int *quota, int q)
1000 struct ravb_private *priv = netdev_priv(ndev);
1001 const struct ravb_hw_info *info = priv->info;
1003 return info->receive(ndev, quota, q);
1006 static void ravb_rcv_snd_disable(struct net_device *ndev)
1008 /* Disable TX and RX */
1009 ravb_modify(ndev, ECMR, ECMR_RE | ECMR_TE, 0);
1012 static void ravb_rcv_snd_enable(struct net_device *ndev)
1014 /* Enable TX and RX */
1015 ravb_modify(ndev, ECMR, ECMR_RE | ECMR_TE, ECMR_RE | ECMR_TE);
1018 /* function for waiting dma process finished */
1019 static int ravb_stop_dma(struct net_device *ndev)
1021 struct ravb_private *priv = netdev_priv(ndev);
1022 const struct ravb_hw_info *info = priv->info;
1025 /* Wait for stopping the hardware TX process */
1026 error = ravb_wait(ndev, TCCR, info->tccr_mask, 0);
1031 error = ravb_wait(ndev, CSR, CSR_TPO0 | CSR_TPO1 | CSR_TPO2 | CSR_TPO3,
1036 /* Stop the E-MAC's RX/TX processes. */
1037 ravb_rcv_snd_disable(ndev);
1039 /* Wait for stopping the RX DMA process */
1040 error = ravb_wait(ndev, CSR, CSR_RPO, 0);
1044 /* Stop AVB-DMAC process */
1045 return ravb_config(ndev);
1048 /* E-MAC interrupt handler */
1049 static void ravb_emac_interrupt_unlocked(struct net_device *ndev)
1051 struct ravb_private *priv = netdev_priv(ndev);
1054 ecsr = ravb_read(ndev, ECSR);
1055 ravb_write(ndev, ecsr, ECSR); /* clear interrupt */
1057 if (ecsr & ECSR_MPD)
1058 pm_wakeup_event(&priv->pdev->dev, 0);
1059 if (ecsr & ECSR_ICD)
1060 ndev->stats.tx_carrier_errors++;
1061 if (ecsr & ECSR_LCHNG) {
1063 if (priv->no_avb_link)
1065 psr = ravb_read(ndev, PSR);
1066 if (priv->avb_link_active_low)
1068 if (!(psr & PSR_LMON)) {
1069 /* DIsable RX and TX */
1070 ravb_rcv_snd_disable(ndev);
1072 /* Enable RX and TX */
1073 ravb_rcv_snd_enable(ndev);
1078 static irqreturn_t ravb_emac_interrupt(int irq, void *dev_id)
1080 struct net_device *ndev = dev_id;
1081 struct ravb_private *priv = netdev_priv(ndev);
1083 spin_lock(&priv->lock);
1084 ravb_emac_interrupt_unlocked(ndev);
1085 spin_unlock(&priv->lock);
1089 /* Error interrupt handler */
1090 static void ravb_error_interrupt(struct net_device *ndev)
1092 struct ravb_private *priv = netdev_priv(ndev);
1095 eis = ravb_read(ndev, EIS);
1096 ravb_write(ndev, ~(EIS_QFS | EIS_RESERVED), EIS);
1097 if (eis & EIS_QFS) {
1098 ris2 = ravb_read(ndev, RIS2);
1099 ravb_write(ndev, ~(RIS2_QFF0 | RIS2_RFFF | RIS2_RESERVED),
1102 /* Receive Descriptor Empty int */
1103 if (ris2 & RIS2_QFF0)
1104 priv->stats[RAVB_BE].rx_over_errors++;
1106 /* Receive Descriptor Empty int */
1107 if (ris2 & RIS2_QFF1)
1108 priv->stats[RAVB_NC].rx_over_errors++;
1110 /* Receive FIFO Overflow int */
1111 if (ris2 & RIS2_RFFF)
1112 priv->rx_fifo_errors++;
1116 static bool ravb_queue_interrupt(struct net_device *ndev, int q)
1118 struct ravb_private *priv = netdev_priv(ndev);
1119 const struct ravb_hw_info *info = priv->info;
1120 u32 ris0 = ravb_read(ndev, RIS0);
1121 u32 ric0 = ravb_read(ndev, RIC0);
1122 u32 tis = ravb_read(ndev, TIS);
1123 u32 tic = ravb_read(ndev, TIC);
1125 if (((ris0 & ric0) & BIT(q)) || ((tis & tic) & BIT(q))) {
1126 if (napi_schedule_prep(&priv->napi[q])) {
1127 /* Mask RX and TX interrupts */
1128 if (!info->multi_irqs) {
1129 ravb_write(ndev, ric0 & ~BIT(q), RIC0);
1130 ravb_write(ndev, tic & ~BIT(q), TIC);
1132 ravb_write(ndev, BIT(q), RID0);
1133 ravb_write(ndev, BIT(q), TID);
1135 __napi_schedule(&priv->napi[q]);
1138 "ignoring interrupt, rx status 0x%08x, rx mask 0x%08x,\n",
1141 " tx status 0x%08x, tx mask 0x%08x.\n",
1149 static bool ravb_timestamp_interrupt(struct net_device *ndev)
1151 u32 tis = ravb_read(ndev, TIS);
1153 if (tis & TIS_TFUF) {
1154 ravb_write(ndev, ~(TIS_TFUF | TIS_RESERVED), TIS);
1155 ravb_get_tx_tstamp(ndev);
1161 static irqreturn_t ravb_interrupt(int irq, void *dev_id)
1163 struct net_device *ndev = dev_id;
1164 struct ravb_private *priv = netdev_priv(ndev);
1165 const struct ravb_hw_info *info = priv->info;
1166 irqreturn_t result = IRQ_NONE;
1169 spin_lock(&priv->lock);
1170 /* Get interrupt status */
1171 iss = ravb_read(ndev, ISS);
1173 /* Received and transmitted interrupts */
1174 if (iss & (ISS_FRS | ISS_FTS | ISS_TFUS)) {
1177 /* Timestamp updated */
1178 if (ravb_timestamp_interrupt(ndev))
1179 result = IRQ_HANDLED;
1181 /* Network control and best effort queue RX/TX */
1182 if (info->nc_queues) {
1183 for (q = RAVB_NC; q >= RAVB_BE; q--) {
1184 if (ravb_queue_interrupt(ndev, q))
1185 result = IRQ_HANDLED;
1188 if (ravb_queue_interrupt(ndev, RAVB_BE))
1189 result = IRQ_HANDLED;
1193 /* E-MAC status summary */
1195 ravb_emac_interrupt_unlocked(ndev);
1196 result = IRQ_HANDLED;
1199 /* Error status summary */
1201 ravb_error_interrupt(ndev);
1202 result = IRQ_HANDLED;
1205 /* gPTP interrupt status summary */
1206 if (iss & ISS_CGIS) {
1207 ravb_ptp_interrupt(ndev);
1208 result = IRQ_HANDLED;
1211 spin_unlock(&priv->lock);
1215 /* Timestamp/Error/gPTP interrupt handler */
1216 static irqreturn_t ravb_multi_interrupt(int irq, void *dev_id)
1218 struct net_device *ndev = dev_id;
1219 struct ravb_private *priv = netdev_priv(ndev);
1220 irqreturn_t result = IRQ_NONE;
1223 spin_lock(&priv->lock);
1224 /* Get interrupt status */
1225 iss = ravb_read(ndev, ISS);
1227 /* Timestamp updated */
1228 if ((iss & ISS_TFUS) && ravb_timestamp_interrupt(ndev))
1229 result = IRQ_HANDLED;
1231 /* Error status summary */
1233 ravb_error_interrupt(ndev);
1234 result = IRQ_HANDLED;
1237 /* gPTP interrupt status summary */
1238 if (iss & ISS_CGIS) {
1239 ravb_ptp_interrupt(ndev);
1240 result = IRQ_HANDLED;
1243 spin_unlock(&priv->lock);
1247 static irqreturn_t ravb_dma_interrupt(int irq, void *dev_id, int q)
1249 struct net_device *ndev = dev_id;
1250 struct ravb_private *priv = netdev_priv(ndev);
1251 irqreturn_t result = IRQ_NONE;
1253 spin_lock(&priv->lock);
1255 /* Network control/Best effort queue RX/TX */
1256 if (ravb_queue_interrupt(ndev, q))
1257 result = IRQ_HANDLED;
1259 spin_unlock(&priv->lock);
1263 static irqreturn_t ravb_be_interrupt(int irq, void *dev_id)
1265 return ravb_dma_interrupt(irq, dev_id, RAVB_BE);
1268 static irqreturn_t ravb_nc_interrupt(int irq, void *dev_id)
1270 return ravb_dma_interrupt(irq, dev_id, RAVB_NC);
1273 static int ravb_poll(struct napi_struct *napi, int budget)
1275 struct net_device *ndev = napi->dev;
1276 struct ravb_private *priv = netdev_priv(ndev);
1277 const struct ravb_hw_info *info = priv->info;
1278 bool gptp = info->gptp || info->ccc_gac;
1279 struct ravb_rx_desc *desc;
1280 unsigned long flags;
1281 int q = napi - priv->napi;
1287 entry = priv->cur_rx[q] % priv->num_rx_ring[q];
1288 desc = &priv->gbeth_rx_ring[entry];
1290 /* Processing RX Descriptor Ring */
1291 /* Clear RX interrupt */
1292 ravb_write(ndev, ~(mask | RIS0_RESERVED), RIS0);
1293 if (gptp || desc->die_dt != DT_FEMPTY) {
1294 if (ravb_rx(ndev, "a, q))
1298 /* Processing TX Descriptor Ring */
1299 spin_lock_irqsave(&priv->lock, flags);
1300 /* Clear TX interrupt */
1301 ravb_write(ndev, ~(mask | TIS_RESERVED), TIS);
1302 ravb_tx_free(ndev, q, true);
1303 netif_wake_subqueue(ndev, q);
1304 spin_unlock_irqrestore(&priv->lock, flags);
1306 napi_complete(napi);
1308 /* Re-enable RX/TX interrupts */
1309 spin_lock_irqsave(&priv->lock, flags);
1310 if (!info->multi_irqs) {
1311 ravb_modify(ndev, RIC0, mask, mask);
1312 ravb_modify(ndev, TIC, mask, mask);
1314 ravb_write(ndev, mask, RIE0);
1315 ravb_write(ndev, mask, TIE);
1317 spin_unlock_irqrestore(&priv->lock, flags);
1319 /* Receive error message handling */
1320 priv->rx_over_errors = priv->stats[RAVB_BE].rx_over_errors;
1321 if (info->nc_queues)
1322 priv->rx_over_errors += priv->stats[RAVB_NC].rx_over_errors;
1323 if (priv->rx_over_errors != ndev->stats.rx_over_errors)
1324 ndev->stats.rx_over_errors = priv->rx_over_errors;
1325 if (priv->rx_fifo_errors != ndev->stats.rx_fifo_errors)
1326 ndev->stats.rx_fifo_errors = priv->rx_fifo_errors;
1328 return budget - quota;
1331 static void ravb_set_duplex_gbeth(struct net_device *ndev)
1333 struct ravb_private *priv = netdev_priv(ndev);
1335 ravb_modify(ndev, ECMR, ECMR_DM, priv->duplex > 0 ? ECMR_DM : 0);
1338 /* PHY state control function */
1339 static void ravb_adjust_link(struct net_device *ndev)
1341 struct ravb_private *priv = netdev_priv(ndev);
1342 const struct ravb_hw_info *info = priv->info;
1343 struct phy_device *phydev = ndev->phydev;
1344 bool new_state = false;
1345 unsigned long flags;
1347 spin_lock_irqsave(&priv->lock, flags);
1349 /* Disable TX and RX right over here, if E-MAC change is ignored */
1350 if (priv->no_avb_link)
1351 ravb_rcv_snd_disable(ndev);
1354 if (info->half_duplex && phydev->duplex != priv->duplex) {
1356 priv->duplex = phydev->duplex;
1357 ravb_set_duplex_gbeth(ndev);
1360 if (phydev->speed != priv->speed) {
1362 priv->speed = phydev->speed;
1363 info->set_rate(ndev);
1366 ravb_modify(ndev, ECMR, ECMR_TXF, 0);
1368 priv->link = phydev->link;
1370 } else if (priv->link) {
1374 if (info->half_duplex)
1378 /* Enable TX and RX right over here, if E-MAC change is ignored */
1379 if (priv->no_avb_link && phydev->link)
1380 ravb_rcv_snd_enable(ndev);
1382 spin_unlock_irqrestore(&priv->lock, flags);
1384 if (new_state && netif_msg_link(priv))
1385 phy_print_status(phydev);
1388 static const struct soc_device_attribute r8a7795es10[] = {
1389 { .soc_id = "r8a7795", .revision = "ES1.0", },
1393 /* PHY init function */
1394 static int ravb_phy_init(struct net_device *ndev)
1396 struct device_node *np = ndev->dev.parent->of_node;
1397 struct ravb_private *priv = netdev_priv(ndev);
1398 const struct ravb_hw_info *info = priv->info;
1399 struct phy_device *phydev;
1400 struct device_node *pn;
1401 phy_interface_t iface;
1408 /* Try connecting to PHY */
1409 pn = of_parse_phandle(np, "phy-handle", 0);
1411 /* In the case of a fixed PHY, the DT node associated
1412 * to the PHY is the Ethernet MAC DT node.
1414 if (of_phy_is_fixed_link(np)) {
1415 err = of_phy_register_fixed_link(np);
1419 pn = of_node_get(np);
1422 iface = priv->rgmii_override ? PHY_INTERFACE_MODE_RGMII
1423 : priv->phy_interface;
1424 phydev = of_phy_connect(ndev, pn, ravb_adjust_link, 0, iface);
1427 netdev_err(ndev, "failed to connect PHY\n");
1429 goto err_deregister_fixed_link;
1432 /* This driver only support 10/100Mbit speeds on R-Car H3 ES1.0
1435 if (soc_device_match(r8a7795es10)) {
1436 err = phy_set_max_speed(phydev, SPEED_100);
1438 netdev_err(ndev, "failed to limit PHY to 100Mbit/s\n");
1439 goto err_phy_disconnect;
1442 netdev_info(ndev, "limited PHY to 100Mbit/s\n");
1445 if (!info->half_duplex) {
1446 /* 10BASE, Pause and Asym Pause is not supported */
1447 phy_remove_link_mode(phydev, ETHTOOL_LINK_MODE_10baseT_Half_BIT);
1448 phy_remove_link_mode(phydev, ETHTOOL_LINK_MODE_10baseT_Full_BIT);
1449 phy_remove_link_mode(phydev, ETHTOOL_LINK_MODE_Pause_BIT);
1450 phy_remove_link_mode(phydev, ETHTOOL_LINK_MODE_Asym_Pause_BIT);
1452 /* Half Duplex is not supported */
1453 phy_remove_link_mode(phydev, ETHTOOL_LINK_MODE_1000baseT_Half_BIT);
1454 phy_remove_link_mode(phydev, ETHTOOL_LINK_MODE_100baseT_Half_BIT);
1457 phy_attached_info(phydev);
1462 phy_disconnect(phydev);
1463 err_deregister_fixed_link:
1464 if (of_phy_is_fixed_link(np))
1465 of_phy_deregister_fixed_link(np);
1470 /* PHY control start function */
1471 static int ravb_phy_start(struct net_device *ndev)
1475 error = ravb_phy_init(ndev);
1479 phy_start(ndev->phydev);
1484 static u32 ravb_get_msglevel(struct net_device *ndev)
1486 struct ravb_private *priv = netdev_priv(ndev);
1488 return priv->msg_enable;
1491 static void ravb_set_msglevel(struct net_device *ndev, u32 value)
1493 struct ravb_private *priv = netdev_priv(ndev);
1495 priv->msg_enable = value;
1498 static const char ravb_gstrings_stats_gbeth[][ETH_GSTRING_LEN] = {
1499 "rx_queue_0_current",
1500 "tx_queue_0_current",
1503 "rx_queue_0_packets",
1504 "tx_queue_0_packets",
1507 "rx_queue_0_mcast_packets",
1508 "rx_queue_0_errors",
1509 "rx_queue_0_crc_errors",
1510 "rx_queue_0_frame_errors",
1511 "rx_queue_0_length_errors",
1512 "rx_queue_0_csum_offload_errors",
1513 "rx_queue_0_over_errors",
1516 static const char ravb_gstrings_stats[][ETH_GSTRING_LEN] = {
1517 "rx_queue_0_current",
1518 "tx_queue_0_current",
1521 "rx_queue_0_packets",
1522 "tx_queue_0_packets",
1525 "rx_queue_0_mcast_packets",
1526 "rx_queue_0_errors",
1527 "rx_queue_0_crc_errors",
1528 "rx_queue_0_frame_errors",
1529 "rx_queue_0_length_errors",
1530 "rx_queue_0_missed_errors",
1531 "rx_queue_0_over_errors",
1533 "rx_queue_1_current",
1534 "tx_queue_1_current",
1537 "rx_queue_1_packets",
1538 "tx_queue_1_packets",
1541 "rx_queue_1_mcast_packets",
1542 "rx_queue_1_errors",
1543 "rx_queue_1_crc_errors",
1544 "rx_queue_1_frame_errors",
1545 "rx_queue_1_length_errors",
1546 "rx_queue_1_missed_errors",
1547 "rx_queue_1_over_errors",
1550 static int ravb_get_sset_count(struct net_device *netdev, int sset)
1552 struct ravb_private *priv = netdev_priv(netdev);
1553 const struct ravb_hw_info *info = priv->info;
1557 return info->stats_len;
1563 static void ravb_get_ethtool_stats(struct net_device *ndev,
1564 struct ethtool_stats *estats, u64 *data)
1566 struct ravb_private *priv = netdev_priv(ndev);
1567 const struct ravb_hw_info *info = priv->info;
1572 num_rx_q = info->nc_queues ? NUM_RX_QUEUE : 1;
1573 /* Device-specific stats */
1574 for (q = RAVB_BE; q < num_rx_q; q++) {
1575 struct net_device_stats *stats = &priv->stats[q];
1577 data[i++] = priv->cur_rx[q];
1578 data[i++] = priv->cur_tx[q];
1579 data[i++] = priv->dirty_rx[q];
1580 data[i++] = priv->dirty_tx[q];
1581 data[i++] = stats->rx_packets;
1582 data[i++] = stats->tx_packets;
1583 data[i++] = stats->rx_bytes;
1584 data[i++] = stats->tx_bytes;
1585 data[i++] = stats->multicast;
1586 data[i++] = stats->rx_errors;
1587 data[i++] = stats->rx_crc_errors;
1588 data[i++] = stats->rx_frame_errors;
1589 data[i++] = stats->rx_length_errors;
1590 data[i++] = stats->rx_missed_errors;
1591 data[i++] = stats->rx_over_errors;
1595 static void ravb_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
1597 struct ravb_private *priv = netdev_priv(ndev);
1598 const struct ravb_hw_info *info = priv->info;
1600 switch (stringset) {
1602 memcpy(data, info->gstrings_stats, info->gstrings_size);
1607 static void ravb_get_ringparam(struct net_device *ndev,
1608 struct ethtool_ringparam *ring)
1610 struct ravb_private *priv = netdev_priv(ndev);
1612 ring->rx_max_pending = BE_RX_RING_MAX;
1613 ring->tx_max_pending = BE_TX_RING_MAX;
1614 ring->rx_pending = priv->num_rx_ring[RAVB_BE];
1615 ring->tx_pending = priv->num_tx_ring[RAVB_BE];
1618 static int ravb_set_ringparam(struct net_device *ndev,
1619 struct ethtool_ringparam *ring)
1621 struct ravb_private *priv = netdev_priv(ndev);
1622 const struct ravb_hw_info *info = priv->info;
1625 if (ring->tx_pending > BE_TX_RING_MAX ||
1626 ring->rx_pending > BE_RX_RING_MAX ||
1627 ring->tx_pending < BE_TX_RING_MIN ||
1628 ring->rx_pending < BE_RX_RING_MIN)
1630 if (ring->rx_mini_pending || ring->rx_jumbo_pending)
1633 if (netif_running(ndev)) {
1634 netif_device_detach(ndev);
1635 /* Stop PTP Clock driver */
1637 ravb_ptp_stop(ndev);
1638 /* Wait for DMA stopping */
1639 error = ravb_stop_dma(ndev);
1642 "cannot set ringparam! Any AVB processes are still running?\n");
1645 synchronize_irq(ndev->irq);
1647 /* Free all the skb's in the RX queue and the DMA buffers. */
1648 ravb_ring_free(ndev, RAVB_BE);
1649 if (info->nc_queues)
1650 ravb_ring_free(ndev, RAVB_NC);
1653 /* Set new parameters */
1654 priv->num_rx_ring[RAVB_BE] = ring->rx_pending;
1655 priv->num_tx_ring[RAVB_BE] = ring->tx_pending;
1657 if (netif_running(ndev)) {
1658 error = ravb_dmac_init(ndev);
1661 "%s: ravb_dmac_init() failed, error %d\n",
1666 ravb_emac_init(ndev);
1668 /* Initialise PTP Clock driver */
1670 ravb_ptp_init(ndev, priv->pdev);
1672 netif_device_attach(ndev);
1678 static int ravb_get_ts_info(struct net_device *ndev,
1679 struct ethtool_ts_info *info)
1681 struct ravb_private *priv = netdev_priv(ndev);
1682 const struct ravb_hw_info *hw_info = priv->info;
1684 info->so_timestamping =
1685 SOF_TIMESTAMPING_TX_SOFTWARE |
1686 SOF_TIMESTAMPING_RX_SOFTWARE |
1687 SOF_TIMESTAMPING_SOFTWARE |
1688 SOF_TIMESTAMPING_TX_HARDWARE |
1689 SOF_TIMESTAMPING_RX_HARDWARE |
1690 SOF_TIMESTAMPING_RAW_HARDWARE;
1691 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
1693 (1 << HWTSTAMP_FILTER_NONE) |
1694 (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1695 (1 << HWTSTAMP_FILTER_ALL);
1696 if (hw_info->gptp || hw_info->ccc_gac)
1697 info->phc_index = ptp_clock_index(priv->ptp.clock);
1702 static void ravb_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
1704 struct ravb_private *priv = netdev_priv(ndev);
1706 wol->supported = WAKE_MAGIC;
1707 wol->wolopts = priv->wol_enabled ? WAKE_MAGIC : 0;
1710 static int ravb_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
1712 struct ravb_private *priv = netdev_priv(ndev);
1713 const struct ravb_hw_info *info = priv->info;
1715 if (!info->magic_pkt || (wol->wolopts & ~WAKE_MAGIC))
1718 priv->wol_enabled = !!(wol->wolopts & WAKE_MAGIC);
1720 device_set_wakeup_enable(&priv->pdev->dev, priv->wol_enabled);
1725 static const struct ethtool_ops ravb_ethtool_ops = {
1726 .nway_reset = phy_ethtool_nway_reset,
1727 .get_msglevel = ravb_get_msglevel,
1728 .set_msglevel = ravb_set_msglevel,
1729 .get_link = ethtool_op_get_link,
1730 .get_strings = ravb_get_strings,
1731 .get_ethtool_stats = ravb_get_ethtool_stats,
1732 .get_sset_count = ravb_get_sset_count,
1733 .get_ringparam = ravb_get_ringparam,
1734 .set_ringparam = ravb_set_ringparam,
1735 .get_ts_info = ravb_get_ts_info,
1736 .get_link_ksettings = phy_ethtool_get_link_ksettings,
1737 .set_link_ksettings = phy_ethtool_set_link_ksettings,
1738 .get_wol = ravb_get_wol,
1739 .set_wol = ravb_set_wol,
1742 static inline int ravb_hook_irq(unsigned int irq, irq_handler_t handler,
1743 struct net_device *ndev, struct device *dev,
1749 name = devm_kasprintf(dev, GFP_KERNEL, "%s:%s", ndev->name, ch);
1752 error = request_irq(irq, handler, 0, name, ndev);
1754 netdev_err(ndev, "cannot request IRQ %s\n", name);
1759 /* Network device open function for Ethernet AVB */
1760 static int ravb_open(struct net_device *ndev)
1762 struct ravb_private *priv = netdev_priv(ndev);
1763 const struct ravb_hw_info *info = priv->info;
1764 struct platform_device *pdev = priv->pdev;
1765 struct device *dev = &pdev->dev;
1768 napi_enable(&priv->napi[RAVB_BE]);
1769 if (info->nc_queues)
1770 napi_enable(&priv->napi[RAVB_NC]);
1772 if (!info->multi_irqs) {
1773 error = request_irq(ndev->irq, ravb_interrupt, IRQF_SHARED,
1776 netdev_err(ndev, "cannot request IRQ\n");
1780 error = ravb_hook_irq(ndev->irq, ravb_multi_interrupt, ndev,
1784 error = ravb_hook_irq(priv->emac_irq, ravb_emac_interrupt, ndev,
1788 error = ravb_hook_irq(priv->rx_irqs[RAVB_BE], ravb_be_interrupt,
1789 ndev, dev, "ch0:rx_be");
1791 goto out_free_irq_emac;
1792 error = ravb_hook_irq(priv->tx_irqs[RAVB_BE], ravb_be_interrupt,
1793 ndev, dev, "ch18:tx_be");
1795 goto out_free_irq_be_rx;
1796 error = ravb_hook_irq(priv->rx_irqs[RAVB_NC], ravb_nc_interrupt,
1797 ndev, dev, "ch1:rx_nc");
1799 goto out_free_irq_be_tx;
1800 error = ravb_hook_irq(priv->tx_irqs[RAVB_NC], ravb_nc_interrupt,
1801 ndev, dev, "ch19:tx_nc");
1803 goto out_free_irq_nc_rx;
1807 error = ravb_dmac_init(ndev);
1809 goto out_free_irq_nc_tx;
1810 ravb_emac_init(ndev);
1812 /* Initialise PTP Clock driver */
1814 ravb_ptp_init(ndev, priv->pdev);
1816 netif_tx_start_all_queues(ndev);
1818 /* PHY control start */
1819 error = ravb_phy_start(ndev);
1826 /* Stop PTP Clock driver */
1828 ravb_ptp_stop(ndev);
1830 if (!info->multi_irqs)
1832 free_irq(priv->tx_irqs[RAVB_NC], ndev);
1834 free_irq(priv->rx_irqs[RAVB_NC], ndev);
1836 free_irq(priv->tx_irqs[RAVB_BE], ndev);
1838 free_irq(priv->rx_irqs[RAVB_BE], ndev);
1840 free_irq(priv->emac_irq, ndev);
1842 free_irq(ndev->irq, ndev);
1844 if (info->nc_queues)
1845 napi_disable(&priv->napi[RAVB_NC]);
1846 napi_disable(&priv->napi[RAVB_BE]);
1850 /* Timeout function for Ethernet AVB */
1851 static void ravb_tx_timeout(struct net_device *ndev, unsigned int txqueue)
1853 struct ravb_private *priv = netdev_priv(ndev);
1855 netif_err(priv, tx_err, ndev,
1856 "transmit timed out, status %08x, resetting...\n",
1857 ravb_read(ndev, ISS));
1859 /* tx_errors count up */
1860 ndev->stats.tx_errors++;
1862 schedule_work(&priv->work);
1865 static void ravb_tx_timeout_work(struct work_struct *work)
1867 struct ravb_private *priv = container_of(work, struct ravb_private,
1869 const struct ravb_hw_info *info = priv->info;
1870 struct net_device *ndev = priv->ndev;
1873 netif_tx_stop_all_queues(ndev);
1875 /* Stop PTP Clock driver */
1877 ravb_ptp_stop(ndev);
1879 /* Wait for DMA stopping */
1880 if (ravb_stop_dma(ndev)) {
1881 /* If ravb_stop_dma() fails, the hardware is still operating
1882 * for TX and/or RX. So, this should not call the following
1883 * functions because ravb_dmac_init() is possible to fail too.
1884 * Also, this should not retry ravb_stop_dma() again and again
1885 * here because it's possible to wait forever. So, this just
1886 * re-enables the TX and RX and skip the following
1887 * re-initialization procedure.
1889 ravb_rcv_snd_enable(ndev);
1893 ravb_ring_free(ndev, RAVB_BE);
1894 if (info->nc_queues)
1895 ravb_ring_free(ndev, RAVB_NC);
1898 error = ravb_dmac_init(ndev);
1900 /* If ravb_dmac_init() fails, descriptors are freed. So, this
1901 * should return here to avoid re-enabling the TX and RX in
1904 netdev_err(ndev, "%s: ravb_dmac_init() failed, error %d\n",
1908 ravb_emac_init(ndev);
1911 /* Initialise PTP Clock driver */
1913 ravb_ptp_init(ndev, priv->pdev);
1915 netif_tx_start_all_queues(ndev);
1918 /* Packet transmit function for Ethernet AVB */
1919 static netdev_tx_t ravb_start_xmit(struct sk_buff *skb, struct net_device *ndev)
1921 struct ravb_private *priv = netdev_priv(ndev);
1922 const struct ravb_hw_info *info = priv->info;
1923 unsigned int num_tx_desc = priv->num_tx_desc;
1924 u16 q = skb_get_queue_mapping(skb);
1925 struct ravb_tstamp_skb *ts_skb;
1926 struct ravb_tx_desc *desc;
1927 unsigned long flags;
1933 spin_lock_irqsave(&priv->lock, flags);
1934 if (priv->cur_tx[q] - priv->dirty_tx[q] > (priv->num_tx_ring[q] - 1) *
1936 netif_err(priv, tx_queued, ndev,
1937 "still transmitting with the full ring!\n");
1938 netif_stop_subqueue(ndev, q);
1939 spin_unlock_irqrestore(&priv->lock, flags);
1940 return NETDEV_TX_BUSY;
1943 if (skb_put_padto(skb, ETH_ZLEN))
1946 entry = priv->cur_tx[q] % (priv->num_tx_ring[q] * num_tx_desc);
1947 priv->tx_skb[q][entry / num_tx_desc] = skb;
1949 if (num_tx_desc > 1) {
1950 buffer = PTR_ALIGN(priv->tx_align[q], DPTR_ALIGN) +
1951 entry / num_tx_desc * DPTR_ALIGN;
1952 len = PTR_ALIGN(skb->data, DPTR_ALIGN) - skb->data;
1954 /* Zero length DMA descriptors are problematic as they seem
1955 * to terminate DMA transfers. Avoid them by simply using a
1956 * length of DPTR_ALIGN (4) when skb data is aligned to
1959 * As skb is guaranteed to have at least ETH_ZLEN (60)
1960 * bytes of data by the call to skb_put_padto() above this
1961 * is safe with respect to both the length of the first DMA
1962 * descriptor (len) overflowing the available data and the
1963 * length of the second DMA descriptor (skb->len - len)
1969 memcpy(buffer, skb->data, len);
1970 dma_addr = dma_map_single(ndev->dev.parent, buffer, len,
1972 if (dma_mapping_error(ndev->dev.parent, dma_addr))
1975 desc = &priv->tx_ring[q][entry];
1976 desc->ds_tagl = cpu_to_le16(len);
1977 desc->dptr = cpu_to_le32(dma_addr);
1979 buffer = skb->data + len;
1980 len = skb->len - len;
1981 dma_addr = dma_map_single(ndev->dev.parent, buffer, len,
1983 if (dma_mapping_error(ndev->dev.parent, dma_addr))
1988 desc = &priv->tx_ring[q][entry];
1990 dma_addr = dma_map_single(ndev->dev.parent, skb->data, skb->len,
1992 if (dma_mapping_error(ndev->dev.parent, dma_addr))
1995 desc->ds_tagl = cpu_to_le16(len);
1996 desc->dptr = cpu_to_le32(dma_addr);
1998 /* TX timestamp required */
1999 if (info->gptp || info->ccc_gac) {
2001 ts_skb = kmalloc(sizeof(*ts_skb), GFP_ATOMIC);
2003 if (num_tx_desc > 1) {
2005 dma_unmap_single(ndev->dev.parent, dma_addr,
2006 len, DMA_TO_DEVICE);
2010 ts_skb->skb = skb_get(skb);
2011 ts_skb->tag = priv->ts_skb_tag++;
2012 priv->ts_skb_tag &= 0x3ff;
2013 list_add_tail(&ts_skb->list, &priv->ts_skb_list);
2015 /* TAG and timestamp required flag */
2016 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
2017 desc->tagh_tsr = (ts_skb->tag >> 4) | TX_TSR;
2018 desc->ds_tagl |= cpu_to_le16(ts_skb->tag << 12);
2021 skb_tx_timestamp(skb);
2023 /* Descriptor type must be set after all the above writes */
2025 if (num_tx_desc > 1) {
2026 desc->die_dt = DT_FEND;
2028 desc->die_dt = DT_FSTART;
2030 desc->die_dt = DT_FSINGLE;
2032 ravb_modify(ndev, TCCR, TCCR_TSRQ0 << q, TCCR_TSRQ0 << q);
2034 priv->cur_tx[q] += num_tx_desc;
2035 if (priv->cur_tx[q] - priv->dirty_tx[q] >
2036 (priv->num_tx_ring[q] - 1) * num_tx_desc &&
2037 !ravb_tx_free(ndev, q, true))
2038 netif_stop_subqueue(ndev, q);
2041 spin_unlock_irqrestore(&priv->lock, flags);
2042 return NETDEV_TX_OK;
2045 dma_unmap_single(ndev->dev.parent, le32_to_cpu(desc->dptr),
2046 le16_to_cpu(desc->ds_tagl), DMA_TO_DEVICE);
2048 dev_kfree_skb_any(skb);
2049 priv->tx_skb[q][entry / num_tx_desc] = NULL;
2053 static u16 ravb_select_queue(struct net_device *ndev, struct sk_buff *skb,
2054 struct net_device *sb_dev)
2056 /* If skb needs TX timestamp, it is handled in network control queue */
2057 return (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) ? RAVB_NC :
2062 static struct net_device_stats *ravb_get_stats(struct net_device *ndev)
2064 struct ravb_private *priv = netdev_priv(ndev);
2065 const struct ravb_hw_info *info = priv->info;
2066 struct net_device_stats *nstats, *stats0, *stats1;
2068 nstats = &ndev->stats;
2069 stats0 = &priv->stats[RAVB_BE];
2071 if (info->tx_counters) {
2072 nstats->tx_dropped += ravb_read(ndev, TROCR);
2073 ravb_write(ndev, 0, TROCR); /* (write clear) */
2076 if (info->carrier_counters) {
2077 nstats->collisions += ravb_read(ndev, CXR41);
2078 ravb_write(ndev, 0, CXR41); /* (write clear) */
2079 nstats->tx_carrier_errors += ravb_read(ndev, CXR42);
2080 ravb_write(ndev, 0, CXR42); /* (write clear) */
2083 nstats->rx_packets = stats0->rx_packets;
2084 nstats->tx_packets = stats0->tx_packets;
2085 nstats->rx_bytes = stats0->rx_bytes;
2086 nstats->tx_bytes = stats0->tx_bytes;
2087 nstats->multicast = stats0->multicast;
2088 nstats->rx_errors = stats0->rx_errors;
2089 nstats->rx_crc_errors = stats0->rx_crc_errors;
2090 nstats->rx_frame_errors = stats0->rx_frame_errors;
2091 nstats->rx_length_errors = stats0->rx_length_errors;
2092 nstats->rx_missed_errors = stats0->rx_missed_errors;
2093 nstats->rx_over_errors = stats0->rx_over_errors;
2094 if (info->nc_queues) {
2095 stats1 = &priv->stats[RAVB_NC];
2097 nstats->rx_packets += stats1->rx_packets;
2098 nstats->tx_packets += stats1->tx_packets;
2099 nstats->rx_bytes += stats1->rx_bytes;
2100 nstats->tx_bytes += stats1->tx_bytes;
2101 nstats->multicast += stats1->multicast;
2102 nstats->rx_errors += stats1->rx_errors;
2103 nstats->rx_crc_errors += stats1->rx_crc_errors;
2104 nstats->rx_frame_errors += stats1->rx_frame_errors;
2105 nstats->rx_length_errors += stats1->rx_length_errors;
2106 nstats->rx_missed_errors += stats1->rx_missed_errors;
2107 nstats->rx_over_errors += stats1->rx_over_errors;
2113 /* Update promiscuous bit */
2114 static void ravb_set_rx_mode(struct net_device *ndev)
2116 struct ravb_private *priv = netdev_priv(ndev);
2117 unsigned long flags;
2119 spin_lock_irqsave(&priv->lock, flags);
2120 ravb_modify(ndev, ECMR, ECMR_PRM,
2121 ndev->flags & IFF_PROMISC ? ECMR_PRM : 0);
2122 spin_unlock_irqrestore(&priv->lock, flags);
2125 /* Device close function for Ethernet AVB */
2126 static int ravb_close(struct net_device *ndev)
2128 struct device_node *np = ndev->dev.parent->of_node;
2129 struct ravb_private *priv = netdev_priv(ndev);
2130 const struct ravb_hw_info *info = priv->info;
2131 struct ravb_tstamp_skb *ts_skb, *ts_skb2;
2133 netif_tx_stop_all_queues(ndev);
2135 /* Disable interrupts by clearing the interrupt masks. */
2136 ravb_write(ndev, 0, RIC0);
2137 ravb_write(ndev, 0, RIC2);
2138 ravb_write(ndev, 0, TIC);
2140 /* Stop PTP Clock driver */
2142 ravb_ptp_stop(ndev);
2144 /* Set the config mode to stop the AVB-DMAC's processes */
2145 if (ravb_stop_dma(ndev) < 0)
2147 "device will be stopped after h/w processes are done.\n");
2149 /* Clear the timestamp list */
2150 if (info->gptp || info->ccc_gac) {
2151 list_for_each_entry_safe(ts_skb, ts_skb2, &priv->ts_skb_list, list) {
2152 list_del(&ts_skb->list);
2153 kfree_skb(ts_skb->skb);
2158 /* PHY disconnect */
2160 phy_stop(ndev->phydev);
2161 phy_disconnect(ndev->phydev);
2162 if (of_phy_is_fixed_link(np))
2163 of_phy_deregister_fixed_link(np);
2166 if (info->multi_irqs) {
2167 free_irq(priv->tx_irqs[RAVB_NC], ndev);
2168 free_irq(priv->rx_irqs[RAVB_NC], ndev);
2169 free_irq(priv->tx_irqs[RAVB_BE], ndev);
2170 free_irq(priv->rx_irqs[RAVB_BE], ndev);
2171 free_irq(priv->emac_irq, ndev);
2173 free_irq(ndev->irq, ndev);
2175 if (info->nc_queues)
2176 napi_disable(&priv->napi[RAVB_NC]);
2177 napi_disable(&priv->napi[RAVB_BE]);
2179 /* Free all the skb's in the RX queue and the DMA buffers. */
2180 ravb_ring_free(ndev, RAVB_BE);
2181 if (info->nc_queues)
2182 ravb_ring_free(ndev, RAVB_NC);
2187 static int ravb_hwtstamp_get(struct net_device *ndev, struct ifreq *req)
2189 struct ravb_private *priv = netdev_priv(ndev);
2190 struct hwtstamp_config config;
2193 config.tx_type = priv->tstamp_tx_ctrl ? HWTSTAMP_TX_ON :
2195 switch (priv->tstamp_rx_ctrl & RAVB_RXTSTAMP_TYPE) {
2196 case RAVB_RXTSTAMP_TYPE_V2_L2_EVENT:
2197 config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT;
2199 case RAVB_RXTSTAMP_TYPE_ALL:
2200 config.rx_filter = HWTSTAMP_FILTER_ALL;
2203 config.rx_filter = HWTSTAMP_FILTER_NONE;
2206 return copy_to_user(req->ifr_data, &config, sizeof(config)) ?
2210 /* Control hardware time stamping */
2211 static int ravb_hwtstamp_set(struct net_device *ndev, struct ifreq *req)
2213 struct ravb_private *priv = netdev_priv(ndev);
2214 struct hwtstamp_config config;
2215 u32 tstamp_rx_ctrl = RAVB_RXTSTAMP_ENABLED;
2218 if (copy_from_user(&config, req->ifr_data, sizeof(config)))
2221 /* Reserved for future extensions */
2225 switch (config.tx_type) {
2226 case HWTSTAMP_TX_OFF:
2229 case HWTSTAMP_TX_ON:
2230 tstamp_tx_ctrl = RAVB_TXTSTAMP_ENABLED;
2236 switch (config.rx_filter) {
2237 case HWTSTAMP_FILTER_NONE:
2240 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
2241 tstamp_rx_ctrl |= RAVB_RXTSTAMP_TYPE_V2_L2_EVENT;
2244 config.rx_filter = HWTSTAMP_FILTER_ALL;
2245 tstamp_rx_ctrl |= RAVB_RXTSTAMP_TYPE_ALL;
2248 priv->tstamp_tx_ctrl = tstamp_tx_ctrl;
2249 priv->tstamp_rx_ctrl = tstamp_rx_ctrl;
2251 return copy_to_user(req->ifr_data, &config, sizeof(config)) ?
2255 /* ioctl to device function */
2256 static int ravb_do_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
2258 struct phy_device *phydev = ndev->phydev;
2260 if (!netif_running(ndev))
2268 return ravb_hwtstamp_get(ndev, req);
2270 return ravb_hwtstamp_set(ndev, req);
2273 return phy_mii_ioctl(phydev, req, cmd);
2276 static int ravb_change_mtu(struct net_device *ndev, int new_mtu)
2278 struct ravb_private *priv = netdev_priv(ndev);
2280 ndev->mtu = new_mtu;
2282 if (netif_running(ndev)) {
2283 synchronize_irq(priv->emac_irq);
2284 ravb_emac_init(ndev);
2287 netdev_update_features(ndev);
2292 static void ravb_set_rx_csum(struct net_device *ndev, bool enable)
2294 struct ravb_private *priv = netdev_priv(ndev);
2295 unsigned long flags;
2297 spin_lock_irqsave(&priv->lock, flags);
2299 /* Disable TX and RX */
2300 ravb_rcv_snd_disable(ndev);
2302 /* Modify RX Checksum setting */
2303 ravb_modify(ndev, ECMR, ECMR_RCSC, enable ? ECMR_RCSC : 0);
2305 /* Enable TX and RX */
2306 ravb_rcv_snd_enable(ndev);
2308 spin_unlock_irqrestore(&priv->lock, flags);
2311 static int ravb_set_features_gbeth(struct net_device *ndev,
2312 netdev_features_t features)
2318 static int ravb_set_features_rcar(struct net_device *ndev,
2319 netdev_features_t features)
2321 netdev_features_t changed = ndev->features ^ features;
2323 if (changed & NETIF_F_RXCSUM)
2324 ravb_set_rx_csum(ndev, features & NETIF_F_RXCSUM);
2326 ndev->features = features;
2331 static int ravb_set_features(struct net_device *ndev,
2332 netdev_features_t features)
2334 struct ravb_private *priv = netdev_priv(ndev);
2335 const struct ravb_hw_info *info = priv->info;
2337 return info->set_feature(ndev, features);
2340 static const struct net_device_ops ravb_netdev_ops = {
2341 .ndo_open = ravb_open,
2342 .ndo_stop = ravb_close,
2343 .ndo_start_xmit = ravb_start_xmit,
2344 .ndo_select_queue = ravb_select_queue,
2345 .ndo_get_stats = ravb_get_stats,
2346 .ndo_set_rx_mode = ravb_set_rx_mode,
2347 .ndo_tx_timeout = ravb_tx_timeout,
2348 .ndo_eth_ioctl = ravb_do_ioctl,
2349 .ndo_change_mtu = ravb_change_mtu,
2350 .ndo_validate_addr = eth_validate_addr,
2351 .ndo_set_mac_address = eth_mac_addr,
2352 .ndo_set_features = ravb_set_features,
2355 /* MDIO bus init function */
2356 static int ravb_mdio_init(struct ravb_private *priv)
2358 struct platform_device *pdev = priv->pdev;
2359 struct device *dev = &pdev->dev;
2363 priv->mdiobb.ops = &bb_ops;
2365 /* MII controller setting */
2366 priv->mii_bus = alloc_mdio_bitbang(&priv->mdiobb);
2370 /* Hook up MII support for ethtool */
2371 priv->mii_bus->name = "ravb_mii";
2372 priv->mii_bus->parent = dev;
2373 snprintf(priv->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
2374 pdev->name, pdev->id);
2376 /* Register MDIO bus */
2377 error = of_mdiobus_register(priv->mii_bus, dev->of_node);
2384 free_mdio_bitbang(priv->mii_bus);
2388 /* MDIO bus release function */
2389 static int ravb_mdio_release(struct ravb_private *priv)
2391 /* Unregister mdio bus */
2392 mdiobus_unregister(priv->mii_bus);
2394 /* Free bitbang info */
2395 free_mdio_bitbang(priv->mii_bus);
2400 static const struct ravb_hw_info ravb_gen3_hw_info = {
2401 .rx_ring_free = ravb_rx_ring_free_rcar,
2402 .rx_ring_format = ravb_rx_ring_format_rcar,
2403 .alloc_rx_desc = ravb_alloc_rx_desc_rcar,
2404 .receive = ravb_rx_rcar,
2405 .set_rate = ravb_set_rate_rcar,
2406 .set_feature = ravb_set_features_rcar,
2407 .dmac_init = ravb_dmac_init_rcar,
2408 .emac_init = ravb_emac_init_rcar,
2409 .gstrings_stats = ravb_gstrings_stats,
2410 .gstrings_size = sizeof(ravb_gstrings_stats),
2411 .net_hw_features = NETIF_F_RXCSUM,
2412 .net_features = NETIF_F_RXCSUM,
2413 .stats_len = ARRAY_SIZE(ravb_gstrings_stats),
2414 .max_rx_len = RX_BUF_SZ + RAVB_ALIGN - 1,
2415 .tccr_mask = TCCR_TSRQ0 | TCCR_TSRQ1 | TCCR_TSRQ2 | TCCR_TSRQ3,
2416 .rx_max_buf_size = SZ_2K,
2417 .internal_delay = 1,
2425 static const struct ravb_hw_info ravb_gen2_hw_info = {
2426 .rx_ring_free = ravb_rx_ring_free_rcar,
2427 .rx_ring_format = ravb_rx_ring_format_rcar,
2428 .alloc_rx_desc = ravb_alloc_rx_desc_rcar,
2429 .receive = ravb_rx_rcar,
2430 .set_rate = ravb_set_rate_rcar,
2431 .set_feature = ravb_set_features_rcar,
2432 .dmac_init = ravb_dmac_init_rcar,
2433 .emac_init = ravb_emac_init_rcar,
2434 .gstrings_stats = ravb_gstrings_stats,
2435 .gstrings_size = sizeof(ravb_gstrings_stats),
2436 .net_hw_features = NETIF_F_RXCSUM,
2437 .net_features = NETIF_F_RXCSUM,
2438 .stats_len = ARRAY_SIZE(ravb_gstrings_stats),
2439 .max_rx_len = RX_BUF_SZ + RAVB_ALIGN - 1,
2440 .tccr_mask = TCCR_TSRQ0 | TCCR_TSRQ1 | TCCR_TSRQ2 | TCCR_TSRQ3,
2441 .rx_max_buf_size = SZ_2K,
2448 static const struct ravb_hw_info gbeth_hw_info = {
2449 .rx_ring_free = ravb_rx_ring_free_gbeth,
2450 .rx_ring_format = ravb_rx_ring_format_gbeth,
2451 .alloc_rx_desc = ravb_alloc_rx_desc_gbeth,
2452 .receive = ravb_rx_gbeth,
2453 .set_rate = ravb_set_rate_gbeth,
2454 .set_feature = ravb_set_features_gbeth,
2455 .dmac_init = ravb_dmac_init_gbeth,
2456 .emac_init = ravb_emac_init_gbeth,
2457 .gstrings_stats = ravb_gstrings_stats_gbeth,
2458 .gstrings_size = sizeof(ravb_gstrings_stats_gbeth),
2459 .stats_len = ARRAY_SIZE(ravb_gstrings_stats_gbeth),
2460 .max_rx_len = ALIGN(GBETH_RX_BUFF_MAX, RAVB_ALIGN),
2461 .tccr_mask = TCCR_TSRQ0,
2462 .rx_max_buf_size = SZ_8K,
2465 .carrier_counters = 1,
2469 static const struct of_device_id ravb_match_table[] = {
2470 { .compatible = "renesas,etheravb-r8a7790", .data = &ravb_gen2_hw_info },
2471 { .compatible = "renesas,etheravb-r8a7794", .data = &ravb_gen2_hw_info },
2472 { .compatible = "renesas,etheravb-rcar-gen2", .data = &ravb_gen2_hw_info },
2473 { .compatible = "renesas,etheravb-r8a7795", .data = &ravb_gen3_hw_info },
2474 { .compatible = "renesas,etheravb-rcar-gen3", .data = &ravb_gen3_hw_info },
2475 { .compatible = "renesas,rzg2l-gbeth", .data = &gbeth_hw_info },
2478 MODULE_DEVICE_TABLE(of, ravb_match_table);
2480 static int ravb_set_gti(struct net_device *ndev)
2482 struct ravb_private *priv = netdev_priv(ndev);
2483 struct device *dev = ndev->dev.parent;
2487 rate = clk_get_rate(priv->clk);
2491 inc = 1000000000ULL << 20;
2494 if (inc < GTI_TIV_MIN || inc > GTI_TIV_MAX) {
2495 dev_err(dev, "gti.tiv increment 0x%llx is outside the range 0x%x - 0x%x\n",
2496 inc, GTI_TIV_MIN, GTI_TIV_MAX);
2500 ravb_write(ndev, inc, GTI);
2505 static void ravb_set_config_mode(struct net_device *ndev)
2507 struct ravb_private *priv = netdev_priv(ndev);
2508 const struct ravb_hw_info *info = priv->info;
2511 ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_CONFIG);
2512 /* Set CSEL value */
2513 ravb_modify(ndev, CCC, CCC_CSEL, CCC_CSEL_HPB);
2514 } else if (info->ccc_gac) {
2515 ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_CONFIG |
2516 CCC_GAC | CCC_CSEL_HPB);
2518 ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_CONFIG);
2522 /* Set tx and rx clock internal delay modes */
2523 static void ravb_parse_delay_mode(struct device_node *np, struct net_device *ndev)
2525 struct ravb_private *priv = netdev_priv(ndev);
2526 bool explicit_delay = false;
2529 if (!of_property_read_u32(np, "rx-internal-delay-ps", &delay)) {
2530 /* Valid values are 0 and 1800, according to DT bindings */
2531 priv->rxcidm = !!delay;
2532 explicit_delay = true;
2534 if (!of_property_read_u32(np, "tx-internal-delay-ps", &delay)) {
2535 /* Valid values are 0 and 2000, according to DT bindings */
2536 priv->txcidm = !!delay;
2537 explicit_delay = true;
2543 /* Fall back to legacy rgmii-*id behavior */
2544 if (priv->phy_interface == PHY_INTERFACE_MODE_RGMII_ID ||
2545 priv->phy_interface == PHY_INTERFACE_MODE_RGMII_RXID) {
2547 priv->rgmii_override = 1;
2550 if (priv->phy_interface == PHY_INTERFACE_MODE_RGMII_ID ||
2551 priv->phy_interface == PHY_INTERFACE_MODE_RGMII_TXID) {
2553 priv->rgmii_override = 1;
2557 static void ravb_set_delay_mode(struct net_device *ndev)
2559 struct ravb_private *priv = netdev_priv(ndev);
2566 ravb_modify(ndev, APSR, APSR_RDM | APSR_TDM, set);
2569 static int ravb_probe(struct platform_device *pdev)
2571 struct device_node *np = pdev->dev.of_node;
2572 const struct ravb_hw_info *info;
2573 struct reset_control *rstc;
2574 struct ravb_private *priv;
2575 struct net_device *ndev;
2577 struct resource *res;
2582 "this driver is required to be instantiated from device tree\n");
2586 rstc = devm_reset_control_get_optional_exclusive(&pdev->dev, NULL);
2588 return dev_err_probe(&pdev->dev, PTR_ERR(rstc),
2589 "failed to get cpg reset\n");
2591 ndev = alloc_etherdev_mqs(sizeof(struct ravb_private),
2592 NUM_TX_QUEUE, NUM_RX_QUEUE);
2596 info = of_device_get_match_data(&pdev->dev);
2598 ndev->features = info->net_features;
2599 ndev->hw_features = info->net_hw_features;
2601 reset_control_deassert(rstc);
2602 pm_runtime_enable(&pdev->dev);
2603 pm_runtime_get_sync(&pdev->dev);
2605 if (info->multi_irqs)
2606 irq = platform_get_irq_byname(pdev, "ch22");
2608 irq = platform_get_irq(pdev, 0);
2615 SET_NETDEV_DEV(ndev, &pdev->dev);
2617 priv = netdev_priv(ndev);
2622 priv->num_tx_ring[RAVB_BE] = BE_TX_RING_SIZE;
2623 priv->num_rx_ring[RAVB_BE] = BE_RX_RING_SIZE;
2624 if (info->nc_queues) {
2625 priv->num_tx_ring[RAVB_NC] = NC_TX_RING_SIZE;
2626 priv->num_rx_ring[RAVB_NC] = NC_RX_RING_SIZE;
2629 priv->addr = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
2630 if (IS_ERR(priv->addr)) {
2631 error = PTR_ERR(priv->addr);
2635 /* The Ether-specific entries in the device structure. */
2636 ndev->base_addr = res->start;
2638 spin_lock_init(&priv->lock);
2639 INIT_WORK(&priv->work, ravb_tx_timeout_work);
2641 error = of_get_phy_mode(np, &priv->phy_interface);
2642 if (error && error != -ENODEV)
2645 priv->no_avb_link = of_property_read_bool(np, "renesas,no-ether-link");
2646 priv->avb_link_active_low =
2647 of_property_read_bool(np, "renesas,ether-link-active-low");
2649 if (info->multi_irqs) {
2650 irq = platform_get_irq_byname(pdev, "ch24");
2655 priv->emac_irq = irq;
2656 for (i = 0; i < NUM_RX_QUEUE; i++) {
2657 irq = platform_get_irq_byname(pdev, ravb_rx_irqs[i]);
2662 priv->rx_irqs[i] = irq;
2664 for (i = 0; i < NUM_TX_QUEUE; i++) {
2665 irq = platform_get_irq_byname(pdev, ravb_tx_irqs[i]);
2670 priv->tx_irqs[i] = irq;
2674 priv->clk = devm_clk_get(&pdev->dev, NULL);
2675 if (IS_ERR(priv->clk)) {
2676 error = PTR_ERR(priv->clk);
2680 priv->refclk = devm_clk_get_optional(&pdev->dev, "refclk");
2681 if (IS_ERR(priv->refclk)) {
2682 error = PTR_ERR(priv->refclk);
2685 clk_prepare_enable(priv->refclk);
2687 ndev->max_mtu = info->rx_max_buf_size - (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN);
2688 ndev->min_mtu = ETH_MIN_MTU;
2690 /* FIXME: R-Car Gen2 has 4byte alignment restriction for tx buffer
2691 * Use two descriptor to handle such situation. First descriptor to
2692 * handle aligned data buffer and second descriptor to handle the
2693 * overflow data because of alignment.
2695 priv->num_tx_desc = info->aligned_tx ? 2 : 1;
2698 ndev->netdev_ops = &ravb_netdev_ops;
2699 ndev->ethtool_ops = &ravb_ethtool_ops;
2701 /* Set AVB config mode */
2702 ravb_set_config_mode(ndev);
2704 if (info->gptp || info->ccc_gac) {
2706 error = ravb_set_gti(ndev);
2708 goto out_disable_refclk;
2710 /* Request GTI loading */
2711 ravb_modify(ndev, GCCR, GCCR_LTI, GCCR_LTI);
2714 if (info->internal_delay) {
2715 ravb_parse_delay_mode(np, ndev);
2716 ravb_set_delay_mode(ndev);
2719 /* Allocate descriptor base address table */
2720 priv->desc_bat_size = sizeof(struct ravb_desc) * DBAT_ENTRY_NUM;
2721 priv->desc_bat = dma_alloc_coherent(ndev->dev.parent, priv->desc_bat_size,
2722 &priv->desc_bat_dma, GFP_KERNEL);
2723 if (!priv->desc_bat) {
2725 "Cannot allocate desc base address table (size %d bytes)\n",
2726 priv->desc_bat_size);
2728 goto out_disable_refclk;
2730 for (q = RAVB_BE; q < DBAT_ENTRY_NUM; q++)
2731 priv->desc_bat[q].die_dt = DT_EOS;
2732 ravb_write(ndev, priv->desc_bat_dma, DBAT);
2734 /* Initialise HW timestamp list */
2735 INIT_LIST_HEAD(&priv->ts_skb_list);
2737 /* Initialise PTP Clock driver */
2739 ravb_ptp_init(ndev, pdev);
2741 /* Debug message level */
2742 priv->msg_enable = RAVB_DEF_MSG_ENABLE;
2744 /* Read and set MAC address */
2745 ravb_read_mac_address(np, ndev);
2746 if (!is_valid_ether_addr(ndev->dev_addr)) {
2747 dev_warn(&pdev->dev,
2748 "no valid MAC address supplied, using a random one\n");
2749 eth_hw_addr_random(ndev);
2753 error = ravb_mdio_init(priv);
2755 dev_err(&pdev->dev, "failed to initialize MDIO\n");
2759 netif_napi_add(ndev, &priv->napi[RAVB_BE], ravb_poll, 64);
2760 if (info->nc_queues)
2761 netif_napi_add(ndev, &priv->napi[RAVB_NC], ravb_poll, 64);
2763 /* Network device register */
2764 error = register_netdev(ndev);
2768 device_set_wakeup_capable(&pdev->dev, 1);
2770 /* Print device information */
2771 netdev_info(ndev, "Base address at %#x, %pM, IRQ %d.\n",
2772 (u32)ndev->base_addr, ndev->dev_addr, ndev->irq);
2774 platform_set_drvdata(pdev, ndev);
2779 if (info->nc_queues)
2780 netif_napi_del(&priv->napi[RAVB_NC]);
2782 netif_napi_del(&priv->napi[RAVB_BE]);
2783 ravb_mdio_release(priv);
2785 dma_free_coherent(ndev->dev.parent, priv->desc_bat_size, priv->desc_bat,
2786 priv->desc_bat_dma);
2788 /* Stop PTP Clock driver */
2790 ravb_ptp_stop(ndev);
2792 clk_disable_unprepare(priv->refclk);
2796 pm_runtime_put(&pdev->dev);
2797 pm_runtime_disable(&pdev->dev);
2798 reset_control_assert(rstc);
2802 static int ravb_remove(struct platform_device *pdev)
2804 struct net_device *ndev = platform_get_drvdata(pdev);
2805 struct ravb_private *priv = netdev_priv(ndev);
2806 const struct ravb_hw_info *info = priv->info;
2808 /* Stop PTP Clock driver */
2810 ravb_ptp_stop(ndev);
2812 clk_disable_unprepare(priv->refclk);
2814 dma_free_coherent(ndev->dev.parent, priv->desc_bat_size, priv->desc_bat,
2815 priv->desc_bat_dma);
2816 /* Set reset mode */
2817 ravb_write(ndev, CCC_OPC_RESET, CCC);
2818 pm_runtime_put_sync(&pdev->dev);
2819 unregister_netdev(ndev);
2820 if (info->nc_queues)
2821 netif_napi_del(&priv->napi[RAVB_NC]);
2822 netif_napi_del(&priv->napi[RAVB_BE]);
2823 ravb_mdio_release(priv);
2824 pm_runtime_disable(&pdev->dev);
2825 reset_control_assert(priv->rstc);
2827 platform_set_drvdata(pdev, NULL);
2832 static int ravb_wol_setup(struct net_device *ndev)
2834 struct ravb_private *priv = netdev_priv(ndev);
2835 const struct ravb_hw_info *info = priv->info;
2837 /* Disable interrupts by clearing the interrupt masks. */
2838 ravb_write(ndev, 0, RIC0);
2839 ravb_write(ndev, 0, RIC2);
2840 ravb_write(ndev, 0, TIC);
2842 /* Only allow ECI interrupts */
2843 synchronize_irq(priv->emac_irq);
2844 if (info->nc_queues)
2845 napi_disable(&priv->napi[RAVB_NC]);
2846 napi_disable(&priv->napi[RAVB_BE]);
2847 ravb_write(ndev, ECSIPR_MPDIP, ECSIPR);
2849 /* Enable MagicPacket */
2850 ravb_modify(ndev, ECMR, ECMR_MPDE, ECMR_MPDE);
2852 return enable_irq_wake(priv->emac_irq);
2855 static int ravb_wol_restore(struct net_device *ndev)
2857 struct ravb_private *priv = netdev_priv(ndev);
2858 const struct ravb_hw_info *info = priv->info;
2861 if (info->nc_queues)
2862 napi_enable(&priv->napi[RAVB_NC]);
2863 napi_enable(&priv->napi[RAVB_BE]);
2865 /* Disable MagicPacket */
2866 ravb_modify(ndev, ECMR, ECMR_MPDE, 0);
2868 ret = ravb_close(ndev);
2872 return disable_irq_wake(priv->emac_irq);
2875 static int __maybe_unused ravb_suspend(struct device *dev)
2877 struct net_device *ndev = dev_get_drvdata(dev);
2878 struct ravb_private *priv = netdev_priv(ndev);
2881 if (!netif_running(ndev))
2884 netif_device_detach(ndev);
2886 if (priv->wol_enabled)
2887 ret = ravb_wol_setup(ndev);
2889 ret = ravb_close(ndev);
2894 static int __maybe_unused ravb_resume(struct device *dev)
2896 struct net_device *ndev = dev_get_drvdata(dev);
2897 struct ravb_private *priv = netdev_priv(ndev);
2898 const struct ravb_hw_info *info = priv->info;
2901 /* If WoL is enabled set reset mode to rearm the WoL logic */
2902 if (priv->wol_enabled)
2903 ravb_write(ndev, CCC_OPC_RESET, CCC);
2905 /* All register have been reset to default values.
2906 * Restore all registers which where setup at probe time and
2907 * reopen device if it was running before system suspended.
2910 /* Set AVB config mode */
2911 ravb_set_config_mode(ndev);
2913 if (info->gptp || info->ccc_gac) {
2915 ret = ravb_set_gti(ndev);
2919 /* Request GTI loading */
2920 ravb_modify(ndev, GCCR, GCCR_LTI, GCCR_LTI);
2923 if (info->internal_delay)
2924 ravb_set_delay_mode(ndev);
2926 /* Restore descriptor base address table */
2927 ravb_write(ndev, priv->desc_bat_dma, DBAT);
2929 if (netif_running(ndev)) {
2930 if (priv->wol_enabled) {
2931 ret = ravb_wol_restore(ndev);
2935 ret = ravb_open(ndev);
2938 netif_device_attach(ndev);
2944 static int __maybe_unused ravb_runtime_nop(struct device *dev)
2946 /* Runtime PM callback shared between ->runtime_suspend()
2947 * and ->runtime_resume(). Simply returns success.
2949 * This driver re-initializes all registers after
2950 * pm_runtime_get_sync() anyway so there is no need
2951 * to save and restore registers here.
2956 static const struct dev_pm_ops ravb_dev_pm_ops = {
2957 SET_SYSTEM_SLEEP_PM_OPS(ravb_suspend, ravb_resume)
2958 SET_RUNTIME_PM_OPS(ravb_runtime_nop, ravb_runtime_nop, NULL)
2961 static struct platform_driver ravb_driver = {
2962 .probe = ravb_probe,
2963 .remove = ravb_remove,
2966 .pm = &ravb_dev_pm_ops,
2967 .of_match_table = ravb_match_table,
2971 module_platform_driver(ravb_driver);
2973 MODULE_AUTHOR("Mitsuhiro Kimura, Masaru Nagai");
2974 MODULE_DESCRIPTION("Renesas Ethernet AVB driver");
2975 MODULE_LICENSE("GPL v2");