Lines Matching refs:dev
125 static inline void emac_report_timeout_error(struct emac_instance *dev, in emac_report_timeout_error() argument
128 if (emac_has_feature(dev, EMAC_FTR_440GX_PHY_CLK_FIX | in emac_report_timeout_error()
131 DBG(dev, "%s" NL, error); in emac_report_timeout_error()
133 printk(KERN_ERR "%pOF: %s\n", dev->ofdev->dev.of_node, error); in emac_report_timeout_error()
140 static inline void emac_rx_clk_tx(struct emac_instance *dev) in emac_rx_clk_tx() argument
143 if (emac_has_feature(dev, EMAC_FTR_440EP_PHY_CLK_FIX)) in emac_rx_clk_tx()
145 0, SDR0_MFR_ECS >> dev->cell_index); in emac_rx_clk_tx()
149 static inline void emac_rx_clk_default(struct emac_instance *dev) in emac_rx_clk_default() argument
152 if (emac_has_feature(dev, EMAC_FTR_440EP_PHY_CLK_FIX)) in emac_rx_clk_default()
154 SDR0_MFR_ECS >> dev->cell_index, 0); in emac_rx_clk_default()
194 static void emac_clean_tx_ring(struct emac_instance *dev);
195 static void __emac_set_multicast_list(struct emac_instance *dev);
213 static inline void emac_tx_enable(struct emac_instance *dev) in emac_tx_enable() argument
215 struct emac_regs __iomem *p = dev->emacp; in emac_tx_enable()
218 DBG(dev, "tx_enable" NL); in emac_tx_enable()
225 static void emac_tx_disable(struct emac_instance *dev) in emac_tx_disable() argument
227 struct emac_regs __iomem *p = dev->emacp; in emac_tx_disable()
230 DBG(dev, "tx_disable" NL); in emac_tx_disable()
234 int n = dev->stop_timeout; in emac_tx_disable()
241 emac_report_timeout_error(dev, "TX disable timeout"); in emac_tx_disable()
245 static void emac_rx_enable(struct emac_instance *dev) in emac_rx_enable() argument
247 struct emac_regs __iomem *p = dev->emacp; in emac_rx_enable()
250 if (unlikely(test_bit(MAL_COMMAC_RX_STOPPED, &dev->commac.flags))) in emac_rx_enable()
253 DBG(dev, "rx_enable" NL); in emac_rx_enable()
259 int n = dev->stop_timeout; in emac_rx_enable()
265 emac_report_timeout_error(dev, in emac_rx_enable()
274 static void emac_rx_disable(struct emac_instance *dev) in emac_rx_disable() argument
276 struct emac_regs __iomem *p = dev->emacp; in emac_rx_disable()
279 DBG(dev, "rx_disable" NL); in emac_rx_disable()
283 int n = dev->stop_timeout; in emac_rx_disable()
290 emac_report_timeout_error(dev, "RX disable timeout"); in emac_rx_disable()
294 static inline void emac_netif_stop(struct emac_instance *dev) in emac_netif_stop() argument
296 netif_tx_lock_bh(dev->ndev); in emac_netif_stop()
297 netif_addr_lock(dev->ndev); in emac_netif_stop()
298 dev->no_mcast = 1; in emac_netif_stop()
299 netif_addr_unlock(dev->ndev); in emac_netif_stop()
300 netif_tx_unlock_bh(dev->ndev); in emac_netif_stop()
301 netif_trans_update(dev->ndev); /* prevent tx timeout */ in emac_netif_stop()
302 mal_poll_disable(dev->mal, &dev->commac); in emac_netif_stop()
303 netif_tx_disable(dev->ndev); in emac_netif_stop()
306 static inline void emac_netif_start(struct emac_instance *dev) in emac_netif_start() argument
308 netif_tx_lock_bh(dev->ndev); in emac_netif_start()
309 netif_addr_lock(dev->ndev); in emac_netif_start()
310 dev->no_mcast = 0; in emac_netif_start()
311 if (dev->mcast_pending && netif_running(dev->ndev)) in emac_netif_start()
312 __emac_set_multicast_list(dev); in emac_netif_start()
313 netif_addr_unlock(dev->ndev); in emac_netif_start()
314 netif_tx_unlock_bh(dev->ndev); in emac_netif_start()
316 netif_wake_queue(dev->ndev); in emac_netif_start()
323 mal_poll_enable(dev->mal, &dev->commac); in emac_netif_start()
326 static inline void emac_rx_disable_async(struct emac_instance *dev) in emac_rx_disable_async() argument
328 struct emac_regs __iomem *p = dev->emacp; in emac_rx_disable_async()
331 DBG(dev, "rx_disable_async" NL); in emac_rx_disable_async()
338 static int emac_reset(struct emac_instance *dev) in emac_reset() argument
340 struct emac_regs __iomem *p = dev->emacp; in emac_reset()
344 DBG(dev, "reset" NL); in emac_reset()
346 if (!dev->reset_failed) { in emac_reset()
350 emac_rx_disable(dev); in emac_reset()
351 emac_tx_disable(dev); in emac_reset()
373 if (emac_has_feature(dev, EMAC_FTR_460EX_PHY_CLK_FIX)) { in emac_reset()
374 if (try_internal_clock || (dev->phy_address == 0xffffffff && in emac_reset()
375 dev->phy_map == 0xffffffff)) { in emac_reset()
378 0, SDR0_ETH_CFG_ECS << dev->cell_index); in emac_reset()
382 SDR0_ETH_CFG_ECS << dev->cell_index, 0); in emac_reset()
392 if (emac_has_feature(dev, EMAC_FTR_460EX_PHY_CLK_FIX)) { in emac_reset()
400 if (try_internal_clock || (dev->phy_address == 0xffffffff && in emac_reset()
401 dev->phy_map == 0xffffffff)) { in emac_reset()
404 SDR0_ETH_CFG_ECS << dev->cell_index, 0); in emac_reset()
410 dev->reset_failed = 0; in emac_reset()
413 emac_report_timeout_error(dev, "reset timeout"); in emac_reset()
414 dev->reset_failed = 1; in emac_reset()
419 static void emac_hash_mc(struct emac_instance *dev) in emac_hash_mc() argument
421 const int regs = EMAC_XAHT_REGS(dev); in emac_hash_mc()
422 u32 *gaht_base = emac_gaht_base(dev); in emac_hash_mc()
427 DBG(dev, "hash_mc %d" NL, netdev_mc_count(dev->ndev)); in emac_hash_mc()
431 netdev_for_each_mc_addr(ha, dev->ndev) { in emac_hash_mc()
433 DBG2(dev, "mc %pM" NL, ha->addr); in emac_hash_mc()
435 slot = EMAC_XAHT_CRC_TO_SLOT(dev, in emac_hash_mc()
437 reg = EMAC_XAHT_SLOT_TO_REG(dev, slot); in emac_hash_mc()
438 mask = EMAC_XAHT_SLOT_TO_MASK(dev, slot); in emac_hash_mc()
449 struct emac_instance *dev = netdev_priv(ndev); in emac_iff2rmr() local
454 if (emac_has_feature(dev, EMAC_FTR_EMAC4)) in emac_iff2rmr()
462 (netdev_mc_count(ndev) > EMAC_XAHT_SLOTS(dev))) in emac_iff2rmr()
467 if (emac_has_feature(dev, EMAC_APM821XX_REQ_JUMBO_FRAME_SIZE)) { in emac_iff2rmr()
475 static u32 __emac_calc_base_mr1(struct emac_instance *dev, int tx_size, int rx_size) in __emac_calc_base_mr1() argument
479 DBG2(dev, "__emac_calc_base_mr1" NL); in __emac_calc_base_mr1()
487 dev->ndev->name, tx_size); in __emac_calc_base_mr1()
499 dev->ndev->name, rx_size); in __emac_calc_base_mr1()
505 static u32 __emac4_calc_base_mr1(struct emac_instance *dev, int tx_size, int rx_size) in __emac4_calc_base_mr1() argument
508 EMAC4_MR1_OBCI(dev->opb_bus_freq / 1000000); in __emac4_calc_base_mr1()
510 DBG2(dev, "__emac4_calc_base_mr1" NL); in __emac4_calc_base_mr1()
527 dev->ndev->name, tx_size); in __emac4_calc_base_mr1()
545 dev->ndev->name, rx_size); in __emac4_calc_base_mr1()
551 static u32 emac_calc_base_mr1(struct emac_instance *dev, int tx_size, int rx_size) in emac_calc_base_mr1() argument
553 return emac_has_feature(dev, EMAC_FTR_EMAC4) ? in emac_calc_base_mr1()
554 __emac4_calc_base_mr1(dev, tx_size, rx_size) : in emac_calc_base_mr1()
555 __emac_calc_base_mr1(dev, tx_size, rx_size); in emac_calc_base_mr1()
558 static inline u32 emac_calc_trtr(struct emac_instance *dev, unsigned int size) in emac_calc_trtr() argument
560 if (emac_has_feature(dev, EMAC_FTR_EMAC4)) in emac_calc_trtr()
566 static inline u32 emac_calc_rwmr(struct emac_instance *dev, in emac_calc_rwmr() argument
569 if (emac_has_feature(dev, EMAC_FTR_EMAC4)) in emac_calc_rwmr()
575 static int emac_configure(struct emac_instance *dev) in emac_configure() argument
577 struct emac_regs __iomem *p = dev->emacp; in emac_configure()
578 struct net_device *ndev = dev->ndev; in emac_configure()
579 int tx_size, rx_size, link = netif_carrier_ok(dev->ndev); in emac_configure()
582 DBG(dev, "configure" NL); in emac_configure()
588 } else if (emac_reset(dev) < 0) in emac_configure()
591 if (emac_has_feature(dev, EMAC_FTR_HAS_TAH)) in emac_configure()
592 tah_reset(dev->tah_dev); in emac_configure()
594 DBG(dev, " link = %d duplex = %d, pause = %d, asym_pause = %d\n", in emac_configure()
595 link, dev->phy.duplex, dev->phy.pause, dev->phy.asym_pause); in emac_configure()
598 tx_size = dev->tx_fifo_size; in emac_configure()
599 rx_size = dev->rx_fifo_size; in emac_configure()
606 else if (dev->phy.duplex == DUPLEX_FULL) in emac_configure()
610 dev->stop_timeout = STOP_TIMEOUT_10; in emac_configure()
611 switch (dev->phy.speed) { in emac_configure()
613 if (emac_phy_gpcs(dev->phy.mode)) { in emac_configure()
615 (dev->phy.gpcs_address != 0xffffffff) ? in emac_configure()
616 dev->phy.gpcs_address : dev->phy.address); in emac_configure()
626 tx_size = dev->tx_fifo_size_gige; in emac_configure()
627 rx_size = dev->rx_fifo_size_gige; in emac_configure()
629 if (dev->ndev->mtu > ETH_DATA_LEN) { in emac_configure()
630 if (emac_has_feature(dev, EMAC_FTR_EMAC4)) in emac_configure()
634 dev->stop_timeout = STOP_TIMEOUT_1000_JUMBO; in emac_configure()
636 dev->stop_timeout = STOP_TIMEOUT_1000; in emac_configure()
640 dev->stop_timeout = STOP_TIMEOUT_100; in emac_configure()
646 if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) in emac_configure()
647 rgmii_set_speed(dev->rgmii_dev, dev->rgmii_port, in emac_configure()
648 dev->phy.speed); in emac_configure()
649 if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII)) in emac_configure()
650 zmii_set_speed(dev->zmii_dev, dev->zmii_port, dev->phy.speed); in emac_configure()
655 if (!emac_has_feature(dev, EMAC_FTR_NO_FLOW_CONTROL_40x) && in emac_configure()
656 dev->phy.duplex == DUPLEX_FULL) { in emac_configure()
657 if (dev->phy.pause) in emac_configure()
659 else if (dev->phy.asym_pause) in emac_configure()
664 mr1 |= emac_calc_base_mr1(dev, tx_size, rx_size); in emac_configure()
679 emac_hash_mc(dev); in emac_configure()
683 if (emac_has_feature(dev, EMAC_FTR_EMAC4)) in emac_configure()
684 r = EMAC4_TMR1((dev->mal_burst_size / dev->fifo_entry_size) + 1, in emac_configure()
685 tx_size / 2 / dev->fifo_entry_size); in emac_configure()
687 r = EMAC_TMR1((dev->mal_burst_size / dev->fifo_entry_size) + 1, in emac_configure()
688 tx_size / 2 / dev->fifo_entry_size); in emac_configure()
690 out_be32(&p->trtr, emac_calc_trtr(dev, tx_size / 2)); in emac_configure()
711 r = emac_calc_rwmr(dev, rx_size / 8 / dev->fifo_entry_size, in emac_configure()
712 rx_size / 4 / dev->fifo_entry_size); in emac_configure()
722 if (emac_has_feature(dev, EMAC_FTR_EMAC4)) in emac_configure()
728 if (emac_phy_gpcs(dev->phy.mode)) { in emac_configure()
729 if (dev->phy.gpcs_address != 0xffffffff) in emac_configure()
730 emac_mii_reset_gpcs(&dev->phy); in emac_configure()
732 emac_mii_reset_phy(&dev->phy); in emac_configure()
738 static void emac_reinitialize(struct emac_instance *dev) in emac_reinitialize() argument
740 DBG(dev, "reinitialize" NL); in emac_reinitialize()
742 emac_netif_stop(dev); in emac_reinitialize()
743 if (!emac_configure(dev)) { in emac_reinitialize()
744 emac_tx_enable(dev); in emac_reinitialize()
745 emac_rx_enable(dev); in emac_reinitialize()
747 emac_netif_start(dev); in emac_reinitialize()
750 static void emac_full_tx_reset(struct emac_instance *dev) in emac_full_tx_reset() argument
752 DBG(dev, "full_tx_reset" NL); in emac_full_tx_reset()
754 emac_tx_disable(dev); in emac_full_tx_reset()
755 mal_disable_tx_channel(dev->mal, dev->mal_tx_chan); in emac_full_tx_reset()
756 emac_clean_tx_ring(dev); in emac_full_tx_reset()
757 dev->tx_cnt = dev->tx_slot = dev->ack_slot = 0; in emac_full_tx_reset()
759 emac_configure(dev); in emac_full_tx_reset()
761 mal_enable_tx_channel(dev->mal, dev->mal_tx_chan); in emac_full_tx_reset()
762 emac_tx_enable(dev); in emac_full_tx_reset()
763 emac_rx_enable(dev); in emac_full_tx_reset()
768 struct emac_instance *dev = container_of(work, struct emac_instance, reset_work); in emac_reset_work() local
770 DBG(dev, "reset_work" NL); in emac_reset_work()
772 mutex_lock(&dev->link_lock); in emac_reset_work()
773 if (dev->opened) { in emac_reset_work()
774 emac_netif_stop(dev); in emac_reset_work()
775 emac_full_tx_reset(dev); in emac_reset_work()
776 emac_netif_start(dev); in emac_reset_work()
778 mutex_unlock(&dev->link_lock); in emac_reset_work()
783 struct emac_instance *dev = netdev_priv(ndev); in emac_tx_timeout() local
785 DBG(dev, "tx_timeout" NL); in emac_tx_timeout()
787 schedule_work(&dev->reset_work); in emac_tx_timeout()
791 static inline int emac_phy_done(struct emac_instance *dev, u32 stacr) in emac_phy_done() argument
795 if (emac_has_feature(dev, EMAC_FTR_STACR_OC_INVERT)) in emac_phy_done()
801 static int __emac_mdio_read(struct emac_instance *dev, u8 id, u8 reg) in __emac_mdio_read() argument
803 struct emac_regs __iomem *p = dev->emacp; in __emac_mdio_read()
807 mutex_lock(&dev->mdio_lock); in __emac_mdio_read()
809 DBG2(dev, "mdio_read(%02x,%02x)" NL, id, reg); in __emac_mdio_read()
812 if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII)) in __emac_mdio_read()
813 zmii_get_mdio(dev->zmii_dev, dev->zmii_port); in __emac_mdio_read()
814 if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) in __emac_mdio_read()
815 rgmii_get_mdio(dev->rgmii_dev, dev->rgmii_port); in __emac_mdio_read()
819 while (!emac_phy_done(dev, in_be32(&p->stacr))) { in __emac_mdio_read()
822 DBG2(dev, " -> timeout wait idle\n"); in __emac_mdio_read()
828 if (emac_has_feature(dev, EMAC_FTR_EMAC4)) in __emac_mdio_read()
829 r = EMAC4_STACR_BASE(dev->opb_bus_freq); in __emac_mdio_read()
831 r = EMAC_STACR_BASE(dev->opb_bus_freq); in __emac_mdio_read()
832 if (emac_has_feature(dev, EMAC_FTR_STACR_OC_INVERT)) in __emac_mdio_read()
834 if (emac_has_feature(dev, EMAC_FTR_HAS_NEW_STACR)) in __emac_mdio_read()
844 while (!emac_phy_done(dev, (r = in_be32(&p->stacr)))) { in __emac_mdio_read()
847 DBG2(dev, " -> timeout wait complete\n"); in __emac_mdio_read()
853 DBG(dev, "mdio_read(%02x, %02x) failed" NL, id, reg); in __emac_mdio_read()
860 DBG2(dev, "mdio_read -> %04x" NL, r); in __emac_mdio_read()
863 if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) in __emac_mdio_read()
864 rgmii_put_mdio(dev->rgmii_dev, dev->rgmii_port); in __emac_mdio_read()
865 if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII)) in __emac_mdio_read()
866 zmii_put_mdio(dev->zmii_dev, dev->zmii_port); in __emac_mdio_read()
867 mutex_unlock(&dev->mdio_lock); in __emac_mdio_read()
872 static void __emac_mdio_write(struct emac_instance *dev, u8 id, u8 reg, in __emac_mdio_write() argument
875 struct emac_regs __iomem *p = dev->emacp; in __emac_mdio_write()
879 mutex_lock(&dev->mdio_lock); in __emac_mdio_write()
881 DBG2(dev, "mdio_write(%02x,%02x,%04x)" NL, id, reg, val); in __emac_mdio_write()
884 if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII)) in __emac_mdio_write()
885 zmii_get_mdio(dev->zmii_dev, dev->zmii_port); in __emac_mdio_write()
886 if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) in __emac_mdio_write()
887 rgmii_get_mdio(dev->rgmii_dev, dev->rgmii_port); in __emac_mdio_write()
891 while (!emac_phy_done(dev, in_be32(&p->stacr))) { in __emac_mdio_write()
894 DBG2(dev, " -> timeout wait idle\n"); in __emac_mdio_write()
900 if (emac_has_feature(dev, EMAC_FTR_EMAC4)) in __emac_mdio_write()
901 r = EMAC4_STACR_BASE(dev->opb_bus_freq); in __emac_mdio_write()
903 r = EMAC_STACR_BASE(dev->opb_bus_freq); in __emac_mdio_write()
904 if (emac_has_feature(dev, EMAC_FTR_STACR_OC_INVERT)) in __emac_mdio_write()
906 if (emac_has_feature(dev, EMAC_FTR_HAS_NEW_STACR)) in __emac_mdio_write()
917 while (!emac_phy_done(dev, in_be32(&p->stacr))) { in __emac_mdio_write()
920 DBG2(dev, " -> timeout wait complete\n"); in __emac_mdio_write()
925 if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) in __emac_mdio_write()
926 rgmii_put_mdio(dev->rgmii_dev, dev->rgmii_port); in __emac_mdio_write()
927 if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII)) in __emac_mdio_write()
928 zmii_put_mdio(dev->zmii_dev, dev->zmii_port); in __emac_mdio_write()
929 mutex_unlock(&dev->mdio_lock); in __emac_mdio_write()
934 struct emac_instance *dev = netdev_priv(ndev); in emac_mdio_read() local
937 res = __emac_mdio_read((dev->mdio_instance && in emac_mdio_read()
938 dev->phy.gpcs_address != id) ? in emac_mdio_read()
939 dev->mdio_instance : dev, in emac_mdio_read()
946 struct emac_instance *dev = netdev_priv(ndev); in emac_mdio_write() local
948 __emac_mdio_write((dev->mdio_instance && in emac_mdio_write()
949 dev->phy.gpcs_address != id) ? in emac_mdio_write()
950 dev->mdio_instance : dev, in emac_mdio_write()
955 static void __emac_set_multicast_list(struct emac_instance *dev) in __emac_set_multicast_list() argument
957 struct emac_regs __iomem *p = dev->emacp; in __emac_set_multicast_list()
958 u32 rmr = emac_iff2rmr(dev->ndev); in __emac_set_multicast_list()
960 DBG(dev, "__multicast %08x" NL, rmr); in __emac_set_multicast_list()
979 dev->mcast_pending = 0; in __emac_set_multicast_list()
980 emac_rx_disable(dev); in __emac_set_multicast_list()
982 emac_hash_mc(dev); in __emac_set_multicast_list()
984 emac_rx_enable(dev); in __emac_set_multicast_list()
990 struct emac_instance *dev = netdev_priv(ndev); in emac_set_multicast_list() local
992 DBG(dev, "multicast" NL); in emac_set_multicast_list()
994 BUG_ON(!netif_running(dev->ndev)); in emac_set_multicast_list()
996 if (dev->no_mcast) { in emac_set_multicast_list()
997 dev->mcast_pending = 1; in emac_set_multicast_list()
1001 mutex_lock(&dev->link_lock); in emac_set_multicast_list()
1002 __emac_set_multicast_list(dev); in emac_set_multicast_list()
1003 mutex_unlock(&dev->link_lock); in emac_set_multicast_list()
1008 struct emac_instance *dev = netdev_priv(ndev); in emac_set_mac_address() local
1010 struct emac_regs __iomem *p = dev->emacp; in emac_set_mac_address()
1015 mutex_lock(&dev->link_lock); in emac_set_mac_address()
1019 emac_rx_disable(dev); in emac_set_mac_address()
1020 emac_tx_disable(dev); in emac_set_mac_address()
1025 emac_tx_enable(dev); in emac_set_mac_address()
1026 emac_rx_enable(dev); in emac_set_mac_address()
1028 mutex_unlock(&dev->link_lock); in emac_set_mac_address()
1033 static int emac_resize_rx_ring(struct emac_instance *dev, int new_mtu) in emac_resize_rx_ring() argument
1040 mutex_lock(&dev->link_lock); in emac_resize_rx_ring()
1041 emac_netif_stop(dev); in emac_resize_rx_ring()
1042 emac_rx_disable(dev); in emac_resize_rx_ring()
1043 mal_disable_rx_channel(dev->mal, dev->mal_rx_chan); in emac_resize_rx_ring()
1045 if (dev->rx_sg_skb) { in emac_resize_rx_ring()
1046 ++dev->estats.rx_dropped_resize; in emac_resize_rx_ring()
1047 dev_kfree_skb(dev->rx_sg_skb); in emac_resize_rx_ring()
1048 dev->rx_sg_skb = NULL; in emac_resize_rx_ring()
1056 if (dev->rx_desc[i].ctrl & MAL_RX_CTRL_FIRST) in emac_resize_rx_ring()
1057 ++dev->estats.rx_dropped_resize; in emac_resize_rx_ring()
1059 dev->rx_desc[i].data_len = 0; in emac_resize_rx_ring()
1060 dev->rx_desc[i].ctrl = MAL_RX_CTRL_EMPTY | in emac_resize_rx_ring()
1065 if (rx_skb_size <= dev->rx_skb_size) in emac_resize_rx_ring()
1072 skb = netdev_alloc_skb_ip_align(dev->ndev, rx_skb_size); in emac_resize_rx_ring()
1078 BUG_ON(!dev->rx_skb[i]); in emac_resize_rx_ring()
1079 dev_kfree_skb(dev->rx_skb[i]); in emac_resize_rx_ring()
1081 dev->rx_desc[i].data_ptr = in emac_resize_rx_ring()
1082 dma_map_single(&dev->ofdev->dev, skb->data - NET_IP_ALIGN, in emac_resize_rx_ring()
1085 dev->rx_skb[i] = skb; in emac_resize_rx_ring()
1089 if (emac_has_feature(dev, EMAC_APM821XX_REQ_JUMBO_FRAME_SIZE)) { in emac_resize_rx_ring()
1091 (dev->ndev->mtu > ETH_DATA_LEN); in emac_resize_rx_ring()
1094 (dev->ndev->mtu > ETH_DATA_LEN); in emac_resize_rx_ring()
1099 set_bit(MAL_COMMAC_RX_STOPPED, &dev->commac.flags); in emac_resize_rx_ring()
1101 dev->ndev->mtu = new_mtu; in emac_resize_rx_ring()
1102 emac_full_tx_reset(dev); in emac_resize_rx_ring()
1105 mal_set_rcbs(dev->mal, dev->mal_rx_chan, emac_rx_size(new_mtu)); in emac_resize_rx_ring()
1108 clear_bit(MAL_COMMAC_RX_STOPPED, &dev->commac.flags); in emac_resize_rx_ring()
1109 dev->rx_slot = 0; in emac_resize_rx_ring()
1110 mal_enable_rx_channel(dev->mal, dev->mal_rx_chan); in emac_resize_rx_ring()
1111 emac_rx_enable(dev); in emac_resize_rx_ring()
1112 emac_netif_start(dev); in emac_resize_rx_ring()
1113 mutex_unlock(&dev->link_lock); in emac_resize_rx_ring()
1121 struct emac_instance *dev = netdev_priv(ndev); in emac_change_mtu() local
1124 DBG(dev, "change_mtu(%d)" NL, new_mtu); in emac_change_mtu()
1129 ret = emac_resize_rx_ring(dev, new_mtu); in emac_change_mtu()
1134 dev->rx_skb_size = emac_rx_skb_size(new_mtu); in emac_change_mtu()
1135 dev->rx_sync_size = emac_rx_sync_size(new_mtu); in emac_change_mtu()
1141 static void emac_clean_tx_ring(struct emac_instance *dev) in emac_clean_tx_ring() argument
1146 if (dev->tx_skb[i]) { in emac_clean_tx_ring()
1147 dev_kfree_skb(dev->tx_skb[i]); in emac_clean_tx_ring()
1148 dev->tx_skb[i] = NULL; in emac_clean_tx_ring()
1149 if (dev->tx_desc[i].ctrl & MAL_TX_CTRL_READY) in emac_clean_tx_ring()
1150 ++dev->estats.tx_dropped; in emac_clean_tx_ring()
1152 dev->tx_desc[i].ctrl = 0; in emac_clean_tx_ring()
1153 dev->tx_desc[i].data_ptr = 0; in emac_clean_tx_ring()
1157 static void emac_clean_rx_ring(struct emac_instance *dev) in emac_clean_rx_ring() argument
1162 if (dev->rx_skb[i]) { in emac_clean_rx_ring()
1163 dev->rx_desc[i].ctrl = 0; in emac_clean_rx_ring()
1164 dev_kfree_skb(dev->rx_skb[i]); in emac_clean_rx_ring()
1165 dev->rx_skb[i] = NULL; in emac_clean_rx_ring()
1166 dev->rx_desc[i].data_ptr = 0; in emac_clean_rx_ring()
1169 if (dev->rx_sg_skb) { in emac_clean_rx_ring()
1170 dev_kfree_skb(dev->rx_sg_skb); in emac_clean_rx_ring()
1171 dev->rx_sg_skb = NULL; in emac_clean_rx_ring()
1176 __emac_prepare_rx_skb(struct sk_buff *skb, struct emac_instance *dev, int slot) in __emac_prepare_rx_skb() argument
1181 dev->rx_skb[slot] = skb; in __emac_prepare_rx_skb()
1182 dev->rx_desc[slot].data_len = 0; in __emac_prepare_rx_skb()
1184 dev->rx_desc[slot].data_ptr = in __emac_prepare_rx_skb()
1185 dma_map_single(&dev->ofdev->dev, skb->data - NET_IP_ALIGN, in __emac_prepare_rx_skb()
1186 dev->rx_sync_size, DMA_FROM_DEVICE) + NET_IP_ALIGN; in __emac_prepare_rx_skb()
1188 dev->rx_desc[slot].ctrl = MAL_RX_CTRL_EMPTY | in __emac_prepare_rx_skb()
1195 emac_alloc_rx_skb(struct emac_instance *dev, int slot) in emac_alloc_rx_skb() argument
1199 skb = __netdev_alloc_skb_ip_align(dev->ndev, dev->rx_skb_size, in emac_alloc_rx_skb()
1202 return __emac_prepare_rx_skb(skb, dev, slot); in emac_alloc_rx_skb()
1206 emac_alloc_rx_skb_napi(struct emac_instance *dev, int slot) in emac_alloc_rx_skb_napi() argument
1210 skb = napi_alloc_skb(&dev->mal->napi, dev->rx_skb_size); in emac_alloc_rx_skb_napi()
1212 return __emac_prepare_rx_skb(skb, dev, slot); in emac_alloc_rx_skb_napi()
1215 static void emac_print_link_status(struct emac_instance *dev) in emac_print_link_status() argument
1217 if (netif_carrier_ok(dev->ndev)) in emac_print_link_status()
1219 dev->ndev->name, dev->phy.speed, in emac_print_link_status()
1220 dev->phy.duplex == DUPLEX_FULL ? "FDX" : "HDX", in emac_print_link_status()
1221 dev->phy.pause ? ", pause enabled" : in emac_print_link_status()
1222 dev->phy.asym_pause ? ", asymmetric pause enabled" : ""); in emac_print_link_status()
1224 printk(KERN_INFO "%s: link is down\n", dev->ndev->name); in emac_print_link_status()
1230 struct emac_instance *dev = netdev_priv(ndev); in emac_open() local
1233 DBG(dev, "open" NL); in emac_open()
1236 err = request_irq(dev->emac_irq, emac_irq, 0, "EMAC", dev); in emac_open()
1239 ndev->name, dev->emac_irq); in emac_open()
1245 if (emac_alloc_rx_skb(dev, i)) { in emac_open()
1251 dev->tx_cnt = dev->tx_slot = dev->ack_slot = dev->rx_slot = 0; in emac_open()
1252 clear_bit(MAL_COMMAC_RX_STOPPED, &dev->commac.flags); in emac_open()
1253 dev->rx_sg_skb = NULL; in emac_open()
1255 mutex_lock(&dev->link_lock); in emac_open()
1256 dev->opened = 1; in emac_open()
1260 if (dev->phy.address >= 0) { in emac_open()
1262 if (dev->phy.def->ops->poll_link(&dev->phy)) { in emac_open()
1263 dev->phy.def->ops->read_link(&dev->phy); in emac_open()
1264 emac_rx_clk_default(dev); in emac_open()
1265 netif_carrier_on(dev->ndev); in emac_open()
1268 emac_rx_clk_tx(dev); in emac_open()
1269 netif_carrier_off(dev->ndev); in emac_open()
1272 dev->link_polling = 1; in emac_open()
1274 schedule_delayed_work(&dev->link_work, link_poll_interval); in emac_open()
1275 emac_print_link_status(dev); in emac_open()
1277 netif_carrier_on(dev->ndev); in emac_open()
1282 emac_configure(dev); in emac_open()
1283 mal_poll_add(dev->mal, &dev->commac); in emac_open()
1284 mal_enable_tx_channel(dev->mal, dev->mal_tx_chan); in emac_open()
1285 mal_set_rcbs(dev->mal, dev->mal_rx_chan, emac_rx_size(ndev->mtu)); in emac_open()
1286 mal_enable_rx_channel(dev->mal, dev->mal_rx_chan); in emac_open()
1287 emac_tx_enable(dev); in emac_open()
1288 emac_rx_enable(dev); in emac_open()
1289 emac_netif_start(dev); in emac_open()
1291 mutex_unlock(&dev->link_lock); in emac_open()
1295 emac_clean_rx_ring(dev); in emac_open()
1296 free_irq(dev->emac_irq, dev); in emac_open()
1303 static int emac_link_differs(struct emac_instance *dev)
1305 u32 r = in_be32(&dev->emacp->mr1);
1329 return speed != dev->phy.speed || duplex != dev->phy.duplex ||
1330 pause != dev->phy.pause || asym_pause != dev->phy.asym_pause;
1336 struct emac_instance *dev = in emac_link_timer() local
1341 mutex_lock(&dev->link_lock); in emac_link_timer()
1342 DBG2(dev, "link timer" NL); in emac_link_timer()
1344 if (!dev->opened) in emac_link_timer()
1347 if (dev->phy.def->ops->poll_link(&dev->phy)) { in emac_link_timer()
1348 if (!netif_carrier_ok(dev->ndev)) { in emac_link_timer()
1349 emac_rx_clk_default(dev); in emac_link_timer()
1351 dev->phy.def->ops->read_link(&dev->phy); in emac_link_timer()
1353 netif_carrier_on(dev->ndev); in emac_link_timer()
1354 emac_netif_stop(dev); in emac_link_timer()
1355 emac_full_tx_reset(dev); in emac_link_timer()
1356 emac_netif_start(dev); in emac_link_timer()
1357 emac_print_link_status(dev); in emac_link_timer()
1361 if (netif_carrier_ok(dev->ndev)) { in emac_link_timer()
1362 emac_rx_clk_tx(dev); in emac_link_timer()
1363 netif_carrier_off(dev->ndev); in emac_link_timer()
1364 netif_tx_disable(dev->ndev); in emac_link_timer()
1365 emac_reinitialize(dev); in emac_link_timer()
1366 emac_print_link_status(dev); in emac_link_timer()
1370 schedule_delayed_work(&dev->link_work, link_poll_interval); in emac_link_timer()
1372 mutex_unlock(&dev->link_lock); in emac_link_timer()
1375 static void emac_force_link_update(struct emac_instance *dev) in emac_force_link_update() argument
1377 netif_carrier_off(dev->ndev); in emac_force_link_update()
1379 if (dev->link_polling) { in emac_force_link_update()
1380 cancel_delayed_work_sync(&dev->link_work); in emac_force_link_update()
1381 if (dev->link_polling) in emac_force_link_update()
1382 schedule_delayed_work(&dev->link_work, PHY_POLL_LINK_OFF); in emac_force_link_update()
1389 struct emac_instance *dev = netdev_priv(ndev); in emac_close() local
1391 DBG(dev, "close" NL); in emac_close()
1393 if (dev->phy.address >= 0) { in emac_close()
1394 dev->link_polling = 0; in emac_close()
1395 cancel_delayed_work_sync(&dev->link_work); in emac_close()
1397 mutex_lock(&dev->link_lock); in emac_close()
1398 emac_netif_stop(dev); in emac_close()
1399 dev->opened = 0; in emac_close()
1400 mutex_unlock(&dev->link_lock); in emac_close()
1402 emac_rx_disable(dev); in emac_close()
1403 emac_tx_disable(dev); in emac_close()
1404 mal_disable_rx_channel(dev->mal, dev->mal_rx_chan); in emac_close()
1405 mal_disable_tx_channel(dev->mal, dev->mal_tx_chan); in emac_close()
1406 mal_poll_del(dev->mal, &dev->commac); in emac_close()
1408 emac_clean_tx_ring(dev); in emac_close()
1409 emac_clean_rx_ring(dev); in emac_close()
1411 free_irq(dev->emac_irq, dev); in emac_close()
1418 static inline u16 emac_tx_csum(struct emac_instance *dev, in emac_tx_csum() argument
1421 if (emac_has_feature(dev, EMAC_FTR_HAS_TAH) && in emac_tx_csum()
1423 ++dev->stats.tx_packets_csum; in emac_tx_csum()
1429 static inline netdev_tx_t emac_xmit_finish(struct emac_instance *dev, int len) in emac_xmit_finish() argument
1431 struct emac_regs __iomem *p = dev->emacp; in emac_xmit_finish()
1432 struct net_device *ndev = dev->ndev; in emac_xmit_finish()
1438 if (emac_has_feature(dev, EMAC_FTR_EMAC4)) in emac_xmit_finish()
1443 if (unlikely(++dev->tx_cnt == NUM_TX_BUFF)) { in emac_xmit_finish()
1445 DBG2(dev, "stopped TX queue" NL); in emac_xmit_finish()
1449 ++dev->stats.tx_packets; in emac_xmit_finish()
1450 dev->stats.tx_bytes += len; in emac_xmit_finish()
1458 struct emac_instance *dev = netdev_priv(ndev); in emac_start_xmit() local
1463 MAL_TX_CTRL_LAST | emac_tx_csum(dev, skb); in emac_start_xmit()
1465 slot = dev->tx_slot++; in emac_start_xmit()
1466 if (dev->tx_slot == NUM_TX_BUFF) { in emac_start_xmit()
1467 dev->tx_slot = 0; in emac_start_xmit()
1471 DBG2(dev, "xmit(%u) %d" NL, len, slot); in emac_start_xmit()
1473 dev->tx_skb[slot] = skb; in emac_start_xmit()
1474 dev->tx_desc[slot].data_ptr = dma_map_single(&dev->ofdev->dev, in emac_start_xmit()
1477 dev->tx_desc[slot].data_len = (u16) len; in emac_start_xmit()
1479 dev->tx_desc[slot].ctrl = ctrl; in emac_start_xmit()
1481 return emac_xmit_finish(dev, len); in emac_start_xmit()
1484 static inline int emac_xmit_split(struct emac_instance *dev, int slot, in emac_xmit_split() argument
1499 dev->tx_skb[slot] = NULL; in emac_xmit_split()
1500 dev->tx_desc[slot].data_ptr = pd; in emac_xmit_split()
1501 dev->tx_desc[slot].data_len = (u16) chunk; in emac_xmit_split()
1502 dev->tx_desc[slot].ctrl = ctrl; in emac_xmit_split()
1503 ++dev->tx_cnt; in emac_xmit_split()
1517 struct emac_instance *dev = netdev_priv(ndev); in emac_start_xmit_sg() local
1534 if (unlikely(dev->tx_cnt + nr_frags + mal_tx_chunks(len) > NUM_TX_BUFF)) in emac_start_xmit_sg()
1538 emac_tx_csum(dev, skb); in emac_start_xmit_sg()
1539 slot = dev->tx_slot; in emac_start_xmit_sg()
1542 dev->tx_skb[slot] = NULL; in emac_start_xmit_sg()
1544 dev->tx_desc[slot].data_ptr = pd = in emac_start_xmit_sg()
1545 dma_map_single(&dev->ofdev->dev, skb->data, len, DMA_TO_DEVICE); in emac_start_xmit_sg()
1546 dev->tx_desc[slot].data_len = (u16) chunk; in emac_start_xmit_sg()
1549 slot = emac_xmit_split(dev, slot, pd + chunk, len, !nr_frags, in emac_start_xmit_sg()
1556 if (unlikely(dev->tx_cnt + mal_tx_chunks(len) >= NUM_TX_BUFF)) in emac_start_xmit_sg()
1559 pd = skb_frag_dma_map(&dev->ofdev->dev, frag, 0, len, in emac_start_xmit_sg()
1562 slot = emac_xmit_split(dev, slot, pd, len, i == nr_frags - 1, in emac_start_xmit_sg()
1566 DBG2(dev, "xmit_sg(%u) %d - %d" NL, skb->len, dev->tx_slot, slot); in emac_start_xmit_sg()
1569 dev->tx_skb[slot] = skb; in emac_start_xmit_sg()
1572 if (dev->tx_slot == NUM_TX_BUFF - 1) in emac_start_xmit_sg()
1575 dev->tx_desc[dev->tx_slot].ctrl = ctrl; in emac_start_xmit_sg()
1576 dev->tx_slot = (slot + 1) % NUM_TX_BUFF; in emac_start_xmit_sg()
1578 return emac_xmit_finish(dev, skb->len); in emac_start_xmit_sg()
1584 while (slot != dev->tx_slot) { in emac_start_xmit_sg()
1585 dev->tx_desc[slot].ctrl = 0; in emac_start_xmit_sg()
1586 --dev->tx_cnt; in emac_start_xmit_sg()
1590 ++dev->estats.tx_undo; in emac_start_xmit_sg()
1594 DBG2(dev, "stopped TX queue" NL); in emac_start_xmit_sg()
1599 static void emac_parse_tx_error(struct emac_instance *dev, u16 ctrl) in emac_parse_tx_error() argument
1601 struct emac_error_stats *st = &dev->estats; in emac_parse_tx_error()
1603 DBG(dev, "BD TX error %04x" NL, ctrl); in emac_parse_tx_error()
1628 struct emac_instance *dev = param; in emac_poll_tx() local
1631 DBG2(dev, "poll_tx, %d %d" NL, dev->tx_cnt, dev->ack_slot); in emac_poll_tx()
1633 if (emac_has_feature(dev, EMAC_FTR_HAS_TAH)) in emac_poll_tx()
1638 netif_tx_lock_bh(dev->ndev); in emac_poll_tx()
1639 if (dev->tx_cnt) { in emac_poll_tx()
1641 int slot = dev->ack_slot, n = 0; in emac_poll_tx()
1643 ctrl = dev->tx_desc[slot].ctrl; in emac_poll_tx()
1645 struct sk_buff *skb = dev->tx_skb[slot]; in emac_poll_tx()
1650 dev->tx_skb[slot] = NULL; in emac_poll_tx()
1655 emac_parse_tx_error(dev, ctrl); in emac_poll_tx()
1657 if (--dev->tx_cnt) in emac_poll_tx()
1661 dev->ack_slot = slot; in emac_poll_tx()
1662 if (netif_queue_stopped(dev->ndev) && in emac_poll_tx()
1663 dev->tx_cnt < EMAC_TX_WAKEUP_THRESH) in emac_poll_tx()
1664 netif_wake_queue(dev->ndev); in emac_poll_tx()
1666 DBG2(dev, "tx %d pkts" NL, n); in emac_poll_tx()
1669 netif_tx_unlock_bh(dev->ndev); in emac_poll_tx()
1672 static inline void emac_recycle_rx_skb(struct emac_instance *dev, int slot, in emac_recycle_rx_skb() argument
1675 struct sk_buff *skb = dev->rx_skb[slot]; in emac_recycle_rx_skb()
1677 DBG2(dev, "recycle %d %d" NL, slot, len); in emac_recycle_rx_skb()
1680 dma_map_single(&dev->ofdev->dev, skb->data - NET_IP_ALIGN, in emac_recycle_rx_skb()
1684 dev->rx_desc[slot].data_len = 0; in emac_recycle_rx_skb()
1686 dev->rx_desc[slot].ctrl = MAL_RX_CTRL_EMPTY | in emac_recycle_rx_skb()
1690 static void emac_parse_rx_error(struct emac_instance *dev, u16 ctrl) in emac_parse_rx_error() argument
1692 struct emac_error_stats *st = &dev->estats; in emac_parse_rx_error()
1694 DBG(dev, "BD RX error %04x" NL, ctrl); in emac_parse_rx_error()
1717 static inline void emac_rx_csum(struct emac_instance *dev, in emac_rx_csum() argument
1721 if (!ctrl && dev->tah_dev) { in emac_rx_csum()
1723 ++dev->stats.rx_packets_csum; in emac_rx_csum()
1728 static inline int emac_rx_sg_append(struct emac_instance *dev, int slot) in emac_rx_sg_append() argument
1730 if (likely(dev->rx_sg_skb != NULL)) { in emac_rx_sg_append()
1731 int len = dev->rx_desc[slot].data_len; in emac_rx_sg_append()
1732 int tot_len = dev->rx_sg_skb->len + len; in emac_rx_sg_append()
1734 if (unlikely(tot_len + NET_IP_ALIGN > dev->rx_skb_size)) { in emac_rx_sg_append()
1735 ++dev->estats.rx_dropped_mtu; in emac_rx_sg_append()
1736 dev_kfree_skb(dev->rx_sg_skb); in emac_rx_sg_append()
1737 dev->rx_sg_skb = NULL; in emac_rx_sg_append()
1739 memcpy(skb_tail_pointer(dev->rx_sg_skb), in emac_rx_sg_append()
1740 dev->rx_skb[slot]->data, len); in emac_rx_sg_append()
1741 skb_put(dev->rx_sg_skb, len); in emac_rx_sg_append()
1742 emac_recycle_rx_skb(dev, slot, len); in emac_rx_sg_append()
1746 emac_recycle_rx_skb(dev, slot, 0); in emac_rx_sg_append()
1753 struct emac_instance *dev = param; in emac_poll_rx() local
1754 int slot = dev->rx_slot, received = 0; in emac_poll_rx()
1756 DBG2(dev, "poll_rx(%d)" NL, budget); in emac_poll_rx()
1762 u16 ctrl = dev->rx_desc[slot].ctrl; in emac_poll_rx()
1767 skb = dev->rx_skb[slot]; in emac_poll_rx()
1769 len = dev->rx_desc[slot].data_len; in emac_poll_rx()
1776 emac_parse_rx_error(dev, ctrl); in emac_poll_rx()
1777 ++dev->estats.rx_dropped_error; in emac_poll_rx()
1778 emac_recycle_rx_skb(dev, slot, 0); in emac_poll_rx()
1784 ++dev->estats.rx_dropped_stack; in emac_poll_rx()
1785 emac_recycle_rx_skb(dev, slot, len); in emac_poll_rx()
1792 copy_skb = napi_alloc_skb(&dev->mal->napi, len); in emac_poll_rx()
1799 emac_recycle_rx_skb(dev, slot, len); in emac_poll_rx()
1801 } else if (unlikely(emac_alloc_rx_skb_napi(dev, slot))) in emac_poll_rx()
1806 skb->protocol = eth_type_trans(skb, dev->ndev); in emac_poll_rx()
1807 emac_rx_csum(dev, skb, ctrl); in emac_poll_rx()
1810 ++dev->estats.rx_dropped_stack; in emac_poll_rx()
1812 ++dev->stats.rx_packets; in emac_poll_rx()
1814 dev->stats.rx_bytes += len; in emac_poll_rx()
1821 BUG_ON(dev->rx_sg_skb); in emac_poll_rx()
1822 if (unlikely(emac_alloc_rx_skb_napi(dev, slot))) { in emac_poll_rx()
1823 DBG(dev, "rx OOM %d" NL, slot); in emac_poll_rx()
1824 ++dev->estats.rx_dropped_oom; in emac_poll_rx()
1825 emac_recycle_rx_skb(dev, slot, 0); in emac_poll_rx()
1827 dev->rx_sg_skb = skb; in emac_poll_rx()
1830 } else if (!emac_rx_sg_append(dev, slot) && in emac_poll_rx()
1833 skb = dev->rx_sg_skb; in emac_poll_rx()
1834 dev->rx_sg_skb = NULL; in emac_poll_rx()
1838 emac_parse_rx_error(dev, ctrl); in emac_poll_rx()
1839 ++dev->estats.rx_dropped_error; in emac_poll_rx()
1847 DBG(dev, "rx OOM %d" NL, slot); in emac_poll_rx()
1849 ++dev->estats.rx_dropped_oom; in emac_poll_rx()
1850 emac_recycle_rx_skb(dev, slot, 0); in emac_poll_rx()
1855 DBG2(dev, "rx %d BDs" NL, received); in emac_poll_rx()
1856 dev->rx_slot = slot; in emac_poll_rx()
1859 if (unlikely(budget && test_bit(MAL_COMMAC_RX_STOPPED, &dev->commac.flags))) { in emac_poll_rx()
1861 if (!(dev->rx_desc[slot].ctrl & MAL_RX_CTRL_EMPTY)) { in emac_poll_rx()
1862 DBG2(dev, "rx restart" NL); in emac_poll_rx()
1867 if (dev->rx_sg_skb) { in emac_poll_rx()
1868 DBG2(dev, "dropping partial rx packet" NL); in emac_poll_rx()
1869 ++dev->estats.rx_dropped_error; in emac_poll_rx()
1870 dev_kfree_skb(dev->rx_sg_skb); in emac_poll_rx()
1871 dev->rx_sg_skb = NULL; in emac_poll_rx()
1874 clear_bit(MAL_COMMAC_RX_STOPPED, &dev->commac.flags); in emac_poll_rx()
1875 mal_enable_rx_channel(dev->mal, dev->mal_rx_chan); in emac_poll_rx()
1876 emac_rx_enable(dev); in emac_poll_rx()
1877 dev->rx_slot = 0; in emac_poll_rx()
1885 struct emac_instance *dev = param; in emac_peek_rx() local
1887 return !(dev->rx_desc[dev->rx_slot].ctrl & MAL_RX_CTRL_EMPTY); in emac_peek_rx()
1893 struct emac_instance *dev = param; in emac_peek_rx_sg() local
1895 int slot = dev->rx_slot; in emac_peek_rx_sg()
1897 u16 ctrl = dev->rx_desc[slot].ctrl; in emac_peek_rx_sg()
1906 if (unlikely(slot == dev->rx_slot)) in emac_peek_rx_sg()
1914 struct emac_instance *dev = param; in emac_rxde() local
1916 ++dev->estats.rx_stopped; in emac_rxde()
1917 emac_rx_disable_async(dev); in emac_rxde()
1923 struct emac_instance *dev = dev_instance; in emac_irq() local
1924 struct emac_regs __iomem *p = dev->emacp; in emac_irq()
1925 struct emac_error_stats *st = &dev->estats; in emac_irq()
1928 spin_lock(&dev->lock); in emac_irq()
1933 DBG(dev, "isr = %08x" NL, isr); in emac_irq()
1966 spin_unlock(&dev->lock); in emac_irq()
1973 struct emac_instance *dev = netdev_priv(ndev); in emac_stats() local
1974 struct emac_stats *st = &dev->stats; in emac_stats()
1975 struct emac_error_stats *est = &dev->estats; in emac_stats()
1979 DBG2(dev, "stats" NL); in emac_stats()
1982 spin_lock_irqsave(&dev->lock, flags); in emac_stats()
2020 spin_unlock_irqrestore(&dev->lock, flags); in emac_stats()
2042 struct emac_instance *dev = netdev_priv(ndev); in emac_ethtool_get_link_ksettings() local
2045 supported = dev->phy.features; in emac_ethtool_get_link_ksettings()
2047 cmd->base.phy_address = dev->phy.address; in emac_ethtool_get_link_ksettings()
2049 mutex_lock(&dev->link_lock); in emac_ethtool_get_link_ksettings()
2050 advertising = dev->phy.advertising; in emac_ethtool_get_link_ksettings()
2051 cmd->base.autoneg = dev->phy.autoneg; in emac_ethtool_get_link_ksettings()
2052 cmd->base.speed = dev->phy.speed; in emac_ethtool_get_link_ksettings()
2053 cmd->base.duplex = dev->phy.duplex; in emac_ethtool_get_link_ksettings()
2054 mutex_unlock(&dev->link_lock); in emac_ethtool_get_link_ksettings()
2068 struct emac_instance *dev = netdev_priv(ndev); in emac_ethtool_set_link_ksettings() local
2069 u32 f = dev->phy.features; in emac_ethtool_set_link_ksettings()
2075 DBG(dev, "set_settings(%d, %d, %d, 0x%08x)" NL, in emac_ethtool_set_link_ksettings()
2079 if (dev->phy.address < 0) in emac_ethtool_set_link_ksettings()
2119 mutex_lock(&dev->link_lock); in emac_ethtool_set_link_ksettings()
2120 dev->phy.def->ops->setup_forced(&dev->phy, cmd->base.speed, in emac_ethtool_set_link_ksettings()
2122 mutex_unlock(&dev->link_lock); in emac_ethtool_set_link_ksettings()
2128 mutex_lock(&dev->link_lock); in emac_ethtool_set_link_ksettings()
2129 dev->phy.def->ops->setup_aneg(&dev->phy, in emac_ethtool_set_link_ksettings()
2131 (dev->phy.advertising & in emac_ethtool_set_link_ksettings()
2134 mutex_unlock(&dev->link_lock); in emac_ethtool_set_link_ksettings()
2136 emac_force_link_update(dev); in emac_ethtool_set_link_ksettings()
2154 struct emac_instance *dev = netdev_priv(ndev); in emac_ethtool_get_pauseparam() local
2156 mutex_lock(&dev->link_lock); in emac_ethtool_get_pauseparam()
2157 if ((dev->phy.features & SUPPORTED_Autoneg) && in emac_ethtool_get_pauseparam()
2158 (dev->phy.advertising & (ADVERTISED_Pause | ADVERTISED_Asym_Pause))) in emac_ethtool_get_pauseparam()
2161 if (dev->phy.duplex == DUPLEX_FULL) { in emac_ethtool_get_pauseparam()
2162 if (dev->phy.pause) in emac_ethtool_get_pauseparam()
2164 else if (dev->phy.asym_pause) in emac_ethtool_get_pauseparam()
2167 mutex_unlock(&dev->link_lock); in emac_ethtool_get_pauseparam()
2170 static int emac_get_regs_len(struct emac_instance *dev) in emac_get_regs_len() argument
2178 struct emac_instance *dev = netdev_priv(ndev); in emac_ethtool_get_regs_len() local
2182 emac_get_regs_len(dev) + mal_get_regs_len(dev->mal); in emac_ethtool_get_regs_len()
2183 if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII)) in emac_ethtool_get_regs_len()
2184 size += zmii_get_regs_len(dev->zmii_dev); in emac_ethtool_get_regs_len()
2185 if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) in emac_ethtool_get_regs_len()
2186 size += rgmii_get_regs_len(dev->rgmii_dev); in emac_ethtool_get_regs_len()
2187 if (emac_has_feature(dev, EMAC_FTR_HAS_TAH)) in emac_ethtool_get_regs_len()
2188 size += tah_get_regs_len(dev->tah_dev); in emac_ethtool_get_regs_len()
2193 static void *emac_dump_regs(struct emac_instance *dev, void *buf) in emac_dump_regs() argument
2197 hdr->index = dev->cell_index; in emac_dump_regs()
2198 if (emac_has_feature(dev, EMAC_FTR_EMAC4SYNC)) { in emac_dump_regs()
2200 } else if (emac_has_feature(dev, EMAC_FTR_EMAC4)) { in emac_dump_regs()
2205 memcpy_fromio(hdr + 1, dev->emacp, sizeof(struct emac_regs)); in emac_dump_regs()
2212 struct emac_instance *dev = netdev_priv(ndev); in emac_ethtool_get_regs() local
2218 buf = mal_dump_regs(dev->mal, buf); in emac_ethtool_get_regs()
2219 buf = emac_dump_regs(dev, buf); in emac_ethtool_get_regs()
2220 if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII)) { in emac_ethtool_get_regs()
2222 buf = zmii_dump_regs(dev->zmii_dev, buf); in emac_ethtool_get_regs()
2224 if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) { in emac_ethtool_get_regs()
2226 buf = rgmii_dump_regs(dev->rgmii_dev, buf); in emac_ethtool_get_regs()
2228 if (emac_has_feature(dev, EMAC_FTR_HAS_TAH)) { in emac_ethtool_get_regs()
2230 buf = tah_dump_regs(dev->tah_dev, buf); in emac_ethtool_get_regs()
2236 struct emac_instance *dev = netdev_priv(ndev); in emac_ethtool_nway_reset() local
2239 DBG(dev, "nway_reset" NL); in emac_ethtool_nway_reset()
2241 if (dev->phy.address < 0) in emac_ethtool_nway_reset()
2244 mutex_lock(&dev->link_lock); in emac_ethtool_nway_reset()
2245 if (!dev->phy.autoneg) { in emac_ethtool_nway_reset()
2250 dev->phy.def->ops->setup_aneg(&dev->phy, dev->phy.advertising); in emac_ethtool_nway_reset()
2252 mutex_unlock(&dev->link_lock); in emac_ethtool_nway_reset()
2253 emac_force_link_update(dev); in emac_ethtool_nway_reset()
2276 struct emac_instance *dev = netdev_priv(ndev); in emac_ethtool_get_ethtool_stats() local
2278 memcpy(tmp_stats, &dev->stats, sizeof(dev->stats)); in emac_ethtool_get_ethtool_stats()
2279 tmp_stats += sizeof(dev->stats) / sizeof(u64); in emac_ethtool_get_ethtool_stats()
2280 memcpy(tmp_stats, &dev->estats, sizeof(dev->estats)); in emac_ethtool_get_ethtool_stats()
2286 struct emac_instance *dev = netdev_priv(ndev); in emac_ethtool_get_drvinfo() local
2291 dev->cell_index, dev->ofdev->dev.of_node); in emac_ethtool_get_drvinfo()
2316 struct emac_instance *dev = netdev_priv(ndev); in emac_ioctl() local
2319 DBG(dev, "ioctl %08x" NL, cmd); in emac_ioctl()
2321 if (dev->phy.address < 0) in emac_ioctl()
2326 data->phy_id = dev->phy.address; in emac_ioctl()
2329 data->val_out = emac_mdio_read(ndev, dev->phy.address, in emac_ioctl()
2334 emac_mdio_write(ndev, dev->phy.address, data->reg_num, in emac_ioctl()
2357 static int emac_check_deps(struct emac_instance *dev, in emac_check_deps() argument
2371 np = *(dev->blist - 1); in emac_check_deps()
2396 static void emac_put_deps(struct emac_instance *dev) in emac_put_deps() argument
2398 platform_device_put(dev->mal_dev); in emac_put_deps()
2399 platform_device_put(dev->zmii_dev); in emac_put_deps()
2400 platform_device_put(dev->rgmii_dev); in emac_put_deps()
2401 platform_device_put(dev->mdio_dev); in emac_put_deps()
2402 platform_device_put(dev->tah_dev); in emac_put_deps()
2418 static int emac_wait_deps(struct emac_instance *dev) in emac_wait_deps() argument
2425 deps[EMAC_DEP_MAL_IDX].phandle = dev->mal_ph; in emac_wait_deps()
2426 deps[EMAC_DEP_ZMII_IDX].phandle = dev->zmii_ph; in emac_wait_deps()
2427 deps[EMAC_DEP_RGMII_IDX].phandle = dev->rgmii_ph; in emac_wait_deps()
2428 if (dev->tah_ph) in emac_wait_deps()
2429 deps[EMAC_DEP_TAH_IDX].phandle = dev->tah_ph; in emac_wait_deps()
2430 if (dev->mdio_ph) in emac_wait_deps()
2431 deps[EMAC_DEP_MDIO_IDX].phandle = dev->mdio_ph; in emac_wait_deps()
2432 if (dev->blist && dev->blist > emac_boot_list) in emac_wait_deps()
2436 emac_check_deps(dev, deps), in emac_wait_deps()
2439 err = emac_check_deps(dev, deps) ? 0 : -ENODEV; in emac_wait_deps()
2446 dev->mal_dev = deps[EMAC_DEP_MAL_IDX].ofdev; in emac_wait_deps()
2447 dev->zmii_dev = deps[EMAC_DEP_ZMII_IDX].ofdev; in emac_wait_deps()
2448 dev->rgmii_dev = deps[EMAC_DEP_RGMII_IDX].ofdev; in emac_wait_deps()
2449 dev->tah_dev = deps[EMAC_DEP_TAH_IDX].ofdev; in emac_wait_deps()
2450 dev->mdio_dev = deps[EMAC_DEP_MDIO_IDX].ofdev; in emac_wait_deps()
2473 struct emac_instance *dev = netdev_priv(ndev); in emac_adjust_link() local
2474 struct phy_device *phy = dev->phy_dev; in emac_adjust_link()
2476 dev->phy.autoneg = phy->autoneg; in emac_adjust_link()
2477 dev->phy.speed = phy->speed; in emac_adjust_link()
2478 dev->phy.duplex = phy->duplex; in emac_adjust_link()
2479 dev->phy.pause = phy->pause; in emac_adjust_link()
2480 dev->phy.asym_pause = phy->asym_pause; in emac_adjust_link()
2481 ethtool_convert_link_mode_to_legacy_u32(&dev->phy.advertising, in emac_adjust_link()
2506 struct emac_instance *dev = netdev_priv(bus->priv); in emac_mii_bus_reset() local
2508 return emac_reset(dev); in emac_mii_bus_reset()
2524 struct net_device *ndev = phy->dev; in emac_mdio_setup_aneg()
2525 struct emac_instance *dev = netdev_priv(ndev); in emac_mdio_setup_aneg() local
2529 return emac_mdio_phy_start_aneg(phy, dev->phy_dev); in emac_mdio_setup_aneg()
2534 struct net_device *ndev = phy->dev; in emac_mdio_setup_forced()
2535 struct emac_instance *dev = netdev_priv(ndev); in emac_mdio_setup_forced() local
2540 return emac_mdio_phy_start_aneg(phy, dev->phy_dev); in emac_mdio_setup_forced()
2545 struct net_device *ndev = phy->dev; in emac_mdio_poll_link()
2546 struct emac_instance *dev = netdev_priv(ndev); in emac_mdio_poll_link() local
2549 res = phy_read_status(dev->phy_dev); in emac_mdio_poll_link()
2551 dev_err(&dev->ofdev->dev, "link update failed (%d).", res); in emac_mdio_poll_link()
2555 return dev->phy_dev->link; in emac_mdio_poll_link()
2560 struct net_device *ndev = phy->dev; in emac_mdio_read_link()
2561 struct emac_instance *dev = netdev_priv(ndev); in emac_mdio_read_link() local
2562 struct phy_device *phy_dev = dev->phy_dev; in emac_mdio_read_link()
2578 struct net_device *ndev = phy->dev; in emac_mdio_init_phy()
2579 struct emac_instance *dev = netdev_priv(ndev); in emac_mdio_init_phy() local
2581 phy_start(dev->phy_dev); in emac_mdio_init_phy()
2582 return phy_init_hw(dev->phy_dev); in emac_mdio_init_phy()
2593 static int emac_dt_mdio_probe(struct emac_instance *dev) in emac_dt_mdio_probe() argument
2598 mii_np = of_get_child_by_name(dev->ofdev->dev.of_node, "mdio"); in emac_dt_mdio_probe()
2600 dev_err(&dev->ofdev->dev, "no mdio definition found."); in emac_dt_mdio_probe()
2609 dev->mii_bus = devm_mdiobus_alloc(&dev->ofdev->dev); in emac_dt_mdio_probe()
2610 if (!dev->mii_bus) { in emac_dt_mdio_probe()
2615 dev->mii_bus->priv = dev->ndev; in emac_dt_mdio_probe()
2616 dev->mii_bus->parent = dev->ndev->dev.parent; in emac_dt_mdio_probe()
2617 dev->mii_bus->name = "emac_mdio"; in emac_dt_mdio_probe()
2618 dev->mii_bus->read = &emac_mii_bus_read; in emac_dt_mdio_probe()
2619 dev->mii_bus->write = &emac_mii_bus_write; in emac_dt_mdio_probe()
2620 dev->mii_bus->reset = &emac_mii_bus_reset; in emac_dt_mdio_probe()
2621 snprintf(dev->mii_bus->id, MII_BUS_ID_SIZE, "%s", dev->ofdev->name); in emac_dt_mdio_probe()
2622 res = of_mdiobus_register(dev->mii_bus, mii_np); in emac_dt_mdio_probe()
2624 dev_err(&dev->ofdev->dev, "cannot register MDIO bus %s (%d)", in emac_dt_mdio_probe()
2625 dev->mii_bus->name, res); in emac_dt_mdio_probe()
2633 static int emac_dt_phy_connect(struct emac_instance *dev, in emac_dt_phy_connect() argument
2636 dev->phy.def = devm_kzalloc(&dev->ofdev->dev, sizeof(*dev->phy.def), in emac_dt_phy_connect()
2638 if (!dev->phy.def) in emac_dt_phy_connect()
2641 dev->phy_dev = of_phy_connect(dev->ndev, phy_handle, &emac_adjust_link, in emac_dt_phy_connect()
2642 0, dev->phy_mode); in emac_dt_phy_connect()
2643 if (!dev->phy_dev) { in emac_dt_phy_connect()
2644 dev_err(&dev->ofdev->dev, "failed to connect to PHY.\n"); in emac_dt_phy_connect()
2648 dev->phy.def->phy_id = dev->phy_dev->drv->phy_id; in emac_dt_phy_connect()
2649 dev->phy.def->phy_id_mask = dev->phy_dev->drv->phy_id_mask; in emac_dt_phy_connect()
2650 dev->phy.def->name = dev->phy_dev->drv->name; in emac_dt_phy_connect()
2651 dev->phy.def->ops = &emac_dt_mdio_phy_ops; in emac_dt_phy_connect()
2652 ethtool_convert_link_mode_to_legacy_u32(&dev->phy.features, in emac_dt_phy_connect()
2653 dev->phy_dev->supported); in emac_dt_phy_connect()
2654 dev->phy.address = dev->phy_dev->mdio.addr; in emac_dt_phy_connect()
2655 dev->phy.mode = dev->phy_dev->interface; in emac_dt_phy_connect()
2659 static int emac_dt_phy_probe(struct emac_instance *dev) in emac_dt_phy_probe() argument
2661 struct device_node *np = dev->ofdev->dev.of_node; in emac_dt_phy_probe()
2668 res = emac_dt_mdio_probe(dev); in emac_dt_phy_probe()
2670 res = emac_dt_phy_connect(dev, phy_handle); in emac_dt_phy_probe()
2672 mdiobus_unregister(dev->mii_bus); in emac_dt_phy_probe()
2680 static int emac_init_phy(struct emac_instance *dev) in emac_init_phy() argument
2682 struct device_node *np = dev->ofdev->dev.of_node; in emac_init_phy()
2683 struct net_device *ndev = dev->ndev; in emac_init_phy()
2687 dev->phy.dev = ndev; in emac_init_phy()
2688 dev->phy.mode = dev->phy_mode; in emac_init_phy()
2691 if ((dev->phy_address == 0xffffffff && dev->phy_map == 0xffffffff) || in emac_init_phy()
2693 emac_reset(dev); in emac_init_phy()
2696 dev->phy.address = -1; in emac_init_phy()
2697 dev->phy.features = SUPPORTED_MII; in emac_init_phy()
2698 if (emac_phy_supports_gige(dev->phy_mode)) in emac_init_phy()
2699 dev->phy.features |= SUPPORTED_1000baseT_Full; in emac_init_phy()
2701 dev->phy.features |= SUPPORTED_100baseT_Full; in emac_init_phy()
2702 dev->phy.pause = 1; in emac_init_phy()
2705 int res = emac_dt_mdio_probe(dev); in emac_init_phy()
2711 dev->phy_dev = of_phy_find_device(np); in emac_init_phy()
2712 if (res || !dev->phy_dev) { in emac_init_phy()
2713 mdiobus_unregister(dev->mii_bus); in emac_init_phy()
2716 emac_adjust_link(dev->ndev); in emac_init_phy()
2717 put_device(&dev->phy_dev->mdio.dev); in emac_init_phy()
2723 phy_map = dev->phy_map | busy_phy_map; in emac_init_phy()
2725 DBG(dev, "PHY maps %08x %08x" NL, dev->phy_map, busy_phy_map); in emac_init_phy()
2727 dev->phy.mdio_read = emac_mdio_read; in emac_init_phy()
2728 dev->phy.mdio_write = emac_mdio_write; in emac_init_phy()
2732 if (emac_has_feature(dev, EMAC_FTR_440GX_PHY_CLK_FIX)) in emac_init_phy()
2736 emac_rx_clk_tx(dev); in emac_init_phy()
2740 if (emac_has_feature(dev, EMAC_FTR_440GX_PHY_CLK_FIX)) in emac_init_phy()
2746 if (emac_phy_gpcs(dev->phy.mode)) { in emac_init_phy()
2755 dev->phy.gpcs_address = dev->gpcs_address; in emac_init_phy()
2756 if (dev->phy.gpcs_address == 0xffffffff) in emac_init_phy()
2757 dev->phy.address = dev->cell_index; in emac_init_phy()
2760 emac_configure(dev); in emac_init_phy()
2762 if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) { in emac_init_phy()
2763 int res = emac_dt_phy_probe(dev); in emac_init_phy()
2779 dev_err(&dev->ofdev->dev, "failed to attach dt phy (%d).\n", in emac_init_phy()
2785 if (dev->phy_address != 0xffffffff) in emac_init_phy()
2786 phy_map = ~(1 << dev->phy_address); in emac_init_phy()
2794 r = emac_mdio_read(dev->ndev, i, MII_BMCR); in emac_init_phy()
2797 if (!emac_mii_phy_probe(&dev->phy, i)) in emac_init_phy()
2803 if (emac_has_feature(dev, EMAC_FTR_440GX_PHY_CLK_FIX)) in emac_init_phy()
2814 if (dev->phy.def->ops->init) in emac_init_phy()
2815 dev->phy.def->ops->init(&dev->phy); in emac_init_phy()
2818 dev->phy.def->features &= ~dev->phy_feat_exc; in emac_init_phy()
2819 dev->phy.features &= ~dev->phy_feat_exc; in emac_init_phy()
2822 if (dev->phy.features & SUPPORTED_Autoneg) { in emac_init_phy()
2823 adv = dev->phy.features; in emac_init_phy()
2824 if (!emac_has_feature(dev, EMAC_FTR_NO_FLOW_CONTROL_40x)) in emac_init_phy()
2827 dev->phy.def->ops->setup_aneg(&dev->phy, adv); in emac_init_phy()
2829 u32 f = dev->phy.def->features; in emac_init_phy()
2847 dev->phy.def->ops->setup_forced(&dev->phy, speed, fd); in emac_init_phy()
2852 static int emac_init_config(struct emac_instance *dev) in emac_init_config() argument
2854 struct device_node *np = dev->ofdev->dev.of_node; in emac_init_config()
2858 if (emac_read_uint_prop(np, "mal-device", &dev->mal_ph, 1)) in emac_init_config()
2860 if (emac_read_uint_prop(np, "mal-tx-channel", &dev->mal_tx_chan, 1)) in emac_init_config()
2862 if (emac_read_uint_prop(np, "mal-rx-channel", &dev->mal_rx_chan, 1)) in emac_init_config()
2864 if (emac_read_uint_prop(np, "cell-index", &dev->cell_index, 1)) in emac_init_config()
2866 if (emac_read_uint_prop(np, "max-frame-size", &dev->max_mtu, 0)) in emac_init_config()
2867 dev->max_mtu = ETH_DATA_LEN; in emac_init_config()
2868 if (emac_read_uint_prop(np, "rx-fifo-size", &dev->rx_fifo_size, 0)) in emac_init_config()
2869 dev->rx_fifo_size = 2048; in emac_init_config()
2870 if (emac_read_uint_prop(np, "tx-fifo-size", &dev->tx_fifo_size, 0)) in emac_init_config()
2871 dev->tx_fifo_size = 2048; in emac_init_config()
2872 if (emac_read_uint_prop(np, "rx-fifo-size-gige", &dev->rx_fifo_size_gige, 0)) in emac_init_config()
2873 dev->rx_fifo_size_gige = dev->rx_fifo_size; in emac_init_config()
2874 if (emac_read_uint_prop(np, "tx-fifo-size-gige", &dev->tx_fifo_size_gige, 0)) in emac_init_config()
2875 dev->tx_fifo_size_gige = dev->tx_fifo_size; in emac_init_config()
2876 if (emac_read_uint_prop(np, "phy-address", &dev->phy_address, 0)) in emac_init_config()
2877 dev->phy_address = 0xffffffff; in emac_init_config()
2878 if (emac_read_uint_prop(np, "phy-map", &dev->phy_map, 0)) in emac_init_config()
2879 dev->phy_map = 0xffffffff; in emac_init_config()
2880 if (emac_read_uint_prop(np, "gpcs-address", &dev->gpcs_address, 0)) in emac_init_config()
2881 dev->gpcs_address = 0xffffffff; in emac_init_config()
2882 if (emac_read_uint_prop(np->parent, "clock-frequency", &dev->opb_bus_freq, 1)) in emac_init_config()
2884 if (emac_read_uint_prop(np, "tah-device", &dev->tah_ph, 0)) in emac_init_config()
2885 dev->tah_ph = 0; in emac_init_config()
2886 if (emac_read_uint_prop(np, "tah-channel", &dev->tah_port, 0)) in emac_init_config()
2887 dev->tah_port = 0; in emac_init_config()
2888 if (emac_read_uint_prop(np, "mdio-device", &dev->mdio_ph, 0)) in emac_init_config()
2889 dev->mdio_ph = 0; in emac_init_config()
2890 if (emac_read_uint_prop(np, "zmii-device", &dev->zmii_ph, 0)) in emac_init_config()
2891 dev->zmii_ph = 0; in emac_init_config()
2892 if (emac_read_uint_prop(np, "zmii-channel", &dev->zmii_port, 0)) in emac_init_config()
2893 dev->zmii_port = 0xffffffff; in emac_init_config()
2894 if (emac_read_uint_prop(np, "rgmii-device", &dev->rgmii_ph, 0)) in emac_init_config()
2895 dev->rgmii_ph = 0; in emac_init_config()
2896 if (emac_read_uint_prop(np, "rgmii-channel", &dev->rgmii_port, 0)) in emac_init_config()
2897 dev->rgmii_port = 0xffffffff; in emac_init_config()
2898 if (emac_read_uint_prop(np, "fifo-entry-size", &dev->fifo_entry_size, 0)) in emac_init_config()
2899 dev->fifo_entry_size = 16; in emac_init_config()
2900 if (emac_read_uint_prop(np, "mal-burst-size", &dev->mal_burst_size, 0)) in emac_init_config()
2901 dev->mal_burst_size = 256; in emac_init_config()
2904 err = of_get_phy_mode(np, &dev->phy_mode); in emac_init_config()
2906 dev->phy_mode = PHY_INTERFACE_MODE_NA; in emac_init_config()
2910 dev->features |= (EMAC_FTR_EMAC4 | EMAC_FTR_EMAC4SYNC); in emac_init_config()
2913 dev->features |= EMAC_FTR_460EX_PHY_CLK_FIX; in emac_init_config()
2916 dev->features |= EMAC_FTR_440EP_PHY_CLK_FIX; in emac_init_config()
2918 dev->features |= (EMAC_APM821XX_REQ_JUMBO_FRAME_SIZE | in emac_init_config()
2923 dev->features |= EMAC_FTR_EMAC4; in emac_init_config()
2925 dev->features |= EMAC_FTR_440GX_PHY_CLK_FIX; in emac_init_config()
2929 dev->features |= EMAC_FTR_440EP_PHY_CLK_FIX; in emac_init_config()
2932 dev->features |= EMAC_FTR_NO_FLOW_CONTROL_40x; in emac_init_config()
2944 dev->features |= EMAC_FTR_STACR_OC_INVERT; in emac_init_config()
2946 dev->features |= EMAC_FTR_HAS_NEW_STACR; in emac_init_config()
2950 dev->features |= EMAC_FTR_HAS_NEW_STACR | in emac_init_config()
2954 if (dev->tah_ph != 0) { in emac_init_config()
2956 dev->features |= EMAC_FTR_HAS_TAH; in emac_init_config()
2963 if (dev->zmii_ph != 0) { in emac_init_config()
2965 dev->features |= EMAC_FTR_HAS_ZMII; in emac_init_config()
2972 if (dev->rgmii_ph != 0) { in emac_init_config()
2974 dev->features |= EMAC_FTR_HAS_RGMII; in emac_init_config()
2982 err = of_get_ethdev_address(np, dev->ndev); in emac_init_config()
2984 return dev_err_probe(&dev->ofdev->dev, err, in emac_init_config()
2988 if (emac_has_feature(dev, EMAC_FTR_EMAC4SYNC)) { in emac_init_config()
2989 dev->xaht_slots_shift = EMAC4SYNC_XAHT_SLOTS_SHIFT; in emac_init_config()
2990 dev->xaht_width_shift = EMAC4SYNC_XAHT_WIDTH_SHIFT; in emac_init_config()
2992 dev->xaht_slots_shift = EMAC4_XAHT_SLOTS_SHIFT; in emac_init_config()
2993 dev->xaht_width_shift = EMAC4_XAHT_WIDTH_SHIFT; in emac_init_config()
2997 if (WARN_ON(EMAC_XAHT_REGS(dev) > EMAC_XAHT_MAX_REGS)) in emac_init_config()
3000 DBG(dev, "features : 0x%08x / 0x%08x\n", dev->features, EMAC_FTRS_POSSIBLE); in emac_init_config()
3001 DBG(dev, "tx_fifo_size : %d (%d gige)\n", dev->tx_fifo_size, dev->tx_fifo_size_gige); in emac_init_config()
3002 DBG(dev, "rx_fifo_size : %d (%d gige)\n", dev->rx_fifo_size, dev->rx_fifo_size_gige); in emac_init_config()
3003 DBG(dev, "max_mtu : %d\n", dev->max_mtu); in emac_init_config()
3004 DBG(dev, "OPB freq : %d\n", dev->opb_bus_freq); in emac_init_config()
3037 struct emac_instance *dev; in emac_probe() local
3038 struct device_node *np = ofdev->dev.of_node; in emac_probe()
3060 dev = netdev_priv(ndev); in emac_probe()
3061 dev->ndev = ndev; in emac_probe()
3062 dev->ofdev = ofdev; in emac_probe()
3063 dev->blist = blist; in emac_probe()
3064 SET_NETDEV_DEV(ndev, &ofdev->dev); in emac_probe()
3067 mutex_init(&dev->mdio_lock); in emac_probe()
3068 mutex_init(&dev->link_lock); in emac_probe()
3069 spin_lock_init(&dev->lock); in emac_probe()
3070 INIT_WORK(&dev->reset_work, emac_reset_work); in emac_probe()
3073 err = emac_init_config(dev); in emac_probe()
3078 dev->emac_irq = irq_of_parse_and_map(np, 0); in emac_probe()
3079 dev->wol_irq = irq_of_parse_and_map(np, 1); in emac_probe()
3080 if (!dev->emac_irq) { in emac_probe()
3085 ndev->irq = dev->emac_irq; in emac_probe()
3089 dev->emacp = of_iomap(np, 0); in emac_probe()
3090 if (dev->emacp == NULL) { in emac_probe()
3097 err = emac_wait_deps(dev); in emac_probe()
3104 dev->mal = platform_get_drvdata(dev->mal_dev); in emac_probe()
3105 if (dev->mdio_dev != NULL) in emac_probe()
3106 dev->mdio_instance = platform_get_drvdata(dev->mdio_dev); in emac_probe()
3109 dev->commac.ops = &emac_commac_ops; in emac_probe()
3110 dev->commac.dev = dev; in emac_probe()
3111 dev->commac.tx_chan_mask = MAL_CHAN_MASK(dev->mal_tx_chan); in emac_probe()
3112 dev->commac.rx_chan_mask = MAL_CHAN_MASK(dev->mal_rx_chan); in emac_probe()
3113 err = mal_register_commac(dev->mal, &dev->commac); in emac_probe()
3116 np, dev->mal_dev->dev.of_node); in emac_probe()
3119 dev->rx_skb_size = emac_rx_skb_size(ndev->mtu); in emac_probe()
3120 dev->rx_sync_size = emac_rx_sync_size(ndev->mtu); in emac_probe()
3123 dev->tx_desc = in emac_probe()
3124 dev->mal->bd_virt + mal_tx_bd_offset(dev->mal, dev->mal_tx_chan); in emac_probe()
3125 dev->rx_desc = in emac_probe()
3126 dev->mal->bd_virt + mal_rx_bd_offset(dev->mal, dev->mal_rx_chan); in emac_probe()
3128 DBG(dev, "tx_desc %p" NL, dev->tx_desc); in emac_probe()
3129 DBG(dev, "rx_desc %p" NL, dev->rx_desc); in emac_probe()
3132 memset(dev->tx_desc, 0, NUM_TX_BUFF * sizeof(struct mal_descriptor)); in emac_probe()
3133 memset(dev->rx_desc, 0, NUM_RX_BUFF * sizeof(struct mal_descriptor)); in emac_probe()
3134 memset(dev->tx_skb, 0, NUM_TX_BUFF * sizeof(struct sk_buff *)); in emac_probe()
3135 memset(dev->rx_skb, 0, NUM_RX_BUFF * sizeof(struct sk_buff *)); in emac_probe()
3138 if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII) && in emac_probe()
3139 (err = zmii_attach(dev->zmii_dev, dev->zmii_port, &dev->phy_mode)) != 0) in emac_probe()
3143 if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII) && in emac_probe()
3144 (err = rgmii_attach(dev->rgmii_dev, dev->rgmii_port, dev->phy_mode)) != 0) in emac_probe()
3148 if (emac_has_feature(dev, EMAC_FTR_HAS_TAH) && in emac_probe()
3149 (err = tah_attach(dev->tah_dev, dev->tah_port)) != 0) in emac_probe()
3153 dev->phy.speed = SPEED_100; in emac_probe()
3154 dev->phy.duplex = DUPLEX_FULL; in emac_probe()
3155 dev->phy.autoneg = AUTONEG_DISABLE; in emac_probe()
3156 dev->phy.pause = dev->phy.asym_pause = 0; in emac_probe()
3157 dev->stop_timeout = STOP_TIMEOUT_100; in emac_probe()
3158 INIT_DELAYED_WORK(&dev->link_work, emac_link_timer); in emac_probe()
3161 if (emac_has_feature(dev, EMAC_FTR_APM821XX_NO_HALF_DUPLEX)) { in emac_probe()
3162 dev->phy_feat_exc = (SUPPORTED_1000baseT_Half | in emac_probe()
3168 err = emac_init_phy(dev); in emac_probe()
3172 if (dev->tah_dev) { in emac_probe()
3177 if (emac_phy_supports_gige(dev->phy_mode)) { in emac_probe()
3179 dev->commac.ops = &emac_commac_sg_ops; in emac_probe()
3186 ndev->max_mtu = dev->max_mtu; in emac_probe()
3201 platform_set_drvdata(ofdev, dev); in emac_probe()
3208 ndev->name, dev->cell_index, np, ndev->dev_addr); in emac_probe()
3210 if (dev->phy_mode == PHY_INTERFACE_MODE_SGMII) in emac_probe()
3213 if (dev->phy.address >= 0) in emac_probe()
3215 dev->phy.def->name, dev->phy.address); in emac_probe()
3223 if (emac_has_feature(dev, EMAC_FTR_HAS_TAH)) in emac_probe()
3224 tah_detach(dev->tah_dev, dev->tah_port); in emac_probe()
3226 if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) in emac_probe()
3227 rgmii_detach(dev->rgmii_dev, dev->rgmii_port); in emac_probe()
3229 if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII)) in emac_probe()
3230 zmii_detach(dev->zmii_dev, dev->zmii_port); in emac_probe()
3232 mal_unregister_commac(dev->mal, &dev->commac); in emac_probe()
3234 emac_put_deps(dev); in emac_probe()
3236 iounmap(dev->emacp); in emac_probe()
3238 if (dev->wol_irq) in emac_probe()
3239 irq_dispose_mapping(dev->wol_irq); in emac_probe()
3240 if (dev->emac_irq) in emac_probe()
3241 irq_dispose_mapping(dev->emac_irq); in emac_probe()
3258 struct emac_instance *dev = platform_get_drvdata(ofdev); in emac_remove() local
3260 DBG(dev, "remove" NL); in emac_remove()
3262 unregister_netdev(dev->ndev); in emac_remove()
3264 cancel_work_sync(&dev->reset_work); in emac_remove()
3266 if (emac_has_feature(dev, EMAC_FTR_HAS_TAH)) in emac_remove()
3267 tah_detach(dev->tah_dev, dev->tah_port); in emac_remove()
3268 if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) in emac_remove()
3269 rgmii_detach(dev->rgmii_dev, dev->rgmii_port); in emac_remove()
3270 if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII)) in emac_remove()
3271 zmii_detach(dev->zmii_dev, dev->zmii_port); in emac_remove()
3273 if (dev->phy_dev) in emac_remove()
3274 phy_disconnect(dev->phy_dev); in emac_remove()
3276 if (dev->mii_bus) in emac_remove()
3277 mdiobus_unregister(dev->mii_bus); in emac_remove()
3279 busy_phy_map &= ~(1 << dev->phy.address); in emac_remove()
3280 DBG(dev, "busy_phy_map now %#x" NL, busy_phy_map); in emac_remove()
3282 mal_unregister_commac(dev->mal, &dev->commac); in emac_remove()
3283 emac_put_deps(dev); in emac_remove()
3285 iounmap(dev->emacp); in emac_remove()
3287 if (dev->wol_irq) in emac_remove()
3288 irq_dispose_mapping(dev->wol_irq); in emac_remove()
3289 if (dev->emac_irq) in emac_remove()
3290 irq_dispose_mapping(dev->emac_irq); in emac_remove()
3292 free_netdev(dev->ndev); in emac_remove()