Lines Matching +full:ether +full:- +full:r8a7790

1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright (C) 2014-2019 Renesas Electronics Corporation
6 * Copyright (C) 2015-2016 Cogent Embedded, Inc. <source@cogentembedded.com>
14 #include <linux/dma-mapping.h>
68 return -ETIMEDOUT; in ravb_wait()
89 switch (priv->speed) { in ravb_set_rate()
101 u32 reserve = (unsigned long)skb->data & (RAVB_ALIGN - 1); in ravb_set_buffer_align()
104 skb_reserve(skb, RAVB_ALIGN - reserve); in ravb_set_buffer_align()
115 ether_addr_copy(ndev->dev_addr, mac); in ravb_read_mac_address()
120 ndev->dev_addr[0] = (mahr >> 24) & 0xFF; in ravb_read_mac_address()
121 ndev->dev_addr[1] = (mahr >> 16) & 0xFF; in ravb_read_mac_address()
122 ndev->dev_addr[2] = (mahr >> 8) & 0xFF; in ravb_read_mac_address()
123 ndev->dev_addr[3] = (mahr >> 0) & 0xFF; in ravb_read_mac_address()
124 ndev->dev_addr[4] = (malr >> 8) & 0xFF; in ravb_read_mac_address()
125 ndev->dev_addr[5] = (malr >> 0) & 0xFF; in ravb_read_mac_address()
134 ravb_modify(priv->ndev, PIR, mask, set ? mask : 0); in ravb_mdio_ctrl()
161 return (ravb_read(priv->ndev, PIR) & PIR_MDI) != 0; in ravb_get_mdio_data()
173 /* Free TX skb function for AVB-IP */
177 struct net_device_stats *stats = &priv->stats[q]; in ravb_tx_free()
178 int num_tx_desc = priv->num_tx_desc; in ravb_tx_free()
184 for (; priv->cur_tx[q] - priv->dirty_tx[q] > 0; priv->dirty_tx[q]++) { in ravb_tx_free()
187 entry = priv->dirty_tx[q] % (priv->num_tx_ring[q] * in ravb_tx_free()
189 desc = &priv->tx_ring[q][entry]; in ravb_tx_free()
190 txed = desc->die_dt == DT_FEMPTY; in ravb_tx_free()
195 size = le16_to_cpu(desc->ds_tagl) & TX_DS; in ravb_tx_free()
197 if (priv->tx_skb[q][entry / num_tx_desc]) { in ravb_tx_free()
198 dma_unmap_single(ndev->dev.parent, le32_to_cpu(desc->dptr), in ravb_tx_free()
201 if (entry % num_tx_desc == num_tx_desc - 1) { in ravb_tx_free()
203 dev_kfree_skb_any(priv->tx_skb[q][entry]); in ravb_tx_free()
204 priv->tx_skb[q][entry] = NULL; in ravb_tx_free()
206 stats->tx_packets++; in ravb_tx_free()
211 stats->tx_bytes += size; in ravb_tx_free()
212 desc->die_dt = DT_EEMPTY; in ravb_tx_free()
221 int num_tx_desc = priv->num_tx_desc; in ravb_ring_free()
225 if (priv->rx_ring[q]) { in ravb_ring_free()
226 for (i = 0; i < priv->num_rx_ring[q]; i++) { in ravb_ring_free()
227 struct ravb_ex_rx_desc *desc = &priv->rx_ring[q][i]; in ravb_ring_free()
229 if (!dma_mapping_error(ndev->dev.parent, in ravb_ring_free()
230 le32_to_cpu(desc->dptr))) in ravb_ring_free()
231 dma_unmap_single(ndev->dev.parent, in ravb_ring_free()
232 le32_to_cpu(desc->dptr), in ravb_ring_free()
237 (priv->num_rx_ring[q] + 1); in ravb_ring_free()
238 dma_free_coherent(ndev->dev.parent, ring_size, priv->rx_ring[q], in ravb_ring_free()
239 priv->rx_desc_dma[q]); in ravb_ring_free()
240 priv->rx_ring[q] = NULL; in ravb_ring_free()
243 if (priv->tx_ring[q]) { in ravb_ring_free()
247 (priv->num_tx_ring[q] * num_tx_desc + 1); in ravb_ring_free()
248 dma_free_coherent(ndev->dev.parent, ring_size, priv->tx_ring[q], in ravb_ring_free()
249 priv->tx_desc_dma[q]); in ravb_ring_free()
250 priv->tx_ring[q] = NULL; in ravb_ring_free()
254 if (priv->rx_skb[q]) { in ravb_ring_free()
255 for (i = 0; i < priv->num_rx_ring[q]; i++) in ravb_ring_free()
256 dev_kfree_skb(priv->rx_skb[q][i]); in ravb_ring_free()
258 kfree(priv->rx_skb[q]); in ravb_ring_free()
259 priv->rx_skb[q] = NULL; in ravb_ring_free()
262 kfree(priv->tx_align[q]); in ravb_ring_free()
263 priv->tx_align[q] = NULL; in ravb_ring_free()
268 kfree(priv->tx_skb[q]); in ravb_ring_free()
269 priv->tx_skb[q] = NULL; in ravb_ring_free()
276 int num_tx_desc = priv->num_tx_desc; in ravb_ring_format()
280 int rx_ring_size = sizeof(*rx_desc) * priv->num_rx_ring[q]; in ravb_ring_format()
281 int tx_ring_size = sizeof(*tx_desc) * priv->num_tx_ring[q] * in ravb_ring_format()
286 priv->cur_rx[q] = 0; in ravb_ring_format()
287 priv->cur_tx[q] = 0; in ravb_ring_format()
288 priv->dirty_rx[q] = 0; in ravb_ring_format()
289 priv->dirty_tx[q] = 0; in ravb_ring_format()
291 memset(priv->rx_ring[q], 0, rx_ring_size); in ravb_ring_format()
293 for (i = 0; i < priv->num_rx_ring[q]; i++) { in ravb_ring_format()
295 rx_desc = &priv->rx_ring[q][i]; in ravb_ring_format()
296 rx_desc->ds_cc = cpu_to_le16(RX_BUF_SZ); in ravb_ring_format()
297 dma_addr = dma_map_single(ndev->dev.parent, priv->rx_skb[q][i]->data, in ravb_ring_format()
303 if (dma_mapping_error(ndev->dev.parent, dma_addr)) in ravb_ring_format()
304 rx_desc->ds_cc = cpu_to_le16(0); in ravb_ring_format()
305 rx_desc->dptr = cpu_to_le32(dma_addr); in ravb_ring_format()
306 rx_desc->die_dt = DT_FEMPTY; in ravb_ring_format()
308 rx_desc = &priv->rx_ring[q][i]; in ravb_ring_format()
309 rx_desc->dptr = cpu_to_le32((u32)priv->rx_desc_dma[q]); in ravb_ring_format()
310 rx_desc->die_dt = DT_LINKFIX; /* type */ in ravb_ring_format()
312 memset(priv->tx_ring[q], 0, tx_ring_size); in ravb_ring_format()
314 for (i = 0, tx_desc = priv->tx_ring[q]; i < priv->num_tx_ring[q]; in ravb_ring_format()
316 tx_desc->die_dt = DT_EEMPTY; in ravb_ring_format()
319 tx_desc->die_dt = DT_EEMPTY; in ravb_ring_format()
322 tx_desc->dptr = cpu_to_le32((u32)priv->tx_desc_dma[q]); in ravb_ring_format()
323 tx_desc->die_dt = DT_LINKFIX; /* type */ in ravb_ring_format()
326 desc = &priv->desc_bat[RX_QUEUE_OFFSET + q]; in ravb_ring_format()
327 desc->die_dt = DT_LINKFIX; /* type */ in ravb_ring_format()
328 desc->dptr = cpu_to_le32((u32)priv->rx_desc_dma[q]); in ravb_ring_format()
331 desc = &priv->desc_bat[q]; in ravb_ring_format()
332 desc->die_dt = DT_LINKFIX; /* type */ in ravb_ring_format()
333 desc->dptr = cpu_to_le32((u32)priv->tx_desc_dma[q]); in ravb_ring_format()
340 int num_tx_desc = priv->num_tx_desc; in ravb_ring_init()
346 priv->rx_skb[q] = kcalloc(priv->num_rx_ring[q], in ravb_ring_init()
347 sizeof(*priv->rx_skb[q]), GFP_KERNEL); in ravb_ring_init()
348 priv->tx_skb[q] = kcalloc(priv->num_tx_ring[q], in ravb_ring_init()
349 sizeof(*priv->tx_skb[q]), GFP_KERNEL); in ravb_ring_init()
350 if (!priv->rx_skb[q] || !priv->tx_skb[q]) in ravb_ring_init()
353 for (i = 0; i < priv->num_rx_ring[q]; i++) { in ravb_ring_init()
354 skb = netdev_alloc_skb(ndev, RX_BUF_SZ + RAVB_ALIGN - 1); in ravb_ring_init()
358 priv->rx_skb[q][i] = skb; in ravb_ring_init()
363 priv->tx_align[q] = kmalloc(DPTR_ALIGN * priv->num_tx_ring[q] + in ravb_ring_init()
364 DPTR_ALIGN - 1, GFP_KERNEL); in ravb_ring_init()
365 if (!priv->tx_align[q]) in ravb_ring_init()
370 ring_size = sizeof(struct ravb_ex_rx_desc) * (priv->num_rx_ring[q] + 1); in ravb_ring_init()
371 priv->rx_ring[q] = dma_alloc_coherent(ndev->dev.parent, ring_size, in ravb_ring_init()
372 &priv->rx_desc_dma[q], in ravb_ring_init()
374 if (!priv->rx_ring[q]) in ravb_ring_init()
377 priv->dirty_rx[q] = 0; in ravb_ring_init()
381 (priv->num_tx_ring[q] * num_tx_desc + 1); in ravb_ring_init()
382 priv->tx_ring[q] = dma_alloc_coherent(ndev->dev.parent, ring_size, in ravb_ring_init()
383 &priv->tx_desc_dma[q], in ravb_ring_init()
385 if (!priv->tx_ring[q]) in ravb_ring_init()
393 return -ENOMEM; in ravb_ring_init()
396 /* E-MAC init function */
400 ravb_write(ndev, ndev->mtu + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN, RFLR); in ravb_emac_init()
404 (ndev->features & NETIF_F_RXCSUM ? ECMR_RCSC : 0) | in ravb_emac_init()
411 (ndev->dev_addr[0] << 24) | (ndev->dev_addr[1] << 16) | in ravb_emac_init()
412 (ndev->dev_addr[2] << 8) | (ndev->dev_addr[3]), MAHR); in ravb_emac_init()
414 (ndev->dev_addr[4] << 8) | (ndev->dev_addr[5]), MALR); in ravb_emac_init()
416 /* E-MAC status register clear */ in ravb_emac_init()
419 /* E-MAC interrupt enable register */ in ravb_emac_init()
458 if (priv->chip_id == RCAR_GEN3) { in ravb_dmac_init()
473 /* Setting the control will start the AVB-DMAC process. */ in ravb_dmac_init()
491 while (count--) { in ravb_get_tx_tstamp()
499 list_for_each_entry_safe(ts_skb, ts_skb2, &priv->ts_skb_list, in ravb_get_tx_tstamp()
501 skb = ts_skb->skb; in ravb_get_tx_tstamp()
502 tag = ts_skb->tag; in ravb_get_tx_tstamp()
503 list_del(&ts_skb->list); in ravb_get_tx_tstamp()
524 if (unlikely(skb->len < sizeof(__sum16))) in ravb_rx_csum()
526 hw_csum = skb_tail_pointer(skb) - sizeof(__sum16); in ravb_rx_csum()
527 skb->csum = csum_unfold((__force __sum16)get_unaligned_le16(hw_csum)); in ravb_rx_csum()
528 skb->ip_summed = CHECKSUM_COMPLETE; in ravb_rx_csum()
529 skb_trim(skb, skb->len - sizeof(__sum16)); in ravb_rx_csum()
536 int entry = priv->cur_rx[q] % priv->num_rx_ring[q]; in ravb_rx()
537 int boguscnt = (priv->dirty_rx[q] + priv->num_rx_ring[q]) - in ravb_rx()
538 priv->cur_rx[q]; in ravb_rx()
539 struct net_device_stats *stats = &priv->stats[q]; in ravb_rx()
550 desc = &priv->rx_ring[q][entry]; in ravb_rx()
551 while (desc->die_dt != DT_FEMPTY) { in ravb_rx()
554 desc_status = desc->msc; in ravb_rx()
555 pkt_len = le16_to_cpu(desc->ds_cc) & RX_DS; in ravb_rx()
557 if (--boguscnt < 0) in ravb_rx()
560 /* We use 0-byte descriptors to mark the DMA mapping errors */ in ravb_rx()
565 stats->multicast++; in ravb_rx()
569 stats->rx_errors++; in ravb_rx()
571 stats->rx_crc_errors++; in ravb_rx()
573 stats->rx_frame_errors++; in ravb_rx()
575 stats->rx_length_errors++; in ravb_rx()
577 stats->rx_missed_errors++; in ravb_rx()
579 u32 get_ts = priv->tstamp_rx_ctrl & RAVB_RXTSTAMP_TYPE; in ravb_rx()
581 skb = priv->rx_skb[q][entry]; in ravb_rx()
582 priv->rx_skb[q][entry] = NULL; in ravb_rx()
583 dma_unmap_single(ndev->dev.parent, le32_to_cpu(desc->dptr), in ravb_rx()
594 ts.tv_sec = ((u64) le16_to_cpu(desc->ts_sh) << in ravb_rx()
595 32) | le32_to_cpu(desc->ts_sl); in ravb_rx()
596 ts.tv_nsec = le32_to_cpu(desc->ts_n); in ravb_rx()
597 shhwtstamps->hwtstamp = timespec64_to_ktime(ts); in ravb_rx()
601 skb->protocol = eth_type_trans(skb, ndev); in ravb_rx()
602 if (ndev->features & NETIF_F_RXCSUM) in ravb_rx()
604 napi_gro_receive(&priv->napi[q], skb); in ravb_rx()
605 stats->rx_packets++; in ravb_rx()
606 stats->rx_bytes += pkt_len; in ravb_rx()
609 entry = (++priv->cur_rx[q]) % priv->num_rx_ring[q]; in ravb_rx()
610 desc = &priv->rx_ring[q][entry]; in ravb_rx()
614 for (; priv->cur_rx[q] - priv->dirty_rx[q] > 0; priv->dirty_rx[q]++) { in ravb_rx()
615 entry = priv->dirty_rx[q] % priv->num_rx_ring[q]; in ravb_rx()
616 desc = &priv->rx_ring[q][entry]; in ravb_rx()
617 desc->ds_cc = cpu_to_le16(RX_BUF_SZ); in ravb_rx()
619 if (!priv->rx_skb[q][entry]) { in ravb_rx()
622 RAVB_ALIGN - 1); in ravb_rx()
626 dma_addr = dma_map_single(ndev->dev.parent, skb->data, in ravb_rx()
627 le16_to_cpu(desc->ds_cc), in ravb_rx()
633 if (dma_mapping_error(ndev->dev.parent, dma_addr)) in ravb_rx()
634 desc->ds_cc = cpu_to_le16(0); in ravb_rx()
635 desc->dptr = cpu_to_le32(dma_addr); in ravb_rx()
636 priv->rx_skb[q][entry] = skb; in ravb_rx()
640 desc->die_dt = DT_FEMPTY; in ravb_rx()
643 *quota -= limit - (++boguscnt); in ravb_rx()
676 /* Stop the E-MAC's RX/TX processes. */ in ravb_stop_dma()
684 /* Stop AVB-DMAC process */ in ravb_stop_dma()
688 /* E-MAC interrupt handler */
698 pm_wakeup_event(&priv->pdev->dev, 0); in ravb_emac_interrupt_unlocked()
700 ndev->stats.tx_carrier_errors++; in ravb_emac_interrupt_unlocked()
703 if (priv->no_avb_link) in ravb_emac_interrupt_unlocked()
706 if (priv->avb_link_active_low) in ravb_emac_interrupt_unlocked()
723 spin_lock(&priv->lock); in ravb_emac_interrupt()
725 spin_unlock(&priv->lock); in ravb_emac_interrupt()
744 priv->stats[RAVB_BE].rx_over_errors++; in ravb_error_interrupt()
748 priv->stats[RAVB_NC].rx_over_errors++; in ravb_error_interrupt()
752 priv->rx_fifo_errors++; in ravb_error_interrupt()
765 if (napi_schedule_prep(&priv->napi[q])) { in ravb_queue_interrupt()
767 if (priv->chip_id == RCAR_GEN2) { in ravb_queue_interrupt()
774 __napi_schedule(&priv->napi[q]); in ravb_queue_interrupt()
807 spin_lock(&priv->lock); in ravb_interrupt()
820 for (q = RAVB_NC; q >= RAVB_BE; q--) { in ravb_interrupt()
826 /* E-MAC status summary */ in ravb_interrupt()
844 spin_unlock(&priv->lock); in ravb_interrupt()
856 spin_lock(&priv->lock); in ravb_multi_interrupt()
876 spin_unlock(&priv->lock); in ravb_multi_interrupt()
886 spin_lock(&priv->lock); in ravb_dma_interrupt()
892 spin_unlock(&priv->lock); in ravb_dma_interrupt()
908 struct net_device *ndev = napi->dev; in ravb_poll()
911 int q = napi - priv->napi; in ravb_poll()
931 spin_lock_irqsave(&priv->lock, flags); in ravb_poll()
936 spin_unlock_irqrestore(&priv->lock, flags); in ravb_poll()
942 /* Re-enable RX/TX interrupts */ in ravb_poll()
943 spin_lock_irqsave(&priv->lock, flags); in ravb_poll()
944 if (priv->chip_id == RCAR_GEN2) { in ravb_poll()
951 spin_unlock_irqrestore(&priv->lock, flags); in ravb_poll()
954 priv->rx_over_errors = priv->stats[RAVB_BE].rx_over_errors; in ravb_poll()
955 priv->rx_over_errors += priv->stats[RAVB_NC].rx_over_errors; in ravb_poll()
956 if (priv->rx_over_errors != ndev->stats.rx_over_errors) in ravb_poll()
957 ndev->stats.rx_over_errors = priv->rx_over_errors; in ravb_poll()
958 if (priv->rx_fifo_errors != ndev->stats.rx_fifo_errors) in ravb_poll()
959 ndev->stats.rx_fifo_errors = priv->rx_fifo_errors; in ravb_poll()
961 return budget - quota; in ravb_poll()
968 struct phy_device *phydev = ndev->phydev; in ravb_adjust_link()
972 spin_lock_irqsave(&priv->lock, flags); in ravb_adjust_link()
974 /* Disable TX and RX right over here, if E-MAC change is ignored */ in ravb_adjust_link()
975 if (priv->no_avb_link) in ravb_adjust_link()
978 if (phydev->link) { in ravb_adjust_link()
979 if (phydev->speed != priv->speed) { in ravb_adjust_link()
981 priv->speed = phydev->speed; in ravb_adjust_link()
984 if (!priv->link) { in ravb_adjust_link()
987 priv->link = phydev->link; in ravb_adjust_link()
989 } else if (priv->link) { in ravb_adjust_link()
991 priv->link = 0; in ravb_adjust_link()
992 priv->speed = 0; in ravb_adjust_link()
995 /* Enable TX and RX right over here, if E-MAC change is ignored */ in ravb_adjust_link()
996 if (priv->no_avb_link && phydev->link) in ravb_adjust_link()
999 spin_unlock_irqrestore(&priv->lock, flags); in ravb_adjust_link()
1013 struct device_node *np = ndev->dev.parent->of_node; in ravb_phy_init()
1020 priv->link = 0; in ravb_phy_init()
1021 priv->speed = 0; in ravb_phy_init()
1024 pn = of_parse_phandle(np, "phy-handle", 0); in ravb_phy_init()
1037 iface = priv->rgmii_override ? PHY_INTERFACE_MODE_RGMII in ravb_phy_init()
1038 : priv->phy_interface; in ravb_phy_init()
1043 err = -ENOENT; in ravb_phy_init()
1047 /* This driver only support 10/100Mbit speeds on R-Car H3 ES1.0 in ravb_phy_init()
1092 phy_start(ndev->phydev); in ravb_phy_start()
1101 return priv->msg_enable; in ravb_get_msglevel()
1108 priv->msg_enable = value; in ravb_set_msglevel()
1153 return -EOPNOTSUPP; in ravb_get_sset_count()
1164 /* Device-specific stats */ in ravb_get_ethtool_stats()
1166 struct net_device_stats *stats = &priv->stats[q]; in ravb_get_ethtool_stats()
1168 data[i++] = priv->cur_rx[q]; in ravb_get_ethtool_stats()
1169 data[i++] = priv->cur_tx[q]; in ravb_get_ethtool_stats()
1170 data[i++] = priv->dirty_rx[q]; in ravb_get_ethtool_stats()
1171 data[i++] = priv->dirty_tx[q]; in ravb_get_ethtool_stats()
1172 data[i++] = stats->rx_packets; in ravb_get_ethtool_stats()
1173 data[i++] = stats->tx_packets; in ravb_get_ethtool_stats()
1174 data[i++] = stats->rx_bytes; in ravb_get_ethtool_stats()
1175 data[i++] = stats->tx_bytes; in ravb_get_ethtool_stats()
1176 data[i++] = stats->multicast; in ravb_get_ethtool_stats()
1177 data[i++] = stats->rx_errors; in ravb_get_ethtool_stats()
1178 data[i++] = stats->rx_crc_errors; in ravb_get_ethtool_stats()
1179 data[i++] = stats->rx_frame_errors; in ravb_get_ethtool_stats()
1180 data[i++] = stats->rx_length_errors; in ravb_get_ethtool_stats()
1181 data[i++] = stats->rx_missed_errors; in ravb_get_ethtool_stats()
1182 data[i++] = stats->rx_over_errors; in ravb_get_ethtool_stats()
1200 ring->rx_max_pending = BE_RX_RING_MAX; in ravb_get_ringparam()
1201 ring->tx_max_pending = BE_TX_RING_MAX; in ravb_get_ringparam()
1202 ring->rx_pending = priv->num_rx_ring[RAVB_BE]; in ravb_get_ringparam()
1203 ring->tx_pending = priv->num_tx_ring[RAVB_BE]; in ravb_get_ringparam()
1212 if (ring->tx_pending > BE_TX_RING_MAX || in ravb_set_ringparam()
1213 ring->rx_pending > BE_RX_RING_MAX || in ravb_set_ringparam()
1214 ring->tx_pending < BE_TX_RING_MIN || in ravb_set_ringparam()
1215 ring->rx_pending < BE_RX_RING_MIN) in ravb_set_ringparam()
1216 return -EINVAL; in ravb_set_ringparam()
1217 if (ring->rx_mini_pending || ring->rx_jumbo_pending) in ravb_set_ringparam()
1218 return -EINVAL; in ravb_set_ringparam()
1223 if (priv->chip_id == RCAR_GEN2) in ravb_set_ringparam()
1232 synchronize_irq(ndev->irq); in ravb_set_ringparam()
1240 priv->num_rx_ring[RAVB_BE] = ring->rx_pending; in ravb_set_ringparam()
1241 priv->num_tx_ring[RAVB_BE] = ring->tx_pending; in ravb_set_ringparam()
1255 if (priv->chip_id == RCAR_GEN2) in ravb_set_ringparam()
1256 ravb_ptp_init(ndev, priv->pdev); in ravb_set_ringparam()
1269 info->so_timestamping = in ravb_get_ts_info()
1276 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON); in ravb_get_ts_info()
1277 info->rx_filters = in ravb_get_ts_info()
1281 info->phc_index = ptp_clock_index(priv->ptp.clock); in ravb_get_ts_info()
1290 wol->supported = WAKE_MAGIC; in ravb_get_wol()
1291 wol->wolopts = priv->wol_enabled ? WAKE_MAGIC : 0; in ravb_get_wol()
1298 if (wol->wolopts & ~WAKE_MAGIC) in ravb_set_wol()
1299 return -EOPNOTSUPP; in ravb_set_wol()
1301 priv->wol_enabled = !!(wol->wolopts & WAKE_MAGIC); in ravb_set_wol()
1303 device_set_wakeup_enable(&priv->pdev->dev, priv->wol_enabled); in ravb_set_wol()
1332 name = devm_kasprintf(dev, GFP_KERNEL, "%s:%s", ndev->name, ch); in ravb_hook_irq()
1334 return -ENOMEM; in ravb_hook_irq()
1346 struct platform_device *pdev = priv->pdev; in ravb_open()
1347 struct device *dev = &pdev->dev; in ravb_open()
1350 napi_enable(&priv->napi[RAVB_BE]); in ravb_open()
1351 napi_enable(&priv->napi[RAVB_NC]); in ravb_open()
1353 if (priv->chip_id == RCAR_GEN2) { in ravb_open()
1354 error = request_irq(ndev->irq, ravb_interrupt, IRQF_SHARED, in ravb_open()
1355 ndev->name, ndev); in ravb_open()
1361 error = ravb_hook_irq(ndev->irq, ravb_multi_interrupt, ndev, in ravb_open()
1365 error = ravb_hook_irq(priv->emac_irq, ravb_emac_interrupt, ndev, in ravb_open()
1369 error = ravb_hook_irq(priv->rx_irqs[RAVB_BE], ravb_be_interrupt, in ravb_open()
1373 error = ravb_hook_irq(priv->tx_irqs[RAVB_BE], ravb_be_interrupt, in ravb_open()
1377 error = ravb_hook_irq(priv->rx_irqs[RAVB_NC], ravb_nc_interrupt, in ravb_open()
1381 error = ravb_hook_irq(priv->tx_irqs[RAVB_NC], ravb_nc_interrupt, in ravb_open()
1394 if (priv->chip_id == RCAR_GEN2) in ravb_open()
1395 ravb_ptp_init(ndev, priv->pdev); in ravb_open()
1408 if (priv->chip_id == RCAR_GEN2) in ravb_open()
1411 if (priv->chip_id == RCAR_GEN2) in ravb_open()
1413 free_irq(priv->tx_irqs[RAVB_NC], ndev); in ravb_open()
1415 free_irq(priv->rx_irqs[RAVB_NC], ndev); in ravb_open()
1417 free_irq(priv->tx_irqs[RAVB_BE], ndev); in ravb_open()
1419 free_irq(priv->rx_irqs[RAVB_BE], ndev); in ravb_open()
1421 free_irq(priv->emac_irq, ndev); in ravb_open()
1423 free_irq(ndev->irq, ndev); in ravb_open()
1425 napi_disable(&priv->napi[RAVB_NC]); in ravb_open()
1426 napi_disable(&priv->napi[RAVB_BE]); in ravb_open()
1440 ndev->stats.tx_errors++; in ravb_tx_timeout()
1442 schedule_work(&priv->work); in ravb_tx_timeout()
1449 struct net_device *ndev = priv->ndev; in ravb_tx_timeout_work()
1455 if (priv->chip_id == RCAR_GEN2) in ravb_tx_timeout_work()
1465 * re-enables the TX and RX and skip the following in ravb_tx_timeout_work()
1466 * re-initialization procedure. in ravb_tx_timeout_work()
1479 * should return here to avoid re-enabling the TX and RX in in ravb_tx_timeout_work()
1490 if (priv->chip_id == RCAR_GEN2) in ravb_tx_timeout_work()
1491 ravb_ptp_init(ndev, priv->pdev); in ravb_tx_timeout_work()
1500 int num_tx_desc = priv->num_tx_desc; in ravb_start_xmit()
1510 spin_lock_irqsave(&priv->lock, flags); in ravb_start_xmit()
1511 if (priv->cur_tx[q] - priv->dirty_tx[q] > (priv->num_tx_ring[q] - 1) * in ravb_start_xmit()
1516 spin_unlock_irqrestore(&priv->lock, flags); in ravb_start_xmit()
1523 entry = priv->cur_tx[q] % (priv->num_tx_ring[q] * num_tx_desc); in ravb_start_xmit()
1524 priv->tx_skb[q][entry / num_tx_desc] = skb; in ravb_start_xmit()
1527 buffer = PTR_ALIGN(priv->tx_align[q], DPTR_ALIGN) + in ravb_start_xmit()
1529 len = PTR_ALIGN(skb->data, DPTR_ALIGN) - skb->data; in ravb_start_xmit()
1540 * length of the second DMA descriptor (skb->len - len) in ravb_start_xmit()
1546 memcpy(buffer, skb->data, len); in ravb_start_xmit()
1547 dma_addr = dma_map_single(ndev->dev.parent, buffer, len, in ravb_start_xmit()
1549 if (dma_mapping_error(ndev->dev.parent, dma_addr)) in ravb_start_xmit()
1552 desc = &priv->tx_ring[q][entry]; in ravb_start_xmit()
1553 desc->ds_tagl = cpu_to_le16(len); in ravb_start_xmit()
1554 desc->dptr = cpu_to_le32(dma_addr); in ravb_start_xmit()
1556 buffer = skb->data + len; in ravb_start_xmit()
1557 len = skb->len - len; in ravb_start_xmit()
1558 dma_addr = dma_map_single(ndev->dev.parent, buffer, len, in ravb_start_xmit()
1560 if (dma_mapping_error(ndev->dev.parent, dma_addr)) in ravb_start_xmit()
1565 desc = &priv->tx_ring[q][entry]; in ravb_start_xmit()
1566 len = skb->len; in ravb_start_xmit()
1567 dma_addr = dma_map_single(ndev->dev.parent, skb->data, skb->len, in ravb_start_xmit()
1569 if (dma_mapping_error(ndev->dev.parent, dma_addr)) in ravb_start_xmit()
1572 desc->ds_tagl = cpu_to_le16(len); in ravb_start_xmit()
1573 desc->dptr = cpu_to_le32(dma_addr); in ravb_start_xmit()
1580 desc--; in ravb_start_xmit()
1581 dma_unmap_single(ndev->dev.parent, dma_addr, in ravb_start_xmit()
1586 ts_skb->skb = skb_get(skb); in ravb_start_xmit()
1587 ts_skb->tag = priv->ts_skb_tag++; in ravb_start_xmit()
1588 priv->ts_skb_tag &= 0x3ff; in ravb_start_xmit()
1589 list_add_tail(&ts_skb->list, &priv->ts_skb_list); in ravb_start_xmit()
1592 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; in ravb_start_xmit()
1593 desc->tagh_tsr = (ts_skb->tag >> 4) | TX_TSR; in ravb_start_xmit()
1594 desc->ds_tagl |= cpu_to_le16(ts_skb->tag << 12); in ravb_start_xmit()
1601 desc->die_dt = DT_FEND; in ravb_start_xmit()
1602 desc--; in ravb_start_xmit()
1603 desc->die_dt = DT_FSTART; in ravb_start_xmit()
1605 desc->die_dt = DT_FSINGLE; in ravb_start_xmit()
1609 priv->cur_tx[q] += num_tx_desc; in ravb_start_xmit()
1610 if (priv->cur_tx[q] - priv->dirty_tx[q] > in ravb_start_xmit()
1611 (priv->num_tx_ring[q] - 1) * num_tx_desc && in ravb_start_xmit()
1616 spin_unlock_irqrestore(&priv->lock, flags); in ravb_start_xmit()
1620 dma_unmap_single(ndev->dev.parent, le32_to_cpu(desc->dptr), in ravb_start_xmit()
1621 le16_to_cpu(desc->ds_tagl), DMA_TO_DEVICE); in ravb_start_xmit()
1624 priv->tx_skb[q][entry / num_tx_desc] = NULL; in ravb_start_xmit()
1632 return (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) ? RAVB_NC : in ravb_select_queue()
1642 nstats = &ndev->stats; in ravb_get_stats()
1643 stats0 = &priv->stats[RAVB_BE]; in ravb_get_stats()
1644 stats1 = &priv->stats[RAVB_NC]; in ravb_get_stats()
1646 if (priv->chip_id == RCAR_GEN3) { in ravb_get_stats()
1647 nstats->tx_dropped += ravb_read(ndev, TROCR); in ravb_get_stats()
1651 nstats->rx_packets = stats0->rx_packets + stats1->rx_packets; in ravb_get_stats()
1652 nstats->tx_packets = stats0->tx_packets + stats1->tx_packets; in ravb_get_stats()
1653 nstats->rx_bytes = stats0->rx_bytes + stats1->rx_bytes; in ravb_get_stats()
1654 nstats->tx_bytes = stats0->tx_bytes + stats1->tx_bytes; in ravb_get_stats()
1655 nstats->multicast = stats0->multicast + stats1->multicast; in ravb_get_stats()
1656 nstats->rx_errors = stats0->rx_errors + stats1->rx_errors; in ravb_get_stats()
1657 nstats->rx_crc_errors = stats0->rx_crc_errors + stats1->rx_crc_errors; in ravb_get_stats()
1658 nstats->rx_frame_errors = in ravb_get_stats()
1659 stats0->rx_frame_errors + stats1->rx_frame_errors; in ravb_get_stats()
1660 nstats->rx_length_errors = in ravb_get_stats()
1661 stats0->rx_length_errors + stats1->rx_length_errors; in ravb_get_stats()
1662 nstats->rx_missed_errors = in ravb_get_stats()
1663 stats0->rx_missed_errors + stats1->rx_missed_errors; in ravb_get_stats()
1664 nstats->rx_over_errors = in ravb_get_stats()
1665 stats0->rx_over_errors + stats1->rx_over_errors; in ravb_get_stats()
1676 spin_lock_irqsave(&priv->lock, flags); in ravb_set_rx_mode()
1678 ndev->flags & IFF_PROMISC ? ECMR_PRM : 0); in ravb_set_rx_mode()
1679 spin_unlock_irqrestore(&priv->lock, flags); in ravb_set_rx_mode()
1685 struct device_node *np = ndev->dev.parent->of_node; in ravb_close()
1697 if (priv->chip_id == RCAR_GEN2) in ravb_close()
1700 /* Set the config mode to stop the AVB-DMAC's processes */ in ravb_close()
1706 list_for_each_entry_safe(ts_skb, ts_skb2, &priv->ts_skb_list, list) { in ravb_close()
1707 list_del(&ts_skb->list); in ravb_close()
1708 kfree_skb(ts_skb->skb); in ravb_close()
1713 if (ndev->phydev) { in ravb_close()
1714 phy_stop(ndev->phydev); in ravb_close()
1715 phy_disconnect(ndev->phydev); in ravb_close()
1720 if (priv->chip_id != RCAR_GEN2) { in ravb_close()
1721 free_irq(priv->tx_irqs[RAVB_NC], ndev); in ravb_close()
1722 free_irq(priv->rx_irqs[RAVB_NC], ndev); in ravb_close()
1723 free_irq(priv->tx_irqs[RAVB_BE], ndev); in ravb_close()
1724 free_irq(priv->rx_irqs[RAVB_BE], ndev); in ravb_close()
1725 free_irq(priv->emac_irq, ndev); in ravb_close()
1727 free_irq(ndev->irq, ndev); in ravb_close()
1729 napi_disable(&priv->napi[RAVB_NC]); in ravb_close()
1730 napi_disable(&priv->napi[RAVB_BE]); in ravb_close()
1745 config.tx_type = priv->tstamp_tx_ctrl ? HWTSTAMP_TX_ON : in ravb_hwtstamp_get()
1747 switch (priv->tstamp_rx_ctrl & RAVB_RXTSTAMP_TYPE) { in ravb_hwtstamp_get()
1758 return copy_to_user(req->ifr_data, &config, sizeof(config)) ? in ravb_hwtstamp_get()
1759 -EFAULT : 0; in ravb_hwtstamp_get()
1770 if (copy_from_user(&config, req->ifr_data, sizeof(config))) in ravb_hwtstamp_set()
1771 return -EFAULT; in ravb_hwtstamp_set()
1775 return -EINVAL; in ravb_hwtstamp_set()
1785 return -ERANGE; in ravb_hwtstamp_set()
1800 priv->tstamp_tx_ctrl = tstamp_tx_ctrl; in ravb_hwtstamp_set()
1801 priv->tstamp_rx_ctrl = tstamp_rx_ctrl; in ravb_hwtstamp_set()
1803 return copy_to_user(req->ifr_data, &config, sizeof(config)) ? in ravb_hwtstamp_set()
1804 -EFAULT : 0; in ravb_hwtstamp_set()
1810 struct phy_device *phydev = ndev->phydev; in ravb_do_ioctl()
1813 return -EINVAL; in ravb_do_ioctl()
1816 return -ENODEV; in ravb_do_ioctl()
1832 ndev->mtu = new_mtu; in ravb_change_mtu()
1835 synchronize_irq(priv->emac_irq); in ravb_change_mtu()
1849 spin_lock_irqsave(&priv->lock, flags); in ravb_set_rx_csum()
1860 spin_unlock_irqrestore(&priv->lock, flags); in ravb_set_rx_csum()
1866 netdev_features_t changed = ndev->features ^ features; in ravb_set_features()
1871 ndev->features = features; in ravb_set_features()
1894 struct platform_device *pdev = priv->pdev; in ravb_mdio_init()
1895 struct device *dev = &pdev->dev; in ravb_mdio_init()
1899 priv->mdiobb.ops = &bb_ops; in ravb_mdio_init()
1902 priv->mii_bus = alloc_mdio_bitbang(&priv->mdiobb); in ravb_mdio_init()
1903 if (!priv->mii_bus) in ravb_mdio_init()
1904 return -ENOMEM; in ravb_mdio_init()
1907 priv->mii_bus->name = "ravb_mii"; in ravb_mdio_init()
1908 priv->mii_bus->parent = dev; in ravb_mdio_init()
1909 snprintf(priv->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x", in ravb_mdio_init()
1910 pdev->name, pdev->id); in ravb_mdio_init()
1913 error = of_mdiobus_register(priv->mii_bus, dev->of_node); in ravb_mdio_init()
1920 free_mdio_bitbang(priv->mii_bus); in ravb_mdio_init()
1928 mdiobus_unregister(priv->mii_bus); in ravb_mdio_release()
1931 free_mdio_bitbang(priv->mii_bus); in ravb_mdio_release()
1937 { .compatible = "renesas,etheravb-r8a7790", .data = (void *)RCAR_GEN2 },
1938 { .compatible = "renesas,etheravb-r8a7794", .data = (void *)RCAR_GEN2 },
1939 { .compatible = "renesas,etheravb-rcar-gen2", .data = (void *)RCAR_GEN2 },
1940 { .compatible = "renesas,etheravb-r8a7795", .data = (void *)RCAR_GEN3 },
1941 { .compatible = "renesas,etheravb-rcar-gen3", .data = (void *)RCAR_GEN3 },
1949 struct device *dev = ndev->dev.parent; in ravb_set_gti()
1953 rate = clk_get_rate(priv->clk); in ravb_set_gti()
1955 return -EINVAL; in ravb_set_gti()
1961 dev_err(dev, "gti.tiv increment 0x%llx is outside the range 0x%x - 0x%x\n", in ravb_set_gti()
1963 return -EINVAL; in ravb_set_gti()
1975 if (priv->chip_id == RCAR_GEN2) { in ravb_set_config_mode()
1999 if (!of_property_read_u32(np, "rx-internal-delay-ps", &delay)) { in ravb_parse_delay_mode()
2001 priv->rxcidm = !!delay; in ravb_parse_delay_mode()
2004 if (!of_property_read_u32(np, "tx-internal-delay-ps", &delay)) { in ravb_parse_delay_mode()
2006 priv->txcidm = !!delay; in ravb_parse_delay_mode()
2013 /* Fall back to legacy rgmii-*id behavior */ in ravb_parse_delay_mode()
2014 if (priv->phy_interface == PHY_INTERFACE_MODE_RGMII_ID || in ravb_parse_delay_mode()
2015 priv->phy_interface == PHY_INTERFACE_MODE_RGMII_RXID) { in ravb_parse_delay_mode()
2016 priv->rxcidm = 1; in ravb_parse_delay_mode()
2017 priv->rgmii_override = 1; in ravb_parse_delay_mode()
2020 if (priv->phy_interface == PHY_INTERFACE_MODE_RGMII_ID || in ravb_parse_delay_mode()
2021 priv->phy_interface == PHY_INTERFACE_MODE_RGMII_TXID) { in ravb_parse_delay_mode()
2023 …"phy-mode %s requires TX clock internal delay mode which is not supported by this hardware revisio… in ravb_parse_delay_mode()
2024 phy_modes(priv->phy_interface))) { in ravb_parse_delay_mode()
2025 priv->txcidm = 1; in ravb_parse_delay_mode()
2026 priv->rgmii_override = 1; in ravb_parse_delay_mode()
2036 if (priv->rxcidm) in ravb_set_delay_mode()
2038 if (priv->txcidm) in ravb_set_delay_mode()
2045 struct device_node *np = pdev->dev.of_node; in ravb_probe()
2054 dev_err(&pdev->dev, in ravb_probe()
2056 return -EINVAL; in ravb_probe()
2062 dev_err(&pdev->dev, "invalid resource\n"); in ravb_probe()
2063 return -EINVAL; in ravb_probe()
2069 return -ENOMEM; in ravb_probe()
2071 ndev->features = NETIF_F_RXCSUM; in ravb_probe()
2072 ndev->hw_features = NETIF_F_RXCSUM; in ravb_probe()
2074 pm_runtime_enable(&pdev->dev); in ravb_probe()
2075 pm_runtime_get_sync(&pdev->dev); in ravb_probe()
2077 /* The Ether-specific entries in the device structure. */ in ravb_probe()
2078 ndev->base_addr = res->start; in ravb_probe()
2080 chip_id = (enum ravb_chip_id)of_device_get_match_data(&pdev->dev); in ravb_probe()
2090 ndev->irq = irq; in ravb_probe()
2092 SET_NETDEV_DEV(ndev, &pdev->dev); in ravb_probe()
2095 priv->ndev = ndev; in ravb_probe()
2096 priv->pdev = pdev; in ravb_probe()
2097 priv->num_tx_ring[RAVB_BE] = BE_TX_RING_SIZE; in ravb_probe()
2098 priv->num_rx_ring[RAVB_BE] = BE_RX_RING_SIZE; in ravb_probe()
2099 priv->num_tx_ring[RAVB_NC] = NC_TX_RING_SIZE; in ravb_probe()
2100 priv->num_rx_ring[RAVB_NC] = NC_RX_RING_SIZE; in ravb_probe()
2101 priv->addr = devm_ioremap_resource(&pdev->dev, res); in ravb_probe()
2102 if (IS_ERR(priv->addr)) { in ravb_probe()
2103 error = PTR_ERR(priv->addr); in ravb_probe()
2107 spin_lock_init(&priv->lock); in ravb_probe()
2108 INIT_WORK(&priv->work, ravb_tx_timeout_work); in ravb_probe()
2110 error = of_get_phy_mode(np, &priv->phy_interface); in ravb_probe()
2111 if (error && error != -ENODEV) in ravb_probe()
2114 priv->no_avb_link = of_property_read_bool(np, "renesas,no-ether-link"); in ravb_probe()
2115 priv->avb_link_active_low = in ravb_probe()
2116 of_property_read_bool(np, "renesas,ether-link-active-low"); in ravb_probe()
2124 priv->emac_irq = irq; in ravb_probe()
2131 priv->rx_irqs[i] = irq; in ravb_probe()
2139 priv->tx_irqs[i] = irq; in ravb_probe()
2143 priv->chip_id = chip_id; in ravb_probe()
2145 priv->clk = devm_clk_get(&pdev->dev, NULL); in ravb_probe()
2146 if (IS_ERR(priv->clk)) { in ravb_probe()
2147 error = PTR_ERR(priv->clk); in ravb_probe()
2151 ndev->max_mtu = 2048 - (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN); in ravb_probe()
2152 ndev->min_mtu = ETH_MIN_MTU; in ravb_probe()
2154 priv->num_tx_desc = chip_id == RCAR_GEN2 ? in ravb_probe()
2158 ndev->netdev_ops = &ravb_netdev_ops; in ravb_probe()
2159 ndev->ethtool_ops = &ravb_ethtool_ops; in ravb_probe()
2172 if (priv->chip_id != RCAR_GEN2) { in ravb_probe()
2178 priv->desc_bat_size = sizeof(struct ravb_desc) * DBAT_ENTRY_NUM; in ravb_probe()
2179 priv->desc_bat = dma_alloc_coherent(ndev->dev.parent, priv->desc_bat_size, in ravb_probe()
2180 &priv->desc_bat_dma, GFP_KERNEL); in ravb_probe()
2181 if (!priv->desc_bat) { in ravb_probe()
2182 dev_err(&pdev->dev, in ravb_probe()
2184 priv->desc_bat_size); in ravb_probe()
2185 error = -ENOMEM; in ravb_probe()
2189 priv->desc_bat[q].die_dt = DT_EOS; in ravb_probe()
2190 ravb_write(ndev, priv->desc_bat_dma, DBAT); in ravb_probe()
2193 INIT_LIST_HEAD(&priv->ts_skb_list); in ravb_probe()
2200 priv->msg_enable = RAVB_DEF_MSG_ENABLE; in ravb_probe()
2204 if (!is_valid_ether_addr(ndev->dev_addr)) { in ravb_probe()
2205 dev_warn(&pdev->dev, in ravb_probe()
2213 dev_err(&pdev->dev, "failed to initialize MDIO\n"); in ravb_probe()
2217 netif_napi_add(ndev, &priv->napi[RAVB_BE], ravb_poll, 64); in ravb_probe()
2218 netif_napi_add(ndev, &priv->napi[RAVB_NC], ravb_poll, 64); in ravb_probe()
2225 device_set_wakeup_capable(&pdev->dev, 1); in ravb_probe()
2229 (u32)ndev->base_addr, ndev->dev_addr, ndev->irq); in ravb_probe()
2236 netif_napi_del(&priv->napi[RAVB_NC]); in ravb_probe()
2237 netif_napi_del(&priv->napi[RAVB_BE]); in ravb_probe()
2240 dma_free_coherent(ndev->dev.parent, priv->desc_bat_size, priv->desc_bat, in ravb_probe()
2241 priv->desc_bat_dma); in ravb_probe()
2249 pm_runtime_put(&pdev->dev); in ravb_probe()
2250 pm_runtime_disable(&pdev->dev); in ravb_probe()
2260 if (priv->chip_id != RCAR_GEN2) in ravb_remove()
2263 dma_free_coherent(ndev->dev.parent, priv->desc_bat_size, priv->desc_bat, in ravb_remove()
2264 priv->desc_bat_dma); in ravb_remove()
2267 pm_runtime_put_sync(&pdev->dev); in ravb_remove()
2269 netif_napi_del(&priv->napi[RAVB_NC]); in ravb_remove()
2270 netif_napi_del(&priv->napi[RAVB_BE]); in ravb_remove()
2272 pm_runtime_disable(&pdev->dev); in ravb_remove()
2289 synchronize_irq(priv->emac_irq); in ravb_wol_setup()
2290 napi_disable(&priv->napi[RAVB_NC]); in ravb_wol_setup()
2291 napi_disable(&priv->napi[RAVB_BE]); in ravb_wol_setup()
2297 return enable_irq_wake(priv->emac_irq); in ravb_wol_setup()
2305 napi_enable(&priv->napi[RAVB_NC]); in ravb_wol_restore()
2306 napi_enable(&priv->napi[RAVB_BE]); in ravb_wol_restore()
2315 return disable_irq_wake(priv->emac_irq); in ravb_wol_restore()
2329 if (priv->wol_enabled) in ravb_suspend()
2344 if (priv->wol_enabled) in ravb_resume()
2363 if (priv->chip_id != RCAR_GEN2) in ravb_resume()
2367 ravb_write(ndev, priv->desc_bat_dma, DBAT); in ravb_resume()
2370 if (priv->wol_enabled) { in ravb_resume()
2386 /* Runtime PM callback shared between ->runtime_suspend() in ravb_runtime_nop()
2387 * and ->runtime_resume(). Simply returns success. in ravb_runtime_nop()
2389 * This driver re-initializes all registers after in ravb_runtime_nop()