This patch adds a support of VIRTIO_NET_F_SPEED_DUPLEX feature
for virtio driver.

There are two ways to specify speed of the link:
  * 'speed' devarg
  * negotiate speed from qemu via VIRTIO_NET_F_SPEED_DUPLEX
The highest priority is devarg. If devarg is not specified,
driver tries to negotiate it from qemu.

Signed-off-by: Ivan Dyukov <ivan.dyu...@gmail.com>
---
 drivers/net/virtio/virtio_ethdev.c | 14 ++++++++++++++
 drivers/net/virtio/virtio_ethdev.h |  3 ++-
 drivers/net/virtio/virtio_pci.h    | 15 +++++++++++++++
 3 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/drivers/net/virtio/virtio_ethdev.c 
b/drivers/net/virtio/virtio_ethdev.c
index 306241d37..b08270714 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1718,6 +1718,20 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t 
req_features)
                     hw->mac_addr[0], hw->mac_addr[1], hw->mac_addr[2],
                     hw->mac_addr[3], hw->mac_addr[4], hw->mac_addr[5]);
 
+       if (vtpci_with_feature(hw, VIRTIO_NET_F_SPEED_DUPLEX)) {
+               config = &local_config;
+               /* if speed is not specified in devargs */
+               if (hw->speed == ETH_SPEED_NUM_UNKNOWN) {
+                       vtpci_read_dev_config(hw,
+                               offsetof(struct virtio_net_config, speed),
+                               &config->speed, sizeof(config->speed));
+                       hw->speed = config->speed;
+               }
+       }
+
+       PMD_INIT_LOG(DEBUG, "link speed = %u%s",
+               hw->speed, hw->speed == ETH_SPEED_NUM_UNKNOWN ?
+               "(UNKNOWN)" : "");
        if (vtpci_with_feature(hw, VIRTIO_NET_F_CTRL_VQ)) {
                config = &local_config;
 
diff --git a/drivers/net/virtio/virtio_ethdev.h 
b/drivers/net/virtio/virtio_ethdev.h
index cd8947656..febaf17a8 100644
--- a/drivers/net/virtio/virtio_ethdev.h
+++ b/drivers/net/virtio/virtio_ethdev.h
@@ -37,7 +37,8 @@
         1ULL << VIRTIO_F_RING_PACKED     |     \
         1ULL << VIRTIO_F_IOMMU_PLATFORM  |     \
         1ULL << VIRTIO_F_ORDER_PLATFORM  |     \
-        1ULL << VIRTIO_F_NOTIFICATION_DATA)
+        1ULL << VIRTIO_F_NOTIFICATION_DATA | \
+        1ULL << VIRTIO_NET_F_SPEED_DUPLEX)
 
 #define VIRTIO_PMD_SUPPORTED_GUEST_FEATURES    \
        (VIRTIO_PMD_DEFAULT_GUEST_FEATURES |    \
diff --git a/drivers/net/virtio/virtio_pci.h b/drivers/net/virtio/virtio_pci.h
index ed98e11c3..2948760ab 100644
--- a/drivers/net/virtio/virtio_pci.h
+++ b/drivers/net/virtio/virtio_pci.h
@@ -141,6 +141,9 @@ struct virtnet_ctl;
  */
 #define VIRTIO_F_NOTIFICATION_DATA 38
 
+/* Device set linkspeed and duplex */
+#define VIRTIO_NET_F_SPEED_DUPLEX 63
+
 /* The Guest publishes the used index for which it expects an interrupt
  * at the end of the avail ring. Host should ignore the avail->flags field. */
 /* The Host publishes the avail index for which it expects a kick
@@ -306,6 +309,18 @@ struct virtio_net_config {
        uint16_t   status;
        uint16_t   max_virtqueue_pairs;
        uint16_t   mtu;
+       /*
+        * speed, in units of 1Mb. All values 0 to INT_MAX are legal.
+        * Any other value stands for unknown.
+        */
+       uint32_t speed;
+       /*
+        * 0x00 - half duplex
+        * 0x01 - full duplex
+        * Any other value stands for unknown.
+        */
+       uint8_t duplex;
+
 } __attribute__((packed));
 
 /*
-- 
2.17.1

Reply via email to