Lines Matching full:ndev
43 void ravb_modify(struct net_device *ndev, enum ravb_reg reg, u32 clear, in ravb_modify() argument
46 ravb_write(ndev, (ravb_read(ndev, reg) & ~clear) | set, reg); in ravb_modify()
49 int ravb_wait(struct net_device *ndev, enum ravb_reg reg, u32 mask, u32 value) in ravb_wait() argument
54 if ((ravb_read(ndev, reg) & mask) == value) in ravb_wait()
61 static int ravb_set_opmode(struct net_device *ndev, u32 opmode) in ravb_set_opmode() argument
75 ravb_modify(ndev, CCC, ccc_mask, opmode); in ravb_set_opmode()
77 error = ravb_wait(ndev, CSR, CSR_OPS, csr_ops); in ravb_set_opmode()
79 netdev_err(ndev, "failed to switch device to requested mode (%u)\n", in ravb_set_opmode()
86 static void ravb_set_rate_gbeth(struct net_device *ndev) in ravb_set_rate_gbeth() argument
88 struct ravb_private *priv = netdev_priv(ndev); in ravb_set_rate_gbeth()
92 ravb_write(ndev, GBETH_GECMR_SPEED_10, GECMR); in ravb_set_rate_gbeth()
95 ravb_write(ndev, GBETH_GECMR_SPEED_100, GECMR); in ravb_set_rate_gbeth()
98 ravb_write(ndev, GBETH_GECMR_SPEED_1000, GECMR); in ravb_set_rate_gbeth()
103 static void ravb_set_rate_rcar(struct net_device *ndev) in ravb_set_rate_rcar() argument
105 struct ravb_private *priv = netdev_priv(ndev); in ravb_set_rate_rcar()
109 ravb_write(ndev, GECMR_SPEED_100, GECMR); in ravb_set_rate_rcar()
112 ravb_write(ndev, GECMR_SPEED_1000, GECMR); in ravb_set_rate_rcar()
123 struct net_device *ndev) in ravb_read_mac_address() argument
127 ret = of_get_ethdev_address(np, ndev); in ravb_read_mac_address()
129 u32 mahr = ravb_read(ndev, MAHR); in ravb_read_mac_address()
130 u32 malr = ravb_read(ndev, MALR); in ravb_read_mac_address()
139 eth_hw_addr_set(ndev, addr); in ravb_read_mac_address()
148 ravb_modify(priv->ndev, PIR, mask, set ? mask : 0); in ravb_mdio_ctrl()
175 return (ravb_read(priv->ndev, PIR) & PIR_MDI) != 0; in ravb_get_mdio_data()
195 static int ravb_tx_free(struct net_device *ndev, int q, bool free_txed_only) in ravb_tx_free() argument
197 struct ravb_private *priv = netdev_priv(ndev); in ravb_tx_free()
219 dma_unmap_single(ndev->dev.parent, le32_to_cpu(desc->dptr), in ravb_tx_free()
238 static void ravb_rx_ring_free(struct net_device *ndev, int q) in ravb_rx_ring_free() argument
240 struct ravb_private *priv = netdev_priv(ndev); in ravb_rx_ring_free()
247 dma_free_coherent(ndev->dev.parent, ring_size, priv->rx_ring[q].raw, in ravb_rx_ring_free()
253 static void ravb_ring_free(struct net_device *ndev, int q) in ravb_ring_free() argument
255 struct ravb_private *priv = netdev_priv(ndev); in ravb_ring_free()
260 ravb_rx_ring_free(ndev, q); in ravb_ring_free()
263 ravb_tx_free(ndev, q, false); in ravb_ring_free()
267 dma_free_coherent(ndev->dev.parent, ring_size, priv->tx_ring[q], in ravb_ring_free()
295 ravb_alloc_rx_buffer(struct net_device *ndev, int q, u32 entry, gfp_t gfp_mask, in ravb_alloc_rx_buffer() argument
298 struct ravb_private *priv = netdev_priv(ndev); in ravb_alloc_rx_buffer()
317 dma_sync_single_for_device(ndev->dev.parent, dma_addr, in ravb_alloc_rx_buffer()
331 ravb_rx_ring_refill(struct net_device *ndev, int q, u32 count, gfp_t gfp_mask) in ravb_rx_ring_refill() argument
333 struct ravb_private *priv = netdev_priv(ndev); in ravb_rx_ring_refill()
342 if (unlikely(ravb_alloc_rx_buffer(ndev, q, entry, in ravb_rx_ring_refill()
355 static void ravb_ring_format(struct net_device *ndev, int q) in ravb_ring_format() argument
357 struct ravb_private *priv = netdev_priv(ndev); in ravb_ring_format()
403 static void *ravb_alloc_rx_desc(struct net_device *ndev, int q) in ravb_alloc_rx_desc() argument
405 struct ravb_private *priv = netdev_priv(ndev); in ravb_alloc_rx_desc()
410 priv->rx_ring[q].raw = dma_alloc_coherent(ndev->dev.parent, ring_size, in ravb_alloc_rx_desc()
418 static int ravb_ring_init(struct net_device *ndev, int q) in ravb_ring_init() argument
420 struct ravb_private *priv = netdev_priv(ndev); in ravb_ring_init()
427 .dev = ndev->dev.parent, in ravb_ring_init()
451 if (!ravb_alloc_rx_desc(ndev, q)) in ravb_ring_init()
458 num_filled = ravb_rx_ring_refill(ndev, q, priv->num_rx_ring[q], in ravb_ring_init()
474 priv->tx_ring[q] = dma_alloc_coherent(ndev->dev.parent, ring_size, in ravb_ring_init()
483 ravb_ring_free(ndev, q); in ravb_ring_init()
488 static void ravb_csum_init_gbeth(struct net_device *ndev) in ravb_csum_init_gbeth() argument
490 bool tx_enable = ndev->features & NETIF_F_HW_CSUM; in ravb_csum_init_gbeth()
491 bool rx_enable = ndev->features & NETIF_F_RXCSUM; in ravb_csum_init_gbeth()
496 ravb_write(ndev, 0, CSR0); in ravb_csum_init_gbeth()
497 if (ravb_wait(ndev, CSR0, CSR0_TPE | CSR0_RPE, 0)) { in ravb_csum_init_gbeth()
498 netdev_err(ndev, "Timeout enabling hardware checksum\n"); in ravb_csum_init_gbeth()
501 ndev->features &= ~NETIF_F_HW_CSUM; in ravb_csum_init_gbeth()
504 ndev->features &= ~NETIF_F_RXCSUM; in ravb_csum_init_gbeth()
507 ravb_write(ndev, CSR1_TIP4 | CSR1_TTCP4 | CSR1_TUDP4, CSR1); in ravb_csum_init_gbeth()
510 ravb_write(ndev, CSR2_RIP4 | CSR2_RTCP4 | CSR2_RUDP4 | CSR2_RICMP4, in ravb_csum_init_gbeth()
515 ravb_write(ndev, CSR0_TPE | CSR0_RPE, CSR0); in ravb_csum_init_gbeth()
518 static void ravb_emac_init_gbeth(struct net_device *ndev) in ravb_emac_init_gbeth() argument
520 struct ravb_private *priv = netdev_priv(ndev); in ravb_emac_init_gbeth()
523 ravb_write(ndev, (1000 << 16) | CXR35_SEL_XMII_MII, CXR35); in ravb_emac_init_gbeth()
524 ravb_modify(ndev, CXR31, CXR31_SEL_LINK0 | CXR31_SEL_LINK1, 0); in ravb_emac_init_gbeth()
526 ravb_write(ndev, (1000 << 16) | CXR35_SEL_XMII_RGMII, CXR35); in ravb_emac_init_gbeth()
527 ravb_modify(ndev, CXR31, CXR31_SEL_LINK0 | CXR31_SEL_LINK1, in ravb_emac_init_gbeth()
532 ravb_write(ndev, priv->info->rx_max_frame_size + ETH_FCS_LEN, RFLR); in ravb_emac_init_gbeth()
535 ravb_write(ndev, ECMR_ZPF | ((priv->duplex > 0) ? ECMR_DM : 0) | in ravb_emac_init_gbeth()
539 ravb_set_rate_gbeth(ndev); in ravb_emac_init_gbeth()
542 ravb_write(ndev, in ravb_emac_init_gbeth()
543 (ndev->dev_addr[0] << 24) | (ndev->dev_addr[1] << 16) | in ravb_emac_init_gbeth()
544 (ndev->dev_addr[2] << 8) | (ndev->dev_addr[3]), MAHR); in ravb_emac_init_gbeth()
545 ravb_write(ndev, (ndev->dev_addr[4] << 8) | (ndev->dev_addr[5]), MALR); in ravb_emac_init_gbeth()
548 ravb_write(ndev, ECSR_ICD | ECSR_LCHNG | ECSR_PFRI, ECSR); in ravb_emac_init_gbeth()
550 ravb_csum_init_gbeth(ndev); in ravb_emac_init_gbeth()
553 ravb_write(ndev, ECSIPR_ICDIP, ECSIPR); in ravb_emac_init_gbeth()
556 static void ravb_emac_init_rcar(struct net_device *ndev) in ravb_emac_init_rcar() argument
558 struct ravb_private *priv = netdev_priv(ndev); in ravb_emac_init_rcar()
567 ravb_write(ndev, priv->info->rx_max_frame_size + ETH_FCS_LEN, RFLR); in ravb_emac_init_rcar()
570 ravb_write(ndev, ECMR_ZPF | ECMR_DM | in ravb_emac_init_rcar()
571 (ndev->features & NETIF_F_RXCSUM ? ECMR_RCSC : 0) | in ravb_emac_init_rcar()
574 ravb_set_rate_rcar(ndev); in ravb_emac_init_rcar()
577 ravb_write(ndev, in ravb_emac_init_rcar()
578 (ndev->dev_addr[0] << 24) | (ndev->dev_addr[1] << 16) | in ravb_emac_init_rcar()
579 (ndev->dev_addr[2] << 8) | (ndev->dev_addr[3]), MAHR); in ravb_emac_init_rcar()
580 ravb_write(ndev, in ravb_emac_init_rcar()
581 (ndev->dev_addr[4] << 8) | (ndev->dev_addr[5]), MALR); in ravb_emac_init_rcar()
584 ravb_write(ndev, ECSR_ICD | ECSR_MPD, ECSR); in ravb_emac_init_rcar()
587 ravb_write(ndev, ECSIPR_ICDIP | ECSIPR_MPDIP | ECSIPR_LCHNGIP, ECSIPR); in ravb_emac_init_rcar()
590 static void ravb_emac_init_rcar_gen4(struct net_device *ndev) in ravb_emac_init_rcar_gen4() argument
592 struct ravb_private *priv = netdev_priv(ndev); in ravb_emac_init_rcar_gen4()
595 ravb_modify(ndev, APSR, APSR_MIISELECT, mii ? APSR_MIISELECT : 0); in ravb_emac_init_rcar_gen4()
597 ravb_emac_init_rcar(ndev); in ravb_emac_init_rcar_gen4()
601 static void ravb_emac_init(struct net_device *ndev) in ravb_emac_init() argument
603 struct ravb_private *priv = netdev_priv(ndev); in ravb_emac_init()
606 info->emac_init(ndev); in ravb_emac_init()
609 static int ravb_dmac_init_gbeth(struct net_device *ndev) in ravb_dmac_init_gbeth() argument
611 struct ravb_private *priv = netdev_priv(ndev); in ravb_dmac_init_gbeth()
614 error = ravb_ring_init(ndev, RAVB_BE); in ravb_dmac_init_gbeth()
619 ravb_ring_format(ndev, RAVB_BE); in ravb_dmac_init_gbeth()
622 ravb_write(ndev, 0x60000000, RCR); in ravb_dmac_init_gbeth()
625 ravb_write(ndev, 0x7ffc0000 | priv->info->rx_max_frame_size, RTC); in ravb_dmac_init_gbeth()
628 ravb_write(ndev, 0x00222200, TGC); in ravb_dmac_init_gbeth()
630 ravb_write(ndev, 0, TCCR); in ravb_dmac_init_gbeth()
633 ravb_write(ndev, RIC0_FRE0, RIC0); in ravb_dmac_init_gbeth()
635 ravb_write(ndev, 0x0, RIC1); in ravb_dmac_init_gbeth()
637 ravb_write(ndev, RIC2_QFE0 | RIC2_RFFE, RIC2); in ravb_dmac_init_gbeth()
639 ravb_write(ndev, TIC_FTE0, TIC); in ravb_dmac_init_gbeth()
644 static int ravb_dmac_init_rcar(struct net_device *ndev) in ravb_dmac_init_rcar() argument
646 struct ravb_private *priv = netdev_priv(ndev); in ravb_dmac_init_rcar()
650 error = ravb_ring_init(ndev, RAVB_BE); in ravb_dmac_init_rcar()
653 error = ravb_ring_init(ndev, RAVB_NC); in ravb_dmac_init_rcar()
655 ravb_ring_free(ndev, RAVB_BE); in ravb_dmac_init_rcar()
660 ravb_ring_format(ndev, RAVB_BE); in ravb_dmac_init_rcar()
661 ravb_ring_format(ndev, RAVB_NC); in ravb_dmac_init_rcar()
664 ravb_write(ndev, in ravb_dmac_init_rcar()
668 ravb_write(ndev, TGC_TQP_AVBMODE1 | 0x00112200, TGC); in ravb_dmac_init_rcar()
671 ravb_write(ndev, TCCR_TFEN, TCCR); in ravb_dmac_init_rcar()
676 ravb_write(ndev, 0, DIL); in ravb_dmac_init_rcar()
678 ravb_write(ndev, CIE_CRIE | CIE_CTIE | CIE_CL0M, CIE); in ravb_dmac_init_rcar()
681 ravb_write(ndev, RIC0_FRE0 | RIC0_FRE1, RIC0); in ravb_dmac_init_rcar()
683 ravb_write(ndev, 0, RIC1); in ravb_dmac_init_rcar()
685 ravb_write(ndev, RIC2_QFE0 | RIC2_QFE1 | RIC2_RFFE, RIC2); in ravb_dmac_init_rcar()
687 ravb_write(ndev, TIC_FTE0 | TIC_FTE1 | TIC_TFUE, TIC); in ravb_dmac_init_rcar()
693 static int ravb_dmac_init(struct net_device *ndev) in ravb_dmac_init() argument
695 struct ravb_private *priv = netdev_priv(ndev); in ravb_dmac_init()
700 error = ravb_set_opmode(ndev, CCC_OPC_CONFIG); in ravb_dmac_init()
704 error = info->dmac_init(ndev); in ravb_dmac_init()
709 return ravb_set_opmode(ndev, CCC_OPC_OPERATION); in ravb_dmac_init()
712 static void ravb_get_tx_tstamp(struct net_device *ndev) in ravb_get_tx_tstamp() argument
714 struct ravb_private *priv = netdev_priv(ndev); in ravb_get_tx_tstamp()
723 count = (ravb_read(ndev, TSR) & TSR_TFFL) >> 8; in ravb_get_tx_tstamp()
725 tfa2 = ravb_read(ndev, TFA2); in ravb_get_tx_tstamp()
727 ts.tv_nsec = (u64)ravb_read(ndev, TFA0); in ravb_get_tx_tstamp()
729 ravb_read(ndev, TFA1); in ravb_get_tx_tstamp()
746 ravb_modify(ndev, TCCR, TCCR_TFR, TCCR_TFR); in ravb_get_tx_tstamp()
804 static int ravb_rx_gbeth(struct net_device *ndev, int budget, int q) in ravb_rx_gbeth() argument
806 struct ravb_private *priv = netdev_priv(ndev); in ravb_rx_gbeth()
857 dma_sync_single_for_cpu(ndev->dev.parent, in ravb_rx_gbeth()
925 skb->protocol = eth_type_trans(skb, ndev); in ravb_rx_gbeth()
926 if (ndev->features & NETIF_F_RXCSUM) in ravb_rx_gbeth()
945 priv->dirty_rx[q] += ravb_rx_ring_refill(ndev, q, in ravb_rx_gbeth()
954 static int ravb_rx_rcar(struct net_device *ndev, int budget, int q) in ravb_rx_rcar() argument
956 struct ravb_private *priv = netdev_priv(ndev); in ravb_rx_rcar()
1005 dma_sync_single_for_cpu(ndev->dev.parent, in ravb_rx_rcar()
1032 skb->protocol = eth_type_trans(skb, ndev); in ravb_rx_rcar()
1033 if (ndev->features & NETIF_F_RXCSUM) in ravb_rx_rcar()
1045 priv->dirty_rx[q] += ravb_rx_ring_refill(ndev, q, in ravb_rx_rcar()
1054 static int ravb_rx(struct net_device *ndev, int budget, int q) in ravb_rx() argument
1056 struct ravb_private *priv = netdev_priv(ndev); in ravb_rx()
1059 return info->receive(ndev, budget, q); in ravb_rx()
1062 static void ravb_rcv_snd_disable(struct net_device *ndev) in ravb_rcv_snd_disable() argument
1065 ravb_modify(ndev, ECMR, ECMR_RE | ECMR_TE, 0); in ravb_rcv_snd_disable()
1068 static void ravb_rcv_snd_enable(struct net_device *ndev) in ravb_rcv_snd_enable() argument
1071 ravb_modify(ndev, ECMR, ECMR_RE | ECMR_TE, ECMR_RE | ECMR_TE); in ravb_rcv_snd_enable()
1075 static int ravb_stop_dma(struct net_device *ndev) in ravb_stop_dma() argument
1077 struct ravb_private *priv = netdev_priv(ndev); in ravb_stop_dma()
1082 error = ravb_wait(ndev, TCCR, info->tccr_mask, 0); in ravb_stop_dma()
1087 error = ravb_wait(ndev, CSR, CSR_TPO0 | CSR_TPO1 | CSR_TPO2 | CSR_TPO3, in ravb_stop_dma()
1093 ravb_rcv_snd_disable(ndev); in ravb_stop_dma()
1096 error = ravb_wait(ndev, CSR, CSR_RPO, 0); in ravb_stop_dma()
1101 return ravb_set_opmode(ndev, CCC_OPC_CONFIG); in ravb_stop_dma()
1105 static void ravb_emac_interrupt_unlocked(struct net_device *ndev) in ravb_emac_interrupt_unlocked() argument
1107 struct ravb_private *priv = netdev_priv(ndev); in ravb_emac_interrupt_unlocked()
1110 ecsr = ravb_read(ndev, ECSR); in ravb_emac_interrupt_unlocked()
1111 ravb_write(ndev, ecsr, ECSR); /* clear interrupt */ in ravb_emac_interrupt_unlocked()
1116 ndev->stats.tx_carrier_errors++; in ravb_emac_interrupt_unlocked()
1121 psr = ravb_read(ndev, PSR); in ravb_emac_interrupt_unlocked()
1126 ravb_rcv_snd_disable(ndev); in ravb_emac_interrupt_unlocked()
1129 ravb_rcv_snd_enable(ndev); in ravb_emac_interrupt_unlocked()
1136 struct net_device *ndev = dev_id; in ravb_emac_interrupt() local
1137 struct ravb_private *priv = netdev_priv(ndev); in ravb_emac_interrupt()
1149 ravb_emac_interrupt_unlocked(ndev); in ravb_emac_interrupt()
1158 static void ravb_error_interrupt(struct net_device *ndev) in ravb_error_interrupt() argument
1160 struct ravb_private *priv = netdev_priv(ndev); in ravb_error_interrupt()
1163 eis = ravb_read(ndev, EIS); in ravb_error_interrupt()
1164 ravb_write(ndev, ~(EIS_QFS | EIS_RESERVED), EIS); in ravb_error_interrupt()
1166 ris2 = ravb_read(ndev, RIS2); in ravb_error_interrupt()
1167 ravb_write(ndev, ~(RIS2_QFF0 | RIS2_QFF1 | RIS2_RFFF | RIS2_RESERVED), in ravb_error_interrupt()
1184 static bool ravb_queue_interrupt(struct net_device *ndev, int q) in ravb_queue_interrupt() argument
1186 struct ravb_private *priv = netdev_priv(ndev); in ravb_queue_interrupt()
1188 u32 ris0 = ravb_read(ndev, RIS0); in ravb_queue_interrupt()
1189 u32 ric0 = ravb_read(ndev, RIC0); in ravb_queue_interrupt()
1190 u32 tis = ravb_read(ndev, TIS); in ravb_queue_interrupt()
1191 u32 tic = ravb_read(ndev, TIC); in ravb_queue_interrupt()
1197 ravb_write(ndev, ric0 & ~BIT(q), RIC0); in ravb_queue_interrupt()
1198 ravb_write(ndev, tic & ~BIT(q), TIC); in ravb_queue_interrupt()
1200 ravb_write(ndev, BIT(q), RID0); in ravb_queue_interrupt()
1201 ravb_write(ndev, BIT(q), TID); in ravb_queue_interrupt()
1205 netdev_warn(ndev, in ravb_queue_interrupt()
1208 netdev_warn(ndev, in ravb_queue_interrupt()
1217 static bool ravb_timestamp_interrupt(struct net_device *ndev) in ravb_timestamp_interrupt() argument
1219 u32 tis = ravb_read(ndev, TIS); in ravb_timestamp_interrupt()
1222 ravb_write(ndev, ~(TIS_TFUF | TIS_RESERVED), TIS); in ravb_timestamp_interrupt()
1223 ravb_get_tx_tstamp(ndev); in ravb_timestamp_interrupt()
1231 struct net_device *ndev = dev_id; in ravb_interrupt() local
1232 struct ravb_private *priv = netdev_priv(ndev); in ravb_interrupt()
1245 iss = ravb_read(ndev, ISS); in ravb_interrupt()
1252 if (ravb_timestamp_interrupt(ndev)) in ravb_interrupt()
1258 if (ravb_queue_interrupt(ndev, q)) in ravb_interrupt()
1262 if (ravb_queue_interrupt(ndev, RAVB_BE)) in ravb_interrupt()
1269 ravb_emac_interrupt_unlocked(ndev); in ravb_interrupt()
1275 ravb_error_interrupt(ndev); in ravb_interrupt()
1281 ravb_ptp_interrupt(ndev); in ravb_interrupt()
1295 struct net_device *ndev = dev_id; in ravb_multi_interrupt() local
1296 struct ravb_private *priv = netdev_priv(ndev); in ravb_multi_interrupt()
1308 iss = ravb_read(ndev, ISS); in ravb_multi_interrupt()
1311 if ((iss & ISS_TFUS) && ravb_timestamp_interrupt(ndev)) in ravb_multi_interrupt()
1316 ravb_error_interrupt(ndev); in ravb_multi_interrupt()
1322 ravb_ptp_interrupt(ndev); in ravb_multi_interrupt()
1335 struct net_device *ndev = dev_id; in ravb_dma_interrupt() local
1336 struct ravb_private *priv = netdev_priv(ndev); in ravb_dma_interrupt()
1348 if (ravb_queue_interrupt(ndev, q)) in ravb_dma_interrupt()
1370 struct net_device *ndev = napi->dev; in ravb_poll() local
1371 struct ravb_private *priv = netdev_priv(ndev); in ravb_poll()
1380 ravb_write(ndev, ~(mask | RIS0_RESERVED), RIS0); in ravb_poll()
1381 work_done = ravb_rx(ndev, budget, q); in ravb_poll()
1386 ravb_write(ndev, ~(mask | TIS_RESERVED), TIS); in ravb_poll()
1387 ravb_tx_free(ndev, q, true); in ravb_poll()
1388 netif_wake_subqueue(ndev, q); in ravb_poll()
1395 if (priv->rx_over_errors != ndev->stats.rx_over_errors) in ravb_poll()
1396 ndev->stats.rx_over_errors = priv->rx_over_errors; in ravb_poll()
1397 if (priv->rx_fifo_errors != ndev->stats.rx_fifo_errors) in ravb_poll()
1398 ndev->stats.rx_fifo_errors = priv->rx_fifo_errors; in ravb_poll()
1404 ravb_modify(ndev, RIC0, mask, mask); in ravb_poll()
1405 ravb_modify(ndev, TIC, mask, mask); in ravb_poll()
1407 ravb_write(ndev, mask, RIE0); in ravb_poll()
1408 ravb_write(ndev, mask, TIE); in ravb_poll()
1416 static void ravb_set_duplex_gbeth(struct net_device *ndev) in ravb_set_duplex_gbeth() argument
1418 struct ravb_private *priv = netdev_priv(ndev); in ravb_set_duplex_gbeth()
1420 ravb_modify(ndev, ECMR, ECMR_DM, priv->duplex > 0 ? ECMR_DM : 0); in ravb_set_duplex_gbeth()
1424 static void ravb_adjust_link(struct net_device *ndev) in ravb_adjust_link() argument
1426 struct ravb_private *priv = netdev_priv(ndev); in ravb_adjust_link()
1428 struct phy_device *phydev = ndev->phydev; in ravb_adjust_link()
1436 ravb_rcv_snd_disable(ndev); in ravb_adjust_link()
1442 ravb_set_duplex_gbeth(ndev); in ravb_adjust_link()
1448 info->set_rate(ndev); in ravb_adjust_link()
1451 ravb_modify(ndev, ECMR, ECMR_TXF, 0); in ravb_adjust_link()
1465 ravb_rcv_snd_enable(ndev); in ravb_adjust_link()
1474 static int ravb_phy_init(struct net_device *ndev) in ravb_phy_init() argument
1476 struct device_node *np = ndev->dev.parent->of_node; in ravb_phy_init()
1477 struct ravb_private *priv = netdev_priv(ndev); in ravb_phy_init()
1504 phydev = of_phy_connect(ndev, pn, ravb_adjust_link, 0, iface); in ravb_phy_init()
1507 netdev_err(ndev, "failed to connect PHY\n"); in ravb_phy_init()
1536 static int ravb_phy_start(struct net_device *ndev) in ravb_phy_start() argument
1540 error = ravb_phy_init(ndev); in ravb_phy_start()
1544 phy_start(ndev->phydev); in ravb_phy_start()
1549 static u32 ravb_get_msglevel(struct net_device *ndev) in ravb_get_msglevel() argument
1551 struct ravb_private *priv = netdev_priv(ndev); in ravb_get_msglevel()
1556 static void ravb_set_msglevel(struct net_device *ndev, u32 value) in ravb_set_msglevel() argument
1558 struct ravb_private *priv = netdev_priv(ndev); in ravb_set_msglevel()
1628 static void ravb_get_ethtool_stats(struct net_device *ndev, in ravb_get_ethtool_stats() argument
1631 struct ravb_private *priv = netdev_priv(ndev); in ravb_get_ethtool_stats()
1660 static void ravb_get_strings(struct net_device *ndev, u32 stringset, u8 *data) in ravb_get_strings() argument
1662 struct ravb_private *priv = netdev_priv(ndev); in ravb_get_strings()
1672 static void ravb_get_ringparam(struct net_device *ndev, in ravb_get_ringparam() argument
1677 struct ravb_private *priv = netdev_priv(ndev); in ravb_get_ringparam()
1685 static int ravb_set_ringparam(struct net_device *ndev, in ravb_set_ringparam() argument
1690 struct ravb_private *priv = netdev_priv(ndev); in ravb_set_ringparam()
1702 if (netif_running(ndev)) { in ravb_set_ringparam()
1703 netif_device_detach(ndev); in ravb_set_ringparam()
1706 ravb_ptp_stop(ndev); in ravb_set_ringparam()
1708 error = ravb_stop_dma(ndev); in ravb_set_ringparam()
1710 netdev_err(ndev, in ravb_set_ringparam()
1714 synchronize_irq(ndev->irq); in ravb_set_ringparam()
1717 ravb_ring_free(ndev, RAVB_BE); in ravb_set_ringparam()
1719 ravb_ring_free(ndev, RAVB_NC); in ravb_set_ringparam()
1726 if (netif_running(ndev)) { in ravb_set_ringparam()
1727 error = ravb_dmac_init(ndev); in ravb_set_ringparam()
1729 netdev_err(ndev, in ravb_set_ringparam()
1735 ravb_emac_init(ndev); in ravb_set_ringparam()
1739 ravb_ptp_init(ndev, priv->pdev); in ravb_set_ringparam()
1741 netif_device_attach(ndev); in ravb_set_ringparam()
1747 static int ravb_get_ts_info(struct net_device *ndev, in ravb_get_ts_info() argument
1750 struct ravb_private *priv = netdev_priv(ndev); in ravb_get_ts_info()
1770 static void ravb_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol) in ravb_get_wol() argument
1772 struct ravb_private *priv = netdev_priv(ndev); in ravb_get_wol()
1778 static int ravb_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol) in ravb_set_wol() argument
1780 struct ravb_private *priv = netdev_priv(ndev); in ravb_set_wol()
1810 static int ravb_set_config_mode(struct net_device *ndev) in ravb_set_config_mode() argument
1812 struct ravb_private *priv = netdev_priv(ndev); in ravb_set_config_mode()
1817 error = ravb_set_opmode(ndev, CCC_OPC_CONFIG); in ravb_set_config_mode()
1821 ravb_modify(ndev, CCC, CCC_CSEL, CCC_CSEL_HPB); in ravb_set_config_mode()
1823 error = ravb_set_opmode(ndev, CCC_OPC_CONFIG | CCC_GAC | CCC_CSEL_HPB); in ravb_set_config_mode()
1825 error = ravb_set_opmode(ndev, CCC_OPC_CONFIG); in ravb_set_config_mode()
1831 static void ravb_set_gti(struct net_device *ndev) in ravb_set_gti() argument
1833 struct ravb_private *priv = netdev_priv(ndev); in ravb_set_gti()
1839 ravb_write(ndev, priv->gti_tiv, GTI); in ravb_set_gti()
1842 ravb_modify(ndev, GCCR, GCCR_LTI, GCCR_LTI); in ravb_set_gti()
1845 static int ravb_compute_gti(struct net_device *ndev) in ravb_compute_gti() argument
1847 struct ravb_private *priv = netdev_priv(ndev); in ravb_compute_gti()
1849 struct device *dev = ndev->dev.parent; in ravb_compute_gti()
1876 static void ravb_parse_delay_mode(struct device_node *np, struct net_device *ndev) in ravb_parse_delay_mode() argument
1878 struct ravb_private *priv = netdev_priv(ndev); in ravb_parse_delay_mode()
1913 static void ravb_set_delay_mode(struct net_device *ndev) in ravb_set_delay_mode() argument
1915 struct ravb_private *priv = netdev_priv(ndev); in ravb_set_delay_mode()
1925 ravb_modify(ndev, APSR, APSR_RDM | APSR_TDM, set); in ravb_set_delay_mode()
1929 static int ravb_open(struct net_device *ndev) in ravb_open() argument
1931 struct ravb_private *priv = netdev_priv(ndev); in ravb_open()
1945 error = ravb_set_config_mode(ndev); in ravb_open()
1949 ravb_set_delay_mode(ndev); in ravb_open()
1950 ravb_write(ndev, priv->desc_bat_dma, DBAT); in ravb_open()
1953 error = ravb_dmac_init(ndev); in ravb_open()
1957 ravb_emac_init(ndev); in ravb_open()
1959 ravb_set_gti(ndev); in ravb_open()
1963 ravb_ptp_init(ndev, priv->pdev); in ravb_open()
1966 error = ravb_phy_start(ndev); in ravb_open()
1970 netif_tx_start_all_queues(ndev); in ravb_open()
1977 ravb_ptp_stop(ndev); in ravb_open()
1978 ravb_stop_dma(ndev); in ravb_open()
1980 ravb_set_opmode(ndev, CCC_OPC_RESET); in ravb_open()
1992 static void ravb_tx_timeout(struct net_device *ndev, unsigned int txqueue) in ravb_tx_timeout() argument
1994 struct ravb_private *priv = netdev_priv(ndev); in ravb_tx_timeout()
1996 netif_err(priv, tx_err, ndev, in ravb_tx_timeout()
1998 ravb_read(ndev, ISS)); in ravb_tx_timeout()
2001 ndev->stats.tx_errors++; in ravb_tx_timeout()
2011 struct net_device *ndev = priv->ndev; in ravb_tx_timeout_work() local
2020 netif_tx_stop_all_queues(ndev); in ravb_tx_timeout_work()
2024 ravb_ptp_stop(ndev); in ravb_tx_timeout_work()
2027 if (ravb_stop_dma(ndev)) { in ravb_tx_timeout_work()
2036 ravb_rcv_snd_enable(ndev); in ravb_tx_timeout_work()
2040 ravb_ring_free(ndev, RAVB_BE); in ravb_tx_timeout_work()
2042 ravb_ring_free(ndev, RAVB_NC); in ravb_tx_timeout_work()
2045 error = ravb_dmac_init(ndev); in ravb_tx_timeout_work()
2051 netdev_err(ndev, "%s: ravb_dmac_init() failed, error %d\n", in ravb_tx_timeout_work()
2055 ravb_emac_init(ndev); in ravb_tx_timeout_work()
2060 ravb_ptp_init(ndev, priv->pdev); in ravb_tx_timeout_work()
2062 netif_tx_start_all_queues(ndev); in ravb_tx_timeout_work()
2099 static netdev_tx_t ravb_start_xmit(struct sk_buff *skb, struct net_device *ndev) in ravb_start_xmit() argument
2101 struct ravb_private *priv = netdev_priv(ndev); in ravb_start_xmit()
2119 netif_err(priv, tx_queued, ndev, in ravb_start_xmit()
2121 netif_stop_subqueue(ndev, q); in ravb_start_xmit()
2153 dma_addr = dma_map_single(ndev->dev.parent, buffer, len, in ravb_start_xmit()
2155 if (dma_mapping_error(ndev->dev.parent, dma_addr)) in ravb_start_xmit()
2164 dma_addr = dma_map_single(ndev->dev.parent, buffer, len, in ravb_start_xmit()
2166 if (dma_mapping_error(ndev->dev.parent, dma_addr)) in ravb_start_xmit()
2173 dma_addr = dma_map_single(ndev->dev.parent, skb->data, skb->len, in ravb_start_xmit()
2175 if (dma_mapping_error(ndev->dev.parent, dma_addr)) in ravb_start_xmit()
2188 dma_unmap_single(ndev->dev.parent, dma_addr, in ravb_start_xmit()
2215 ravb_modify(ndev, TCCR, TCCR_TSRQ0 << q, TCCR_TSRQ0 << q); in ravb_start_xmit()
2220 !ravb_tx_free(ndev, q, true)) in ravb_start_xmit()
2221 netif_stop_subqueue(ndev, q); in ravb_start_xmit()
2228 dma_unmap_single(ndev->dev.parent, le32_to_cpu(desc->dptr), in ravb_start_xmit()
2236 static u16 ravb_select_queue(struct net_device *ndev, struct sk_buff *skb, in ravb_select_queue() argument
2245 static struct net_device_stats *ravb_get_stats(struct net_device *ndev) in ravb_get_stats() argument
2247 struct ravb_private *priv = netdev_priv(ndev); in ravb_get_stats()
2252 nstats = &ndev->stats; in ravb_get_stats()
2262 nstats->tx_dropped += ravb_read(ndev, TROCR); in ravb_get_stats()
2263 ravb_write(ndev, 0, TROCR); /* (write clear) */ in ravb_get_stats()
2267 nstats->collisions += ravb_read(ndev, CXR41); in ravb_get_stats()
2268 ravb_write(ndev, 0, CXR41); /* (write clear) */ in ravb_get_stats()
2269 nstats->tx_carrier_errors += ravb_read(ndev, CXR42); in ravb_get_stats()
2270 ravb_write(ndev, 0, CXR42); /* (write clear) */ in ravb_get_stats()
2306 static void ravb_set_rx_mode(struct net_device *ndev) in ravb_set_rx_mode() argument
2308 struct ravb_private *priv = netdev_priv(ndev); in ravb_set_rx_mode()
2312 ravb_modify(ndev, ECMR, ECMR_PRM, in ravb_set_rx_mode()
2313 ndev->flags & IFF_PROMISC ? ECMR_PRM : 0); in ravb_set_rx_mode()
2318 static int ravb_close(struct net_device *ndev) in ravb_close() argument
2320 struct device_node *np = ndev->dev.parent->of_node; in ravb_close()
2321 struct ravb_private *priv = netdev_priv(ndev); in ravb_close()
2327 netif_tx_stop_all_queues(ndev); in ravb_close()
2330 ravb_write(ndev, 0, RIC0); in ravb_close()
2331 ravb_write(ndev, 0, RIC2); in ravb_close()
2332 ravb_write(ndev, 0, TIC); in ravb_close()
2335 if (ndev->phydev) { in ravb_close()
2336 phy_stop(ndev->phydev); in ravb_close()
2337 phy_disconnect(ndev->phydev); in ravb_close()
2344 ravb_ptp_stop(ndev); in ravb_close()
2347 if (ravb_stop_dma(ndev) < 0) in ravb_close()
2348 netdev_err(ndev, in ravb_close()
2367 ravb_ring_free(ndev, RAVB_BE); in ravb_close()
2369 ravb_ring_free(ndev, RAVB_NC); in ravb_close()
2372 ravb_get_stats(ndev); in ravb_close()
2375 error = ravb_set_opmode(ndev, CCC_OPC_RESET); in ravb_close()
2385 static int ravb_hwtstamp_get(struct net_device *ndev, struct ifreq *req) in ravb_hwtstamp_get() argument
2387 struct ravb_private *priv = netdev_priv(ndev); in ravb_hwtstamp_get()
2409 static int ravb_hwtstamp_set(struct net_device *ndev, struct ifreq *req) in ravb_hwtstamp_set() argument
2411 struct ravb_private *priv = netdev_priv(ndev); in ravb_hwtstamp_set()
2450 static int ravb_do_ioctl(struct net_device *ndev, struct ifreq *req, int cmd) in ravb_do_ioctl() argument
2452 struct phy_device *phydev = ndev->phydev; in ravb_do_ioctl()
2454 if (!netif_running(ndev)) in ravb_do_ioctl()
2462 return ravb_hwtstamp_get(ndev, req); in ravb_do_ioctl()
2464 return ravb_hwtstamp_set(ndev, req); in ravb_do_ioctl()
2470 static int ravb_change_mtu(struct net_device *ndev, int new_mtu) in ravb_change_mtu() argument
2472 struct ravb_private *priv = netdev_priv(ndev); in ravb_change_mtu()
2474 WRITE_ONCE(ndev->mtu, new_mtu); in ravb_change_mtu()
2476 if (netif_running(ndev)) { in ravb_change_mtu()
2478 ravb_emac_init(ndev); in ravb_change_mtu()
2481 netdev_update_features(ndev); in ravb_change_mtu()
2486 static void ravb_set_rx_csum(struct net_device *ndev, bool enable) in ravb_set_rx_csum() argument
2488 struct ravb_private *priv = netdev_priv(ndev); in ravb_set_rx_csum()
2494 ravb_rcv_snd_disable(ndev); in ravb_set_rx_csum()
2497 ravb_modify(ndev, ECMR, ECMR_RCSC, enable ? ECMR_RCSC : 0); in ravb_set_rx_csum()
2500 ravb_rcv_snd_enable(ndev); in ravb_set_rx_csum()
2505 static int ravb_endisable_csum_gbeth(struct net_device *ndev, enum ravb_reg reg, in ravb_endisable_csum_gbeth() argument
2511 ravb_write(ndev, csr0 & ~mask, CSR0); in ravb_endisable_csum_gbeth()
2512 ret = ravb_wait(ndev, CSR0, mask, 0); in ravb_endisable_csum_gbeth()
2514 ravb_write(ndev, val, reg); in ravb_endisable_csum_gbeth()
2516 ravb_write(ndev, csr0, CSR0); in ravb_endisable_csum_gbeth()
2521 static int ravb_set_features_gbeth(struct net_device *ndev, in ravb_set_features_gbeth() argument
2524 netdev_features_t changed = ndev->features ^ features; in ravb_set_features_gbeth()
2525 struct ravb_private *priv = netdev_priv(ndev); in ravb_set_features_gbeth()
2537 ret = ravb_endisable_csum_gbeth(ndev, CSR2, val, CSR0_RPE); in ravb_set_features_gbeth()
2548 ret = ravb_endisable_csum_gbeth(ndev, CSR1, val, CSR0_TPE); in ravb_set_features_gbeth()
2559 static int ravb_set_features_rcar(struct net_device *ndev, in ravb_set_features_rcar() argument
2562 netdev_features_t changed = ndev->features ^ features; in ravb_set_features_rcar()
2565 ravb_set_rx_csum(ndev, features & NETIF_F_RXCSUM); in ravb_set_features_rcar()
2570 static int ravb_set_features(struct net_device *ndev, in ravb_set_features() argument
2573 struct ravb_private *priv = netdev_priv(ndev); in ravb_set_features()
2581 ret = info->set_feature(ndev, features); in ravb_set_features()
2590 ndev->features = features; in ravb_set_features()
2811 struct net_device *ndev = priv->ndev; in ravb_setup_irq() local
2834 error = devm_request_irq(dev, irq_num, handler, flags, devname, ndev); in ravb_setup_irq()
2836 netdev_err(ndev, "cannot request IRQ %s\n", devname); in ravb_setup_irq()
2844 struct net_device *ndev = priv->ndev; in ravb_setup_irqs() local
2849 return ravb_setup_irq(priv, NULL, NULL, &ndev->irq, ravb_interrupt); in ravb_setup_irqs()
2859 error = ravb_setup_irq(priv, irq_name, "ch22:multi", &ndev->irq, ravb_multi_interrupt); in ravb_setup_irqs()
2899 struct net_device *ndev; in ravb_probe() local
2914 ndev = alloc_etherdev_mqs(sizeof(struct ravb_private), in ravb_probe()
2916 if (!ndev) in ravb_probe()
2921 ndev->features = info->net_features; in ravb_probe()
2922 ndev->hw_features = info->net_hw_features; in ravb_probe()
2928 SET_NETDEV_DEV(ndev, &pdev->dev); in ravb_probe()
2930 priv = netdev_priv(ndev); in ravb_probe()
2933 priv->ndev = ndev; in ravb_probe()
2967 platform_set_drvdata(pdev, ndev); in ravb_probe()
2982 ndev->base_addr = res->start; in ravb_probe()
2995 ndev->max_mtu = info->tx_max_frame_size - in ravb_probe()
2997 ndev->min_mtu = ETH_MIN_MTU; in ravb_probe()
3007 ndev->netdev_ops = &ravb_netdev_ops; in ravb_probe()
3008 ndev->ethtool_ops = &ravb_ethtool_ops; in ravb_probe()
3010 error = ravb_compute_gti(ndev); in ravb_probe()
3014 ravb_parse_delay_mode(np, ndev); in ravb_probe()
3018 priv->desc_bat = dma_alloc_coherent(ndev->dev.parent, priv->desc_bat_size, in ravb_probe()
3037 error = ravb_set_opmode(ndev, CCC_OPC_CONFIG); in ravb_probe()
3042 ravb_read_mac_address(np, ndev); in ravb_probe()
3043 if (!is_valid_ether_addr(ndev->dev_addr)) { in ravb_probe()
3046 eth_hw_addr_random(ndev); in ravb_probe()
3057 error = ravb_set_opmode(ndev, CCC_OPC_RESET); in ravb_probe()
3061 netif_napi_add(ndev, &priv->napi[RAVB_BE], ravb_poll); in ravb_probe()
3063 netif_napi_add(ndev, &priv->napi[RAVB_NC], ravb_poll); in ravb_probe()
3066 netdev_sw_irq_coalesce_default_on(ndev); in ravb_probe()
3068 dev_set_threaded(ndev, true); in ravb_probe()
3072 error = register_netdev(ndev); in ravb_probe()
3079 netdev_info(ndev, "Base address at %#x, %pM, IRQ %d.\n", in ravb_probe()
3080 (u32)ndev->base_addr, ndev->dev_addr, ndev->irq); in ravb_probe()
3095 ravb_set_opmode(ndev, CCC_OPC_RESET); in ravb_probe()
3096 dma_free_coherent(ndev->dev.parent, priv->desc_bat_size, priv->desc_bat, in ravb_probe()
3107 free_netdev(ndev); in ravb_probe()
3113 struct net_device *ndev = platform_get_drvdata(pdev); in ravb_remove() local
3114 struct ravb_private *priv = netdev_priv(ndev); in ravb_remove()
3123 unregister_netdev(ndev); in ravb_remove()
3130 dma_free_coherent(ndev->dev.parent, priv->desc_bat_size, priv->desc_bat, in ravb_remove()
3138 free_netdev(ndev); in ravb_remove()
3142 static int ravb_wol_setup(struct net_device *ndev) in ravb_wol_setup() argument
3144 struct ravb_private *priv = netdev_priv(ndev); in ravb_wol_setup()
3148 ravb_write(ndev, 0, RIC0); in ravb_wol_setup()
3149 ravb_write(ndev, 0, RIC2); in ravb_wol_setup()
3150 ravb_write(ndev, 0, TIC); in ravb_wol_setup()
3157 ravb_write(ndev, ECSIPR_MPDIP, ECSIPR); in ravb_wol_setup()
3160 ravb_modify(ndev, ECMR, ECMR_MPDE, ECMR_MPDE); in ravb_wol_setup()
3163 ravb_ptp_stop(ndev); in ravb_wol_setup()
3168 static int ravb_wol_restore(struct net_device *ndev) in ravb_wol_restore() argument
3170 struct ravb_private *priv = netdev_priv(ndev); in ravb_wol_restore()
3175 error = ravb_set_opmode(ndev, CCC_OPC_RESET); in ravb_wol_restore()
3180 error = ravb_set_config_mode(ndev); in ravb_wol_restore()
3185 ravb_ptp_init(ndev, priv->pdev); in ravb_wol_restore()
3192 ravb_modify(ndev, ECMR, ECMR_MPDE, 0); in ravb_wol_restore()
3194 ravb_close(ndev); in ravb_wol_restore()
3201 struct net_device *ndev = dev_get_drvdata(dev); in ravb_suspend() local
3202 struct ravb_private *priv = netdev_priv(ndev); in ravb_suspend()
3205 if (!netif_running(ndev)) in ravb_suspend()
3208 netif_device_detach(ndev); in ravb_suspend()
3211 return ravb_wol_setup(ndev); in ravb_suspend()
3213 ret = ravb_close(ndev); in ravb_suspend()
3227 struct net_device *ndev = dev_get_drvdata(dev); in ravb_resume() local
3228 struct ravb_private *priv = netdev_priv(ndev); in ravb_resume()
3235 if (!netif_running(ndev)) in ravb_resume()
3240 ret = ravb_wol_restore(ndev); in ravb_resume()
3250 ret = ravb_open(ndev); in ravb_resume()
3254 ravb_set_rx_mode(ndev); in ravb_resume()
3255 netif_device_attach(ndev); in ravb_resume()
3270 struct net_device *ndev = dev_get_drvdata(dev); in ravb_runtime_suspend() local
3271 struct ravb_private *priv = netdev_priv(ndev); in ravb_runtime_suspend()
3280 struct net_device *ndev = dev_get_drvdata(dev); in ravb_runtime_resume() local
3281 struct ravb_private *priv = netdev_priv(ndev); in ravb_runtime_resume()