net/virtio: set offload flag for jumbo frames
PATCH v4 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.
---v3->v4:
* make use of hw-max_mtu which is calculated during device init. This way we don't have to re-read the mtu from config space again. This is safe because hw->max_mtu is not changed after init.
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 | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/net/virtio/virtio_ethdev.c +10 -0
@@ -2351,6 +2351,16 @@ 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 )) { +uint32_t ether_hdr_len =ETHER_HDR_LEN +VLAN_TAG_LEN + + hw->vtnet_hdr_size; +if (dev->data->dev_conf.rxmode.max_rx_pkt_len <= + hw->max_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
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_MTUis 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_MTUis not set. We can set the offload flag.Fixes a4996bd89c42 ("ethdev: new Rx/Tx offloads API")Signed-off-by Jens Freimann <[email protected]>---
v3->v4:
* make use of hw-max_mtu which is calculated during device init. This way we don't have to re-read the mtu from config space again. This is safe becausehw->max_mtuis not changed after init.
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 | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/net/virtio/virtio_ethdev.c +0
-0@@ -2351,6 +2351,16 @@ 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 ;
drivers/net/virtio/virtio_ethdev.c virtio_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) · line 2363
Quoted 10 lines
drivers/net/virtio/virtio_ethdev.c +10
-0+if (host_features & (1ULL <<VIRTIO_NET_F_MTU )) { +uint32_t ether_hdr_len =ETHER_HDR_LEN +VLAN_TAG_LEN + + hw->vtnet_hdr_size; +if (dev->data->dev_conf.rxmode.max_rx_pkt_len <= + hw->max_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 ; + } +
As I wrote for v3, hw->max_mtu already calculated taking VIRTIO_NET_F_MTU into account. If VIRTIO_NET_F_MTU is not set, hw->max_mtu is equal to "VIRTIO_MAX_RX_PKTLEN - ETHER_HDR_LEN - VLAN_TAG_LEN - hw->vtnet_hdr_size". i.e. "hw->max_mtu + ether_hdr_len" equal to VIRTIO_MAX_RX_PKTLEN which is larger or equal to rxmode.max_rx_pkt_len.
So, there is no need to check for VIRTIO_NET_F_MTU here. You may just perform same check for both cases.
This doesn't give any performance or so, but will simplify the code.
Quoted 4 lines
drivers/net/virtio/virtio_ethdev.c +0
-0dev_info->tx_offload_capa =DEV_TX_OFFLOAD_MULTI_SEGS |DEV_TX_OFFLOAD_VLAN_INSERT ;if (host_features & (1ULL <<VIRTIO_NET_F_CSUM )) {
Quoted 12 lines · Ilya Maximets
drivers/net/virtio/virtio_ethdev.c virtio_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) · line 2363
Quoted 10 lines · Jens Freimann
drivers/net/virtio/virtio_ethdev.c +10
-0+if (host_features & (1ULL <<VIRTIO_NET_F_MTU )) { +uint32_t ether_hdr_len =ETHER_HDR_LEN +VLAN_TAG_LEN + + hw->vtnet_hdr_size; +if (dev->data->dev_conf.rxmode.max_rx_pkt_len <= + hw->max_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 ; + } +
Quoted 7 lines
As I wrote for v3,
hw->max_mtualready calculated takingVIRTIO_NET_F_MTUinto account. IfVIRTIO_NET_F_MTUis not set,hw->max_mtuis equal to "VIRTIO_MAX_RX_PKTLEN-ETHER_HDR_LEN-VLAN_TAG_LEN-hw->vtnet_hdr_size". i.e. "hw->max_mtu+ether_hdr_len" equal toVIRTIO_MAX_RX_PKTLENwhich is larger or equal to rxmode.max_rx_pkt_len.
So, there is no need to check forVIRTIO_NET_F_MTUhere. You may just perform same check for both cases.
I should read more carefully :). I think I get what you mean now. hw->max_mtu already includes ether_hdr_len, so it doesn't need re-calculation here. And in case of VIRTIO_NET_F_MTU the mtu is checked during feature negotiation.
So it basically boils down to
if (dev->data->dev_conf.rxmode.max_rx_pkt_len <= w->max_mtu)
dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_JUMBO_FRAME;Quoted 1 line
This doesn't give any performance or so, but will simplify the code.
Thanks for the review!
regards,
Jens
Quoted 21 lines · Jens Freimann
Quoted 12 lines · Ilya Maximets
Quoted 10 lines · Jens Freimann
+ if (
host_features& (1ULL <<VIRTIO_NET_F_MTU)) {
+uint32_tether_hdr_len=ETHER_HDR_LEN+VLAN_TAG_LEN+ +hw->vtnet_hdr_size;
+ if (dev->data->dev_conf.rxmode.max_rx_pkt_len<= +hw->max_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; + }
+Quoted 7 lines
As I wrote for v3,
hw->max_mtualready calculated takingVIRTIO_NET_F_MTUinto account. IfVIRTIO_NET_F_MTUis not set,hw->max_mtuis equal to "VIRTIO_MAX_RX_PKTLEN-ETHER_HDR_LEN-VLAN_TAG_LEN-hw->vtnet_hdr_size". i.e. "hw->max_mtu+ether_hdr_len" equal toVIRTIO_MAX_RX_PKTLENwhich is larger or equal to rxmode.max_rx_pkt_len.
So, there is no need to check forVIRTIO_NET_F_MTUhere. You may just perform same check for both cases.
Quoted 7 lines
I should read more carefully :). I think I get what you mean now.
hw->max_mtualready includesether_hdr_len, so it doesn't need
re-calculation here. And in case ofVIRTIO_NET_F_MTUthe mtu is
checked during feature negotiation.
So it basically boils down to if (dev->data->dev_conf.rxmode.max_rx_pkt_len<=w->max_mtu)dev_info->rx_offload_capa|=DEV_RX_OFFLOAD_JUMBO_FRAME;
'hw->max_mtu' does not include 'ether_hdr_len'. But yes, VIRTIO_NET_F_MTU already checked during negotiation. So, it will be:
if (dev->data->dev_conf.rxmode.max_rx_pkt_len <= hw->max_mtu + ether_hdr_len)
dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_JUMBO_FRAME;
Quoted 7 lines
Quoted 1 line
This doesn't give any performance or so, but will simplify the code.
Thanks for the review!
regards,
Jens