Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
[linux-2.6-block.git] / drivers / net / ethernet / mellanox / mlx5 / core / en_ethtool.c
index 65624ac65b4c347ac5dedf55f3b209de799e7e5f..68834b715f6c114c89d6df339cb9cc81a72b8f75 100644 (file)
@@ -211,13 +211,14 @@ static void mlx5e_get_strings(struct net_device *dev,
                                sprintf(data + (idx++) * ETH_GSTRING_LEN,
                                        "rx%d_%s", i, rq_stats_strings[j]);
 
-               for (i = 0; i < priv->params.num_channels; i++)
-                       for (tc = 0; tc < priv->params.num_tc; tc++)
+               for (tc = 0; tc < priv->params.num_tc; tc++)
+                       for (i = 0; i < priv->params.num_channels; i++)
                                for (j = 0; j < NUM_SQ_STATS; j++)
                                        sprintf(data +
-                                               (idx++) * ETH_GSTRING_LEN,
-                                               "tx%d_%d_%s", i, tc,
-                                               sq_stats_strings[j]);
+                                             (idx++) * ETH_GSTRING_LEN,
+                                             "tx%d_%s",
+                                             priv->channeltc_to_txq_map[i][tc],
+                                             sq_stats_strings[j]);
                break;
        }
 }
@@ -249,8 +250,8 @@ static void mlx5e_get_ethtool_stats(struct net_device *dev,
                                                &priv->state) ? 0 :
                                       ((u64 *)&priv->channel[i]->rq.stats)[j];
 
-       for (i = 0; i < priv->params.num_channels; i++)
-               for (tc = 0; tc < priv->params.num_tc; tc++)
+       for (tc = 0; tc < priv->params.num_tc; tc++)
+               for (i = 0; i < priv->params.num_channels; i++)
                        for (j = 0; j < NUM_SQ_STATS; j++)
                                data[idx++] = !test_bit(MLX5E_STATE_OPENED,
                                                        &priv->state) ? 0 :
