diff mbox series

[1/3] mlx5_vdpa: should exclude header length and fcs from mtu

Message ID 1612614564-4220-1-git-send-email-si-wei.liu@oracle.com
State New
Headers show
Series [1/3] mlx5_vdpa: should exclude header length and fcs from mtu | expand

Commit Message

Si-Wei Liu Feb. 6, 2021, 12:29 p.m. UTC
When feature VIRTIO_NET_F_MTU is negotiated on mlx5_vdpa,
22 extra bytes worth of MTU length is shown in guest.
This is because the mlx5_query_port_max_mtu API returns
the "hardware" MTU value, which does not just contain the
Ethernet payload, but includes extra lengths starting
from the Ethernet header up to the FCS altogether.

Fix the MTU so packets won't get dropped silently.

Signed-off-by: Si-Wei Liu <si-wei.liu@oracle.com>
---
 drivers/vdpa/mlx5/core/mlx5_vdpa.h |  4 ++++
 drivers/vdpa/mlx5/net/mlx5_vnet.c  | 15 ++++++++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

Comments

Jason Wang Feb. 8, 2021, 4:38 a.m. UTC | #1
On 2021/2/6 下午8:29, Si-Wei Liu wrote:
> When feature VIRTIO_NET_F_MTU is negotiated on mlx5_vdpa,

> 22 extra bytes worth of MTU length is shown in guest.

> This is because the mlx5_query_port_max_mtu API returns

> the "hardware" MTU value, which does not just contain the

> Ethernet payload, but includes extra lengths starting

> from the Ethernet header up to the FCS altogether.

>

> Fix the MTU so packets won't get dropped silently.

>

> Signed-off-by: Si-Wei Liu <si-wei.liu@oracle.com>



Acked-by: Jason Wang <jasowang@redhat.com>



> ---

>   drivers/vdpa/mlx5/core/mlx5_vdpa.h |  4 ++++

>   drivers/vdpa/mlx5/net/mlx5_vnet.c  | 15 ++++++++++++++-

>   2 files changed, 18 insertions(+), 1 deletion(-)

>

> diff --git a/drivers/vdpa/mlx5/core/mlx5_vdpa.h b/drivers/vdpa/mlx5/core/mlx5_vdpa.h

> index 08f742f..b6cc53b 100644

> --- a/drivers/vdpa/mlx5/core/mlx5_vdpa.h

> +++ b/drivers/vdpa/mlx5/core/mlx5_vdpa.h

> @@ -4,9 +4,13 @@

>   #ifndef __MLX5_VDPA_H__

>   #define __MLX5_VDPA_H__

>   

> +#include <linux/etherdevice.h>

> +#include <linux/if_vlan.h>

>   #include <linux/vdpa.h>

>   #include <linux/mlx5/driver.h>

>   

> +#define MLX5V_ETH_HARD_MTU (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN)

> +

>   struct mlx5_vdpa_direct_mr {

>   	u64 start;

>   	u64 end;

> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c

> index dc88559..b8416c4 100644

> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c

> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c

> @@ -1907,6 +1907,19 @@ static int mlx5_get_vq_irq(struct vdpa_device *vdv, u16 idx)

>   	.free = mlx5_vdpa_free,

>   };

>   

> +static int query_mtu(struct mlx5_core_dev *mdev, u16 *mtu)

> +{

> +	u16 hw_mtu;

> +	int err;

> +

> +	err = mlx5_query_nic_vport_mtu(mdev, &hw_mtu);

> +	if (err)

> +		return err;

> +

> +	*mtu = hw_mtu - MLX5V_ETH_HARD_MTU;

> +	return 0;

> +}

> +

>   static int alloc_resources(struct mlx5_vdpa_net *ndev)

