PM/Suspend: Introduce two new platform callbacks to avoid breakage
[safe/jmp/linux-2.6] / drivers / net / fec_mpc52xx.c
index 43b5f30..8bbe7f6 100644 (file)
 
 #define DRIVER_NAME "mpc52xx-fec"
 
+#define FEC5200_PHYADDR_NONE   (-1)
+#define FEC5200_PHYADDR_7WIRE  (-2)
+
+/* Private driver data structure */
+struct mpc52xx_fec_priv {
+       int duplex;
+       int speed;
+       int r_irq;
+       int t_irq;
+       struct mpc52xx_fec __iomem *fec;
+       struct bcom_task *rx_dmatsk;
+       struct bcom_task *tx_dmatsk;
+       spinlock_t lock;
+       int msg_enable;
+
+       /* MDIO link details */
+       int phy_addr;
+       unsigned int phy_speed;
+       struct phy_device *phydev;
+       enum phy_state link;
+};
+
+
 static irqreturn_t mpc52xx_fec_interrupt(int, void *);
 static irqreturn_t mpc52xx_fec_rx_interrupt(int, void *);
 static irqreturn_t mpc52xx_fec_tx_interrupt(int, void *);
@@ -55,7 +78,7 @@ module_param_array_named(mac, mpc52xx_fec_mac_addr, byte, NULL, 0);
 MODULE_PARM_DESC(mac, "six hex digits, ie. 0x1,0x2,0xc0,0x01,0xba,0xbe");
 
 #define MPC52xx_MESSAGES_DEFAULT ( NETIF_MSG_DRV | NETIF_MSG_PROBE | \
-               NETIF_MSG_LINK | NETIF_MSG_IFDOWN | NETIF_MSG_IFDOWN )
+               NETIF_MSG_LINK | NETIF_MSG_IFDOWN | NETIF_MSG_IFUP)
 static int debug = -1; /* the above default */
 module_param(debug, int, 0);
 MODULE_PARM_DESC(debug, "debugging messages level");
@@ -106,7 +129,8 @@ static void mpc52xx_fec_free_rx_buffers(struct net_device *dev, struct bcom_task
                struct sk_buff *skb;
 
                skb = bcom_retrieve_buffer(s, NULL, (struct bcom_bd **)&bd);
-               dma_unmap_single(&dev->dev, bd->skb_pa, skb->len, DMA_FROM_DEVICE);
+               dma_unmap_single(dev->dev.parent, bd->skb_pa, skb->len,
+                                DMA_FROM_DEVICE);
                kfree_skb(skb);
        }
 }
