]> err.no Git - linux-2.6/blobdiff - drivers/net/mv643xx_eth.c
at91_ether: use netstats in net_device structure
[linux-2.6] / drivers / net / mv643xx_eth.c
index 296687baccf757826dd000a071fac4ffadecd7e9..83a877f3a553ee94611dced9e87d28f2222aecaf 100644 (file)
@@ -55,7 +55,7 @@
 #include <asm/system.h>
 
 static char mv643xx_eth_driver_name[] = "mv643xx_eth";
-static char mv643xx_eth_driver_version[] = "1.0";
+static char mv643xx_eth_driver_version[] = "1.1";
 
 #define MV643XX_ETH_CHECKSUM_OFFLOAD_TX
 #define MV643XX_ETH_NAPI
@@ -108,6 +108,10 @@ static char mv643xx_eth_driver_version[] = "1.0";
 #define INT_MASK(p)                    (0x0468 + ((p) << 10))
 #define INT_MASK_EXT(p)                        (0x046c + ((p) << 10))
 #define TX_FIFO_URGENT_THRESHOLD(p)    (0x0474 + ((p) << 10))
+#define TXQ_FIX_PRIO_CONF_MOVED(p)     (0x04dc + ((p) << 10))
+#define TX_BW_RATE_MOVED(p)            (0x04e0 + ((p) << 10))
+#define TX_BW_MTU_MOVED(p)             (0x04e8 + ((p) << 10))
+#define TX_BW_BURST_MOVED(p)           (0x04ec + ((p) << 10))
 #define RXQ_CURRENT_DESC_PTR(p, q)     (0x060c + ((p) << 10) + ((q) << 4))
 #define RXQ_COMMAND(p)                 (0x0680 + ((p) << 10))
 #define TXQ_CURRENT_DESC_PTR(p, q)     (0x06c0 + ((p) << 10) + ((q) << 2))
@@ -250,6 +254,7 @@ struct mv643xx_eth_shared_private {
         */
        unsigned int t_clk;
        int extended_rx_coal_limit;
+       int tx_bw_control_moved;
 };
 
 
@@ -484,7 +489,7 @@ static void rxq_refill(struct rx_queue *rxq)
                skb_reserve(skb, 2);
        }
 
-       if (rxq->rx_desc_count == 0) {
+       if (rxq->rx_desc_count != rxq->rx_ring_size) {
                rxq->rx_oom.expires = jiffies + (HZ / 10);
                add_timer(&rxq->rx_oom);
        }
@@ -831,9 +836,15 @@ static void tx_set_rate(struct mv643xx_eth_private *mp, int rate, int burst)
        if (bucket_size > 65535)
                bucket_size = 65535;
 
-       wrl(mp, TX_BW_RATE(mp->port_num), token_rate);
-       wrl(mp, TX_BW_MTU(mp->port_num), mtu);
-       wrl(mp, TX_BW_BURST(mp->port_num), bucket_size);
+       if (mp->shared->tx_bw_control_moved) {
+               wrl(mp, TX_BW_RATE_MOVED(mp->port_num), token_rate);
+               wrl(mp, TX_BW_MTU_MOVED(mp->port_num), mtu);
+               wrl(mp, TX_BW_BURST_MOVED(mp->port_num), bucket_size);
+       } else {
+               wrl(mp, TX_BW_RATE(mp->port_num), token_rate);
+               wrl(mp, TX_BW_MTU(mp->port_num), mtu);
+               wrl(mp, TX_BW_BURST(mp->port_num), bucket_size);
+       }
 }
 
 static void txq_set_rate(struct tx_queue *txq, int rate, int burst)
@@ -864,7 +875,10 @@ static void txq_set_fixed_prio_mode(struct tx_queue *txq)
        /*
         * Turn on fixed priority mode.
         */
-       off = TXQ_FIX_PRIO_CONF(mp->port_num);
+       if (mp->shared->tx_bw_control_moved)
+               off = TXQ_FIX_PRIO_CONF_MOVED(mp->port_num);
+       else
+               off = TXQ_FIX_PRIO_CONF(mp->port_num);
 
        val = rdl(mp, off);
        val |= 1 << txq->index;
@@ -880,7 +894,10 @@ static void txq_set_wrr(struct tx_queue *txq, int weight)
        /*
         * Turn off fixed priority mode.
         */