>   {

>   	struct mlx5_vdpa_net_resources *res = &ndev->res;

> @@ -1992,7 +2005,7 @@ static int mlx5v_probe(struct auxiliary_device *adev,

>   	init_mvqs(ndev);

>   	mutex_init(&ndev->reslock);

>   	config = &ndev->config;

> -	err = mlx5_query_nic_vport_mtu(mdev, &ndev->mtu);

> +	err = query_mtu(mdev, &ndev->mtu);

>   	if (err)

>   		goto err_mtu;

>
Eli Cohen Feb. 8, 2021, 5:35 a.m. UTC | #2
On Sat, Feb 06, 2021 at 04:29:22AM -0800, Si-Wei Liu wrote:
> When feature VIRTIO_NET_F_MTU is negotiated on mlx5_vdpa,

> 22 extra bytes worth of MTU length is shown in guest.

> This is because the mlx5_query_port_max_mtu API returns

> the "hardware" MTU value, which does not just contain the

> Ethernet payload, but includes extra lengths starting

> from the Ethernet header up to the FCS altogether.

> 

> Fix the MTU so packets won't get dropped silently.

> 

> Signed-off-by: Si-Wei Liu <si-wei.liu@oracle.com>


Acked-by: Eli Cohen <elic@nvidia.com>


> ---

>  drivers/vdpa/mlx5/core/mlx5_vdpa.h |  4 ++++

>  drivers/vdpa/mlx5/net/mlx5_vnet.c  | 15 ++++++++++++++-

>  2 files changed, 18 insertions(+), 1 deletion(-)

> 

> diff --git a/drivers/vdpa/mlx5/core/mlx5_vdpa.h b/drivers/vdpa/mlx5/core/mlx5_vdpa.h

> index 08f742f..b6cc53b 100644

> --- a/drivers/vdpa/mlx5/core/mlx5_vdpa.h

> +++ b/drivers/vdpa/mlx5/core/mlx5_vdpa.h

> @@ -4,9 +4,13 @@

>  #ifndef __MLX5_VDPA_H__

>  #define __MLX5_VDPA_H__

>  

> +#include <linux/etherdevice.h>

> +#include <linux/if_vlan.h>

>  #include <linux/vdpa.h>

>  #include <linux/mlx5/driver.h>

>  

> +#define MLX5V_ETH_HARD_MTU (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN)

> +

>  struct mlx5_vdpa_direct_mr {

>  	u64 start;

>  	u64 end;

> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c

> index dc88559..b8416c4 100644

> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c

> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c

> @@ -1907,6 +1907,19 @@ static int mlx5_get_vq_irq(struct vdpa_device *vdv, u16 idx)

>  	.free = mlx5_vdpa_free,

>  };

>  

> +static int query_mtu(struct mlx5_core_dev *mdev, u16 *mtu)

> +{

> +	u16 hw_mtu;

> +	int err;

> +

> +	err = mlx5_query_nic_vport_mtu(mdev, &hw_mtu);

> +	if (err)

> +		return err;

> +

> +	*mtu = hw_mtu - MLX5V_ETH_HARD_MTU;

> +	return 0;

> +}

> +

>  static int alloc_resources(struct mlx5_vdpa_net *ndev)

>  {

>  	struct mlx5_vdpa_net_resources *res = &ndev->res;

> @@ -1992,7 +2005,7 @@ static int mlx5v_probe(struct auxiliary_device *adev,

>  	init_mvqs(ndev);

>  	mutex_init(&ndev->reslock);

>  	config = &ndev->config;

> -	err = mlx5_query_nic_vport_mtu(mdev, &ndev->mtu);

> +	err = query_mtu(mdev, &ndev->mtu);

>  	if (err)

>  		goto err_mtu;

>  

> -- 

> 1.8.3.1

>
diff mbox series

Patch

diff --git a/drivers/vdpa/mlx5/core/mlx5_vdpa.h b/drivers/vdpa/mlx5/core/mlx5_vdpa.h
index 08f742f..b6cc53b 100644
--- a/drivers/vdpa/mlx5/core/mlx5_vdpa.h
+++ b/drivers/vdpa/mlx5/core/mlx5_vdpa.h
@@ -4,9 +4,13 @@ 
 #ifndef __MLX5_VDPA_H__
 #define __MLX5_VDPA_H__
 
+#include <linux/etherdevice.h>
+#include <linux/if_vlan.h>
 #include <linux/vdpa.h>
 #include <linux/mlx5/driver.h>
 
+#define MLX5V_ETH_HARD_MTU (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN)
+
 struct mlx5_vdpa_direct_mr {
 	u64 start;
 	u64 end;
diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
index dc88559..b8416c4 100644
--- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
+++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
@@ -1907,6 +1907,19 @@  static int mlx5_get_vq_irq(struct vdpa_device *vdv, u16 idx)
 	.free = mlx5_vdpa_free,
 };
 
+static int query_mtu(struct mlx5_core_dev *mdev, u16 *mtu)
+{
+	u16 hw_mtu;
+	int err;
+
+	err = mlx5_query_nic_vport_mtu(mdev, &hw_mtu);
+	if (err)
+		return err;
+
+	*mtu = hw_mtu - MLX5V_ETH_HARD_MTU;
+	return 0;
+}
+
 static int alloc_resources(struct mlx5_vdpa_net *ndev)
 {
 	struct mlx5_vdpa_net_resources *res = &ndev->res;
@@ -1992,7 +2005,7 @@  static int mlx5v_probe(struct auxiliary_device *adev,
 	init_mvqs(ndev);
 	mutex_init(&ndev->reslock);
 	config = &ndev->config;
-	err = mlx5_query_nic_vport_mtu(mdev, &ndev->mtu);
+	err = query_mtu(mdev, &ndev->mtu);
 	if (err)
 		goto err_mtu;