@@ -127,7 +151,7 @@ static int mpc52xx_fec_alloc_rx_buffers(struct net_device *dev, struct bcom_task
                bd = (struct bcom_fec_bd *)bcom_prepare_next_buffer(rxtsk);
 
                bd->status = FEC_RX_BUFFER_SIZE;
-               bd->skb_pa = dma_map_single(&dev->dev, skb->data,
+               bd->skb_pa = dma_map_single(dev->dev.parent, skb->data,
                                FEC_RX_BUFFER_SIZE, DMA_FROM_DEVICE);
 
                bcom_submit_next_buffer(rxtsk, skb);
@@ -174,9 +198,6 @@ static void mpc52xx_fec_adjust_link(struct net_device *dev)
                if (priv->link == PHY_DOWN) {
                        new_state = 1;
                        priv->link = phydev->link;
-                       netif_schedule(dev);
-                       netif_carrier_on(dev);
-                       netif_start_queue(dev);
                }
 
        } else if (priv->link) {
@@ -184,8 +205,6 @@ static void mpc52xx_fec_adjust_link(struct net_device *dev)
                priv->link = PHY_DOWN;
                priv->speed = 0;
                priv->duplex = -1;
-               netif_stop_queue(dev);
-               netif_carrier_off(dev);
        }
 
        if (new_state && netif_msg_link(priv))
@@ -198,7 +217,7 @@ static int mpc52xx_fec_init_phy(struct net_device *dev)
        struct phy_device *phydev;
        char phy_id[BUS_ID_SIZE];
 
-       snprintf(phy_id, BUS_ID_SIZE, "%x:%02x",
+       snprintf(phy_id, sizeof(phy_id), "%x:%02x",
                        (unsigned int)dev->base_addr, priv->phy_addr);
 
        priv->link = PHY_DOWN;
@@ -223,7 +242,7 @@ static int mpc52xx_fec_phy_start(struct net_device *dev)
        struct mpc52xx_fec_priv *priv = netdev_priv(dev);
        int err;
 
-       if (!priv->has_phy)
+       if (priv->phy_addr < 0)
                return 0;
 
        err = mpc52xx_fec_init_phy(dev);
@@ -243,7 +262,7 @@ static void mpc52xx_fec_phy_stop(struct net_device *dev)
 {
        struct mpc52xx_fec_priv *priv = netdev_priv(dev);
 
-       if (!priv->has_phy)
+       if (!priv->phydev)
                return;
 
        phy_disconnect(priv->phydev);
@@ -252,20 +271,11 @@ static void mpc52xx_fec_phy_stop(struct net_device *dev)
        phy_write(priv->phydev, MII_BMCR, BMCR_PDOWN);
 }
 
-static int mpc52xx_fec_phy_mii_ioctl(struct mpc52xx_fec_priv *priv,
-               struct mii_ioctl_data *mii_data, int cmd)
-{
-       if (!priv->has_phy)
-               return -ENOTSUPP;
-
-       return phy_mii_ioctl(priv->phydev, mii_data, cmd);
-}
-
 static void mpc52xx_fec_phy_hw_init(struct mpc52xx_fec_priv *priv)
 {
        struct mpc52xx_fec __iomem *fec = priv->fec;
 
-       if (!priv->has_phy)
+       if (priv->phydev)
                return;
 
        out_be32(&fec->mii_speed, priv->phy_speed);
@@ -352,7 +362,7 @@ static int mpc52xx_fec_close(struct net_device *dev)
  * invariant will hold if you make sure that the netif_*_queue()
  * calls are done at the proper times.
  */
-static int mpc52xx_fec_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
+static int mpc52xx_fec_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
        struct mpc52xx_fec_priv *priv = netdev_priv(dev);
        struct bcom_fec_bd *bd;
@@ -360,7 +370,7 @@ static int mpc52xx_fec_hard_start_xmit(struct sk_buff *skb, struct net_device *d
        if (bcom_queue_full(priv->tx_dmatsk)) {
                if (net_ratelimit())
                        dev_err(&dev->dev, "transmit queue overrun\n");
-               return 1;
+               return NETDEV_TX_BUSY;
        }
 
        spin_lock_irq(&priv->lock);
@@ -370,7 +380,8 @@ static int mpc52xx_fec_hard_start_xmit(struct sk_buff *skb, struct net_device *d
                bcom_prepare_next_buffer(priv->tx_dmatsk);
 
        bd->status = skb->len | BCOM_FEC_TX_BD_TFD | BCOM_FEC_TX_BD_TC;
-       bd->skb_pa = dma_map_single(&dev->dev, skb->data, skb->len, DMA_TO_DEVICE);
+       bd->skb_pa = dma_map_single(dev->dev.parent, skb->data, skb->len,
+                                   DMA_TO_DEVICE);
 
        bcom_submit_next_buffer(priv->tx_dmatsk, skb);
 
@@ -380,8 +391,23 @@ static int mpc52xx_fec_hard_start_xmit(struct sk_buff *skb, struct net_device *d
 
        spin_unlock_irq(&priv->lock);
 
-       return 0;
+       return NETDEV_TX_OK;
+}
+
+#ifdef CONFIG_NET_POLL_CONTROLLER
+static void mpc52xx_fec_poll_controller(struct net_device *dev)
+{
+       struct mpc52xx_fec_priv *priv = netdev_priv(dev);
+
+       disable_irq(priv->t_irq);
+       mpc52xx_fec_tx_interrupt(priv->t_irq, dev);
+       enable_irq(priv->t_irq);
+       disable_irq(priv->r_irq);
+       mpc52xx_fec_rx_interrupt(priv->r_irq, dev);
+       enable_irq(priv->r_irq);
 }
+#endif
+
 
 /* This handles BestComm transmit task interrupts
  */
@@ -397,7 +423,8 @@ static irqreturn_t mpc52xx_fec_tx_interrupt(int irq, void *dev_id)
                struct bcom_fec_bd *bd;
                skb = bcom_retrieve_buffer(priv->tx_dmatsk, NULL,
                                (struct bcom_bd **)&bd);
-               dma_unmap_single(&dev->dev, bd->skb_pa, skb->len, DMA_TO_DEVICE);
+               dma_unmap_single(dev->dev.parent, bd->skb_pa, skb->len,
+                                DMA_TO_DEVICE);
 
                dev_kfree_skb_irq(skb);
        }
@@ -422,7 +449,8 @@ static irqreturn_t mpc52xx_fec_rx_interrupt(int irq, void *dev_id)
 
                rskb = bcom_retrieve_buffer(priv->rx_dmatsk, &status,
                                (struct bcom_bd **)&bd);
-               dma_unmap_single(&dev->dev, bd->skb_pa, rskb->len, DMA_FROM_DEVICE);
+               dma_unmap_single(dev->dev.parent, bd->skb_pa, rskb->len,
+                                DMA_FROM_DEVICE);
 
                /* Test for errors in received frame */
                if (status & BCOM_FEC_RX_BD_ERRORS) {
@@ -431,7 +459,8 @@ static irqreturn_t mpc52xx_fec_rx_interrupt(int irq, void *dev_id)
                                bcom_prepare_next_buffer(priv->rx_dmatsk);
 
                        bd->status = FEC_RX_BUFFER_SIZE;
-                       bd->skb_pa = dma_map_single(&dev->dev, rskb->data,
+                       bd->skb_pa = dma_map_single(dev->dev.parent,
+                                       rskb->data,
                                        FEC_RX_BUFFER_SIZE, DMA_FROM_DEVICE);
 
                        bcom_submit_next_buffer(priv->rx_dmatsk, rskb);
@@ -454,7 +483,6 @@ static irqreturn_t mpc52xx_fec_rx_interrupt(int irq, void *dev_id)
                        rskb->protocol = eth_type_trans(rskb, dev);
 
                        netif_rx(rskb);
-                       dev->last_rx = jiffies;
                } else {
                        /* Can't get a new one : reuse the same & drop pkt */
                        dev_notice(&dev->dev, "Memory squeeze, dropping packet.\n");
@@ -467,7 +495,7 @@ static irqreturn_t mpc52xx_fec_rx_interrupt(int irq, void *dev_id)
                        bcom_prepare_next_buffer(priv->rx_dmatsk);
 
                bd->status = FEC_RX_BUFFER_SIZE;
-               bd->skb_pa = dma_map_single(&dev->dev, skb->data,
+               bd->skb_pa = dma_map_single(dev->dev.parent, skb->data,
                                FEC_RX_BUFFER_SIZE, DMA_FROM_DEVICE);
 
                bcom_submit_next_buffer(priv->rx_dmatsk, skb);
@@ -491,20 +519,23 @@ static irqreturn_t mpc52xx_fec_interrupt(int irq, void *dev_id)
 
        out_be32(&fec->ievent, ievent);         /* clear pending events */
 
-       if (ievent & ~(FEC_IEVENT_RFIFO_ERROR | FEC_IEVENT_XFIFO_ERROR)) {
-               if (ievent & ~FEC_IEVENT_TFINT)
-                       dev_dbg(&dev->dev, "ievent: %08x\n", ievent);
+       /* on fifo error, soft-reset fec */
+       if (ievent & (FEC_IEVENT_RFIFO_ERROR | FEC_IEVENT_XFIFO_ERROR)) {
+
+               if (net_ratelimit() && (ievent & FEC_IEVENT_RFIFO_ERROR))
+                       dev_warn(&dev->dev, "FEC_IEVENT_RFIFO_ERROR\n");
+               if (net_ratelimit() && (ievent & FEC_IEVENT_XFIFO_ERROR))
+                       dev_warn(&dev->dev, "FEC_IEVENT_XFIFO_ERROR\n");
+
+               mpc52xx_fec_reset(dev);
+
+               netif_wake_queue(dev);
                return IRQ_HANDLED;
        }
 
-       if (net_ratelimit() && (ievent & FEC_IEVENT_RFIFO_ERROR))
-               dev_warn(&dev->dev, "FEC_IEVENT_RFIFO_ERROR\n");
-       if (net_ratelimit() && (ievent & FEC_IEVENT_XFIFO_ERROR))
-               dev_warn(&dev->dev, "FEC_IEVENT_XFIFO_ERROR\n");
-
-       mpc52xx_fec_reset(dev);
+       if (ievent & ~FEC_IEVENT_TFINT)
+               dev_dbg(&dev->dev, "ievent: %08x\n", ievent);
 
-       netif_wake_queue(dev);
        return IRQ_HANDLED;
 }
 
@@ -701,7 +732,7 @@ static void mpc52xx_fec_start(struct net_device *dev)
        rcntrl = FEC_RX_BUFFER_SIZE << 16;      /* max frame length */
        rcntrl |= FEC_RCNTRL_FCE;
 
-       if (priv->has_phy)
+       if (priv->phy_addr != FEC5200_PHYADDR_7WIRE)
                rcntrl |= FEC_RCNTRL_MII_MODE;
 
        if (priv->duplex == DUPLEX_FULL)
@@ -812,12 +843,20 @@ static void mpc52xx_fec_get_drvinfo(struct net_device *dev,
 static int mpc52xx_fec_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
 {
        struct mpc52xx_fec_priv *priv = netdev_priv(dev);
+
+       if (!priv->phydev)
+               return -ENODEV;
+
        return phy_ethtool_gset(priv->phydev, cmd);
 }
 
 static int mpc52xx_fec_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
 {
        struct mpc52xx_fec_priv *priv = netdev_priv(dev);
+
+       if (!priv->phydev)
+               return -ENODEV;
+
        return phy_ethtool_sset(priv->phydev, cmd);
 }
 
@@ -847,9 +886,28 @@ static int mpc52xx_fec_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
 {
        struct mpc52xx_fec_priv *priv = netdev_priv(dev);
 
-       return mpc52xx_fec_phy_mii_ioctl(priv, if_mii(rq), cmd);
+       if (!priv->phydev)
+               return -ENOTSUPP;
+
+       return phy_mii_ioctl(priv->phydev, if_mii(rq), cmd);
 }
 
+static const struct net_device_ops mpc52xx_fec_netdev_ops = {
+       .ndo_open = mpc52xx_fec_open,
+       .ndo_stop = mpc52xx_fec_close,
+       .ndo_start_xmit = mpc52xx_fec_start_xmit,
+       .ndo_set_multicast_list = mpc52xx_fec_set_multicast_list,
+       .ndo_set_mac_address = mpc52xx_fec_set_mac_address,
+       .ndo_validate_addr = eth_validate_addr,
+       .ndo_do_ioctl = mpc52xx_fec_ioctl,
+       .ndo_change_mtu = eth_change_mtu,
+       .ndo_tx_timeout = mpc52xx_fec_tx_timeout,
+       .ndo_get_stats = mpc52xx_fec_get_stats,
+#ifdef CONFIG_NET_POLL_CONTROLLER
+       .ndo_poll_controller = mpc52xx_fec_poll_controller,
+#endif
+};
+
 /* ======================================================================== */
 /* OF Driver                                                                */
 /* ======================================================================== */
@@ -861,7 +919,10 @@ mpc52xx_fec_probe(struct of_device *op, const struct of_device_id *match)
        struct net_device *ndev;
        struct mpc52xx_fec_priv *priv = NULL;
        struct resource mem;
-       const phandle *ph;
+       struct device_node *phy_node;
+       const phandle *phy_handle;
+       const u32 *prop;
+       int prop_size;
 
        phys_addr_t rx_fifo;
        phys_addr_t tx_fifo;
@@ -891,20 +952,11 @@ mpc52xx_fec_probe(struct of_device *op, const struct of_device_id *match)
                return -EBUSY;
 
        /* Init ether ndev with what we have */
-       ndev->open              = mpc52xx_fec_open;
-       ndev->stop              = mpc52xx_fec_close;
-       ndev->hard_start_xmit   = mpc52xx_fec_hard_start_xmit;
-       ndev->do_ioctl          = mpc52xx_fec_ioctl;
+       ndev->netdev_ops        = &mpc52xx_fec_netdev_ops;
        ndev->ethtool_ops       = &mpc52xx_fec_ethtool_ops;
-       ndev->get_stats         = mpc52xx_fec_get_stats;
-       ndev->set_mac_address   = mpc52xx_fec_set_mac_address;
-       ndev->set_multicast_list = mpc52xx_fec_set_multicast_list;
-       ndev->tx_timeout        = mpc52xx_fec_tx_timeout;
        ndev->watchdog_timeo    = FEC_WATCHDOG_TIMEOUT;
        ndev->base_addr         = mem.start;
 
-       priv->t_irq = priv->r_irq = ndev->irq = NO_IRQ; /* IRQ are free for now */
-
        spin_lock_init(&priv->lock);
 
        /* ioremap the zones */
@@ -945,26 +997,37 @@ mpc52xx_fec_probe(struct of_device *op, const struct of_device_id *match)
                mpc52xx_fec_get_paddr(ndev, ndev->dev_addr);
 
        priv->msg_enable = netif_msg_init(debug, MPC52xx_MESSAGES_DEFAULT);
-       priv->duplex = DUPLEX_FULL;
-
-       /* is the phy present in device tree? */
-       ph = of_get_property(op->node, "phy-handle", NULL);
-       if (ph) {
-               const unsigned int *prop;
-               struct device_node *phy_dn;
-               priv->has_phy = 1;
 
-               phy_dn = of_find_node_by_phandle(*ph);
-               prop = of_get_property(phy_dn, "reg", NULL);
-               priv->phy_addr = *prop;
+       /*
+        * Link mode configuration
+        */
 
-               of_node_put(phy_dn);
+       /* Start with safe defaults for link connection */
+       priv->phy_addr = FEC5200_PHYADDR_NONE;
+       priv->speed = 100;
+       priv->duplex = DUPLEX_HALF;
+       priv->phy_speed = ((mpc52xx_find_ipb_freq(op->node) >> 20) / 5) << 1;
+
+       /* the 7-wire property means don't use MII mode */
+       if (of_find_property(op->node, "fsl,7-wire-mode", NULL))
+               priv->phy_addr = FEC5200_PHYADDR_7WIRE;
+
+       /* The current speed preconfigures the speed of the MII link */
+       prop = of_get_property(op->node, "current-speed", &prop_size);
+       if (prop && (prop_size >= sizeof(u32) * 2)) {
+               priv->speed = prop[0];
+               priv->duplex = prop[1] ? DUPLEX_FULL : DUPLEX_HALF;
+       }
 
-               /* Phy speed */
-               priv->phy_speed = ((mpc52xx_find_ipb_freq(op->node) >> 20) / 5) << 1;
-       } else {
-               dev_info(&ndev->dev, "can't find \"phy-handle\" in device"
-                               " tree, using 7-wire mode\n");
+       /* If there is a phy handle, setup link to that phy */
+       phy_handle = of_get_property(op->node, "phy-handle", &prop_size);
+       if (phy_handle && (prop_size >= sizeof(phandle))) {
+               phy_node = of_find_node_by_phandle(*phy_handle);
+               prop = of_get_property(phy_node, "reg", &prop_size);
+               if (prop && (prop_size >= sizeof(u32)))
+                       if ((*prop >= 0) && (*prop < PHY_MAX_ADDR))
+                               priv->phy_addr = *prop;
+               of_node_put(phy_node);
        }
 
        /* Hardware init */
@@ -979,6 +1042,20 @@ mpc52xx_fec_probe(struct of_device *op, const struct of_device_id *match)
        if (rv < 0)
                goto probe_error;
 
+       /* Now report the link setup */
+       switch (priv->phy_addr) {
+        case FEC5200_PHYADDR_NONE:
+               dev_info(&ndev->dev, "Fixed speed MII link: %i%cD\n",
+                        priv->speed, priv->duplex ? 'F' : 'H');
+               break;
+        case FEC5200_PHYADDR_7WIRE:
+               dev_info(&ndev->dev, "using 7-wire PHY mode\n");
+               break;
+        default:
+               dev_info(&ndev->dev, "Using PHY at MDIO address %i\n",
+                        priv->phy_addr);
+       }
+
        /* We're done ! */
        dev_set_drvdata(&op->dev, ndev);
 
@@ -1057,8 +1134,9 @@ static int mpc52xx_fec_of_resume(struct of_device *op)
 #endif
 
 static struct of_device_id mpc52xx_fec_match[] = {
-       { .type = "network", .compatible = "fsl,mpc5200-fec", },
-       { .type = "network", .compatible = "mpc5200-fec", },
+       { .compatible = "fsl,mpc5200b-fec", },
+       { .compatible = "fsl,mpc5200-fec", },
+       { .compatible = "mpc5200-fec", },
        { }
 };