net/mlx5e: Support DSCP trust state to Ethernet's IP packet on SQ
authorHuy Nguyen <huyn@mellanox.com>
Tue, 18 Jul 2017 21:34:51 +0000 (16:34 -0500)
committerSaeed Mahameed <saeedm@mellanox.com>
Sun, 5 Nov 2017 04:26:42 +0000 (21:26 -0700)
If the port is in DSCP trust state, packets are placed in the right
priority queue based on the dscp value. This is done by selecting
the transmit queue based on the dscp of the skb.

Until now select_queue honors priority only from the vlan header.
However that is not sufficient in cases where port trust state is DSCP
mode as packet might not even contain vlan header. Therefore if the port
is in dscp trust state and vport's min inline mode is not NONE,
copy the IP header to the eseg's inline header if the skb has it.
This is done by changing the transmit queue sq's min inline mode to L3.
Note that the min inline mode of sqs that belong to other features such
as xdpsq, icosq are not modified.

Signed-off-by: Huy Nguyen <huyn@mellanox.com>
Reviewed-by: Parav Pandit <parav@mellanox.com>
Reviewed-by: Or Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
drivers/net/ethernet/mellanox/mlx5/core/en.h
drivers/net/ethernet/mellanox/mlx5/core/en_common.c
drivers/net/ethernet/mellanox/mlx5/core/en_dcbnl.c
drivers/net/ethernet/mellanox/mlx5/core/en_main.c
drivers/net/ethernet/mellanox/mlx5/core/en_tx.c

index ab6f0c18850fab759c29c49098cf49a9c14f81d9..fae7b62d173fab74e9a9c2c61de18017a62ddcb5 100644 (file)
@@ -1083,4 +1083,5 @@ void mlx5e_destroy_netdev(struct mlx5e_priv *priv);
 void mlx5e_build_nic_params(struct mlx5_core_dev *mdev,
                            struct mlx5e_params *params,
                            u16 max_channels);
+u8 mlx5e_params_calculate_tx_min_inline(struct mlx5_core_dev *mdev);
 #endif /* __MLX5_EN_H__ */
index 157d0291723791d02c2ff2cd8e6f6a92b4ce6ea7..784e282803db1a71706628e7a1381da0388885c0 100644 (file)
@@ -171,3 +171,15 @@ out:
 
        return err;
 }
+
+u8 mlx5e_params_calculate_tx_min_inline(struct mlx5_core_dev *mdev)
+{
+       u8 min_inline_mode;
+
+       mlx5_query_min_inline(mdev, &min_inline_mode);
+       if (min_inline_mode == MLX5_INLINE_MODE_NONE &&
+           !MLX5_CAP_ETH(mdev, wqe_vlan_insert))
+               min_inline_mode = MLX5_INLINE_MODE_L2;
+
+       return min_inline_mode;
+}
index aa59c432415944fa3ff6ed1678e0261922702d3d..b402d69a701b1c2ba3e728f0d228717396ca1e81 100644 (file)
@@ -960,6 +960,40 @@ void mlx5e_dcbnl_delete_app(struct mlx5e_priv *priv)
        mlx5e_dcbnl_dscp_app(priv, DELETE);
 }
 
+static void mlx5e_trust_update_tx_min_inline_mode(struct mlx5e_priv *priv,
+                                                 struct mlx5e_params *params)
+{
+       params->tx_min_inline_mode = mlx5e_params_calculate_tx_min_inline(priv->mdev);
+       if (priv->dcbx_dp.trust_state == MLX5_QPTS_TRUST_DSCP &&
+           params->tx_min_inline_mode == MLX5_INLINE_MODE_L2)
+               params->tx_min_inline_mode = MLX5_INLINE_MODE_IP;
+}
+
+static void mlx5e_trust_update_sq_inline_mode(struct mlx5e_priv *priv)
+{
+       struct mlx5e_channels new_channels = {};
+
+       mutex_lock(&priv->state_lock);
+
+       if (!test_bit(MLX5E_STATE_OPENED, &priv->state))
+               goto out;
+
+       new_channels.params = priv->channels.params;
+       mlx5e_trust_update_tx_min_inline_mode(priv, &new_channels.params);
+
+       /* Skip if tx_min_inline is the same */
+       if (new_channels.params.tx_min_inline_mode ==
+           priv->channels.params.tx_min_inline_mode)
+               goto out;
+
+       if (mlx5e_open_channels(priv, &new_channels))
+               goto out;
+       mlx5e_switch_priv_channels(priv, &new_channels, NULL);
+
+out:
+       mutex_unlock(&priv->state_lock);
+}
+
 static int mlx5e_set_trust_state(struct mlx5e_priv *priv, u8 trust_state)
 {
        int err;
@@ -968,6 +1002,7 @@ static int mlx5e_set_trust_state(struct mlx5e_priv *priv, u8 trust_state)
        if (err)
                return err;
        priv->dcbx_dp.trust_state = trust_state;
+       mlx5e_trust_update_sq_inline_mode(priv);
 
        return err;
 }
