sfc: 10Xpress: Report support for pause frames
[linux-2.6.git] / drivers / net / ucc_geth_ethtool.c
index 64bef7c..7075f26 100644 (file)
@@ -5,9 +5,9 @@
  *
  * Author: Li Yang <leoli@freescale.com>
  *
- * Limitation: 
+ * Limitation:
  * Can only get/set setttings of the first queue.
- * Need to re-open the interface manually after changing some paramters.
+ * Need to re-open the interface manually after changing some parameters.
  *
  * This program is free software; you can redistribute  it and/or modify it
  * under  the terms of  the GNU General  Public License as published by the
@@ -28,7 +28,6 @@
 #include <linux/mm.h>
 #include <linux/delay.h>
 #include <linux/dma-mapping.h>
-#include <linux/fsl_devices.h>
 #include <linux/ethtool.h>
 #include <linux/mii.h>
 #include <linux/phy.h>
 #include <asm/irq.h>
 #include <asm/uaccess.h>
 #include <asm/types.h>
-#include <asm/uaccess.h>
 
 #include "ucc_geth.h"
-#include "ucc_geth_mii.h"
 
 static char hw_stat_gstrings[][ETH_GSTRING_LEN] = {
        "tx-64-frames",
@@ -73,6 +70,7 @@ static char tx_fw_stat_gstrings[][ETH_GSTRING_LEN] = {
        "tx-frames-ok",
        "tx-excessive-differ-frames",
        "tx-256-511-frames",
+       "tx-512-1023-frames",
        "tx-1024-1518-frames",
        "tx-jumbo-frames",
 };
@@ -108,12 +106,6 @@ static char rx_fw_stat_gstrings[][ETH_GSTRING_LEN] = {
 #define UEC_TX_FW_STATS_LEN ARRAY_SIZE(tx_fw_stat_gstrings)
 #define UEC_RX_FW_STATS_LEN ARRAY_SIZE(rx_fw_stat_gstrings)
 
-extern int init_flow_control_params(u32 automatic_flow_control_mode,
-               int rx_flow_control_enable,
-               int tx_flow_control_enable, u16 pause_period,
-               u16 extension_field, volatile u32 *upsmr_register,
-               volatile u32 *uempr_register, volatile u32 *maccfg1_register);
-
 static int
 uec_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
 {
@@ -165,7 +157,7 @@ uec_set_pauseparam(struct net_device *netdev,
 
        ugeth->ug_info->receiveFlowControl = pause->rx_pause;
        ugeth->ug_info->transmitFlowControl = pause->tx_pause;
-       
+
        if (ugeth->phydev->autoneg) {
                if (netif_running(netdev)) {
                        /* FIXME: automatically restart */
@@ -276,20 +268,26 @@ uec_set_ringparam(struct net_device *netdev,
        return ret;
 }
 
-static int uec_get_stats_count(struct net_device *netdev)
+static int uec_get_sset_count(struct net_device *netdev, int sset)
 {
        struct ucc_geth_private *ugeth = netdev_priv(netdev);
        u32 stats_mode = ugeth->ug_info->statisticsMode;
        int len = 0;
 
-       if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE)
-               len += UEC_HW_STATS_LEN;
-       if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX)
-               len += UEC_TX_FW_STATS_LEN;
-       if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX)
-               len += UEC_RX_FW_STATS_LEN;
+       switch (sset) {
+       case ETH_SS_STATS:
+               if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE)
+                       len += UEC_HW_STATS_LEN;
+               if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX)
+                       len += UEC_TX_FW_STATS_LEN;
+               if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX)
+                       len += UEC_RX_FW_STATS_LEN;
 
-       return len;
+               return len;
+
+       default:
+               return -EOPNOTSUPP;
+       }
 }
 
 static void uec_get_strings(struct net_device *netdev, u32 stringset, u8 *buf)
@@ -308,7 +306,7 @@ static void uec_get_strings(struct net_device *netdev, u32 stringset, u8 *buf)
                buf += UEC_TX_FW_STATS_LEN * ETH_GSTRING_LEN;
        }
        if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX)
-               memcpy(buf, tx_fw_stat_gstrings, UEC_RX_FW_STATS_LEN *
+               memcpy(buf, rx_fw_stat_gstrings, UEC_RX_FW_STATS_LEN *
                                ETH_GSTRING_LEN);
 }
 
