Lines Matching refs:ndev
53 void ravb_modify(struct net_device *ndev, enum ravb_reg reg, u32 clear, in ravb_modify() argument
56 ravb_write(ndev, (ravb_read(ndev, reg) & ~clear) | set, reg); in ravb_modify()
59 int ravb_wait(struct net_device *ndev, enum ravb_reg reg, u32 mask, u32 value) in ravb_wait() argument
64 if ((ravb_read(ndev, reg) & mask) == value) in ravb_wait()
71 static int ravb_config(struct net_device *ndev) in ravb_config() argument
76 ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_CONFIG); in ravb_config()
78 error = ravb_wait(ndev, CSR, CSR_OPS, CSR_OPS_CONFIG); in ravb_config()
80 netdev_err(ndev, "failed to switch device to config mode\n"); in ravb_config()
85 static void ravb_set_rate(struct net_device *ndev) in ravb_set_rate() argument
87 struct ravb_private *priv = netdev_priv(ndev); in ravb_set_rate()
91 ravb_write(ndev, GECMR_SPEED_100, GECMR); in ravb_set_rate()
94 ravb_write(ndev, GECMR_SPEED_1000, GECMR); in ravb_set_rate()
112 static void ravb_read_mac_address(struct net_device *ndev, const u8 *mac) in ravb_read_mac_address() argument
115 ether_addr_copy(ndev->dev_addr, mac); in ravb_read_mac_address()
117 u32 mahr = ravb_read(ndev, MAHR); in ravb_read_mac_address()
118 u32 malr = ravb_read(ndev, MALR); 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()
174 static int ravb_tx_free(struct net_device *ndev, int q, bool free_txed_only) in ravb_tx_free() argument
176 struct ravb_private *priv = netdev_priv(ndev); in ravb_tx_free()
198 dma_unmap_single(ndev->dev.parent, le32_to_cpu(desc->dptr), in ravb_tx_free()
218 static void ravb_ring_free(struct net_device *ndev, int q) in ravb_ring_free() argument
220 struct ravb_private *priv = netdev_priv(ndev); in ravb_ring_free()
229 if (!dma_mapping_error(ndev->dev.parent, in ravb_ring_free()
231 dma_unmap_single(ndev->dev.parent, in ravb_ring_free()
238 dma_free_coherent(ndev->dev.parent, ring_size, priv->rx_ring[q], in ravb_ring_free()
244 ravb_tx_free(ndev, q, false); in ravb_ring_free()
248 dma_free_coherent(ndev->dev.parent, ring_size, priv->tx_ring[q], in ravb_ring_free()
273 static void ravb_ring_format(struct net_device *ndev, int q) in ravb_ring_format() argument
275 struct ravb_private *priv = netdev_priv(ndev); 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()
337 static int ravb_ring_init(struct net_device *ndev, int q) in ravb_ring_init() argument
339 struct ravb_private *priv = netdev_priv(ndev); in ravb_ring_init()
354 skb = netdev_alloc_skb(ndev, RX_BUF_SZ + RAVB_ALIGN - 1); in ravb_ring_init()
371 priv->rx_ring[q] = dma_alloc_coherent(ndev->dev.parent, ring_size, in ravb_ring_init()
382 priv->tx_ring[q] = dma_alloc_coherent(ndev->dev.parent, ring_size, in ravb_ring_init()
391 ravb_ring_free(ndev, q); in ravb_ring_init()
397 static void ravb_emac_init(struct net_device *ndev) in ravb_emac_init() argument
400 ravb_write(ndev, ndev->mtu + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN, RFLR); in ravb_emac_init()
403 ravb_write(ndev, ECMR_ZPF | ECMR_DM | in ravb_emac_init()
404 (ndev->features & NETIF_F_RXCSUM ? ECMR_RCSC : 0) | in ravb_emac_init()
407 ravb_set_rate(ndev); in ravb_emac_init()
410 ravb_write(ndev, 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()
413 ravb_write(ndev, in ravb_emac_init()
414 (ndev->dev_addr[4] << 8) | (ndev->dev_addr[5]), MALR); in ravb_emac_init()
417 ravb_write(ndev, ECSR_ICD | ECSR_MPD, ECSR); in ravb_emac_init()
420 ravb_write(ndev, ECSIPR_ICDIP | ECSIPR_MPDIP | ECSIPR_LCHNGIP, ECSIPR); in ravb_emac_init()
424 static int ravb_dmac_init(struct net_device *ndev) in ravb_dmac_init() argument
426 struct ravb_private *priv = netdev_priv(ndev); in ravb_dmac_init()
430 error = ravb_config(ndev); in ravb_dmac_init()
434 error = ravb_ring_init(ndev, RAVB_BE); in ravb_dmac_init()
437 error = ravb_ring_init(ndev, RAVB_NC); in ravb_dmac_init()
439 ravb_ring_free(ndev, RAVB_BE); in ravb_dmac_init()
444 ravb_ring_format(ndev, RAVB_BE); in ravb_dmac_init()
445 ravb_ring_format(ndev, RAVB_NC); in ravb_dmac_init()
448 ravb_write(ndev, in ravb_dmac_init()
452 ravb_write(ndev, TGC_TQP_AVBMODE1 | 0x00112200, TGC); in ravb_dmac_init()
455 ravb_write(ndev, TCCR_TFEN, TCCR); in ravb_dmac_init()
460 ravb_write(ndev, 0, DIL); in ravb_dmac_init()
462 ravb_write(ndev, CIE_CRIE | CIE_CTIE | CIE_CL0M, CIE); in ravb_dmac_init()
465 ravb_write(ndev, RIC0_FRE0 | RIC0_FRE1, RIC0); in ravb_dmac_init()
467 ravb_write(ndev, 0, RIC1); in ravb_dmac_init()
469 ravb_write(ndev, RIC2_QFE0 | RIC2_QFE1 | RIC2_RFFE, RIC2); in ravb_dmac_init()
471 ravb_write(ndev, TIC_FTE0 | TIC_FTE1 | TIC_TFUE, TIC); in ravb_dmac_init()
474 ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_OPERATION); in ravb_dmac_init()
479 static void ravb_get_tx_tstamp(struct net_device *ndev) in ravb_get_tx_tstamp() argument
481 struct ravb_private *priv = netdev_priv(ndev); in ravb_get_tx_tstamp()
490 count = (ravb_read(ndev, TSR) & TSR_TFFL) >> 8; in ravb_get_tx_tstamp()
492 tfa2 = ravb_read(ndev, TFA2); in ravb_get_tx_tstamp()
494 ts.tv_nsec = (u64)ravb_read(ndev, TFA0); in ravb_get_tx_tstamp()
496 ravb_read(ndev, TFA1); in ravb_get_tx_tstamp()
513 ravb_modify(ndev, TCCR, TCCR_TFR, TCCR_TFR); in ravb_get_tx_tstamp()
533 static bool ravb_rx(struct net_device *ndev, int *quota, int q) in ravb_rx() argument
535 struct ravb_private *priv = netdev_priv(ndev); in ravb_rx()
583 dma_unmap_single(ndev->dev.parent, le32_to_cpu(desc->dptr), in ravb_rx()
601 skb->protocol = eth_type_trans(skb, ndev); in ravb_rx()
602 if (ndev->features & NETIF_F_RXCSUM) in ravb_rx()
620 skb = netdev_alloc_skb(ndev, in ravb_rx()
626 dma_addr = dma_map_single(ndev->dev.parent, skb->data, in ravb_rx()
633 if (dma_mapping_error(ndev->dev.parent, dma_addr)) in ravb_rx()
648 static void ravb_rcv_snd_disable(struct net_device *ndev) in ravb_rcv_snd_disable() argument
651 ravb_modify(ndev, ECMR, ECMR_RE | ECMR_TE, 0); in ravb_rcv_snd_disable()
654 static void ravb_rcv_snd_enable(struct net_device *ndev) in ravb_rcv_snd_enable() argument
657 ravb_modify(ndev, ECMR, ECMR_RE | ECMR_TE, ECMR_RE | ECMR_TE); in ravb_rcv_snd_enable()
661 static int ravb_stop_dma(struct net_device *ndev) in ravb_stop_dma() argument
666 error = ravb_wait(ndev, TCCR, in ravb_stop_dma()
671 error = ravb_wait(ndev, CSR, CSR_TPO0 | CSR_TPO1 | CSR_TPO2 | CSR_TPO3, in ravb_stop_dma()
677 ravb_rcv_snd_disable(ndev); in ravb_stop_dma()
680 error = ravb_wait(ndev, CSR, CSR_RPO, 0); in ravb_stop_dma()
685 return ravb_config(ndev); in ravb_stop_dma()
689 static void ravb_emac_interrupt_unlocked(struct net_device *ndev) in ravb_emac_interrupt_unlocked() argument
691 struct ravb_private *priv = netdev_priv(ndev); in ravb_emac_interrupt_unlocked()
694 ecsr = ravb_read(ndev, ECSR); in ravb_emac_interrupt_unlocked()
695 ravb_write(ndev, ecsr, ECSR); /* clear interrupt */ in ravb_emac_interrupt_unlocked()
700 ndev->stats.tx_carrier_errors++; in ravb_emac_interrupt_unlocked()
705 psr = ravb_read(ndev, PSR); in ravb_emac_interrupt_unlocked()
710 ravb_rcv_snd_disable(ndev); in ravb_emac_interrupt_unlocked()
713 ravb_rcv_snd_enable(ndev); in ravb_emac_interrupt_unlocked()
720 struct net_device *ndev = dev_id; in ravb_emac_interrupt() local
721 struct ravb_private *priv = netdev_priv(ndev); in ravb_emac_interrupt()
724 ravb_emac_interrupt_unlocked(ndev); in ravb_emac_interrupt()
730 static void ravb_error_interrupt(struct net_device *ndev) in ravb_error_interrupt() argument
732 struct ravb_private *priv = netdev_priv(ndev); in ravb_error_interrupt()
735 eis = ravb_read(ndev, EIS); in ravb_error_interrupt()
736 ravb_write(ndev, ~(EIS_QFS | EIS_RESERVED), EIS); in ravb_error_interrupt()
738 ris2 = ravb_read(ndev, RIS2); in ravb_error_interrupt()
739 ravb_write(ndev, ~(RIS2_QFF0 | RIS2_RFFF | RIS2_RESERVED), in ravb_error_interrupt()
756 static bool ravb_queue_interrupt(struct net_device *ndev, int q) in ravb_queue_interrupt() argument
758 struct ravb_private *priv = netdev_priv(ndev); in ravb_queue_interrupt()
759 u32 ris0 = ravb_read(ndev, RIS0); in ravb_queue_interrupt()
760 u32 ric0 = ravb_read(ndev, RIC0); in ravb_queue_interrupt()
761 u32 tis = ravb_read(ndev, TIS); in ravb_queue_interrupt()
762 u32 tic = ravb_read(ndev, TIC); in ravb_queue_interrupt()
768 ravb_write(ndev, ric0 & ~BIT(q), RIC0); in ravb_queue_interrupt()
769 ravb_write(ndev, tic & ~BIT(q), TIC); in ravb_queue_interrupt()
771 ravb_write(ndev, BIT(q), RID0); in ravb_queue_interrupt()
772 ravb_write(ndev, BIT(q), TID); in ravb_queue_interrupt()
776 netdev_warn(ndev, in ravb_queue_interrupt()
779 netdev_warn(ndev, in ravb_queue_interrupt()
788 static bool ravb_timestamp_interrupt(struct net_device *ndev) in ravb_timestamp_interrupt() argument
790 u32 tis = ravb_read(ndev, TIS); in ravb_timestamp_interrupt()
793 ravb_write(ndev, ~(TIS_TFUF | TIS_RESERVED), TIS); in ravb_timestamp_interrupt()
794 ravb_get_tx_tstamp(ndev); in ravb_timestamp_interrupt()
802 struct net_device *ndev = dev_id; in ravb_interrupt() local
803 struct ravb_private *priv = netdev_priv(ndev); in ravb_interrupt()
809 iss = ravb_read(ndev, ISS); in ravb_interrupt()
816 if (ravb_timestamp_interrupt(ndev)) in ravb_interrupt()
821 if (ravb_queue_interrupt(ndev, q)) in ravb_interrupt()
828 ravb_emac_interrupt_unlocked(ndev); in ravb_interrupt()
834 ravb_error_interrupt(ndev); in ravb_interrupt()
840 ravb_ptp_interrupt(ndev); in ravb_interrupt()
851 struct net_device *ndev = dev_id; in ravb_multi_interrupt() local
852 struct ravb_private *priv = netdev_priv(ndev); in ravb_multi_interrupt()
858 iss = ravb_read(ndev, ISS); in ravb_multi_interrupt()
861 if ((iss & ISS_TFUS) && ravb_timestamp_interrupt(ndev)) in ravb_multi_interrupt()
866 ravb_error_interrupt(ndev); in ravb_multi_interrupt()
872 ravb_ptp_interrupt(ndev); in ravb_multi_interrupt()
882 struct net_device *ndev = dev_id; in ravb_dma_interrupt() local
883 struct ravb_private *priv = netdev_priv(ndev); in ravb_dma_interrupt()
889 if (ravb_queue_interrupt(ndev, q)) in ravb_dma_interrupt()
908 struct net_device *ndev = napi->dev; in ravb_poll() local
909 struct ravb_private *priv = netdev_priv(ndev); in ravb_poll()
917 tis = ravb_read(ndev, TIS); in ravb_poll()
918 ris0 = ravb_read(ndev, RIS0); in ravb_poll()
925 ravb_write(ndev, ~(mask | RIS0_RESERVED), RIS0); in ravb_poll()
926 if (ravb_rx(ndev, "a, q)) in ravb_poll()
933 ravb_write(ndev, ~(mask | TIS_RESERVED), TIS); in ravb_poll()
934 ravb_tx_free(ndev, q, true); in ravb_poll()
935 netif_wake_subqueue(ndev, q); in ravb_poll()
945 ravb_modify(ndev, RIC0, mask, mask); in ravb_poll()
946 ravb_modify(ndev, TIC, mask, mask); in ravb_poll()
948 ravb_write(ndev, mask, RIE0); in ravb_poll()
949 ravb_write(ndev, mask, TIE); 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()
965 static void ravb_adjust_link(struct net_device *ndev) in ravb_adjust_link() argument
967 struct ravb_private *priv = netdev_priv(ndev); in ravb_adjust_link()
968 struct phy_device *phydev = ndev->phydev; in ravb_adjust_link()
976 ravb_rcv_snd_disable(ndev); in ravb_adjust_link()
982 ravb_set_rate(ndev); in ravb_adjust_link()
985 ravb_modify(ndev, ECMR, ECMR_TXF, 0); in ravb_adjust_link()
997 ravb_rcv_snd_enable(ndev); in ravb_adjust_link()
1011 static int ravb_phy_init(struct net_device *ndev) in ravb_phy_init() argument
1013 struct device_node *np = ndev->dev.parent->of_node; in ravb_phy_init()
1014 struct ravb_private *priv = netdev_priv(ndev); in ravb_phy_init()
1039 phydev = of_phy_connect(ndev, pn, ravb_adjust_link, 0, iface); in ravb_phy_init()
1042 netdev_err(ndev, "failed to connect PHY\n"); in ravb_phy_init()
1053 netdev_err(ndev, "failed to limit PHY to 100Mbit/s\n"); in ravb_phy_init()
1057 netdev_info(ndev, "limited PHY to 100Mbit/s\n"); in ravb_phy_init()
1084 static int ravb_phy_start(struct net_device *ndev) in ravb_phy_start() argument
1088 error = ravb_phy_init(ndev); in ravb_phy_start()
1092 phy_start(ndev->phydev); in ravb_phy_start()
1097 static u32 ravb_get_msglevel(struct net_device *ndev) in ravb_get_msglevel() argument
1099 struct ravb_private *priv = netdev_priv(ndev); in ravb_get_msglevel()
1104 static void ravb_set_msglevel(struct net_device *ndev, u32 value) in ravb_set_msglevel() argument
1106 struct ravb_private *priv = netdev_priv(ndev); in ravb_set_msglevel()
1157 static void ravb_get_ethtool_stats(struct net_device *ndev, in ravb_get_ethtool_stats() argument
1160 struct ravb_private *priv = netdev_priv(ndev); in ravb_get_ethtool_stats()
1186 static void ravb_get_strings(struct net_device *ndev, u32 stringset, u8 *data) in ravb_get_strings() argument
1195 static void ravb_get_ringparam(struct net_device *ndev, in ravb_get_ringparam() argument
1198 struct ravb_private *priv = netdev_priv(ndev); in ravb_get_ringparam()
1206 static int ravb_set_ringparam(struct net_device *ndev, in ravb_set_ringparam() argument
1209 struct ravb_private *priv = netdev_priv(ndev); in ravb_set_ringparam()
1220 if (netif_running(ndev)) { in ravb_set_ringparam()
1221 netif_device_detach(ndev); in ravb_set_ringparam()
1224 ravb_ptp_stop(ndev); in ravb_set_ringparam()
1226 error = ravb_stop_dma(ndev); in ravb_set_ringparam()
1228 netdev_err(ndev, in ravb_set_ringparam()
1232 synchronize_irq(ndev->irq); in ravb_set_ringparam()
1235 ravb_ring_free(ndev, RAVB_BE); in ravb_set_ringparam()
1236 ravb_ring_free(ndev, RAVB_NC); in ravb_set_ringparam()
1243 if (netif_running(ndev)) { in ravb_set_ringparam()
1244 error = ravb_dmac_init(ndev); in ravb_set_ringparam()
1246 netdev_err(ndev, in ravb_set_ringparam()
1252 ravb_emac_init(ndev); in ravb_set_ringparam()
1256 ravb_ptp_init(ndev, priv->pdev); in ravb_set_ringparam()
1258 netif_device_attach(ndev); in ravb_set_ringparam()
1264 static int ravb_get_ts_info(struct net_device *ndev, in ravb_get_ts_info() argument
1267 struct ravb_private *priv = netdev_priv(ndev); in ravb_get_ts_info()
1286 static void ravb_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol) in ravb_get_wol() argument
1288 struct ravb_private *priv = netdev_priv(ndev); in ravb_get_wol()
1294 static int ravb_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol) in ravb_set_wol() argument
1296 struct ravb_private *priv = netdev_priv(ndev); in ravb_set_wol()
1326 struct net_device *ndev, struct device *dev, in ravb_hook_irq() argument
1332 name = devm_kasprintf(dev, GFP_KERNEL, "%s:%s", ndev->name, ch); in ravb_hook_irq()
1335 error = request_irq(irq, handler, 0, name, ndev); in ravb_hook_irq()
1337 netdev_err(ndev, "cannot request IRQ %s\n", name); in ravb_hook_irq()
1343 static int ravb_open(struct net_device *ndev) in ravb_open() argument
1345 struct ravb_private *priv = netdev_priv(ndev); in ravb_open()
1354 error = request_irq(ndev->irq, ravb_interrupt, IRQF_SHARED, in ravb_open()
1355 ndev->name, ndev); in ravb_open()
1357 netdev_err(ndev, "cannot request IRQ\n"); 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()
1370 ndev, dev, "ch0:rx_be"); in ravb_open()
1374 ndev, dev, "ch18:tx_be"); in ravb_open()
1378 ndev, dev, "ch1:rx_nc"); in ravb_open()
1382 ndev, dev, "ch19:tx_nc"); in ravb_open()
1388 error = ravb_dmac_init(ndev); in ravb_open()
1391 ravb_emac_init(ndev); in ravb_open()
1395 ravb_ptp_init(ndev, priv->pdev); in ravb_open()
1397 netif_tx_start_all_queues(ndev); in ravb_open()
1400 error = ravb_phy_start(ndev); in ravb_open()
1409 ravb_ptp_stop(ndev); 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()
1431 static void ravb_tx_timeout(struct net_device *ndev, unsigned int txqueue) in ravb_tx_timeout() argument
1433 struct ravb_private *priv = netdev_priv(ndev); in ravb_tx_timeout()
1435 netif_err(priv, tx_err, ndev, in ravb_tx_timeout()
1437 ravb_read(ndev, ISS)); in ravb_tx_timeout()
1440 ndev->stats.tx_errors++; in ravb_tx_timeout()
1449 struct net_device *ndev = priv->ndev; in ravb_tx_timeout_work() local
1452 netif_tx_stop_all_queues(ndev); in ravb_tx_timeout_work()
1456 ravb_ptp_stop(ndev); in ravb_tx_timeout_work()
1459 if (ravb_stop_dma(ndev)) { in ravb_tx_timeout_work()
1468 ravb_rcv_snd_enable(ndev); in ravb_tx_timeout_work()
1472 ravb_ring_free(ndev, RAVB_BE); in ravb_tx_timeout_work()
1473 ravb_ring_free(ndev, RAVB_NC); in ravb_tx_timeout_work()
1476 error = ravb_dmac_init(ndev); in ravb_tx_timeout_work()
1482 netdev_err(ndev, "%s: ravb_dmac_init() failed, error %d\n", in ravb_tx_timeout_work()
1486 ravb_emac_init(ndev); in ravb_tx_timeout_work()
1491 ravb_ptp_init(ndev, priv->pdev); in ravb_tx_timeout_work()
1493 netif_tx_start_all_queues(ndev); in ravb_tx_timeout_work()
1497 static netdev_tx_t ravb_start_xmit(struct sk_buff *skb, struct net_device *ndev) in ravb_start_xmit() argument
1499 struct ravb_private *priv = netdev_priv(ndev); in ravb_start_xmit()
1513 netif_err(priv, tx_queued, ndev, in ravb_start_xmit()
1515 netif_stop_subqueue(ndev, q); 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()
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()
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()
1581 dma_unmap_single(ndev->dev.parent, dma_addr, in ravb_start_xmit()
1607 ravb_modify(ndev, TCCR, TCCR_TSRQ0 << q, TCCR_TSRQ0 << q); in ravb_start_xmit()
1612 !ravb_tx_free(ndev, q, true)) in ravb_start_xmit()
1613 netif_stop_subqueue(ndev, q); in ravb_start_xmit()
1620 dma_unmap_single(ndev->dev.parent, le32_to_cpu(desc->dptr), in ravb_start_xmit()
1628 static u16 ravb_select_queue(struct net_device *ndev, struct sk_buff *skb, in ravb_select_queue() argument
1637 static struct net_device_stats *ravb_get_stats(struct net_device *ndev) in ravb_get_stats() argument
1639 struct ravb_private *priv = netdev_priv(ndev); in ravb_get_stats()
1642 nstats = &ndev->stats; in ravb_get_stats()
1647 nstats->tx_dropped += ravb_read(ndev, TROCR); in ravb_get_stats()
1648 ravb_write(ndev, 0, TROCR); /* (write clear) */ in ravb_get_stats()
1671 static void ravb_set_rx_mode(struct net_device *ndev) in ravb_set_rx_mode() argument
1673 struct ravb_private *priv = netdev_priv(ndev); in ravb_set_rx_mode()
1677 ravb_modify(ndev, ECMR, ECMR_PRM, in ravb_set_rx_mode()
1678 ndev->flags & IFF_PROMISC ? ECMR_PRM : 0); in ravb_set_rx_mode()
1683 static int ravb_close(struct net_device *ndev) in ravb_close() argument
1685 struct device_node *np = ndev->dev.parent->of_node; in ravb_close()
1686 struct ravb_private *priv = netdev_priv(ndev); in ravb_close()
1689 netif_tx_stop_all_queues(ndev); in ravb_close()
1692 ravb_write(ndev, 0, RIC0); in ravb_close()
1693 ravb_write(ndev, 0, RIC2); in ravb_close()
1694 ravb_write(ndev, 0, TIC); in ravb_close()
1698 ravb_ptp_stop(ndev); in ravb_close()
1701 if (ravb_stop_dma(ndev) < 0) in ravb_close()
1702 netdev_err(ndev, 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()
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()
1733 ravb_ring_free(ndev, RAVB_BE); in ravb_close()
1734 ravb_ring_free(ndev, RAVB_NC); in ravb_close()
1739 static int ravb_hwtstamp_get(struct net_device *ndev, struct ifreq *req) in ravb_hwtstamp_get() argument
1741 struct ravb_private *priv = netdev_priv(ndev); in ravb_hwtstamp_get()
1763 static int ravb_hwtstamp_set(struct net_device *ndev, struct ifreq *req) in ravb_hwtstamp_set() argument
1765 struct ravb_private *priv = netdev_priv(ndev); in ravb_hwtstamp_set()
1808 static int ravb_do_ioctl(struct net_device *ndev, struct ifreq *req, int cmd) in ravb_do_ioctl() argument
1810 struct phy_device *phydev = ndev->phydev; in ravb_do_ioctl()
1812 if (!netif_running(ndev)) in ravb_do_ioctl()
1820 return ravb_hwtstamp_get(ndev, req); in ravb_do_ioctl()
1822 return ravb_hwtstamp_set(ndev, req); in ravb_do_ioctl()
1828 static int ravb_change_mtu(struct net_device *ndev, int new_mtu) in ravb_change_mtu() argument
1830 struct ravb_private *priv = netdev_priv(ndev); in ravb_change_mtu()
1832 ndev->mtu = new_mtu; in ravb_change_mtu()
1834 if (netif_running(ndev)) { in ravb_change_mtu()
1836 ravb_emac_init(ndev); in ravb_change_mtu()
1839 netdev_update_features(ndev); in ravb_change_mtu()
1844 static void ravb_set_rx_csum(struct net_device *ndev, bool enable) in ravb_set_rx_csum() argument
1846 struct ravb_private *priv = netdev_priv(ndev); in ravb_set_rx_csum()
1852 ravb_rcv_snd_disable(ndev); in ravb_set_rx_csum()
1855 ravb_modify(ndev, ECMR, ECMR_RCSC, enable ? ECMR_RCSC : 0); in ravb_set_rx_csum()
1858 ravb_rcv_snd_enable(ndev); in ravb_set_rx_csum()
1863 static int ravb_set_features(struct net_device *ndev, in ravb_set_features() argument
1866 netdev_features_t changed = ndev->features ^ features; in ravb_set_features()
1869 ravb_set_rx_csum(ndev, features & NETIF_F_RXCSUM); in ravb_set_features()
1871 ndev->features = features; in ravb_set_features()
1946 static int ravb_set_gti(struct net_device *ndev) in ravb_set_gti() argument
1948 struct ravb_private *priv = netdev_priv(ndev); in ravb_set_gti()
1949 struct device *dev = ndev->dev.parent; in ravb_set_gti()
1966 ravb_write(ndev, inc, GTI); in ravb_set_gti()
1971 static void ravb_set_config_mode(struct net_device *ndev) in ravb_set_config_mode() argument
1973 struct ravb_private *priv = netdev_priv(ndev); in ravb_set_config_mode()
1976 ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_CONFIG); in ravb_set_config_mode()
1978 ravb_modify(ndev, CCC, CCC_CSEL, CCC_CSEL_HPB); in ravb_set_config_mode()
1980 ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_CONFIG | in ravb_set_config_mode()
1993 static void ravb_parse_delay_mode(struct device_node *np, struct net_device *ndev) in ravb_parse_delay_mode() argument
1995 struct ravb_private *priv = netdev_priv(ndev); in ravb_parse_delay_mode()
2031 static void ravb_set_delay_mode(struct net_device *ndev) in ravb_set_delay_mode() argument
2033 struct ravb_private *priv = netdev_priv(ndev); in ravb_set_delay_mode()
2040 ravb_modify(ndev, APSR, APSR_DM, set); in ravb_set_delay_mode()
2048 struct net_device *ndev; in ravb_probe() local
2066 ndev = alloc_etherdev_mqs(sizeof(struct ravb_private), in ravb_probe()
2068 if (!ndev) in ravb_probe()
2071 ndev->features = NETIF_F_RXCSUM; in ravb_probe()
2072 ndev->hw_features = NETIF_F_RXCSUM; in ravb_probe()
2078 ndev->base_addr = res->start; in ravb_probe()
2090 ndev->irq = irq; in ravb_probe()
2092 SET_NETDEV_DEV(ndev, &pdev->dev); in ravb_probe()
2094 priv = netdev_priv(ndev); in ravb_probe()
2095 priv->ndev = ndev; 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()
2158 ndev->netdev_ops = &ravb_netdev_ops; in ravb_probe()
2159 ndev->ethtool_ops = &ravb_ethtool_ops; in ravb_probe()
2162 ravb_set_config_mode(ndev); in ravb_probe()
2165 error = ravb_set_gti(ndev); in ravb_probe()
2170 ravb_modify(ndev, GCCR, GCCR_LTI, GCCR_LTI); in ravb_probe()
2173 ravb_parse_delay_mode(np, ndev); in ravb_probe()
2174 ravb_set_delay_mode(ndev); in ravb_probe()
2179 priv->desc_bat = dma_alloc_coherent(ndev->dev.parent, priv->desc_bat_size, in ravb_probe()
2190 ravb_write(ndev, priv->desc_bat_dma, DBAT); in ravb_probe()
2197 ravb_ptp_init(ndev, pdev); in ravb_probe()
2203 ravb_read_mac_address(ndev, of_get_mac_address(np)); in ravb_probe()
2204 if (!is_valid_ether_addr(ndev->dev_addr)) { in ravb_probe()
2207 eth_hw_addr_random(ndev); 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()
2221 error = register_netdev(ndev); in ravb_probe()
2228 netdev_info(ndev, "Base address at %#x, %pM, IRQ %d.\n", in ravb_probe()
2229 (u32)ndev->base_addr, ndev->dev_addr, ndev->irq); in ravb_probe()
2231 platform_set_drvdata(pdev, ndev); in ravb_probe()
2240 dma_free_coherent(ndev->dev.parent, priv->desc_bat_size, priv->desc_bat, in ravb_probe()
2245 ravb_ptp_stop(ndev); in ravb_probe()
2247 free_netdev(ndev); in ravb_probe()
2256 struct net_device *ndev = platform_get_drvdata(pdev); in ravb_remove() local
2257 struct ravb_private *priv = netdev_priv(ndev); in ravb_remove()
2261 ravb_ptp_stop(ndev); in ravb_remove()
2263 dma_free_coherent(ndev->dev.parent, priv->desc_bat_size, priv->desc_bat, in ravb_remove()
2266 ravb_write(ndev, CCC_OPC_RESET, CCC); in ravb_remove()
2268 unregister_netdev(ndev); in ravb_remove()
2273 free_netdev(ndev); in ravb_remove()
2279 static int ravb_wol_setup(struct net_device *ndev) in ravb_wol_setup() argument
2281 struct ravb_private *priv = netdev_priv(ndev); in ravb_wol_setup()
2284 ravb_write(ndev, 0, RIC0); in ravb_wol_setup()
2285 ravb_write(ndev, 0, RIC2); in ravb_wol_setup()
2286 ravb_write(ndev, 0, TIC); in ravb_wol_setup()
2292 ravb_write(ndev, ECSIPR_MPDIP, ECSIPR); in ravb_wol_setup()
2295 ravb_modify(ndev, ECMR, ECMR_MPDE, ECMR_MPDE); in ravb_wol_setup()
2300 static int ravb_wol_restore(struct net_device *ndev) in ravb_wol_restore() argument
2302 struct ravb_private *priv = netdev_priv(ndev); in ravb_wol_restore()
2309 ravb_modify(ndev, ECMR, ECMR_MPDE, 0); in ravb_wol_restore()
2311 ret = ravb_close(ndev); in ravb_wol_restore()
2320 struct net_device *ndev = dev_get_drvdata(dev); in ravb_suspend() local
2321 struct ravb_private *priv = netdev_priv(ndev); in ravb_suspend()
2324 if (!netif_running(ndev)) in ravb_suspend()
2327 netif_device_detach(ndev); in ravb_suspend()
2330 ret = ravb_wol_setup(ndev); in ravb_suspend()
2332 ret = ravb_close(ndev); in ravb_suspend()
2339 struct net_device *ndev = dev_get_drvdata(dev); in ravb_resume() local
2340 struct ravb_private *priv = netdev_priv(ndev); in ravb_resume()
2345 ravb_write(ndev, CCC_OPC_RESET, CCC); in ravb_resume()
2353 ravb_set_config_mode(ndev); in ravb_resume()
2356 ret = ravb_set_gti(ndev); in ravb_resume()
2361 ravb_modify(ndev, GCCR, GCCR_LTI, GCCR_LTI); in ravb_resume()
2364 ravb_set_delay_mode(ndev); in ravb_resume()
2367 ravb_write(ndev, priv->desc_bat_dma, DBAT); in ravb_resume()
2369 if (netif_running(ndev)) { in ravb_resume()
2371 ret = ravb_wol_restore(ndev); in ravb_resume()
2375 ret = ravb_open(ndev); in ravb_resume()
2378 netif_device_attach(ndev); in ravb_resume()