bnx2x: Change to D3hot only on removal
[deliverable/linux.git] / drivers / net / ethernet / broadcom / bnx2x / bnx2x_ethtool.c
index ce1a91618677c13e232f4b017485722857e35520..263950cddfe20f31ce1f6fdf82adccab2debc003 100644 (file)
@@ -1381,12 +1381,28 @@ static int bnx2x_nvram_read32(struct bnx2x *bp, u32 offset, u32 *buf,
        return rc;
 }
 
+static bool bnx2x_is_nvm_accessible(struct bnx2x *bp)
+{
+       int rc = 1;
+       u16 pm = 0;
+       struct net_device *dev = pci_get_drvdata(bp->pdev);
+
+       if (bp->pm_cap)
+               rc = pci_read_config_word(bp->pdev,
+                                         bp->pm_cap + PCI_PM_CTRL, &pm);
+
+       if ((rc && !netif_running(dev)) || (!rc && ((pm & PCI_D0) != PCI_D0)))
+               return false;
+
+       return true;
+}
+
 static int bnx2x_get_eeprom(struct net_device *dev,
                            struct ethtool_eeprom *eeprom, u8 *eebuf)
 {
        struct bnx2x *bp = netdev_priv(dev);
 
-       if (!netif_running(dev)) {
+       if (!bnx2x_is_nvm_accessible(bp)) {
                DP(BNX2X_MSG_ETHTOOL  | BNX2X_MSG_NVM,
                   "cannot access eeprom when the interface is down\n");
                return -EAGAIN;
@@ -1411,7 +1427,7 @@ static int bnx2x_get_module_eeprom(struct net_device *dev,
        u8 *user_data = data;
        unsigned int start_addr = ee->offset, xfer_size = 0;
 
-       if (!netif_running(dev)) {
+       if (!bnx2x_is_nvm_accessible(bp)) {
                DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
                   "cannot access eeprom when the interface is down\n");
                return -EAGAIN;
@@ -1474,7 +1490,7 @@ static int bnx2x_get_module_info(struct net_device *dev,
        int phy_idx, rc;
        u8 sff8472_comp, diag_type;
 
-       if (!netif_running(dev)) {
+       if (!bnx2x_is_nvm_accessible(bp)) {
                DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
                   "cannot access eeprom when the interface is down\n");
                return -EAGAIN;
@@ -1676,7 +1692,8 @@ static int bnx2x_set_eeprom(struct net_device *dev,
        int port = BP_PORT(bp);
        int rc = 0;
        u32 ext_phy_config;
-       if (!netif_running(dev)) {
+
+       if (!bnx2x_is_nvm_accessible(bp)) {
                DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
                   "cannot access eeprom when the interface is down\n");
                return -EAGAIN;
@@ -1921,6 +1938,19 @@ static const char bnx2x_tests_str_arr[BNX2X_NUM_TESTS_SF][ETH_GSTRING_LEN] = {
        "link_test (online)         "
 };
 
+enum {
+       BNX2X_PRI_FLAG_ISCSI,
+       BNX2X_PRI_FLAG_FCOE,
+       BNX2X_PRI_FLAG_STORAGE,
+       BNX2X_PRI_FLAG_LEN,
+};
+
+static const char bnx2x_private_arr[BNX2X_PRI_FLAG_LEN][ETH_GSTRING_LEN] = {
+       "iSCSI offload support",
+       "FCoE offload support",
+       "Storage only interface"
+};
+
 static u32 bnx2x_eee_to_adv(u32 eee_adv)
 {
        u32 modes = 0;
@@ -2160,7 +2190,7 @@ static int bnx2x_test_registers(struct bnx2x *bp)
                { BNX2X_CHIP_MASK_ALL, 0xffffffff, 0, 0x00000000 }
        };
 
-       if (!netif_running(bp->dev)) {
+       if (!bnx2x_is_nvm_accessible(bp)) {
                DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
                   "cannot access eeprom when the interface is down\n");
                return rc;
@@ -2264,7 +2294,7 @@ static int bnx2x_test_memory(struct bnx2x *bp)
                { NULL, 0xffffffff, {0, 0, 0, 0} }
        };
 
-       if (!netif_running(bp->dev)) {
+       if (!bnx2x_is_nvm_accessible(bp)) {
                DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
                   "cannot access eeprom when the interface is down\n");
                return rc;
@@ -2978,32 +3008,47 @@ static int bnx2x_num_stat_queues(struct bnx2x *bp)
 static int bnx2x_get_sset_count(struct net_device *dev, int stringset)
 {
        struct bnx2x *bp = netdev_priv(dev);
-       int i, num_stats;
+       int i, num_strings = 0;
 
        switch (stringset) {
        case ETH_SS_STATS:
                if (is_multi(bp)) {
-                       num_stats = bnx2x_num_stat_queues(bp) *
-                                               BNX2X_NUM_Q_STATS;
+                       num_strings = bnx2x_num_stat_queues(bp) *
+                                     BNX2X_NUM_Q_STATS;
                } else
-                       num_stats = 0;
+                       num_strings = 0;
                if (IS_MF_MODE_STAT(bp)) {
                        for (i = 0; i < BNX2X_NUM_STATS; i++)
                                if (IS_FUNC_STAT(i))
-                                       num_stats++;
+                                       num_strings++;
                } else
-                       num_stats += BNX2X_NUM_STATS;
+                       num_strings += BNX2X_NUM_STATS;
 
-               return num_stats;
+               return num_strings;
 
        case ETH_SS_TEST:
                return BNX2X_NUM_TESTS(bp);
 
+       case ETH_SS_PRIV_FLAGS:
+               return BNX2X_PRI_FLAG_LEN;
+
        default:
                return -EINVAL;
        }
 }
 
+static u32 bnx2x_get_private_flags(struct net_device *dev)
+{
+       struct bnx2x *bp = netdev_priv(dev);
+       u32 flags = 0;
+
+       flags |= (!(bp->flags & NO_ISCSI_FLAG) ? 1 : 0) << BNX2X_PRI_FLAG_ISCSI;
+       flags |= (!(bp->flags & NO_FCOE_FLAG)  ? 1 : 0) << BNX2X_PRI_FLAG_FCOE;
+       flags |= (!!IS_MF_STORAGE_ONLY(bp)) << BNX2X_PRI_FLAG_STORAGE;
+
+       return flags;
+}
+
 static void bnx2x_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
 {
        struct bnx2x *bp = netdev_priv(dev);
@@ -3045,6 +3090,12 @@ static void bnx2x_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
                        start = 4;
                memcpy(buf, bnx2x_tests_str_arr + start,
                       ETH_GSTRING_LEN * BNX2X_NUM_TESTS(bp));
+               break;
+
+       case ETH_SS_PRIV_FLAGS:
+               memcpy(buf, bnx2x_private_arr,
+                      ETH_GSTRING_LEN * BNX2X_PRI_FLAG_LEN);
+               break;
        }
 }
 
@@ -3106,17 +3157,12 @@ static int bnx2x_set_phys_id(struct net_device *dev,
 {
        struct bnx2x *bp = netdev_priv(dev);
 
-       if (!netif_running(dev)) {
+       if (!bnx2x_is_nvm_accessible(bp)) {
                DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
                   "cannot access eeprom when the interface is down\n");
                return -EAGAIN;
        }
 
-       if (!bp->port.pmf) {
-               DP(BNX2X_MSG_ETHTOOL, "Interface is not pmf\n");
-               return -EOPNOTSUPP;
-       }
-
        switch (state) {
        case ETHTOOL_ID_ACTIVE:
                return 1;       /* cycle on/off once per second */
@@ -3445,6 +3491,7 @@ static const struct ethtool_ops bnx2x_ethtool_ops = {
        .set_pauseparam         = bnx2x_set_pauseparam,
        .self_test              = bnx2x_self_test,
        .get_sset_count         = bnx2x_get_sset_count,
+       .get_priv_flags         = bnx2x_get_private_flags,
        .get_strings            = bnx2x_get_strings,
        .set_phys_id            = bnx2x_set_phys_id,
        .get_ethtool_stats      = bnx2x_get_ethtool_stats,
This page took 0.031791 seconds and 5 git commands to generate.