net/virtio: improve Tx offload features negotiation
authorMaxime Coquelin <maxime.coquelin@redhat.com>
Mon, 2 Jul 2018 15:25:45 +0000 (17:25 +0200)
committerFerruh Yigit <ferruh.yigit@intel.com>
Wed, 4 Jul 2018 15:03:48 +0000 (17:03 +0200)
This patch improves the Tx offload features selection depending
on whether the application request for offloads.

When the application doesn't request for Tx offload features,
the corresponding features bits aren't negotiated.

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Reviewed-by: Tiwei Bie <tiwei.bie@intel.com>
drivers/net/virtio/virtio_ethdev.c
drivers/net/virtio/virtio_ethdev.h

index 73c4287..1d223d0 100644 (file)
@@ -1806,8 +1806,10 @@ static int
 virtio_dev_configure(struct rte_eth_dev *dev)
 {
        const struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
+       const struct rte_eth_txmode *txmode = &dev->data->dev_conf.txmode;
        struct virtio_hw *hw = dev->data->dev_private;
        uint64_t rx_offloads = rxmode->offloads;
+       uint64_t tx_offloads = txmode->offloads;
        uint64_t req_features;
        int ret;
 
@@ -1829,6 +1831,15 @@ virtio_dev_configure(struct rte_eth_dev *dev)
                        (1ULL << VIRTIO_NET_F_GUEST_TSO4) |
                        (1ULL << VIRTIO_NET_F_GUEST_TSO6);
 
+       if (tx_offloads & (DEV_TX_OFFLOAD_UDP_CKSUM |
+                          DEV_TX_OFFLOAD_TCP_CKSUM))
+               req_features |= (1ULL << VIRTIO_NET_F_CSUM);
+
+       if (tx_offloads & DEV_TX_OFFLOAD_TCP_TSO)
+               req_features |=
+                       (1ULL << VIRTIO_NET_F_HOST_TSO4) |
+                       (1ULL << VIRTIO_NET_F_HOST_TSO6);
+
        /* if request features changed, reinit the device */
        if (req_features != hw->req_guest_features) {
                ret = virtio_init_device(dev, req_features);
@@ -2155,14 +2166,14 @@ virtio_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 
        dev_info->tx_offload_capa = DEV_TX_OFFLOAD_MULTI_SEGS |
                                    DEV_TX_OFFLOAD_VLAN_INSERT;
-       if (hw->guest_features & (1ULL << VIRTIO_NET_F_CSUM)) {
+       if (host_features & (1ULL << VIRTIO_NET_F_CSUM)) {
                dev_info->tx_offload_capa |=
                        DEV_TX_OFFLOAD_UDP_CKSUM |
                        DEV_TX_OFFLOAD_TCP_CKSUM;
        }
        tso_mask = (1ULL << VIRTIO_NET_F_HOST_TSO4) |
                (1ULL << VIRTIO_NET_F_HOST_TSO6);
-       if ((hw->guest_features & tso_mask) == tso_mask)
+       if ((host_features & tso_mask) == tso_mask)
                dev_info->tx_offload_capa |= DEV_TX_OFFLOAD_TCP_TSO;
 }
 
index 350e9ce..f4d09df 100644 (file)
@@ -28,9 +28,6 @@
         1u << VIRTIO_NET_F_CTRL_VQ       |     \
         1u << VIRTIO_NET_F_CTRL_RX       |     \
         1u << VIRTIO_NET_F_CTRL_VLAN     |     \
-        1u << VIRTIO_NET_F_CSUM          |     \
-        1u << VIRTIO_NET_F_HOST_TSO4     |     \
-        1u << VIRTIO_NET_F_HOST_TSO6     |     \
         1u << VIRTIO_NET_F_MRG_RXBUF     |     \
         1u << VIRTIO_NET_F_MTU | \
         1ULL << VIRTIO_NET_F_GUEST_ANNOUNCE |  \