@@ -996,6 +1031,8 @@ static int mlx5e_trust_initialize(struct mlx5e_priv *priv)
        if (err)
                return err;
 
+       mlx5e_trust_update_tx_min_inline_mode(priv, &priv->channels.params);
+
        err = mlx5_query_dscp2prio(priv->mdev, priv->dcbx_dp.dscp2prio);
        if (err)
                return err;
index 8633476fb53624432a77723b7e5cc24827e4ca30..a97ee38143aa96d73b2038190b8dcf24d14e7ae3 100644 (file)
@@ -4071,10 +4071,7 @@ void mlx5e_build_nic_params(struct mlx5_core_dev *mdev,
 
        /* TX inline */
        params->tx_max_inline = mlx5e_get_max_inline_cap(mdev);
-       mlx5_query_min_inline(mdev, &params->tx_min_inline_mode);
-       if (params->tx_min_inline_mode == MLX5_INLINE_MODE_NONE &&
-           !MLX5_CAP_ETH(mdev, wqe_vlan_insert))
-               params->tx_min_inline_mode = MLX5_INLINE_MODE_L2;
+       params->tx_min_inline_mode = mlx5e_params_calculate_tx_min_inline(mdev);
 
        /* RSS */
        params->rss_hfunc = ETH_RSS_HASH_XOR;
index a7c208a1ad83fd63f7a6661f464eacb2eb94e580..de651de35c9b380eddf49ca46f687041f9d0fd74 100644 (file)
@@ -32,6 +32,7 @@
 
 #include <linux/tcp.h>
 #include <linux/if_vlan.h>
+#include <net/dsfield.h>
 #include "en.h"
 #include "ipoib/ipoib.h"
 #include "en_accel/ipsec_rxtx.h"
@@ -86,6 +87,20 @@ static void mlx5e_dma_unmap_wqe_err(struct mlx5e_txqsq *sq, u8 num_dma)
        }
 }
 
+#ifdef CONFIG_MLX5_CORE_EN_DCB
+static inline int mlx5e_get_dscp_up(struct mlx5e_priv *priv, struct sk_buff *skb)
+{
+       int dscp_cp = 0;
+
+       if (skb->protocol == htons(ETH_P_IP))
+               dscp_cp = ipv4_get_dsfield(ip_hdr(skb)) >> 2;
+       else if (skb->protocol == htons(ETH_P_IPV6))
+               dscp_cp = ipv6_get_dsfield(ipv6_hdr(skb)) >> 2;
+
+       return priv->dcbx_dp.dscp2prio[dscp_cp];
+}
+#endif
+
 u16 mlx5e_select_queue(struct net_device *dev, struct sk_buff *skb,
                       void *accel_priv, select_queue_fallback_t fallback)
 {
@@ -97,8 +112,13 @@ u16 mlx5e_select_queue(struct net_device *dev, struct sk_buff *skb,
        if (!netdev_get_num_tc(dev))
                return channel_ix;
 
-       if (skb_vlan_tag_present(skb))
-               up = skb->vlan_tci >> VLAN_PRIO_SHIFT;
+#ifdef CONFIG_MLX5_CORE_EN_DCB
+       if (priv->dcbx_dp.trust_state == MLX5_QPTS_TRUST_DSCP)
+               up = mlx5e_get_dscp_up(priv, skb);
+       else
+#endif
+               if (skb_vlan_tag_present(skb))
+                       up = skb->vlan_tci >> VLAN_PRIO_SHIFT;
 
        /* channel_ix can be larger than num_channels since
         * dev->num_real_tx_queues = num_channels * num_tc