++ i = 0;
++ do { /* drain RX buffers */
++ while (queue_get_desc(port->plat->rxq, port, 0) >= 0)
++ buffs--;
++ if (!buffs)
++ break;
++ if (qmgr_stat_empty(TX_QUEUE(port->id))) {
++ /* we have to inject some packet */
++ struct desc *desc;
++ u32 phys;
++ int n = queue_get_desc(port->plat->txreadyq, port, 1);
++ BUG_ON(n < 0);
++ desc = tx_desc_ptr(port, n);
++ phys = tx_desc_phys(port, n);
++ desc->buf_len = desc->pkt_len = 1;
++ wmb();
++ queue_put_desc(TX_QUEUE(port->id), phys, desc);
++ }
++ udelay(1);
++ } while (++i < MAX_CLOSE_WAIT);
++
++ if (buffs)
++ printk(KERN_CRIT "%s: unable to drain RX queue, %i buffer(s)"
++ " left in NPE\n", dev->name, buffs);
++#if DEBUG_CLOSE
++ if (!buffs)
++ printk(KERN_DEBUG "Draining RX queue took %i cycles\n", i);
++#endif
++
++ buffs = TX_DESCS;
++ while (queue_get_desc(TX_QUEUE(port->id), port, 1) >= 0)
++ buffs--; /* cancel TX */
++
++ i = 0;
++ do {
++ while (queue_get_desc(port->plat->txreadyq, port, 1) >= 0)
++ buffs--;
++ if (!buffs)
++ break;
++ } while (++i < MAX_CLOSE_WAIT);
++
++ if (buffs)
++ printk(KERN_CRIT "%s: unable to drain TX queue, %i buffer(s) "
++ "left in NPE\n", dev->name, buffs);
++#if DEBUG_CLOSE
++ if (!buffs)
++ printk(KERN_DEBUG "Draining TX queues took %i cycles\n", i);
++#endif
++
++ msg.byte3 = 0;
++ if (npe_send_recv_message(port->npe, &msg, "ETH_DISABLE_LOOPBACK"))
++ printk(KERN_CRIT "%s: unable to disable loopback\n",
++ dev->name);
++
++ port->mii_bmcr = mdio_read(dev, port->plat->phy, MII_BMCR) &
++ ~(BMCR_RESET | BMCR_PDOWN); /* may have been altered */
++ mdio_write(dev, port->plat->phy, MII_BMCR,
++ port->mii_bmcr | BMCR_PDOWN);
++
++ if (!ports_open)
++ qmgr_disable_irq(TXDONE_QUEUE);
++ cancel_rearming_delayed_work(&port->mdio_thread);
++ napi_disable(&port->napi);
++ destroy_queues(port);
++ release_queues(port);
++ return 0;
++}
++
++static int __devinit eth_init_one(struct platform_device *pdev)
++{
++ struct port *port;
++ struct net_device *dev;
++ struct eth_plat_info *plat = pdev->dev.platform_data;
++ u32 regs_phys;
++ int err;
++
++ if (!(dev = alloc_etherdev(sizeof(struct port))))
++ return -ENOMEM;
++
++ SET_NETDEV_DEV(dev, &pdev->dev);
++ port = netdev_priv(dev);
++ port->netdev = dev;
++ port->id = pdev->id;
++
++ switch (port->id) {
++ case IXP4XX_ETH_NPEA:
++ port->regs = (struct eth_regs __iomem *)IXP4XX_EthA_BASE_VIRT;
++ regs_phys = IXP4XX_EthA_BASE_PHYS;
++ break;
++ case IXP4XX_ETH_NPEB:
++ port->regs = (struct eth_regs __iomem *)IXP4XX_EthB_BASE_VIRT;
++ regs_phys = IXP4XX_EthB_BASE_PHYS;
++ break;
++ case IXP4XX_ETH_NPEC:
++ port->regs = (struct eth_regs __iomem *)IXP4XX_EthC_BASE_VIRT;
++ regs_phys = IXP4XX_EthC_BASE_PHYS;
++ break;
++ default:
++ err = -ENOSYS;
++ goto err_free;
++ }
++
++ dev->open = eth_open;
++ dev->hard_start_xmit = eth_xmit;
++ dev->stop = eth_close;
++ dev->get_stats = eth_stats;
++ dev->do_ioctl = eth_ioctl;
++ dev->set_multicast_list = eth_set_mcast_list;
++ dev->tx_queue_len = 100;
++
++ netif_napi_add(dev, &port->napi, eth_poll, ETH_NAPI_WEIGHT);
++
++ if (!(port->npe = npe_request(NPE_ID(port->id)))) {
++ err = -EIO;
++ goto err_free;
++ }
++
++ if (register_netdev(dev)) {
++ err = -EIO;
++ goto err_npe_rel;
++ }
++
++ port->mem_res = request_mem_region(regs_phys, REGS_SIZE, dev->name);
++ if (!port->mem_res) {
++ err = -EBUSY;
++ goto err_unreg;
++ }
++
++ port->plat = plat;
++ npe_port_tab[NPE_ID(port->id)] = port;
++ memcpy(dev->dev_addr, plat->hwaddr, ETH_ALEN);
++
++ platform_set_drvdata(pdev, dev);
++
++ __raw_writel(DEFAULT_CORE_CNTRL | CORE_RESET,
++ &port->regs->core_control);
++ udelay(50);
++ __raw_writel(DEFAULT_CORE_CNTRL, &port->regs->core_control);
++ udelay(50);
++
++ port->mii.dev = dev;
++ port->mii.mdio_read = mdio_read;
++ port->mii.mdio_write = mdio_write;
++ port->mii.phy_id = plat->phy;
++ port->mii.phy_id_mask = 0x1F;
++ port->mii.reg_num_mask = 0x1F;
++
++ printk(KERN_INFO "%s: MII PHY %i on %s\n", dev->name, plat->phy,
++ npe_name(port->npe));
++
++ phy_reset(dev, plat->phy);
++ port->mii_bmcr = mdio_read(dev, plat->phy, MII_BMCR) &
++ ~(BMCR_RESET | BMCR_PDOWN);
++ mdio_write(dev, plat->phy, MII_BMCR, port->mii_bmcr | BMCR_PDOWN);
++
++ INIT_DELAYED_WORK(&port->mdio_thread, mdio_thread);
++ return 0;
++
++err_unreg:
++ unregister_netdev(dev);
++err_npe_rel:
++ npe_release(port->npe);
++err_free:
++ free_netdev(dev);
++ return err;
++}
++
++static int __devexit eth_remove_one(struct platform_device *pdev)
++{
++ struct net_device *dev = platform_get_drvdata(pdev);
++ struct port *port = netdev_priv(dev);
++
++ unregister_netdev(dev);
++ npe_port_tab[NPE_ID(port->id)] = NULL;
++ platform_set_drvdata(pdev, NULL);
++ npe_release(port->npe);
++ release_resource(port->mem_res);
++ free_netdev(dev);
++ return 0;
++}
++
++static struct platform_driver drv = {
++ .driver.name = DRV_NAME,
++ .probe = eth_init_one,
++ .remove = eth_remove_one,
++};
++
++static int __init eth_init_module(void)
++{
++ if (!(ixp4xx_read_feature_bits() & IXP4XX_FEATURE_NPEB_ETH0))
++ return -ENOSYS;
++
++ /* All MII PHY accesses use NPE-B Ethernet registers */
++ spin_lock_init(&mdio_lock);
++ mdio_regs = (struct eth_regs __iomem *)IXP4XX_EthB_BASE_VIRT;
++ __raw_writel(DEFAULT_CORE_CNTRL, &mdio_regs->core_control);
++
++ return platform_driver_register(&drv);
++}
++
++static void __exit eth_cleanup_module(void)
++{
++ platform_driver_unregister(&drv);
++}
++
++MODULE_AUTHOR("Krzysztof Halasa");
++MODULE_DESCRIPTION("Intel IXP4xx Ethernet driver");
++MODULE_LICENSE("GPL v2");
++module_init(eth_init_module);
++module_exit(eth_cleanup_module);
+diff --git a/drivers/net/wan/Kconfig b/drivers/net/wan/Kconfig
+index a3df09e..94e7aa7 100644
+--- a/drivers/net/wan/Kconfig
++++ b/drivers/net/wan/Kconfig
+@@ -334,6 +334,15 @@ config DSCC4_PCI_RST
+
+ Say Y if your card supports this feature.
+
++config IXP4XX_HSS
++ tristate "IXP4xx HSS (synchronous serial port) support"
++ depends on HDLC && ARM && ARCH_IXP4XX
++ select IXP4XX_NPE
++ select IXP4XX_QMGR