Lines Matching full:dev
116 static inline void emac_report_timeout_error(struct emac_instance *dev, in emac_report_timeout_error() argument
119 if (emac_has_feature(dev, EMAC_FTR_440GX_PHY_CLK_FIX | in emac_report_timeout_error()
122 DBG(dev, "%s" NL, error); in emac_report_timeout_error()
124 printk(KERN_ERR "%pOF: %s\n", dev->ofdev->dev.of_node, error); in emac_report_timeout_error()
131 static inline void emac_rx_clk_tx(struct emac_instance *dev) in emac_rx_clk_tx() argument
134 if (emac_has_feature(dev, EMAC_FTR_440EP_PHY_CLK_FIX)) in emac_rx_clk_tx()
136 0, SDR0_MFR_ECS >> dev->cell_index); in emac_rx_clk_tx()
140 static inline void emac_rx_clk_default(struct emac_instance *dev) in emac_rx_clk_default() argument
143 if (emac_has_feature(dev, EMAC_FTR_440EP_PHY_CLK_FIX)) in emac_rx_clk_default()
145 SDR0_MFR_ECS >> dev->cell_index, 0); in emac_rx_clk_default()
185 static void emac_clean_tx_ring(struct emac_instance *dev);
186 static void __emac_set_multicast_list(struct emac_instance *dev);
204 static inline void emac_tx_enable(struct emac_instance *dev) in emac_tx_enable() argument
206 struct emac_regs __iomem *p = dev->emacp; in emac_tx_enable()
209 DBG(dev, "tx_enable" NL); in emac_tx_enable()
216 static void emac_tx_disable(struct emac_instance *dev) in emac_tx_disable() argument
218 struct emac_regs __iomem *p = dev->emacp; in emac_tx_disable()
221 DBG(dev, "tx_disable" NL); in emac_tx_disable()
225 int n = dev->stop_timeout; in emac_tx_disable()
232 emac_report_timeout_error(dev, "TX disable timeout"); in emac_tx_disable()
236 static void emac_rx_enable(struct emac_instance *dev) in emac_rx_enable() argument
238 struct emac_regs __iomem *p = dev->emacp; in emac_rx_enable()
241 if (unlikely(test_bit(MAL_COMMAC_RX_STOPPED, &dev->commac.flags))) in emac_rx_enable()
244 DBG(dev, "rx_enable" NL); in emac_rx_enable()
250 int n = dev->stop_timeout; in emac_rx_enable()
256 emac_report_timeout_error(dev, in emac_rx_enable()
265 static void emac_rx_disable(struct emac_instance *dev) in emac_rx_disable() argument
267 struct emac_regs __iomem *p = dev->emacp; in emac_rx_disable()
270 DBG(dev, "rx_disable" NL); in emac_rx_disable()
274 int n = dev->stop_timeout; in emac_rx_disable()
281 emac_report_timeout_error(dev, "RX disable timeout"); in emac_rx_disable()
285 static inline void emac_netif_stop(struct emac_instance *dev) in emac_netif_stop() argument
287 netif_tx_lock_bh(dev->ndev); in emac_netif_stop()
288 netif_addr_lock(dev->ndev); in emac_netif_stop()
289 dev->no_mcast = 1; in emac_netif_stop()
290 netif_addr_unlock(dev->ndev); in emac_netif_stop()
291 netif_tx_unlock_bh(dev->ndev); in emac_netif_stop()
292 netif_trans_update(dev->ndev); /* prevent tx timeout */ in emac_netif_stop()
293 mal_poll_disable(dev->mal, &dev->commac); in emac_netif_stop()
294 netif_tx_disable(dev->ndev); in emac_netif_stop()
297 static inline void emac_netif_start(struct emac_instance *dev) in emac_netif_start() argument
299 netif_tx_lock_bh(dev->ndev); in emac_netif_start()
300 netif_addr_lock(dev->ndev); in emac_netif_start()
301 dev->no_mcast = 0; in emac_netif_start()
302 if (dev->mcast_pending && netif_running(dev->ndev)) in emac_netif_start()
303 __emac_set_multicast_list(dev); in emac_netif_start()
304 netif_addr_unlock(dev->ndev); in emac_netif_start()
305 netif_tx_unlock_bh(dev->ndev); in emac_netif_start()
307 netif_wake_queue(dev->ndev); in emac_netif_start()
314 mal_poll_enable(dev->mal, &dev->commac); in emac_netif_start()
317 static inline void emac_rx_disable_async(struct emac_instance *dev) in emac_rx_disable_async() argument
319 struct emac_regs __iomem *p = dev->emacp; in emac_rx_disable_async()
322 DBG(dev, "rx_disable_async" NL); in emac_rx_disable_async()
329 static int emac_reset(struct emac_instance *dev) in emac_reset() argument
331 struct emac_regs __iomem *p = dev->emacp; in emac_reset()
335 DBG(dev, "reset" NL); in emac_reset()
337 if (!dev->reset_failed) { in emac_reset()
341 emac_rx_disable(dev); in emac_reset()
342 emac_tx_disable(dev); in emac_reset()
364 if (emac_has_feature(dev, EMAC_FTR_460EX_PHY_CLK_FIX)) { in emac_reset()
365 if (try_internal_clock || (dev->phy_address == 0xffffffff && in emac_reset()
366 dev->phy_map == 0xffffffff)) { in emac_reset()
369 0, SDR0_ETH_CFG_ECS << dev->cell_index); in emac_reset()
373 SDR0_ETH_CFG_ECS << dev->cell_index, 0); in emac_reset()
383 if (emac_has_feature(dev, EMAC_FTR_460EX_PHY_CLK_FIX)) { in emac_reset()
391 if (try_internal_clock || (dev->phy_address == 0xffffffff && in emac_reset()
392 dev->phy_map == 0xffffffff)) { in emac_reset()
395 SDR0_ETH_CFG_ECS << dev->cell_index, 0); in emac_reset()
401 dev->reset_failed = 0; in emac_reset()
404 emac_report_timeout_error(dev, "reset timeout"); in emac_reset()
405 dev->reset_failed = 1; in emac_reset()
410 static void emac_hash_mc(struct emac_instance *dev) in emac_hash_mc() argument
412 u32 __iomem *gaht_base = emac_gaht_base(dev); in emac_hash_mc()
413 const int regs = EMAC_XAHT_REGS(dev); in emac_hash_mc()
418 DBG(dev, "hash_mc %d" NL, netdev_mc_count(dev->ndev)); in emac_hash_mc()
422 netdev_for_each_mc_addr(ha, dev->ndev) { in emac_hash_mc()
424 DBG2(dev, "mc %pM" NL, ha->addr); in emac_hash_mc()
426 slot = EMAC_XAHT_CRC_TO_SLOT(dev, in emac_hash_mc()
428 reg = EMAC_XAHT_SLOT_TO_REG(dev, slot); in emac_hash_mc()
429 mask = EMAC_XAHT_SLOT_TO_MASK(dev, slot); in emac_hash_mc()
440 struct emac_instance *dev = netdev_priv(ndev); in emac_iff2rmr() local
445 if (emac_has_feature(dev, EMAC_FTR_EMAC4)) in emac_iff2rmr()
453 (netdev_mc_count(ndev) > EMAC_XAHT_SLOTS(dev))) in emac_iff2rmr()
458 if (emac_has_feature(dev, EMAC_APM821XX_REQ_JUMBO_FRAME_SIZE)) { in emac_iff2rmr()
466 static u32 __emac_calc_base_mr1(struct emac_instance *dev, int tx_size, int rx_size) in __emac_calc_base_mr1() argument
470 DBG2(dev, "__emac_calc_base_mr1" NL); in __emac_calc_base_mr1()
478 dev->ndev->name, tx_size); in __emac_calc_base_mr1()
490 dev->ndev->name, rx_size); in __emac_calc_base_mr1()
496 static u32 __emac4_calc_base_mr1(struct emac_instance *dev, int tx_size, int rx_size) in __emac4_calc_base_mr1() argument
499 EMAC4_MR1_OBCI(dev->opb_bus_freq / 1000000); in __emac4_calc_base_mr1()
501 DBG2(dev, "__emac4_calc_base_mr1" NL); in __emac4_calc_base_mr1()
518 dev->ndev->name, tx_size); in __emac4_calc_base_mr1()
536 dev->ndev->name, rx_size); in __emac4_calc_base_mr1()
542 static u32 emac_calc_base_mr1(struct emac_instance *dev, int tx_size, int rx_size) in emac_calc_base_mr1() argument
544 return emac_has_feature(dev, EMAC_FTR_EMAC4) ? in emac_calc_base_mr1()
545 __emac4_calc_base_mr1(dev, tx_size, rx_size) : in emac_calc_base_mr1()
546 __emac_calc_base_mr1(dev, tx_size, rx_size); in emac_calc_base_mr1()
549 static inline u32 emac_calc_trtr(struct emac_instance *dev, unsigned int size) in emac_calc_trtr() argument
551 if (emac_has_feature(dev, EMAC_FTR_EMAC4)) in emac_calc_trtr()
557 static inline u32 emac_calc_rwmr(struct emac_instance *dev, in emac_calc_rwmr() argument
560 if (emac_has_feature(dev, EMAC_FTR_EMAC4)) in emac_calc_rwmr()
566 static int emac_configure(struct emac_instance *dev) in emac_configure() argument
568 struct emac_regs __iomem *p = dev->emacp; in emac_configure()
569 struct net_device *ndev = dev->ndev; in emac_configure()
570 int tx_size, rx_size, link = netif_carrier_ok(dev->ndev); in emac_configure()
573 DBG(dev, "configure" NL); in emac_configure()
579 } else if (emac_reset(dev) < 0) in emac_configure()
582 if (emac_has_feature(dev, EMAC_FTR_HAS_TAH)) in emac_configure()
583 tah_reset(dev->tah_dev); in emac_configure()
585 DBG(dev, " link = %d duplex = %d, pause = %d, asym_pause = %d\n", in emac_configure()
586 link, dev->phy.duplex, dev->phy.pause, dev->phy.asym_pause); in emac_configure()
589 tx_size = dev->tx_fifo_size; in emac_configure()
590 rx_size = dev->rx_fifo_size; in emac_configure()
597 else if (dev->phy.duplex == DUPLEX_FULL) in emac_configure()
601 dev->stop_timeout = STOP_TIMEOUT_10; in emac_configure()
602 switch (dev->phy.speed) { in emac_configure()
604 if (emac_phy_gpcs(dev->phy.mode)) { in emac_configure()
606 (dev->phy.gpcs_address != 0xffffffff) ? in emac_configure()
607 dev->phy.gpcs_address : dev->phy.address); in emac_configure()
617 tx_size = dev->tx_fifo_size_gige; in emac_configure()
618 rx_size = dev->rx_fifo_size_gige; in emac_configure()
620 if (dev->ndev->mtu > ETH_DATA_LEN) { in emac_configure()
621 if (emac_has_feature(dev, EMAC_FTR_EMAC4)) in emac_configure()
625 dev->stop_timeout = STOP_TIMEOUT_1000_JUMBO; in emac_configure()
627 dev->stop_timeout = STOP_TIMEOUT_1000; in emac_configure()
631 dev->stop_timeout = STOP_TIMEOUT_100; in emac_configure()
637 if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) in emac_configure()
638 rgmii_set_speed(dev->rgmii_dev, dev->rgmii_port, in emac_configure()
639 dev->phy.speed); in emac_configure()
640 if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII)) in emac_configure()
641 zmii_set_speed(dev->zmii_dev, dev->zmii_port, dev->phy.speed); in emac_configure()
646 if (!emac_has_feature(dev, EMAC_FTR_NO_FLOW_CONTROL_40x) && in emac_configure()
647 dev->phy.duplex == DUPLEX_FULL) { in emac_configure()
648 if (dev->phy.pause) in emac_configure()
650 else if (dev->phy.asym_pause) in emac_configure()
655 mr1 |= emac_calc_base_mr1(dev, tx_size, rx_size); in emac_configure()
670 emac_hash_mc(dev); in emac_configure()
674 if (emac_has_feature(dev, EMAC_FTR_EMAC4)) in emac_configure()
675 r = EMAC4_TMR1((dev->mal_burst_size / dev->fifo_entry_size) + 1, in emac_configure()
676 tx_size / 2 / dev->fifo_entry_size); in emac_configure()
678 r = EMAC_TMR1((dev->mal_burst_size / dev->fifo_entry_size) + 1, in emac_configure()
679 tx_size / 2 / dev->fifo_entry_size); in emac_configure()
681 out_be32(&p->trtr, emac_calc_trtr(dev, tx_size / 2)); in emac_configure()
702 r = emac_calc_rwmr(dev, rx_size / 8 / dev->fifo_entry_size, in emac_configure()
703 rx_size / 4 / dev->fifo_entry_size); in emac_configure()
713 if (emac_has_feature(dev, EMAC_FTR_EMAC4)) in emac_configure()
719 if (emac_phy_gpcs(dev->phy.mode)) { in emac_configure()
720 if (dev->phy.gpcs_address != 0xffffffff) in emac_configure()
721 emac_mii_reset_gpcs(&dev->phy); in emac_configure()
723 emac_mii_reset_phy(&dev->phy); in emac_configure()
729 static void emac_reinitialize(struct emac_instance *dev) in emac_reinitialize() argument
731 DBG(dev, "reinitialize" NL); in emac_reinitialize()
733 emac_netif_stop(dev); in emac_reinitialize()
734 if (!emac_configure(dev)) { in emac_reinitialize()
735 emac_tx_enable(dev); in emac_reinitialize()
736 emac_rx_enable(dev); in emac_reinitialize()
738 emac_netif_start(dev); in emac_reinitialize()
741 static void emac_full_tx_reset(struct emac_instance *dev) in emac_full_tx_reset() argument
743 DBG(dev, "full_tx_reset" NL); in emac_full_tx_reset()
745 emac_tx_disable(dev); in emac_full_tx_reset()
746 mal_disable_tx_channel(dev->mal, dev->mal_tx_chan); in emac_full_tx_reset()
747 emac_clean_tx_ring(dev); in emac_full_tx_reset()
748 dev->tx_cnt = dev->tx_slot = dev->ack_slot = 0; in emac_full_tx_reset()
750 emac_configure(dev); in emac_full_tx_reset()
752 mal_enable_tx_channel(dev->mal, dev->mal_tx_chan); in emac_full_tx_reset()
753 emac_tx_enable(dev); in emac_full_tx_reset()
754 emac_rx_enable(dev); in emac_full_tx_reset()
759 struct emac_instance *dev = container_of(work, struct emac_instance, reset_work); in emac_reset_work() local
761 DBG(dev, "reset_work" NL); in emac_reset_work()
763 mutex_lock(&dev->link_lock); in emac_reset_work()
764 if (dev->opened) { in emac_reset_work()
765 emac_netif_stop(dev); in emac_reset_work()
766 emac_full_tx_reset(dev); in emac_reset_work()
767 emac_netif_start(dev); in emac_reset_work()
769 mutex_unlock(&dev->link_lock); in emac_reset_work()
774 struct emac_instance *dev = netdev_priv(ndev); in emac_tx_timeout() local
776 DBG(dev, "tx_timeout" NL); in emac_tx_timeout()
778 schedule_work(&dev->reset_work); in emac_tx_timeout()
782 static inline int emac_phy_done(struct emac_instance *dev, u32 stacr) in emac_phy_done() argument
786 if (emac_has_feature(dev, EMAC_FTR_STACR_OC_INVERT)) in emac_phy_done()
792 static int __emac_mdio_read(struct emac_instance *dev, u8 id, u8 reg) in __emac_mdio_read() argument
794 struct emac_regs __iomem *p = dev->emacp; in __emac_mdio_read()
798 mutex_lock(&dev->mdio_lock); in __emac_mdio_read()
800 DBG2(dev, "mdio_read(%02x,%02x)" NL, id, reg); in __emac_mdio_read()
803 if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII)) in __emac_mdio_read()
804 zmii_get_mdio(dev->zmii_dev, dev->zmii_port); in __emac_mdio_read()
805 if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) in __emac_mdio_read()
806 rgmii_get_mdio(dev->rgmii_dev, dev->rgmii_port); in __emac_mdio_read()
810 while (!emac_phy_done(dev, in_be32(&p->stacr))) { in __emac_mdio_read()
813 DBG2(dev, " -> timeout wait idle\n"); in __emac_mdio_read()
819 if (emac_has_feature(dev, EMAC_FTR_EMAC4)) in __emac_mdio_read()
820 r = EMAC4_STACR_BASE(dev->opb_bus_freq); in __emac_mdio_read()
822 r = EMAC_STACR_BASE(dev->opb_bus_freq); in __emac_mdio_read()
823 if (emac_has_feature(dev, EMAC_FTR_STACR_OC_INVERT)) in __emac_mdio_read()
825 if (emac_has_feature(dev, EMAC_FTR_HAS_NEW_STACR)) in __emac_mdio_read()
835 while (!emac_phy_done(dev, (r = in_be32(&p->stacr)))) { in __emac_mdio_read()
838 DBG2(dev, " -> timeout wait complete\n"); in __emac_mdio_read()
844 DBG(dev, "mdio_read(%02x, %02x) failed" NL, id, reg); in __emac_mdio_read()
851 DBG2(dev, "mdio_read -> %04x" NL, r); in __emac_mdio_read()
854 if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) in __emac_mdio_read()
855 rgmii_put_mdio(dev->rgmii_dev, dev->rgmii_port); in __emac_mdio_read()
856 if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII)) in __emac_mdio_read()
857 zmii_put_mdio(dev->zmii_dev, dev->zmii_port); in __emac_mdio_read()
858 mutex_unlock(&dev->mdio_lock); in __emac_mdio_read()
863 static void __emac_mdio_write(struct emac_instance *dev, u8 id, u8 reg, in __emac_mdio_write() argument
866 struct emac_regs __iomem *p = dev->emacp; in __emac_mdio_write()
870 mutex_lock(&dev->mdio_lock); in __emac_mdio_write()
872 DBG2(dev, "mdio_write(%02x,%02x,%04x)" NL, id, reg, val); in __emac_mdio_write()
875 if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII)) in __emac_mdio_write()
876 zmii_get_mdio(dev->zmii_dev, dev->zmii_port); in __emac_mdio_write()
877 if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) in __emac_mdio_write()
878 rgmii_get_mdio(dev->rgmii_dev, dev->rgmii_port); in __emac_mdio_write()
882 while (!emac_phy_done(dev, in_be32(&p->stacr))) { in __emac_mdio_write()
885 DBG2(dev, " -> timeout wait idle\n"); in __emac_mdio_write()
891 if (emac_has_feature(dev, EMAC_FTR_EMAC4)) in __emac_mdio_write()
892 r = EMAC4_STACR_BASE(dev->opb_bus_freq); in __emac_mdio_write()
894 r = EMAC_STACR_BASE(dev->opb_bus_freq); in __emac_mdio_write()
895 if (emac_has_feature(dev, EMAC_FTR_STACR_OC_INVERT)) in __emac_mdio_write()
897 if (emac_has_feature(dev, EMAC_FTR_HAS_NEW_STACR)) in __emac_mdio_write()
908 while (!emac_phy_done(dev, in_be32(&p->stacr))) { in __emac_mdio_write()
911 DBG2(dev, " -> timeout wait complete\n"); in __emac_mdio_write()
916 if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) in __emac_mdio_write()
917 rgmii_put_mdio(dev->rgmii_dev, dev->rgmii_port); in __emac_mdio_write()
918 if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII)) in __emac_mdio_write()
919 zmii_put_mdio(dev->zmii_dev, dev->zmii_port); in __emac_mdio_write()
920 mutex_unlock(&dev->mdio_lock); in __emac_mdio_write()
925 struct emac_instance *dev = netdev_priv(ndev); in emac_mdio_read() local
928 res = __emac_mdio_read((dev->mdio_instance && in emac_mdio_read()
929 dev->phy.gpcs_address != id) ? in emac_mdio_read()
930 dev->mdio_instance : dev, in emac_mdio_read()
937 struct emac_instance *dev = netdev_priv(ndev); in emac_mdio_write() local
939 __emac_mdio_write((dev->mdio_instance && in emac_mdio_write()
940 dev->phy.gpcs_address != id) ? in emac_mdio_write()
941 dev->mdio_instance : dev, in emac_mdio_write()
946 static void __emac_set_multicast_list(struct emac_instance *dev) in __emac_set_multicast_list() argument
948 struct emac_regs __iomem *p = dev->emacp; in __emac_set_multicast_list()
949 u32 rmr = emac_iff2rmr(dev->ndev); in __emac_set_multicast_list()
951 DBG(dev, "__multicast %08x" NL, rmr); in __emac_set_multicast_list()
968 dev->mcast_pending = 0; in __emac_set_multicast_list()
969 emac_rx_disable(dev); in __emac_set_multicast_list()
971 emac_hash_mc(dev); in __emac_set_multicast_list()
973 emac_rx_enable(dev); in __emac_set_multicast_list()
979 struct emac_instance *dev = netdev_priv(ndev); in emac_set_multicast_list() local
981 DBG(dev, "multicast" NL); in emac_set_multicast_list()
983 BUG_ON(!netif_running(dev->ndev)); in emac_set_multicast_list()
985 if (dev->no_mcast) { in emac_set_multicast_list()
986 dev->mcast_pending = 1; in emac_set_multicast_list()
990 mutex_lock(&dev->link_lock); in emac_set_multicast_list()
991 __emac_set_multicast_list(dev); in emac_set_multicast_list()
992 mutex_unlock(&dev->link_lock); in emac_set_multicast_list()
997 struct emac_instance *dev = netdev_priv(ndev); in emac_set_mac_address() local
999 struct emac_regs __iomem *p = dev->emacp; in emac_set_mac_address()
1004 mutex_lock(&dev->link_lock); in emac_set_mac_address()
1008 emac_rx_disable(dev); in emac_set_mac_address()
1009 emac_tx_disable(dev); in emac_set_mac_address()
1014 emac_tx_enable(dev); in emac_set_mac_address()
1015 emac_rx_enable(dev); in emac_set_mac_address()
1017 mutex_unlock(&dev->link_lock); in emac_set_mac_address()
1022 static int emac_resize_rx_ring(struct emac_instance *dev, int new_mtu) in emac_resize_rx_ring() argument
1029 mutex_lock(&dev->link_lock); in emac_resize_rx_ring()
1030 emac_netif_stop(dev); in emac_resize_rx_ring()
1031 emac_rx_disable(dev); in emac_resize_rx_ring()
1032 mal_disable_rx_channel(dev->mal, dev->mal_rx_chan); in emac_resize_rx_ring()
1034 if (dev->rx_sg_skb) { in emac_resize_rx_ring()
1035 ++dev->estats.rx_dropped_resize; in emac_resize_rx_ring()
1036 dev_kfree_skb(dev->rx_sg_skb); in emac_resize_rx_ring()
1037 dev->rx_sg_skb = NULL; in emac_resize_rx_ring()
1045 if (dev->rx_desc[i].ctrl & MAL_RX_CTRL_FIRST) in emac_resize_rx_ring()
1046 ++dev->estats.rx_dropped_resize; in emac_resize_rx_ring()
1048 dev->rx_desc[i].data_len = 0; in emac_resize_rx_ring()
1049 dev->rx_desc[i].ctrl = MAL_RX_CTRL_EMPTY | in emac_resize_rx_ring()
1054 if (rx_skb_size <= dev->rx_skb_size) in emac_resize_rx_ring()
1061 skb = netdev_alloc_skb_ip_align(dev->ndev, rx_skb_size); in emac_resize_rx_ring()
1067 BUG_ON(!dev->rx_skb[i]); in emac_resize_rx_ring()
1068 dev_kfree_skb(dev->rx_skb[i]); in emac_resize_rx_ring()
1070 dev->rx_desc[i].data_ptr = in emac_resize_rx_ring()
1071 dma_map_single(&dev->ofdev->dev, skb->data - NET_IP_ALIGN, in emac_resize_rx_ring()
1074 dev->rx_skb[i] = skb; in emac_resize_rx_ring()
1078 if (emac_has_feature(dev, EMAC_APM821XX_REQ_JUMBO_FRAME_SIZE)) { in emac_resize_rx_ring()
1080 (dev->ndev->mtu > ETH_DATA_LEN); in emac_resize_rx_ring()
1083 (dev->ndev->mtu > ETH_DATA_LEN); in emac_resize_rx_ring()
1088 set_bit(MAL_COMMAC_RX_STOPPED, &dev->commac.flags); in emac_resize_rx_ring()
1090 WRITE_ONCE(dev->ndev->mtu, new_mtu); in emac_resize_rx_ring()
1091 emac_full_tx_reset(dev); in emac_resize_rx_ring()
1094 mal_set_rcbs(dev->mal, dev->mal_rx_chan, emac_rx_size(new_mtu)); in emac_resize_rx_ring()
1097 clear_bit(MAL_COMMAC_RX_STOPPED, &dev->commac.flags); in emac_resize_rx_ring()
1098 dev->rx_slot = 0; in emac_resize_rx_ring()
1099 mal_enable_rx_channel(dev->mal, dev->mal_rx_chan); in emac_resize_rx_ring()
1100 emac_rx_enable(dev); in emac_resize_rx_ring()
1101 emac_netif_start(dev); in emac_resize_rx_ring()
1102 mutex_unlock(&dev->link_lock); in emac_resize_rx_ring()
1110 struct emac_instance *dev = netdev_priv(ndev); in emac_change_mtu() local
1113 DBG(dev, "change_mtu(%d)" NL, new_mtu); in emac_change_mtu()
1118 ret = emac_resize_rx_ring(dev, new_mtu); in emac_change_mtu()
1123 dev->rx_skb_size = emac_rx_skb_size(new_mtu); in emac_change_mtu()
1124 dev->rx_sync_size = emac_rx_sync_size(new_mtu); in emac_change_mtu()
1130 static void emac_clean_tx_ring(struct emac_instance *dev) in emac_clean_tx_ring() argument
1135 if (dev->tx_skb[i]) { in emac_clean_tx_ring()
1136 dev_kfree_skb(dev->tx_skb[i]); in emac_clean_tx_ring()
1137 dev->tx_skb[i] = NULL; in emac_clean_tx_ring()
1138 if (dev->tx_desc[i].ctrl & MAL_TX_CTRL_READY) in emac_clean_tx_ring()
1139 ++dev->estats.tx_dropped; in emac_clean_tx_ring()
1141 dev->tx_desc[i].ctrl = 0; in emac_clean_tx_ring()
1142 dev->tx_desc[i].data_ptr = 0; in emac_clean_tx_ring()
1146 static void emac_clean_rx_ring(struct emac_instance *dev) in emac_clean_rx_ring() argument
1151 if (dev->rx_skb[i]) { in emac_clean_rx_ring()
1152 dev->rx_desc[i].ctrl = 0; in emac_clean_rx_ring()
1153 dev_kfree_skb(dev->rx_skb[i]); in emac_clean_rx_ring()
1154 dev->rx_skb[i] = NULL; in emac_clean_rx_ring()
1155 dev->rx_desc[i].data_ptr = 0; in emac_clean_rx_ring()
1158 if (dev->rx_sg_skb) { in emac_clean_rx_ring()
1159 dev_kfree_skb(dev->rx_sg_skb); in emac_clean_rx_ring()
1160 dev->rx_sg_skb = NULL; in emac_clean_rx_ring()
1165 __emac_prepare_rx_skb(struct sk_buff *skb, struct emac_instance *dev, int slot) in __emac_prepare_rx_skb() argument
1170 dev->rx_skb[slot] = skb; in __emac_prepare_rx_skb()
1171 dev->rx_desc[slot].data_len = 0; in __emac_prepare_rx_skb()
1173 dev->rx_desc[slot].data_ptr = in __emac_prepare_rx_skb()
1174 dma_map_single(&dev->ofdev->dev, skb->data - NET_IP_ALIGN, in __emac_prepare_rx_skb()
1175 dev->rx_sync_size, DMA_FROM_DEVICE) + NET_IP_ALIGN; in __emac_prepare_rx_skb()
1177 dev->rx_desc[slot].ctrl = MAL_RX_CTRL_EMPTY | in __emac_prepare_rx_skb()
1184 emac_alloc_rx_skb(struct emac_instance *dev, int slot) in emac_alloc_rx_skb() argument
1188 skb = __netdev_alloc_skb_ip_align(dev->ndev, dev->rx_skb_size, in emac_alloc_rx_skb()
1191 return __emac_prepare_rx_skb(skb, dev, slot); in emac_alloc_rx_skb()
1195 emac_alloc_rx_skb_napi(struct emac_instance *dev, int slot) in emac_alloc_rx_skb_napi() argument
1199 skb = napi_alloc_skb(&dev->mal->napi, dev->rx_skb_size); in emac_alloc_rx_skb_napi()
1201 return __emac_prepare_rx_skb(skb, dev, slot); in emac_alloc_rx_skb_napi()
1204 static void emac_print_link_status(struct emac_instance *dev) in emac_print_link_status() argument
1206 if (netif_carrier_ok(dev->ndev)) in emac_print_link_status()
1208 dev->ndev->name, dev->phy.speed, in emac_print_link_status()
1209 dev->phy.duplex == DUPLEX_FULL ? "FDX" : "HDX", in emac_print_link_status()
1210 dev->phy.pause ? ", pause enabled" : in emac_print_link_status()
1211 dev->phy.asym_pause ? ", asymmetric pause enabled" : ""); in emac_print_link_status()
1213 printk(KERN_INFO "%s: link is down\n", dev->ndev->name); in emac_print_link_status()
1219 struct emac_instance *dev = netdev_priv(ndev); in emac_open() local
1222 DBG(dev, "open" NL); in emac_open()
1226 if (emac_alloc_rx_skb(dev, i)) { in emac_open()
1232 dev->tx_cnt = dev->tx_slot = dev->ack_slot = dev->rx_slot = 0; in emac_open()
1233 clear_bit(MAL_COMMAC_RX_STOPPED, &dev->commac.flags); in emac_open()
1234 dev->rx_sg_skb = NULL; in emac_open()
1236 mutex_lock(&dev->link_lock); in emac_open()
1237 dev->opened = 1; in emac_open()
1241 if (dev->phy.address >= 0) { in emac_open()
1243 if (dev->phy.def->ops->poll_link(&dev->phy)) { in emac_open()
1244 dev->phy.def->ops->read_link(&dev->phy); in emac_open()
1245 emac_rx_clk_default(dev); in emac_open()
1246 netif_carrier_on(dev->ndev); in emac_open()
1249 emac_rx_clk_tx(dev); in emac_open()
1250 netif_carrier_off(dev->ndev); in emac_open()
1253 dev->link_polling = 1; in emac_open()
1255 schedule_delayed_work(&dev->link_work, link_poll_interval); in emac_open()
1256 emac_print_link_status(dev); in emac_open()
1258 netif_carrier_on(dev->ndev); in emac_open()
1263 emac_configure(dev); in emac_open()
1264 mal_poll_add(dev->mal, &dev->commac); in emac_open()
1265 mal_enable_tx_channel(dev->mal, dev->mal_tx_chan); in emac_open()
1266 mal_set_rcbs(dev->mal, dev->mal_rx_chan, emac_rx_size(ndev->mtu)); in emac_open()
1267 mal_enable_rx_channel(dev->mal, dev->mal_rx_chan); in emac_open()
1268 emac_tx_enable(dev); in emac_open()
1269 emac_rx_enable(dev); in emac_open()
1270 emac_netif_start(dev); in emac_open()
1272 mutex_unlock(&dev->link_lock); in emac_open()
1276 emac_clean_rx_ring(dev); in emac_open()
1282 static int emac_link_differs(struct emac_instance *dev)
1284 u32 r = in_be32(&dev->emacp->mr1);
1308 return speed != dev->phy.speed || duplex != dev->phy.duplex ||
1309 pause != dev->phy.pause || asym_pause != dev->phy.asym_pause;
1315 struct emac_instance *dev = in emac_link_timer() local
1320 mutex_lock(&dev->link_lock); in emac_link_timer()
1321 DBG2(dev, "link timer" NL); in emac_link_timer()
1323 if (!dev->opened) in emac_link_timer()
1326 if (dev->phy.def->ops->poll_link(&dev->phy)) { in emac_link_timer()
1327 if (!netif_carrier_ok(dev->ndev)) { in emac_link_timer()
1328 emac_rx_clk_default(dev); in emac_link_timer()
1330 dev->phy.def->ops->read_link(&dev->phy); in emac_link_timer()
1332 netif_carrier_on(dev->ndev); in emac_link_timer()
1333 emac_netif_stop(dev); in emac_link_timer()
1334 emac_full_tx_reset(dev); in emac_link_timer()
1335 emac_netif_start(dev); in emac_link_timer()
1336 emac_print_link_status(dev); in emac_link_timer()
1340 if (netif_carrier_ok(dev->ndev)) { in emac_link_timer()
1341 emac_rx_clk_tx(dev); in emac_link_timer()
1342 netif_carrier_off(dev->ndev); in emac_link_timer()
1343 netif_tx_disable(dev->ndev); in emac_link_timer()
1344 emac_reinitialize(dev); in emac_link_timer()
1345 emac_print_link_status(dev); in emac_link_timer()
1349 schedule_delayed_work(&dev->link_work, link_poll_interval); in emac_link_timer()
1351 mutex_unlock(&dev->link_lock); in emac_link_timer()
1354 static void emac_force_link_update(struct emac_instance *dev) in emac_force_link_update() argument
1356 netif_carrier_off(dev->ndev); in emac_force_link_update()
1358 if (dev->link_polling) { in emac_force_link_update()
1359 cancel_delayed_work_sync(&dev->link_work); in emac_force_link_update()
1360 if (dev->link_polling) in emac_force_link_update()
1361 schedule_delayed_work(&dev->link_work, PHY_POLL_LINK_OFF); in emac_force_link_update()
1368 struct emac_instance *dev = netdev_priv(ndev); in emac_close() local
1370 DBG(dev, "close" NL); in emac_close()
1372 if (dev->phy.address >= 0) { in emac_close()
1373 dev->link_polling = 0; in emac_close()
1374 cancel_delayed_work_sync(&dev->link_work); in emac_close()
1376 mutex_lock(&dev->link_lock); in emac_close()
1377 emac_netif_stop(dev); in emac_close()
1378 dev->opened = 0; in emac_close()
1379 mutex_unlock(&dev->link_lock); in emac_close()
1381 emac_rx_disable(dev); in emac_close()
1382 emac_tx_disable(dev); in emac_close()
1383 mal_disable_rx_channel(dev->mal, dev->mal_rx_chan); in emac_close()
1384 mal_disable_tx_channel(dev->mal, dev->mal_tx_chan); in emac_close()
1385 mal_poll_del(dev->mal, &dev->commac); in emac_close()
1387 emac_clean_tx_ring(dev); in emac_close()
1388 emac_clean_rx_ring(dev); in emac_close()
1395 static inline u16 emac_tx_csum(struct emac_instance *dev, in emac_tx_csum() argument
1398 if (emac_has_feature(dev, EMAC_FTR_HAS_TAH) && in emac_tx_csum()
1400 ++dev->stats.tx_packets_csum; in emac_tx_csum()
1406 static inline netdev_tx_t emac_xmit_finish(struct emac_instance *dev, int len) in emac_xmit_finish() argument
1408 struct emac_regs __iomem *p = dev->emacp; in emac_xmit_finish()
1409 struct net_device *ndev = dev->ndev; in emac_xmit_finish()
1412 * difference, then we can store the TMR0 value in "dev" in emac_xmit_finish()
1415 if (emac_has_feature(dev, EMAC_FTR_EMAC4)) in emac_xmit_finish()
1420 if (unlikely(++dev->tx_cnt == NUM_TX_BUFF)) { in emac_xmit_finish()
1422 DBG2(dev, "stopped TX queue" NL); in emac_xmit_finish()
1426 ++dev->stats.tx_packets; in emac_xmit_finish()
1427 dev->stats.tx_bytes += len; in emac_xmit_finish()
1435 struct emac_instance *dev = netdev_priv(ndev); in emac_start_xmit() local
1440 MAL_TX_CTRL_LAST | emac_tx_csum(dev, skb); in emac_start_xmit()
1442 slot = dev->tx_slot++; in emac_start_xmit()
1443 if (dev->tx_slot == NUM_TX_BUFF) { in emac_start_xmit()
1444 dev->tx_slot = 0; in emac_start_xmit()
1448 DBG2(dev, "xmit(%u) %d" NL, len, slot); in emac_start_xmit()
1450 dev->tx_skb[slot] = skb; in emac_start_xmit()
1451 dev->tx_desc[slot].data_ptr = dma_map_single(&dev->ofdev->dev, in emac_start_xmit()
1454 dev->tx_desc[slot].data_len = (u16) len; in emac_start_xmit()
1456 dev->tx_desc[slot].ctrl = ctrl; in emac_start_xmit()
1458 return emac_xmit_finish(dev, len); in emac_start_xmit()
1461 static inline int emac_xmit_split(struct emac_instance *dev, int slot, in emac_xmit_split() argument
1476 dev->tx_skb[slot] = NULL; in emac_xmit_split()
1477 dev->tx_desc[slot].data_ptr = pd; in emac_xmit_split()
1478 dev->tx_desc[slot].data_len = (u16) chunk; in emac_xmit_split()
1479 dev->tx_desc[slot].ctrl = ctrl; in emac_xmit_split()
1480 ++dev->tx_cnt; in emac_xmit_split()
1494 struct emac_instance *dev = netdev_priv(ndev); in emac_start_xmit_sg() local
1511 if (unlikely(dev->tx_cnt + nr_frags + mal_tx_chunks(len) > NUM_TX_BUFF)) in emac_start_xmit_sg()
1515 emac_tx_csum(dev, skb); in emac_start_xmit_sg()
1516 slot = dev->tx_slot; in emac_start_xmit_sg()
1519 dev->tx_skb[slot] = NULL; in emac_start_xmit_sg()
1521 dev->tx_desc[slot].data_ptr = pd = in emac_start_xmit_sg()
1522 dma_map_single(&dev->ofdev->dev, skb->data, len, DMA_TO_DEVICE); in emac_start_xmit_sg()
1523 dev->tx_desc[slot].data_len = (u16) chunk; in emac_start_xmit_sg()
1526 slot = emac_xmit_split(dev, slot, pd + chunk, len, !nr_frags, in emac_start_xmit_sg()
1533 if (unlikely(dev->tx_cnt + mal_tx_chunks(len) >= NUM_TX_BUFF)) in emac_start_xmit_sg()
1536 pd = skb_frag_dma_map(&dev->ofdev->dev, frag, 0, len, in emac_start_xmit_sg()
1539 slot = emac_xmit_split(dev, slot, pd, len, i == nr_frags - 1, in emac_start_xmit_sg()
1543 DBG2(dev, "xmit_sg(%u) %d - %d" NL, skb->len, dev->tx_slot, slot); in emac_start_xmit_sg()
1546 dev->tx_skb[slot] = skb; in emac_start_xmit_sg()
1549 if (dev->tx_slot == NUM_TX_BUFF - 1) in emac_start_xmit_sg()
1552 dev->tx_desc[dev->tx_slot].ctrl = ctrl; in emac_start_xmit_sg()
1553 dev->tx_slot = (slot + 1) % NUM_TX_BUFF; in emac_start_xmit_sg()
1555 return emac_xmit_finish(dev, skb->len); in emac_start_xmit_sg()
1561 while (slot != dev->tx_slot) { in emac_start_xmit_sg()
1562 dev->tx_desc[slot].ctrl = 0; in emac_start_xmit_sg()
1563 --dev->tx_cnt; in emac_start_xmit_sg()
1567 ++dev->estats.tx_undo; in emac_start_xmit_sg()
1571 DBG2(dev, "stopped TX queue" NL); in emac_start_xmit_sg()
1576 static void emac_parse_tx_error(struct emac_instance *dev, u16 ctrl) in emac_parse_tx_error() argument
1578 struct emac_error_stats *st = &dev->estats; in emac_parse_tx_error()
1580 DBG(dev, "BD TX error %04x" NL, ctrl); in emac_parse_tx_error()
1605 struct emac_instance *dev = param; in emac_poll_tx() local
1608 DBG2(dev, "poll_tx, %d %d" NL, dev->tx_cnt, dev->ack_slot); in emac_poll_tx()
1610 if (emac_has_feature(dev, EMAC_FTR_HAS_TAH)) in emac_poll_tx()
1615 netif_tx_lock_bh(dev->ndev); in emac_poll_tx()
1616 if (dev->tx_cnt) { in emac_poll_tx()
1618 int slot = dev->ack_slot, n = 0; in emac_poll_tx()
1620 ctrl = dev->tx_desc[slot].ctrl; in emac_poll_tx()
1622 struct sk_buff *skb = dev->tx_skb[slot]; in emac_poll_tx()
1627 dev->tx_skb[slot] = NULL; in emac_poll_tx()
1632 emac_parse_tx_error(dev, ctrl); in emac_poll_tx()
1634 if (--dev->tx_cnt) in emac_poll_tx()
1638 dev->ack_slot = slot; in emac_poll_tx()
1639 if (netif_queue_stopped(dev->ndev) && in emac_poll_tx()
1640 dev->tx_cnt < EMAC_TX_WAKEUP_THRESH) in emac_poll_tx()
1641 netif_wake_queue(dev->ndev); in emac_poll_tx()
1643 DBG2(dev, "tx %d pkts" NL, n); in emac_poll_tx()
1646 netif_tx_unlock_bh(dev->ndev); in emac_poll_tx()
1649 static inline void emac_recycle_rx_skb(struct emac_instance *dev, int slot, in emac_recycle_rx_skb() argument
1652 struct sk_buff *skb = dev->rx_skb[slot]; in emac_recycle_rx_skb()
1654 DBG2(dev, "recycle %d %d" NL, slot, len); in emac_recycle_rx_skb()
1657 dma_map_single(&dev->ofdev->dev, skb->data - NET_IP_ALIGN, in emac_recycle_rx_skb()
1661 dev->rx_desc[slot].data_len = 0; in emac_recycle_rx_skb()
1663 dev->rx_desc[slot].ctrl = MAL_RX_CTRL_EMPTY | in emac_recycle_rx_skb()
1667 static void emac_parse_rx_error(struct emac_instance *dev, u16 ctrl) in emac_parse_rx_error() argument
1669 struct emac_error_stats *st = &dev->estats; in emac_parse_rx_error()
1671 DBG(dev, "BD RX error %04x" NL, ctrl); in emac_parse_rx_error()
1694 static inline void emac_rx_csum(struct emac_instance *dev, in emac_rx_csum() argument
1698 if (!ctrl && dev->tah_dev) { in emac_rx_csum()
1700 ++dev->stats.rx_packets_csum; in emac_rx_csum()
1705 static inline int emac_rx_sg_append(struct emac_instance *dev, int slot) in emac_rx_sg_append() argument
1707 if (likely(dev->rx_sg_skb != NULL)) { in emac_rx_sg_append()
1708 int len = dev->rx_desc[slot].data_len; in emac_rx_sg_append()
1709 int tot_len = dev->rx_sg_skb->len + len; in emac_rx_sg_append()
1711 if (unlikely(tot_len + NET_IP_ALIGN > dev->rx_skb_size)) { in emac_rx_sg_append()
1712 ++dev->estats.rx_dropped_mtu; in emac_rx_sg_append()
1713 dev_kfree_skb(dev->rx_sg_skb); in emac_rx_sg_append()
1714 dev->rx_sg_skb = NULL; in emac_rx_sg_append()
1716 memcpy(skb_tail_pointer(dev->rx_sg_skb), in emac_rx_sg_append()
1717 dev->rx_skb[slot]->data, len); in emac_rx_sg_append()
1718 skb_put(dev->rx_sg_skb, len); in emac_rx_sg_append()
1719 emac_recycle_rx_skb(dev, slot, len); in emac_rx_sg_append()
1723 emac_recycle_rx_skb(dev, slot, 0); in emac_rx_sg_append()
1730 struct emac_instance *dev = param; in emac_poll_rx() local
1731 int slot = dev->rx_slot, received = 0; in emac_poll_rx()
1733 DBG2(dev, "poll_rx(%d)" NL, budget); in emac_poll_rx()
1739 u16 ctrl = dev->rx_desc[slot].ctrl; in emac_poll_rx()
1744 skb = dev->rx_skb[slot]; in emac_poll_rx()
1746 len = dev->rx_desc[slot].data_len; in emac_poll_rx()
1753 emac_parse_rx_error(dev, ctrl); in emac_poll_rx()
1754 ++dev->estats.rx_dropped_error; in emac_poll_rx()
1755 emac_recycle_rx_skb(dev, slot, 0); in emac_poll_rx()
1761 ++dev->estats.rx_dropped_stack; in emac_poll_rx()
1762 emac_recycle_rx_skb(dev, slot, len); in emac_poll_rx()
1769 copy_skb = napi_alloc_skb(&dev->mal->napi, len); in emac_poll_rx()
1776 emac_recycle_rx_skb(dev, slot, len); in emac_poll_rx()
1778 } else if (unlikely(emac_alloc_rx_skb_napi(dev, slot))) in emac_poll_rx()
1783 skb->protocol = eth_type_trans(skb, dev->ndev); in emac_poll_rx()
1784 emac_rx_csum(dev, skb, ctrl); in emac_poll_rx()
1787 ++dev->estats.rx_dropped_stack; in emac_poll_rx()
1789 ++dev->stats.rx_packets; in emac_poll_rx()
1791 dev->stats.rx_bytes += len; in emac_poll_rx()
1798 BUG_ON(dev->rx_sg_skb); in emac_poll_rx()
1799 if (unlikely(emac_alloc_rx_skb_napi(dev, slot))) { in emac_poll_rx()
1800 DBG(dev, "rx OOM %d" NL, slot); in emac_poll_rx()
1801 ++dev->estats.rx_dropped_oom; in emac_poll_rx()
1802 emac_recycle_rx_skb(dev, slot, 0); in emac_poll_rx()
1804 dev->rx_sg_skb = skb; in emac_poll_rx()
1807 } else if (!emac_rx_sg_append(dev, slot) && in emac_poll_rx()
1810 skb = dev->rx_sg_skb; in emac_poll_rx()
1811 dev->rx_sg_skb = NULL; in emac_poll_rx()
1815 emac_parse_rx_error(dev, ctrl); in emac_poll_rx()
1816 ++dev->estats.rx_dropped_error; in emac_poll_rx()
1824 DBG(dev, "rx OOM %d" NL, slot); in emac_poll_rx()
1826 ++dev->estats.rx_dropped_oom; in emac_poll_rx()
1827 emac_recycle_rx_skb(dev, slot, 0); in emac_poll_rx()
1832 DBG2(dev, "rx %d BDs" NL, received); in emac_poll_rx()
1833 dev->rx_slot = slot; in emac_poll_rx()
1836 if (unlikely(budget && test_bit(MAL_COMMAC_RX_STOPPED, &dev->commac.flags))) { in emac_poll_rx()
1838 if (!(dev->rx_desc[slot].ctrl & MAL_RX_CTRL_EMPTY)) { in emac_poll_rx()
1839 DBG2(dev, "rx restart" NL); in emac_poll_rx()
1844 if (dev->rx_sg_skb) { in emac_poll_rx()
1845 DBG2(dev, "dropping partial rx packet" NL); in emac_poll_rx()
1846 ++dev->estats.rx_dropped_error; in emac_poll_rx()
1847 dev_kfree_skb(dev->rx_sg_skb); in emac_poll_rx()
1848 dev->rx_sg_skb = NULL; in emac_poll_rx()
1851 clear_bit(MAL_COMMAC_RX_STOPPED, &dev->commac.flags); in emac_poll_rx()
1852 mal_enable_rx_channel(dev->mal, dev->mal_rx_chan); in emac_poll_rx()
1853 emac_rx_enable(dev); in emac_poll_rx()
1854 dev->rx_slot = 0; in emac_poll_rx()
1862 struct emac_instance *dev = param; in emac_peek_rx() local
1864 return !(dev->rx_desc[dev->rx_slot].ctrl & MAL_RX_CTRL_EMPTY); in emac_peek_rx()
1870 struct emac_instance *dev = param; in emac_peek_rx_sg() local
1872 int slot = dev->rx_slot; in emac_peek_rx_sg()
1874 u16 ctrl = dev->rx_desc[slot].ctrl; in emac_peek_rx_sg()
1883 if (unlikely(slot == dev->rx_slot)) in emac_peek_rx_sg()
1891 struct emac_instance *dev = param; in emac_rxde() local
1893 ++dev->estats.rx_stopped; in emac_rxde()
1894 emac_rx_disable_async(dev); in emac_rxde()
1900 struct emac_instance *dev = dev_instance; in emac_irq() local
1901 struct emac_regs __iomem *p = dev->emacp; in emac_irq()
1902 struct emac_error_stats *st = &dev->estats; in emac_irq()
1905 spin_lock(&dev->lock); in emac_irq()
1910 DBG(dev, "isr = %08x" NL, isr); in emac_irq()
1943 spin_unlock(&dev->lock); in emac_irq()
1950 struct emac_instance *dev = netdev_priv(ndev); in emac_stats() local
1951 struct emac_stats *st = &dev->stats; in emac_stats()
1952 struct emac_error_stats *est = &dev->estats; in emac_stats()
1956 DBG2(dev, "stats" NL); in emac_stats()
1959 spin_lock_irqsave(&dev->lock, flags); in emac_stats()
1997 spin_unlock_irqrestore(&dev->lock, flags); in emac_stats()
2019 struct emac_instance *dev = netdev_priv(ndev); in emac_ethtool_get_link_ksettings() local
2022 supported = dev->phy.features; in emac_ethtool_get_link_ksettings()
2024 cmd->base.phy_address = dev->phy.address; in emac_ethtool_get_link_ksettings()
2026 mutex_lock(&dev->link_lock); in emac_ethtool_get_link_ksettings()
2027 advertising = dev->phy.advertising; in emac_ethtool_get_link_ksettings()
2028 cmd->base.autoneg = dev->phy.autoneg; in emac_ethtool_get_link_ksettings()
2029 cmd->base.speed = dev->phy.speed; in emac_ethtool_get_link_ksettings()
2030 cmd->base.duplex = dev->phy.duplex; in emac_ethtool_get_link_ksettings()
2031 mutex_unlock(&dev->link_lock); in emac_ethtool_get_link_ksettings()
2045 struct emac_instance *dev = netdev_priv(ndev); in emac_ethtool_set_link_ksettings() local
2046 u32 f = dev->phy.features; in emac_ethtool_set_link_ksettings()
2052 DBG(dev, "set_settings(%d, %d, %d, 0x%08x)" NL, in emac_ethtool_set_link_ksettings()
2056 if (dev->phy.address < 0) in emac_ethtool_set_link_ksettings()
2096 mutex_lock(&dev->link_lock); in emac_ethtool_set_link_ksettings()
2097 dev->phy.def->ops->setup_forced(&dev->phy, cmd->base.speed, in emac_ethtool_set_link_ksettings()
2099 mutex_unlock(&dev->link_lock); in emac_ethtool_set_link_ksettings()
2105 mutex_lock(&dev->link_lock); in emac_ethtool_set_link_ksettings()
2106 dev->phy.def->ops->setup_aneg(&dev->phy, in emac_ethtool_set_link_ksettings()
2108 (dev->phy.advertising & in emac_ethtool_set_link_ksettings()
2111 mutex_unlock(&dev->link_lock); in emac_ethtool_set_link_ksettings()
2113 emac_force_link_update(dev); in emac_ethtool_set_link_ksettings()
2131 struct emac_instance *dev = netdev_priv(ndev); in emac_ethtool_get_pauseparam() local
2133 mutex_lock(&dev->link_lock); in emac_ethtool_get_pauseparam()
2134 if ((dev->phy.features & SUPPORTED_Autoneg) && in emac_ethtool_get_pauseparam()
2135 (dev->phy.advertising & (ADVERTISED_Pause | ADVERTISED_Asym_Pause))) in emac_ethtool_get_pauseparam()
2138 if (dev->phy.duplex == DUPLEX_FULL) { in emac_ethtool_get_pauseparam()
2139 if (dev->phy.pause) in emac_ethtool_get_pauseparam()
2141 else if (dev->phy.asym_pause) in emac_ethtool_get_pauseparam()
2144 mutex_unlock(&dev->link_lock); in emac_ethtool_get_pauseparam()
2147 static int emac_get_regs_len(struct emac_instance *dev) in emac_get_regs_len() argument
2155 struct emac_instance *dev = netdev_priv(ndev); in emac_ethtool_get_regs_len() local
2159 emac_get_regs_len(dev) + mal_get_regs_len(dev->mal); in emac_ethtool_get_regs_len()
2160 if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII)) in emac_ethtool_get_regs_len()
2161 size += zmii_get_regs_len(dev->zmii_dev); in emac_ethtool_get_regs_len()
2162 if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) in emac_ethtool_get_regs_len()
2163 size += rgmii_get_regs_len(dev->rgmii_dev); in emac_ethtool_get_regs_len()
2164 if (emac_has_feature(dev, EMAC_FTR_HAS_TAH)) in emac_ethtool_get_regs_len()
2165 size += tah_get_regs_len(dev->tah_dev); in emac_ethtool_get_regs_len()
2170 static void *emac_dump_regs(struct emac_instance *dev, void *buf) in emac_dump_regs() argument
2174 hdr->index = dev->cell_index; in emac_dump_regs()
2175 if (emac_has_feature(dev, EMAC_FTR_EMAC4SYNC)) { in emac_dump_regs()
2177 } else if (emac_has_feature(dev, EMAC_FTR_EMAC4)) { in emac_dump_regs()
2182 memcpy_fromio(hdr + 1, dev->emacp, sizeof(struct emac_regs)); in emac_dump_regs()
2189 struct emac_instance *dev = netdev_priv(ndev); in emac_ethtool_get_regs() local
2195 buf = mal_dump_regs(dev->mal, buf); in emac_ethtool_get_regs()
2196 buf = emac_dump_regs(dev, buf); in emac_ethtool_get_regs()
2197 if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII)) { in emac_ethtool_get_regs()
2199 buf = zmii_dump_regs(dev->zmii_dev, buf); in emac_ethtool_get_regs()
2201 if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) { in emac_ethtool_get_regs()
2203 buf = rgmii_dump_regs(dev->rgmii_dev, buf); in emac_ethtool_get_regs()
2205 if (emac_has_feature(dev, EMAC_FTR_HAS_TAH)) { in emac_ethtool_get_regs()
2207 buf = tah_dump_regs(dev->tah_dev, buf); in emac_ethtool_get_regs()
2213 struct emac_instance *dev = netdev_priv(ndev); in emac_ethtool_nway_reset() local
2216 DBG(dev, "nway_reset" NL); in emac_ethtool_nway_reset()
2218 if (dev->phy.address < 0) in emac_ethtool_nway_reset()
2221 mutex_lock(&dev->link_lock); in emac_ethtool_nway_reset()
2222 if (!dev->phy.autoneg) { in emac_ethtool_nway_reset()
2227 dev->phy.def->ops->setup_aneg(&dev->phy, dev->phy.advertising); in emac_ethtool_nway_reset()
2229 mutex_unlock(&dev->link_lock); in emac_ethtool_nway_reset()
2230 emac_force_link_update(dev); in emac_ethtool_nway_reset()
2253 struct emac_instance *dev = netdev_priv(ndev); in emac_ethtool_get_ethtool_stats() local
2255 memcpy(tmp_stats, &dev->stats, sizeof(dev->stats)); in emac_ethtool_get_ethtool_stats()
2256 tmp_stats += sizeof(dev->stats) / sizeof(u64); in emac_ethtool_get_ethtool_stats()
2257 memcpy(tmp_stats, &dev->estats, sizeof(dev->estats)); in emac_ethtool_get_ethtool_stats()
2263 struct emac_instance *dev = netdev_priv(ndev); in emac_ethtool_get_drvinfo() local
2268 dev->cell_index, dev->ofdev->dev.of_node); in emac_ethtool_get_drvinfo()
2293 struct emac_instance *dev = netdev_priv(ndev); in emac_ioctl() local
2296 DBG(dev, "ioctl %08x" NL, cmd); in emac_ioctl()
2298 if (dev->phy.address < 0) in emac_ioctl()
2303 data->phy_id = dev->phy.address; in emac_ioctl()
2306 data->val_out = emac_mdio_read(ndev, dev->phy.address, in emac_ioctl()
2311 emac_mdio_write(ndev, dev->phy.address, data->reg_num, in emac_ioctl()
2334 static int emac_check_deps(struct emac_instance *dev, in emac_check_deps() argument
2348 np = *(dev->blist - 1); in emac_check_deps()
2375 static void emac_put_deps(struct emac_instance *dev) in emac_put_deps() argument
2377 platform_device_put(dev->mal_dev); in emac_put_deps()
2378 platform_device_put(dev->zmii_dev); in emac_put_deps()
2379 platform_device_put(dev->rgmii_dev); in emac_put_deps()
2380 platform_device_put(dev->mdio_dev); in emac_put_deps()
2381 platform_device_put(dev->tah_dev); in emac_put_deps()
2384 static int emac_wait_deps(struct emac_instance *dev) in emac_wait_deps() argument
2391 deps[EMAC_DEP_MAL_IDX].phandle = dev->mal_ph; in emac_wait_deps()
2392 deps[EMAC_DEP_ZMII_IDX].phandle = dev->zmii_ph; in emac_wait_deps()
2393 deps[EMAC_DEP_RGMII_IDX].phandle = dev->rgmii_ph; in emac_wait_deps()
2394 if (dev->tah_ph) in emac_wait_deps()
2395 deps[EMAC_DEP_TAH_IDX].phandle = dev->tah_ph; in emac_wait_deps()
2396 if (dev->mdio_ph) in emac_wait_deps()
2397 deps[EMAC_DEP_MDIO_IDX].phandle = dev->mdio_ph; in emac_wait_deps()
2398 if (dev->blist && dev->blist > emac_boot_list) in emac_wait_deps()
2400 err = emac_check_deps(dev, deps); in emac_wait_deps()
2407 dev->mal_dev = deps[EMAC_DEP_MAL_IDX].ofdev; in emac_wait_deps()
2408 dev->zmii_dev = deps[EMAC_DEP_ZMII_IDX].ofdev; in emac_wait_deps()
2409 dev->rgmii_dev = deps[EMAC_DEP_RGMII_IDX].ofdev; in emac_wait_deps()
2410 dev->tah_dev = deps[EMAC_DEP_TAH_IDX].ofdev; in emac_wait_deps()
2411 dev->mdio_dev = deps[EMAC_DEP_MDIO_IDX].ofdev; in emac_wait_deps()
2433 struct emac_instance *dev = netdev_priv(ndev); in emac_adjust_link() local
2436 dev->phy.autoneg = phy->autoneg; in emac_adjust_link()
2437 dev->phy.speed = phy->speed; in emac_adjust_link()
2438 dev->phy.duplex = phy->duplex; in emac_adjust_link()
2439 dev->phy.pause = phy->pause; in emac_adjust_link()
2440 dev->phy.asym_pause = phy->asym_pause; in emac_adjust_link()
2441 ethtool_convert_link_mode_to_legacy_u32(&dev->phy.advertising, in emac_adjust_link()
2466 struct emac_instance *dev = netdev_priv(bus->priv); in emac_mii_bus_reset() local
2468 return emac_reset(dev); in emac_mii_bus_reset()
2484 struct net_device *ndev = phy->dev; in emac_mdio_setup_aneg()
2493 struct net_device *ndev = phy->dev; in emac_mdio_setup_forced()
2503 struct net_device *ndev = phy->dev; in emac_mdio_poll_link()
2504 struct emac_instance *dev = netdev_priv(ndev); in emac_mdio_poll_link() local
2509 dev_err(&dev->ofdev->dev, "link update failed (%d).", res); in emac_mdio_poll_link()
2518 struct net_device *ndev = phy->dev; in emac_mdio_read_link()
2535 struct net_device *ndev = phy->dev; in emac_mdio_init_phy()
2549 static int emac_dt_mdio_probe(struct emac_instance *dev) in emac_dt_mdio_probe() argument
2555 mii_np = of_get_child_by_name(dev->ofdev->dev.of_node, "mdio"); in emac_dt_mdio_probe()
2557 dev_err(&dev->ofdev->dev, "no mdio definition found."); in emac_dt_mdio_probe()
2566 bus = devm_mdiobus_alloc(&dev->ofdev->dev); in emac_dt_mdio_probe()
2572 bus->priv = dev->ndev; in emac_dt_mdio_probe()
2573 bus->parent = dev->ndev->dev.parent; in emac_dt_mdio_probe()
2578 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", dev->ofdev->name); in emac_dt_mdio_probe()
2579 res = devm_of_mdiobus_register(&dev->ofdev->dev, bus, mii_np); in emac_dt_mdio_probe()
2581 dev_err(&dev->ofdev->dev, "cannot register MDIO bus %s (%d)", in emac_dt_mdio_probe()
2590 static int emac_dt_phy_connect(struct emac_instance *dev, in emac_dt_phy_connect() argument
2595 dev->phy.def = devm_kzalloc(&dev->ofdev->dev, sizeof(*dev->phy.def), in emac_dt_phy_connect()
2597 if (!dev->phy.def) in emac_dt_phy_connect()
2600 phy_dev = of_phy_connect(dev->ndev, phy_handle, &emac_adjust_link, 0, in emac_dt_phy_connect()
2601 dev->phy_mode); in emac_dt_phy_connect()
2603 dev_err(&dev->ofdev->dev, "failed to connect to PHY.\n"); in emac_dt_phy_connect()
2607 dev->phy.def->phy_id = phy_dev->drv->phy_id; in emac_dt_phy_connect()
2608 dev->phy.def->phy_id_mask = phy_dev->drv->phy_id_mask; in emac_dt_phy_connect()
2609 dev->phy.def->name = phy_dev->drv->name; in emac_dt_phy_connect()
2610 dev->phy.def->ops = &emac_dt_mdio_phy_ops; in emac_dt_phy_connect()
2611 ethtool_convert_link_mode_to_legacy_u32(&dev->phy.features, in emac_dt_phy_connect()
2613 dev->phy.address = phy_dev->mdio.addr; in emac_dt_phy_connect()
2614 dev->phy.mode = phy_dev->interface; in emac_dt_phy_connect()
2618 static int emac_dt_phy_probe(struct emac_instance *dev) in emac_dt_phy_probe() argument
2620 struct device_node *np = dev->ofdev->dev.of_node; in emac_dt_phy_probe()
2627 res = emac_dt_mdio_probe(dev); in emac_dt_phy_probe()
2629 res = emac_dt_phy_connect(dev, phy_handle); in emac_dt_phy_probe()
2637 static int emac_init_phy(struct emac_instance *dev) in emac_init_phy() argument
2639 struct device_node *np = dev->ofdev->dev.of_node; in emac_init_phy()
2640 struct net_device *ndev = dev->ndev; in emac_init_phy()
2644 dev->phy.dev = ndev; in emac_init_phy()
2645 dev->phy.mode = dev->phy_mode; in emac_init_phy()
2648 if ((dev->phy_address == 0xffffffff && dev->phy_map == 0xffffffff) || in emac_init_phy()
2650 emac_reset(dev); in emac_init_phy()
2653 dev->phy.address = -1; in emac_init_phy()
2654 dev->phy.features = SUPPORTED_MII; in emac_init_phy()
2655 if (emac_phy_supports_gige(dev->phy_mode)) in emac_init_phy()
2656 dev->phy.features |= SUPPORTED_1000baseT_Full; in emac_init_phy()
2658 dev->phy.features |= SUPPORTED_100baseT_Full; in emac_init_phy()
2659 dev->phy.pause = 1; in emac_init_phy()
2662 int res = emac_dt_mdio_probe(dev); in emac_init_phy()
2671 emac_adjust_link(dev->ndev); in emac_init_phy()
2672 put_device(&ndev->phydev->mdio.dev); in emac_init_phy()
2678 phy_map = dev->phy_map | busy_phy_map; in emac_init_phy()
2680 DBG(dev, "PHY maps %08x %08x" NL, dev->phy_map, busy_phy_map); in emac_init_phy()
2682 dev->phy.mdio_read = emac_mdio_read; in emac_init_phy()
2683 dev->phy.mdio_write = emac_mdio_write; in emac_init_phy()
2687 if (emac_has_feature(dev, EMAC_FTR_440GX_PHY_CLK_FIX)) in emac_init_phy()
2691 emac_rx_clk_tx(dev); in emac_init_phy()
2695 if (emac_has_feature(dev, EMAC_FTR_440GX_PHY_CLK_FIX)) in emac_init_phy()
2701 if (emac_phy_gpcs(dev->phy.mode)) { in emac_init_phy()
2710 dev->phy.gpcs_address = dev->gpcs_address; in emac_init_phy()
2711 if (dev->phy.gpcs_address == 0xffffffff) in emac_init_phy()
2712 dev->phy.address = dev->cell_index; in emac_init_phy()
2715 emac_configure(dev); in emac_init_phy()
2717 if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) { in emac_init_phy()
2718 int res = emac_dt_phy_probe(dev); in emac_init_phy()
2734 dev_err(&dev->ofdev->dev, "failed to attach dt phy (%d).\n", in emac_init_phy()
2740 if (dev->phy_address != 0xffffffff) in emac_init_phy()
2741 phy_map = ~(1 << dev->phy_address); in emac_init_phy()
2749 r = emac_mdio_read(dev->ndev, i, MII_BMCR); in emac_init_phy()
2752 if (!emac_mii_phy_probe(&dev->phy, i)) in emac_init_phy()
2758 if (emac_has_feature(dev, EMAC_FTR_440GX_PHY_CLK_FIX)) in emac_init_phy()
2769 if (dev->phy.def->ops->init) in emac_init_phy()
2770 dev->phy.def->ops->init(&dev->phy); in emac_init_phy()
2773 dev->phy.def->features &= ~dev->phy_feat_exc; in emac_init_phy()
2774 dev->phy.features &= ~dev->phy_feat_exc; in emac_init_phy()
2777 if (dev->phy.features & SUPPORTED_Autoneg) { in emac_init_phy()
2778 adv = dev->phy.features; in emac_init_phy()
2779 if (!emac_has_feature(dev, EMAC_FTR_NO_FLOW_CONTROL_40x)) in emac_init_phy()
2782 dev->phy.def->ops->setup_aneg(&dev->phy, adv); in emac_init_phy()
2784 u32 f = dev->phy.def->features; in emac_init_phy()
2802 dev->phy.def->ops->setup_forced(&dev->phy, speed, fd); in emac_init_phy()
2807 static int emac_init_config(struct emac_instance *dev) in emac_init_config() argument
2809 struct device_node *np = dev->ofdev->dev.of_node; in emac_init_config()
2813 if (emac_read_uint_prop(np, "mal-device", &dev->mal_ph, 1)) in emac_init_config()
2815 if (emac_read_uint_prop(np, "mal-tx-channel", &dev->mal_tx_chan, 1)) in emac_init_config()
2817 if (emac_read_uint_prop(np, "mal-rx-channel", &dev->mal_rx_chan, 1)) in emac_init_config()
2819 if (emac_read_uint_prop(np, "cell-index", &dev->cell_index, 1)) in emac_init_config()
2821 if (emac_read_uint_prop(np, "max-frame-size", &dev->max_mtu, 0)) in emac_init_config()
2822 dev->max_mtu = ETH_DATA_LEN; in emac_init_config()
2823 if (emac_read_uint_prop(np, "rx-fifo-size", &dev->rx_fifo_size, 0)) in emac_init_config()
2824 dev->rx_fifo_size = 2048; in emac_init_config()
2825 if (emac_read_uint_prop(np, "tx-fifo-size", &dev->tx_fifo_size, 0)) in emac_init_config()
2826 dev->tx_fifo_size = 2048; in emac_init_config()
2827 if (emac_read_uint_prop(np, "rx-fifo-size-gige", &dev->rx_fifo_size_gige, 0)) in emac_init_config()
2828 dev->rx_fifo_size_gige = dev->rx_fifo_size; in emac_init_config()
2829 if (emac_read_uint_prop(np, "tx-fifo-size-gige", &dev->tx_fifo_size_gige, 0)) in emac_init_config()
2830 dev->tx_fifo_size_gige = dev->tx_fifo_size; in emac_init_config()
2831 if (emac_read_uint_prop(np, "phy-address", &dev->phy_address, 0)) in emac_init_config()
2832 dev->phy_address = 0xffffffff; in emac_init_config()
2833 if (emac_read_uint_prop(np, "phy-map", &dev->phy_map, 0)) in emac_init_config()
2834 dev->phy_map = 0xffffffff; in emac_init_config()
2835 if (emac_read_uint_prop(np, "gpcs-address", &dev->gpcs_address, 0)) in emac_init_config()
2836 dev->gpcs_address = 0xffffffff; in emac_init_config()
2837 if (emac_read_uint_prop(np->parent, "clock-frequency", &dev->opb_bus_freq, 1)) in emac_init_config()
2839 if (emac_read_uint_prop(np, "tah-device", &dev->tah_ph, 0)) in emac_init_config()
2840 dev->tah_ph = 0; in emac_init_config()
2841 if (emac_read_uint_prop(np, "tah-channel", &dev->tah_port, 0)) in emac_init_config()
2842 dev->tah_port = 0; in emac_init_config()
2843 if (emac_read_uint_prop(np, "mdio-device", &dev->mdio_ph, 0)) in emac_init_config()
2844 dev->mdio_ph = 0; in emac_init_config()
2845 if (emac_read_uint_prop(np, "zmii-device", &dev->zmii_ph, 0)) in emac_init_config()
2846 dev->zmii_ph = 0; in emac_init_config()
2847 if (emac_read_uint_prop(np, "zmii-channel", &dev->zmii_port, 0)) in emac_init_config()
2848 dev->zmii_port = 0xffffffff; in emac_init_config()
2849 if (emac_read_uint_prop(np, "rgmii-device", &dev->rgmii_ph, 0)) in emac_init_config()
2850 dev->rgmii_ph = 0; in emac_init_config()
2851 if (emac_read_uint_prop(np, "rgmii-channel", &dev->rgmii_port, 0)) in emac_init_config()
2852 dev->rgmii_port = 0xffffffff; in emac_init_config()
2853 if (emac_read_uint_prop(np, "fifo-entry-size", &dev->fifo_entry_size, 0)) in emac_init_config()
2854 dev->fifo_entry_size = 16; in emac_init_config()
2855 if (emac_read_uint_prop(np, "mal-burst-size", &dev->mal_burst_size, 0)) in emac_init_config()
2856 dev->mal_burst_size = 256; in emac_init_config()
2859 err = of_get_phy_mode(np, &dev->phy_mode); in emac_init_config()
2861 dev->phy_mode = PHY_INTERFACE_MODE_NA; in emac_init_config()
2865 dev->features |= (EMAC_FTR_EMAC4 | EMAC_FTR_EMAC4SYNC); in emac_init_config()
2868 dev->features |= EMAC_FTR_460EX_PHY_CLK_FIX; in emac_init_config()
2871 dev->features |= EMAC_FTR_440EP_PHY_CLK_FIX; in emac_init_config()
2873 dev->features |= (EMAC_APM821XX_REQ_JUMBO_FRAME_SIZE | in emac_init_config()
2878 dev->features |= EMAC_FTR_EMAC4; in emac_init_config()
2880 dev->features |= EMAC_FTR_440GX_PHY_CLK_FIX; in emac_init_config()
2884 dev->features |= EMAC_FTR_440EP_PHY_CLK_FIX; in emac_init_config()
2887 dev->features |= EMAC_FTR_NO_FLOW_CONTROL_40x; in emac_init_config()
2899 dev->features |= EMAC_FTR_STACR_OC_INVERT; in emac_init_config()
2901 dev->features |= EMAC_FTR_HAS_NEW_STACR; in emac_init_config()
2905 dev->features |= EMAC_FTR_HAS_NEW_STACR | in emac_init_config()
2909 if (dev->tah_ph != 0) { in emac_init_config()
2911 dev->features |= EMAC_FTR_HAS_TAH; in emac_init_config()
2918 if (dev->zmii_ph != 0) { in emac_init_config()
2920 dev->features |= EMAC_FTR_HAS_ZMII; in emac_init_config()
2927 if (dev->rgmii_ph != 0) { in emac_init_config()
2929 dev->features |= EMAC_FTR_HAS_RGMII; in emac_init_config()
2937 err = of_get_ethdev_address(np, dev->ndev); in emac_init_config()
2939 return dev_err_probe(&dev->ofdev->dev, err, in emac_init_config()
2943 if (emac_has_feature(dev, EMAC_FTR_EMAC4SYNC)) { in emac_init_config()
2944 dev->xaht_slots_shift = EMAC4SYNC_XAHT_SLOTS_SHIFT; in emac_init_config()
2945 dev->xaht_width_shift = EMAC4SYNC_XAHT_WIDTH_SHIFT; in emac_init_config()
2947 dev->xaht_slots_shift = EMAC4_XAHT_SLOTS_SHIFT; in emac_init_config()
2948 dev->xaht_width_shift = EMAC4_XAHT_WIDTH_SHIFT; in emac_init_config()
2952 if (WARN_ON(EMAC_XAHT_REGS(dev) > EMAC_XAHT_MAX_REGS)) in emac_init_config()
2955 DBG(dev, "features : 0x%08x / 0x%08x\n", dev->features, EMAC_FTRS_POSSIBLE); in emac_init_config()
2956 DBG(dev, "tx_fifo_size : %d (%d gige)\n", dev->tx_fifo_size, dev->tx_fifo_size_gige); in emac_init_config()
2957 DBG(dev, "rx_fifo_size : %d (%d gige)\n", dev->rx_fifo_size, dev->rx_fifo_size_gige); in emac_init_config()
2958 DBG(dev, "max_mtu : %d\n", dev->max_mtu); in emac_init_config()
2959 DBG(dev, "OPB freq : %d\n", dev->opb_bus_freq); in emac_init_config()
2992 struct emac_instance *dev; in emac_probe() local
2993 struct device_node *np = ofdev->dev.of_node; in emac_probe()
3011 ndev = devm_alloc_etherdev(&ofdev->dev, sizeof(struct emac_instance)); in emac_probe()
3015 dev = netdev_priv(ndev); in emac_probe()
3016 dev->ndev = ndev; in emac_probe()
3017 dev->ofdev = ofdev; in emac_probe()
3018 dev->blist = blist; in emac_probe()
3019 SET_NETDEV_DEV(ndev, &ofdev->dev); in emac_probe()
3022 mutex_init(&dev->mdio_lock); in emac_probe()
3023 mutex_init(&dev->link_lock); in emac_probe()
3024 spin_lock_init(&dev->lock); in emac_probe()
3025 INIT_WORK(&dev->reset_work, emac_reset_work); in emac_probe()
3028 err = emac_init_config(dev); in emac_probe()
3033 dev->emac_irq = irq_of_parse_and_map(np, 0); in emac_probe()
3034 if (!dev->emac_irq) { in emac_probe()
3041 err = devm_request_irq(&ofdev->dev, dev->emac_irq, emac_irq, 0, "EMAC", in emac_probe()
3042 dev); in emac_probe()
3044 dev_err_probe(&ofdev->dev, err, "failed to request IRQ %d", in emac_probe()
3045 dev->emac_irq); in emac_probe()
3049 ndev->irq = dev->emac_irq; in emac_probe()
3053 dev->emacp = devm_of_iomap(&ofdev->dev, np, 0, NULL); in emac_probe()
3054 if (!dev->emacp) { in emac_probe()
3055 dev_err(&ofdev->dev, "can't map device registers"); in emac_probe()
3061 err = emac_wait_deps(dev); in emac_probe()
3064 dev->mal = platform_get_drvdata(dev->mal_dev); in emac_probe()
3065 if (dev->mdio_dev != NULL) in emac_probe()
3066 dev->mdio_instance = platform_get_drvdata(dev->mdio_dev); in emac_probe()
3069 dev->commac.ops = &emac_commac_ops; in emac_probe()
3070 dev->commac.dev = dev; in emac_probe()
3071 dev->commac.tx_chan_mask = MAL_CHAN_MASK(dev->mal_tx_chan); in emac_probe()
3072 dev->commac.rx_chan_mask = MAL_CHAN_MASK(dev->mal_rx_chan); in emac_probe()
3073 err = mal_register_commac(dev->mal, &dev->commac); in emac_probe()
3076 np, dev->mal_dev->dev.of_node); in emac_probe()
3079 dev->rx_skb_size = emac_rx_skb_size(ndev->mtu); in emac_probe()
3080 dev->rx_sync_size = emac_rx_sync_size(ndev->mtu); in emac_probe()
3083 dev->tx_desc = in emac_probe()
3084 dev->mal->bd_virt + mal_tx_bd_offset(dev->mal, dev->mal_tx_chan); in emac_probe()
3085 dev->rx_desc = in emac_probe()
3086 dev->mal->bd_virt + mal_rx_bd_offset(dev->mal, dev->mal_rx_chan); in emac_probe()
3088 DBG(dev, "tx_desc %p" NL, dev->tx_desc); in emac_probe()
3089 DBG(dev, "rx_desc %p" NL, dev->rx_desc); in emac_probe()
3092 memset(dev->tx_desc, 0, NUM_TX_BUFF * sizeof(struct mal_descriptor)); in emac_probe()
3093 memset(dev->rx_desc, 0, NUM_RX_BUFF * sizeof(struct mal_descriptor)); in emac_probe()
3094 memset(dev->tx_skb, 0, NUM_TX_BUFF * sizeof(struct sk_buff *)); in emac_probe()
3095 memset(dev->rx_skb, 0, NUM_RX_BUFF * sizeof(struct sk_buff *)); in emac_probe()
3098 if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII) && in emac_probe()
3099 (err = zmii_attach(dev->zmii_dev, dev->zmii_port, &dev->phy_mode)) != 0) in emac_probe()
3103 if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII) && in emac_probe()
3104 (err = rgmii_attach(dev->rgmii_dev, dev->rgmii_port, dev->phy_mode)) != 0) in emac_probe()
3108 if (emac_has_feature(dev, EMAC_FTR_HAS_TAH) && in emac_probe()
3109 (err = tah_attach(dev->tah_dev, dev->tah_port)) != 0) in emac_probe()
3113 dev->phy.speed = SPEED_100; in emac_probe()
3114 dev->phy.duplex = DUPLEX_FULL; in emac_probe()
3115 dev->phy.autoneg = AUTONEG_DISABLE; in emac_probe()
3116 dev->phy.pause = dev->phy.asym_pause = 0; in emac_probe()
3117 dev->stop_timeout = STOP_TIMEOUT_100; in emac_probe()
3118 INIT_DELAYED_WORK(&dev->link_work, emac_link_timer); in emac_probe()
3121 if (emac_has_feature(dev, EMAC_FTR_APM821XX_NO_HALF_DUPLEX)) { in emac_probe()
3122 dev->phy_feat_exc = (SUPPORTED_1000baseT_Half | in emac_probe()
3128 err = emac_init_phy(dev); in emac_probe()
3132 if (dev->tah_dev) { in emac_probe()
3137 if (emac_phy_supports_gige(dev->phy_mode)) { in emac_probe()
3139 dev->commac.ops = &emac_commac_sg_ops; in emac_probe()
3146 ndev->max_mtu = dev->max_mtu; in emac_probe()
3150 err = devm_register_netdev(&ofdev->dev, ndev); in emac_probe()
3161 platform_set_drvdata(ofdev, dev); in emac_probe()
3164 ndev->name, dev->cell_index, np, ndev->dev_addr); in emac_probe()
3166 if (dev->phy_mode == PHY_INTERFACE_MODE_SGMII) in emac_probe()
3169 if (dev->phy.address >= 0) in emac_probe()
3171 dev->phy.def->name, dev->phy.address); in emac_probe()
3179 if (emac_has_feature(dev, EMAC_FTR_HAS_TAH)) in emac_probe()
3180 tah_detach(dev->tah_dev, dev->tah_port); in emac_probe()
3182 if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) in emac_probe()
3183 rgmii_detach(dev->rgmii_dev, dev->rgmii_port); in emac_probe()
3185 if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII)) in emac_probe()
3186 zmii_detach(dev->zmii_dev, dev->zmii_port); in emac_probe()
3188 mal_unregister_commac(dev->mal, &dev->commac); in emac_probe()
3190 emac_put_deps(dev); in emac_probe()
3199 struct emac_instance *dev = platform_get_drvdata(ofdev); in emac_remove() local
3201 DBG(dev, "remove" NL); in emac_remove()
3203 cancel_work_sync(&dev->reset_work); in emac_remove()
3205 if (emac_has_feature(dev, EMAC_FTR_HAS_TAH)) in emac_remove()
3206 tah_detach(dev->tah_dev, dev->tah_port); in emac_remove()
3207 if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) in emac_remove()
3208 rgmii_detach(dev->rgmii_dev, dev->rgmii_port); in emac_remove()
3209 if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII)) in emac_remove()
3210 zmii_detach(dev->zmii_dev, dev->zmii_port); in emac_remove()
3212 busy_phy_map &= ~(1 << dev->phy.address); in emac_remove()
3213 DBG(dev, "busy_phy_map now %#x" NL, busy_phy_map); in emac_remove()
3215 mal_unregister_commac(dev->mal, &dev->commac); in emac_remove()
3216 emac_put_deps(dev); in emac_remove()