Skip to contentSkip to conversation

net/virtio: set offload flag for jumbo frames

PATCH Superseded Jens Freimann 3 participants 4 messages Jan 31, 2019 Network drivers

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 net/virtio: set offload flag for jumbo frames

Port configuration fails because offload flags don't match the expected value when max-pkt-len is set to a value that should enable receive port offloading but doesn't.

There are two cases to consider:

1. VIRTIO_NET_F_MTU is set. Then we need to check if the requested max-pkt-len fits into the MTU plus header. If yes we set the offload flag.
2. VIRTIO_NET_F_MTU is not set. We can set the offload flag.

Fixes a4996bd89c42 ("ethdev: new Rx/Tx offloads API")

---
v2->v3:
* remove unnecessary brackets (Maxime)
* fix commit message (David)

v1->v2:
* include virtnet hdr, ethernet header, vlan tag when comparing against max-rx-pkt-len (Maxime)

 drivers/net/virtio/virtio_ethdev.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/net/virtio/virtio_ethdev.c +14 -0
index 7c4c1df00..f39d4e630 100644
@@ -2351,6 +2351,20 @@ virtio_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	if ((host_features & tso_mask) == tso_mask)
 		dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_TCP_LRO;
 
+	if (host_features & (1ULL << VIRTIO_NET_F_MTU)) {
+		struct virtio_net_config config;
+		uint32_t ether_hdr_len = ETHER_HDR_LEN + VLAN_TAG_LEN +
+			hw->vtnet_hdr_size;
+		vtpci_read_dev_config(hw,
+				offsetof(struct virtio_net_config, mtu),
+				&config.mtu, sizeof(config.mtu));
+		if (dev->data->dev_conf.rxmode.max_rx_pkt_len <=
+				config.mtu + ether_hdr_len)
+			dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_JUMBO_FRAME;
+	} else {
+		dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_JUMBO_FRAME;
+	}
+
 	dev_info->tx_offload_capa = DEV_TX_OFFLOAD_MULTI_SEGS |
 				    DEV_TX_OFFLOAD_VLAN_INSERT;
 	if (host_features & (1ULL << VIRTIO_NET_F_CSUM)) {
Signature · 1 line
2.17.2
Reviewed-by on v3 1/1
#1 lore raw
Quoted 20 lines · Jens Freimann

Port configuration fails because offload flags don't match the expected value when max-pkt-len is set to a value that should enable receive port offloading but doesn't.

There are two cases to consider:

1. VIRTIO_NET_F_MTU is set. Then we need to check if the requested max-pkt-len fits into the MTU plus header. If yes we set the offload flag.
2. VIRTIO_NET_F_MTU is not set. We can set the offload flag.

Fixes a4996bd89c42 ("ethdev: new Rx/Tx offloads API")

---
v2->v3:
* remove unnecessary brackets (Maxime)
* fix commit message (David)

Quoted 6 lines

v1->v2:
* include virtnet hdr, ethernet header, vlan tag when comparing against max-rx-pkt-len (Maxime)

  drivers/net/virtio/virtio_ethdev.c | 14 ++++++++++++++
  1 file changed, 14 insertions(+)

Thanks,
Maxime

Quoted 27 lines
drivers/net/virtio/virtio_ethdev.c +14 -0
index 7c4c1df00..f39d4e630 100644
@@ -2351,6 +2351,20 @@ virtio_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
  	if ((host_features & tso_mask) == tso_mask)
  		dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_TCP_LRO;
 
+	if (host_features & (1ULL << VIRTIO_NET_F_MTU)) {
+		struct virtio_net_config config;
+		uint32_t ether_hdr_len = ETHER_HDR_LEN + VLAN_TAG_LEN +
+			hw->vtnet_hdr_size;
+		vtpci_read_dev_config(hw,
+				offsetof(struct virtio_net_config, mtu),
+				&config.mtu, sizeof(config.mtu));
+		if (dev->data->dev_conf.rxmode.max_rx_pkt_len <=
+				config.mtu + ether_hdr_len)
+			dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_JUMBO_FRAME;
+	} else {
+		dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_JUMBO_FRAME;
+	}
+
  	dev_info->tx_offload_capa = DEV_TX_OFFLOAD_MULTI_SEGS |
  				    DEV_TX_OFFLOAD_VLAN_INSERT;
  	if (host_features & (1ULL << VIRTIO_NET_F_CSUM)) {
#2 lore raw
In reply to Jens Freimann
Quoted 40 lines · Jens Freimann

Port configuration fails because offload flags don't match the expected value when max-pkt-len is set to a value that should enable receive port offloading but doesn't.

There are two cases to consider:

1. VIRTIO_NET_F_MTU is set. Then we need to check if the requested max-pkt-len fits into the MTU plus header. If yes we set the offload flag.
2. VIRTIO_NET_F_MTU is not set. We can set the offload flag.

Fixes a4996bd89c42 ("ethdev: new Rx/Tx offloads API")

---
v2->v3:
* remove unnecessary brackets (Maxime)
* fix commit message (David)

v1->v2:
* include virtnet hdr, ethernet header, vlan tag when comparing against max-rx-pkt-len (Maxime)

 drivers/net/virtio/virtio_ethdev.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/net/virtio/virtio_ethdev.c +4 -0
index 7c4c1df00..f39d4e630 100644
@@ -2351,6 +2351,20 @@ virtio_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	if ((host_features & tso_mask) == tso_mask)
 		dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_TCP_LRO;
 
+	if (host_features & (1ULL << VIRTIO_NET_F_MTU)) {
+		struct virtio_net_config config;
+		uint32_t ether_hdr_len = ETHER_HDR_LEN + VLAN_TAG_LEN +
+			hw->vtnet_hdr_size;

drivers/net/virtio/virtio_ethdev.c virtio_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) · line 2367

Quoted 10 lines
drivers/net/virtio/virtio_ethdev.c +10 -0
+		vtpci_read_dev_config(hw,
+				offsetof(struct virtio_net_config, mtu),
+				&config.mtu, sizeof(config.mtu));
+		if (dev->data->dev_conf.rxmode.max_rx_pkt_len <=
+				config.mtu + ether_hdr_len)
+			dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_JUMBO_FRAME;
+	} else {
+		dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_JUMBO_FRAME;
+	}
+

Why we can't just use 'hw->max_mtu' here for checking instead of reading 'config.mtu' ?
Also, It's already calculated with regards to VIRTIO_NET_F_MTU.

Quoted 4 lines
drivers/net/virtio/virtio_ethdev.c +0 -0
 	dev_info->tx_offload_capa = DEV_TX_OFFLOAD_MULTI_SEGS |
 				    DEV_TX_OFFLOAD_VLAN_INSERT;
 	if (host_features & (1ULL << VIRTIO_NET_F_CSUM)) {
#3 lore raw
Quoted 47 lines · Ilya Maximets
Quoted 46 lines · Jens Freimann

Port configuration fails because offload flags don't match the expected value when max-pkt-len is set to a value that should enable receive port offloading but doesn't.

There are two cases to consider:

1. VIRTIO_NET_F_MTU is set. Then we need to check if the requested max-pkt-len fits into the MTU plus header. If yes we set the offload flag.
2. VIRTIO_NET_F_MTU is not set. We can set the offload flag.

Fixes a4996bd89c42 ("ethdev: new Rx/Tx offloads API")

---
v2->v3:
* remove unnecessary brackets (Maxime)
* fix commit message (David)

v1->v2:
* include virtnet hdr, ethernet header, vlan tag when comparing against max-rx-pkt-len (Maxime)

 drivers/net/virtio/virtio_ethdev.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/net/virtio/virtio_ethdev.c +10 -0
index 7c4c1df00..f39d4e630 100644
@@ -2351,6 +2351,20 @@ virtio_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	if ((host_features & tso_mask) == tso_mask)
 		dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_TCP_LRO;
 
+	if (host_features & (1ULL << VIRTIO_NET_F_MTU)) {
+		struct virtio_net_config config;
+		uint32_t ether_hdr_len = ETHER_HDR_LEN + VLAN_TAG_LEN +
+			hw->vtnet_hdr_size;
+		vtpci_read_dev_config(hw,
+				offsetof(struct virtio_net_config, mtu),
+				&config.mtu, sizeof(config.mtu));
+		if (dev->data->dev_conf.rxmode.max_rx_pkt_len <=
+				config.mtu + ether_hdr_len)
+			dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_JUMBO_FRAME;
Quoted 8 lines

drivers/net/virtio/virtio_ethdev.c virtio_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) · line 2367

Quoted 4 lines
drivers/net/virtio/virtio_ethdev.c +4 -0
+	} else {
+		dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_JUMBO_FRAME;
+	}
+

Why we can't just use 'hw->max_mtu' here for checking instead of reading 'config.mtu' ?
Also, It's already calculated with regards to VIRTIO_NET_F_MTU.

Can't mtu have changed after device init? If not then yes, I guess we could use hw->max_mtu.

regards,
Jens