@@ -385,6 +386,8 @@ static int mlx5e_set_channels(struct net_device *dev,
                mlx5e_close_locked(dev);
 
        priv->params.num_channels = count;
+       mlx5e_build_default_indir_rqt(priv->params.indirection_rqt,
+                                     MLX5E_INDIR_RQT_SIZE, count);
 
        if (was_opened)
                err = mlx5e_open_locked(dev);
@@ -399,6 +402,9 @@ static int mlx5e_get_coalesce(struct net_device *netdev,
 {
        struct mlx5e_priv *priv = netdev_priv(netdev);
 
+       if (!MLX5_CAP_GEN(priv->mdev, cq_moderation))
+               return -ENOTSUPP;
+
        coal->rx_coalesce_usecs       = priv->params.rx_cq_moderation_usec;
        coal->rx_max_coalesced_frames = priv->params.rx_cq_moderation_pkts;
        coal->tx_coalesce_usecs       = priv->params.tx_cq_moderation_usec;
@@ -416,11 +422,18 @@ static int mlx5e_set_coalesce(struct net_device *netdev,
        int tc;
        int i;
 
+       if (!MLX5_CAP_GEN(mdev, cq_moderation))
+               return -ENOTSUPP;
+
+       mutex_lock(&priv->state_lock);
        priv->params.tx_cq_moderation_usec = coal->tx_coalesce_usecs;
        priv->params.tx_cq_moderation_pkts = coal->tx_max_coalesced_frames;
        priv->params.rx_cq_moderation_usec = coal->rx_coalesce_usecs;
        priv->params.rx_cq_moderation_pkts = coal->rx_max_coalesced_frames;
 
+       if (!test_bit(MLX5E_STATE_OPENED, &priv->state))
+               goto out;
+
        for (i = 0; i < priv->params.num_channels; ++i) {
                c = priv->channel[i];
 
@@ -436,6 +449,8 @@ static int mlx5e_set_coalesce(struct net_device *netdev,
                                               coal->rx_max_coalesced_frames);
        }
 
+out:
+       mutex_unlock(&priv->state_lock);
        return 0;
 }
 
@@ -703,18 +718,36 @@ static int mlx5e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
        return 0;
 }
 
+static void mlx5e_modify_tirs_hash(struct mlx5e_priv *priv, void *in, int inlen)
+{
+       struct mlx5_core_dev *mdev = priv->mdev;
+       void *tirc = MLX5_ADDR_OF(modify_tir_in, in, ctx);
+       int i;
+
+       MLX5_SET(modify_tir_in, in, bitmask.hash, 1);
+       mlx5e_build_tir_ctx_hash(tirc, priv);
+
+       for (i = 0; i < MLX5E_NUM_TT; i++)
+               if (IS_HASHING_TT(i))
+                       mlx5_core_modify_tir(mdev, priv->tirn[i], in, inlen);
+}
+
 static int mlx5e_set_rxfh(struct net_device *dev, const u32 *indir,
                          const u8 *key, const u8 hfunc)
 {
        struct mlx5e_priv *priv = netdev_priv(dev);
-       bool close_open;
-       int err = 0;
+       int inlen = MLX5_ST_SZ_BYTES(modify_tir_in);
+       void *in;
 
        if ((hfunc != ETH_RSS_HASH_NO_CHANGE) &&
            (hfunc != ETH_RSS_HASH_XOR) &&
            (hfunc != ETH_RSS_HASH_TOP))
                return -EINVAL;
 
+       in = mlx5_vzalloc(inlen);
+       if (!in)
+               return -ENOMEM;
+
        mutex_lock(&priv->state_lock);
 
        if (indir) {
@@ -723,11 +756,6 @@ static int mlx5e_set_rxfh(struct net_device *dev, const u32 *indir,
                mlx5e_redirect_rqt(priv, MLX5E_INDIRECTION_RQT);
        }
 
-       close_open = (key || (hfunc != ETH_RSS_HASH_NO_CHANGE)) &&
-                    test_bit(MLX5E_STATE_OPENED, &priv->state);
-       if (close_open)
-               mlx5e_close_locked(dev);
-
        if (key)
                memcpy(priv->params.toeplitz_hash_key, key,
                       sizeof(priv->params.toeplitz_hash_key));
@@ -735,12 +763,13 @@ static int mlx5e_set_rxfh(struct net_device *dev, const u32 *indir,
        if (hfunc != ETH_RSS_HASH_NO_CHANGE)
                priv->params.rss_hfunc = hfunc;
 
-       if (close_open)
-               err = mlx5e_open_locked(priv->netdev);
+       mlx5e_modify_tirs_hash(priv, in, inlen);
 
        mutex_unlock(&priv->state_lock);
 
-       return err;
+       kvfree(in);
+
+       return 0;
 }
 
 static int mlx5e_get_rxnfc(struct net_device *netdev,
@@ -884,6 +913,129 @@ static int mlx5e_get_ts_info(struct net_device *dev,
        return 0;
 }
 
+static __u32 mlx5e_get_wol_supported(struct mlx5_core_dev *mdev)
+{
+       __u32 ret = 0;
+
+       if (MLX5_CAP_GEN(mdev, wol_g))
+               ret |= WAKE_MAGIC;
+
+       if (MLX5_CAP_GEN(mdev, wol_s))
+               ret |= WAKE_MAGICSECURE;
+
+       if (MLX5_CAP_GEN(mdev, wol_a))
+               ret |= WAKE_ARP;
+
+       if (MLX5_CAP_GEN(mdev, wol_b))
+               ret |= WAKE_BCAST;
+
+       if (MLX5_CAP_GEN(mdev, wol_m))
+               ret |= WAKE_MCAST;
+
+       if (MLX5_CAP_GEN(mdev, wol_u))
+               ret |= WAKE_UCAST;
+
+       if (MLX5_CAP_GEN(mdev, wol_p))
+               ret |= WAKE_PHY;
+
+       return ret;
+}
+
+static __u32 mlx5e_refomrat_wol_mode_mlx5_to_linux(u8 mode)
+{
+       __u32 ret = 0;
+
+       if (mode & MLX5_WOL_MAGIC)
+               ret |= WAKE_MAGIC;
+
+       if (mode & MLX5_WOL_SECURED_MAGIC)
+               ret |= WAKE_MAGICSECURE;
+
+       if (mode & MLX5_WOL_ARP)
+               ret |= WAKE_ARP;
+
+       if (mode & MLX5_WOL_BROADCAST)
+               ret |= WAKE_BCAST;
+
+       if (mode & MLX5_WOL_MULTICAST)
+               ret |= WAKE_MCAST;
+
+       if (mode & MLX5_WOL_UNICAST)
+               ret |= WAKE_UCAST;
+
+       if (mode & MLX5_WOL_PHY_ACTIVITY)
+               ret |= WAKE_PHY;
+
+       return ret;
+}
+
+static u8 mlx5e_refomrat_wol_mode_linux_to_mlx5(__u32 mode)
+{
+       u8 ret = 0;
+
+       if (mode & WAKE_MAGIC)
+               ret |= MLX5_WOL_MAGIC;
+
+       if (mode & WAKE_MAGICSECURE)
+               ret |= MLX5_WOL_SECURED_MAGIC;
+
+       if (mode & WAKE_ARP)
+               ret |= MLX5_WOL_ARP;
+
+       if (mode & WAKE_BCAST)
+               ret |= MLX5_WOL_BROADCAST;
+
+       if (mode & WAKE_MCAST)
+               ret |= MLX5_WOL_MULTICAST;
+
+       if (mode & WAKE_UCAST)
+               ret |= MLX5_WOL_UNICAST;
+
+       if (mode & WAKE_PHY)
+               ret |= MLX5_WOL_PHY_ACTIVITY;
+
+       return ret;
+}
+
+static void mlx5e_get_wol(struct net_device *netdev,
+                         struct ethtool_wolinfo *wol)
+{
+       struct mlx5e_priv *priv = netdev_priv(netdev);
+       struct mlx5_core_dev *mdev = priv->mdev;
+       u8 mlx5_wol_mode;
+       int err;
+
+       memset(wol, 0, sizeof(*wol));
+
+       wol->supported = mlx5e_get_wol_supported(mdev);
+       if (!wol->supported)
+               return;
+
+       err = mlx5_query_port_wol(mdev, &mlx5_wol_mode);
+       if (err)
+               return;
+
+       wol->wolopts = mlx5e_refomrat_wol_mode_mlx5_to_linux(mlx5_wol_mode);
+}
+
+static int mlx5e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
+{
+       struct mlx5e_priv *priv = netdev_priv(netdev);
+       struct mlx5_core_dev *mdev = priv->mdev;
+       __u32 wol_supported = mlx5e_get_wol_supported(mdev);
+       u32 mlx5_wol_mode;
+
+       if (!wol_supported)
+               return -ENOTSUPP;
+
+       if (wol->wolopts & ~wol_supported)
+               return -EINVAL;
+
+       mlx5_wol_mode = mlx5e_refomrat_wol_mode_linux_to_mlx5(wol->wolopts);
+
+       return mlx5_set_port_wol(mdev, mlx5_wol_mode);
+}
+
 const struct ethtool_ops mlx5e_ethtool_ops = {
        .get_drvinfo       = mlx5e_get_drvinfo,
        .get_link          = ethtool_op_get_link,
@@ -908,4 +1060,6 @@ const struct ethtool_ops mlx5e_ethtool_ops = {
        .get_pauseparam    = mlx5e_get_pauseparam,
        .set_pauseparam    = mlx5e_set_pauseparam,
        .get_ts_info       = mlx5e_get_ts_info,
+       .get_wol           = mlx5e_get_wol,
+       .set_wol           = mlx5e_set_wol,
 };