-       off = TXQ_FIX_PRIO_CONF(mp->port_num);
+       if (mp->shared->tx_bw_control_moved)
+               off = TXQ_FIX_PRIO_CONF_MOVED(mp->port_num);
+       else
+               off = TXQ_FIX_PRIO_CONF(mp->port_num);
 
        val = rdl(mp, off);
        val &= ~(1 << txq->index);
@@ -1093,6 +1110,22 @@ static int mv643xx_eth_get_settings(struct net_device *dev, struct ethtool_cmd *
        return err;
 }
 
+static int mv643xx_eth_get_settings_phyless(struct net_device *dev, struct ethtool_cmd *cmd)
+{
+       cmd->supported = SUPPORTED_MII;
+       cmd->advertising = ADVERTISED_MII;
+       cmd->speed = SPEED_1000;
+       cmd->duplex = DUPLEX_FULL;
+       cmd->port = PORT_MII;
+       cmd->phy_address = 0;
+       cmd->transceiver = XCVR_INTERNAL;
+       cmd->autoneg = AUTONEG_DISABLE;
+       cmd->maxtxpkt = 1;
+       cmd->maxrxpkt = 1;
+
+       return 0;
+}
+
 static int mv643xx_eth_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
 {
        struct mv643xx_eth_private *mp = netdev_priv(dev);
@@ -1110,6 +1143,11 @@ static int mv643xx_eth_set_settings(struct net_device *dev, struct ethtool_cmd *
        return err;
 }
 
+static int mv643xx_eth_set_settings_phyless(struct net_device *dev, struct ethtool_cmd *cmd)
+{
+       return -EINVAL;
+}
+
 static void mv643xx_eth_get_drvinfo(struct net_device *dev,
                                    struct ethtool_drvinfo *drvinfo)
 {
@@ -1127,6 +1165,11 @@ static int mv643xx_eth_nway_reset(struct net_device *dev)
        return mii_nway_restart(&mp->mii);
 }
 
+static int mv643xx_eth_nway_reset_phyless(struct net_device *dev)
+{
+       return -EINVAL;
+}
+
 static u32 mv643xx_eth_get_link(struct net_device *dev)
 {
        struct mv643xx_eth_private *mp = netdev_priv(dev);
@@ -1134,6 +1177,11 @@ static u32 mv643xx_eth_get_link(struct net_device *dev)
        return mii_link_ok(&mp->mii);
 }
 
+static u32 mv643xx_eth_get_link_phyless(struct net_device *dev)
+{
+       return 1;
+}
+
 static void mv643xx_eth_get_strings(struct net_device *dev,
                                    uint32_t stringset, uint8_t *data)
 {
@@ -1193,6 +1241,18 @@ static const struct ethtool_ops mv643xx_eth_ethtool_ops = {
        .get_sset_count         = mv643xx_eth_get_sset_count,
 };
 
+static const struct ethtool_ops mv643xx_eth_ethtool_ops_phyless = {
+       .get_settings           = mv643xx_eth_get_settings_phyless,
+       .set_settings           = mv643xx_eth_set_settings_phyless,
+       .get_drvinfo            = mv643xx_eth_get_drvinfo,
+       .nway_reset             = mv643xx_eth_nway_reset_phyless,
+       .get_link               = mv643xx_eth_get_link_phyless,
+       .set_sg                 = ethtool_op_set_sg,
+       .get_strings            = mv643xx_eth_get_strings,
+       .get_ethtool_stats      = mv643xx_eth_get_ethtool_stats,
+       .get_sset_count         = mv643xx_eth_get_sset_count,
+};
+
 
 /* address handling *********************************************************/
 static void uc_addr_get(struct mv643xx_eth_private *mp, unsigned char *addr)
@@ -1639,12 +1699,16 @@ static irqreturn_t mv643xx_eth_irq(int irq, void *dev_id)
        }
 
        if (int_cause_ext & (INT_EXT_PHY | INT_EXT_LINK)) {
-               if (mii_link_ok(&mp->mii)) {
-                       struct ethtool_cmd cmd;
+               if (mp->phy_addr == -1 || mii_link_ok(&mp->mii)) {
                        int i;
 
-                       mii_ethtool_gset(&mp->mii, &cmd);
-                       update_pscr(mp, cmd.speed, cmd.duplex);
+                       if (mp->phy_addr != -1) {
+                               struct ethtool_cmd cmd;
+
+                               mii_ethtool_gset(&mp->mii, &cmd);
+                               update_pscr(mp, cmd.speed, cmd.duplex);
+                       }
+
                        for (i = 0; i < 8; i++)
                                if (mp->txq_mask & (1 << i))
                                        txq_enable(mp->txq + i);
@@ -1734,7 +1798,6 @@ static void phy_reset(struct mv643xx_eth_private *mp)
 static void port_start(struct mv643xx_eth_private *mp)
 {
        u32 pscr;
-       struct ethtool_cmd ethtool_cmd;
        int i;
 
        /*
@@ -1754,9 +1817,16 @@ static void port_start(struct mv643xx_eth_private *mp)
 
        wrl(mp, SDMA_CONFIG(mp->port_num), PORT_SDMA_CONFIG_DEFAULT_VALUE);
 
-       mv643xx_eth_get_settings(mp->dev, &ethtool_cmd);
-       phy_reset(mp);
-       mv643xx_eth_set_settings(mp->dev, &ethtool_cmd);
+       /*
+        * Perform PHY reset, if there is a PHY.
+        */
+       if (mp->phy_addr != -1) {
+               struct ethtool_cmd cmd;
+
+               mv643xx_eth_get_settings(mp->dev, &cmd);
+               phy_reset(mp);
+               mv643xx_eth_set_settings(mp->dev, &cmd);
+       }
 
        /*
         * Configure TX path and queues.
@@ -1973,7 +2043,10 @@ static int mv643xx_eth_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
 {
        struct mv643xx_eth_private *mp = netdev_priv(dev);
 
-       return generic_mii_ioctl(&mp->mii, if_mii(ifr), cmd, NULL);
+       if (mp->phy_addr != -1)
+               return generic_mii_ioctl(&mp->mii, if_mii(ifr), cmd, NULL);
+
+       return -EOPNOTSUPP;
 }
 
 static int mv643xx_eth_change_mtu(struct net_device *dev, int new_mtu)
@@ -2108,6 +2181,16 @@ static void infer_hw_params(struct mv643xx_eth_shared_private *msp)
                msp->extended_rx_coal_limit = 1;
        else
                msp->extended_rx_coal_limit = 0;
+
+       /*
+        * Check whether the TX rate control registers are in the
+        * old or the new place.
+        */
+       writel(1, msp->base + TX_BW_MTU_MOVED(0));
+       if (readl(msp->base + TX_BW_MTU_MOVED(0)) & 1)
+               msp->tx_bw_control_moved = 1;
+       else
+               msp->tx_bw_control_moved = 0;
 }
 
 static int mv643xx_eth_shared_probe(struct platform_device *pdev)
@@ -2360,10 +2443,15 @@ static int mv643xx_eth_probe(struct platform_device *pdev)
        mib_counters_clear(mp);
        INIT_WORK(&mp->tx_timeout_task, tx_timeout_task);
 
-       err = phy_init(mp, pd);
-       if (err)
-               goto out;
-       SET_ETHTOOL_OPS(dev, &mv643xx_eth_ethtool_ops);
+       if (mp->phy_addr != -1) {
+               err = phy_init(mp, pd);
+               if (err)
+                       goto out;
+
+               SET_ETHTOOL_OPS(dev, &mv643xx_eth_ethtool_ops);
+       } else {
+               SET_ETHTOOL_OPS(dev, &mv643xx_eth_ethtool_ops_phyless);
+       }
 
 
        res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
@@ -2482,8 +2570,8 @@ static void __exit mv643xx_eth_cleanup_module(void)
 }
 module_exit(mv643xx_eth_cleanup_module);
 
-MODULE_AUTHOR("Rabeeh Khoury, Assaf Hoffman, Matthew Dharm, Manish Lachwani "
-             "and Dale Farnsworth");
+MODULE_AUTHOR("Rabeeh Khoury, Assaf Hoffman, Matthew Dharm, "
+             "Manish Lachwani, Dale Farnsworth and Lennert Buytenhek");
 MODULE_DESCRIPTION("Ethernet driver for Marvell MV643XX");
 MODULE_LICENSE("GPL");
 MODULE_ALIAS("platform:" MV643XX_ETH_SHARED_NAME);