@@ -321,19 +319,23 @@ static void uec_get_ethtool_stats(struct net_device *netdev,
        int i, j = 0;
 
        if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE) {
-               base = (u32 __iomem *)&ugeth->ug_regs->tx64;
+               if (ugeth->ug_regs)
+                       base = (u32 __iomem *)&ugeth->ug_regs->tx64;
+               else
+                       base = NULL;
+
                for (i = 0; i < UEC_HW_STATS_LEN; i++)
-                       data[j++] = (u64)in_be32(&base[i]);
+                       data[j++] = base ? in_be32(&base[i]) : 0;
        }
        if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX) {
                base = (u32 __iomem *)ugeth->p_tx_fw_statistics_pram;
                for (i = 0; i < UEC_TX_FW_STATS_LEN; i++)
-                       data[j++] = (u64)in_be32(&base[i]);
+                       data[j++] = base ? in_be32(&base[i]) : 0;
        }
        if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX) {
                base = (u32 __iomem *)ugeth->p_rx_fw_statistics_pram;
                for (i = 0; i < UEC_RX_FW_STATS_LEN; i++)
-                       data[j++] = (u64)in_be32(&base[i]);
+                       data[j++] = base ? in_be32(&base[i]) : 0;
        }
 }
 
@@ -353,12 +355,48 @@ uec_get_drvinfo(struct net_device *netdev,
        strncpy(drvinfo->version, DRV_VERSION, 32);
        strncpy(drvinfo->fw_version, "N/A", 32);
        strncpy(drvinfo->bus_info, "QUICC ENGINE", 32);
-       drvinfo->n_stats = uec_get_stats_count(netdev);
-       drvinfo->testinfo_len = 0;
        drvinfo->eedump_len = 0;
        drvinfo->regdump_len = uec_get_regs_len(netdev);
 }
 
+#ifdef CONFIG_PM
+
+static void uec_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
+{
+       struct ucc_geth_private *ugeth = netdev_priv(netdev);
+       struct phy_device *phydev = ugeth->phydev;
+
+       if (phydev && phydev->irq)
+               wol->supported |= WAKE_PHY;
+       if (qe_alive_during_sleep())
+               wol->supported |= WAKE_MAGIC;
+
+       wol->wolopts = ugeth->wol_en;
+}
+
+static int uec_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
+{
+       struct ucc_geth_private *ugeth = netdev_priv(netdev);
+       struct phy_device *phydev = ugeth->phydev;
+
+       if (wol->wolopts & ~(WAKE_PHY | WAKE_MAGIC))
+               return -EINVAL;
+       else if (wol->wolopts & WAKE_PHY && (!phydev || !phydev->irq))
+               return -EINVAL;
+       else if (wol->wolopts & WAKE_MAGIC && !qe_alive_during_sleep())
+               return -EINVAL;
+
+       ugeth->wol_en = wol->wolopts;
+       device_set_wakeup_enable(&netdev->dev, ugeth->wol_en);
+
+       return 0;
+}
+
+#else
+#define uec_get_wol NULL
+#define uec_set_wol NULL
+#endif /* CONFIG_PM */
+
 static const struct ethtool_ops uec_ethtool_ops = {
        .get_settings           = uec_get_settings,
        .set_settings           = uec_set_settings,
@@ -373,12 +411,12 @@ static const struct ethtool_ops uec_ethtool_ops = {
        .set_ringparam          = uec_set_ringparam,
        .get_pauseparam         = uec_get_pauseparam,
        .set_pauseparam         = uec_set_pauseparam,
-       .get_sg                 = ethtool_op_get_sg,
        .set_sg                 = ethtool_op_set_sg,
-       .get_tso                = ethtool_op_get_tso,
-       .get_stats_count        = uec_get_stats_count,
+       .get_sset_count         = uec_get_sset_count,
        .get_strings            = uec_get_strings,
        .get_ethtool_stats      = uec_get_ethtool_stats,
+       .get_wol                = uec_get_wol,
+       .set_wol                = uec_set_wol,
 };
 
 void uec_set_ethtool_ops(struct net_device *netdev)