Skip to contentSkip to conversation

virtio: patches

PATCH Applied Stephen Hemminger 3 participants 12 messages Jun 11, 2015 – Jun 12, 2015 Network drivers

lore
Share & tools
lore
#0 lore raw

v3 cover virtio: patches

From: Stephen Hemminger <[email protected]>

This is update to earlier virtio patches, the only change is to handle the rename to drivers/net

Stephen Hemminger (5):
virtio: remove blank lines
virtio: don't enable/disable rx modes unless supported
virtio: don't set mac table unless negotiated
virtio: clarify feature bit handling
virtio: fix ring size negotiation

 drivers/net/virtio/virtio_ethdev.c | 70 +++++++++++++++------------
 drivers/net/virtio/virtio_ethdev.h | 27 ++++-------
 drivers/net/virtio/virtio_pci.h    | 96 +++++++++++++++++++-------------------
 drivers/net/virtio/virtqueue.h     |  8 +---
 4 files changed, 100 insertions(+), 101 deletions(-)
Signature · 1 line
2.1.4
#1 lore raw

PATCH v3 1/5 virtio: remove blank lines

From: Stephen Hemminger <[email protected]>

Putting blank line between function and following conditional just wastes screen space, and makes code less obvious.

---
 drivers/net/virtio/virtio_ethdev.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/net/virtio/virtio_ethdev.c +0 -6
index f74e413..77f18a0 100644
@@ -228,7 +228,6 @@ virtio_set_multiple_queues(struct rte_eth_dev *dev, uint16_t nb_queues)
 	dlen[0] = sizeof(uint16_t);
 
 	ret = virtio_send_command(hw->cvq, &ctrl, dlen, 1);
-
 	if (ret) {
 		PMD_INIT_LOG(ERR, "Multiqueue configured but send command "
 			  "failed, this is too late now...");
@@ -394,7 +393,6 @@ virtio_dev_cq_queue_setup(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx,
 	PMD_INIT_FUNC_TRACE();
 	ret = virtio_dev_queue_setup(dev, VTNET_CQ, VTNET_SQ_CQ_QUEUE_IDX,
 			vtpci_queue_idx, nb_desc, socket_id, &vq);
-
 	if (ret < 0) {
 		PMD_INIT_LOG(ERR, "control vq initialization failed");
 		return ret;
@@ -434,7 +432,6 @@ virtio_dev_promiscuous_enable(struct rte_eth_dev *dev)
 	dlen[0] = 1;
 
 	ret = virtio_send_command(hw->cvq, &ctrl, dlen, 1);
-
 	if (ret)
 		PMD_INIT_LOG(ERR, "Failed to enable promisc");
 }
@@ -453,7 +450,6 @@ virtio_dev_promiscuous_disable(struct rte_eth_dev *dev)
 	dlen[0] = 1;
 
 	ret = virtio_send_command(hw->cvq, &ctrl, dlen, 1);
-
 	if (ret)
 		PMD_INIT_LOG(ERR, "Failed to disable promisc");
 }
@@ -472,7 +468,6 @@ virtio_dev_allmulticast_enable(struct rte_eth_dev *dev)
 	dlen[0] = 1;
 
 	ret = virtio_send_command(hw->cvq, &ctrl, dlen, 1);
-
 	if (ret)
 		PMD_INIT_LOG(ERR, "Failed to enable allmulticast");
 }
@@ -491,7 +486,6 @@ virtio_dev_allmulticast_disable(struct rte_eth_dev *dev)
 	dlen[0] = 1;
 
 	ret = virtio_send_command(hw->cvq, &ctrl, dlen, 1);
-
 	if (ret)
 		PMD_INIT_LOG(ERR, "Failed to disable allmulticast");
 }
Signature · 1 line
2.1.4
#3 lore raw

PATCH v3 2/5 virtio: don't enable/disable rx modes unless supported

In reply to Stephen Hemminger

From: Stephen Hemminger <[email protected]>

If negotiation with host says that controlling Rx mode is not supported, then don't try.

---
 drivers/net/virtio/virtio_ethdev.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/net/virtio/virtio_ethdev.c +20 -0
index 77f18a0..3476ad3 100644
@@ -426,6 +426,11 @@ virtio_dev_promiscuous_enable(struct rte_eth_dev *dev)
 	int dlen[1];
 	int ret;
 
+	if (!vtpci_with_feature(hw, VIRTIO_NET_F_CTRL_RX)) {
+		PMD_INIT_LOG(INFO, "host does not support rx control\n");
+		return;
+	}
+
 	ctrl.hdr.class = VIRTIO_NET_CTRL_RX;
 	ctrl.hdr.cmd = VIRTIO_NET_CTRL_RX_PROMISC;
 	ctrl.data[0] = 1;
@@ -444,6 +449,11 @@ virtio_dev_promiscuous_disable(struct rte_eth_dev *dev)
 	int dlen[1];
 	int ret;
 
+	if (!vtpci_with_feature(hw, VIRTIO_NET_F_CTRL_RX)) {
+		PMD_INIT_LOG(INFO, "host does not support rx control\n");
+		return;
+	}
+
 	ctrl.hdr.class = VIRTIO_NET_CTRL_RX;
 	ctrl.hdr.cmd = VIRTIO_NET_CTRL_RX_PROMISC;
 	ctrl.data[0] = 0;
@@ -462,6 +472,11 @@ virtio_dev_allmulticast_enable(struct rte_eth_dev *dev)
 	int dlen[1];
 	int ret;
 
+	if (!vtpci_with_feature(hw, VIRTIO_NET_F_CTRL_RX)) {
+		PMD_INIT_LOG(INFO, "host does not support rx control\n");
+		return;
+	}
+
 	ctrl.hdr.class = VIRTIO_NET_CTRL_RX;
 	ctrl.hdr.cmd = VIRTIO_NET_CTRL_RX_ALLMULTI;
 	ctrl.data[0] = 1;
@@ -480,6 +495,11 @@ virtio_dev_allmulticast_disable(struct rte_eth_dev *dev)
 	int dlen[1];
 	int ret;
 
+	if (!vtpci_with_feature(hw, VIRTIO_NET_F_CTRL_RX)) {
+		PMD_INIT_LOG(INFO, "host does not support rx control\n");
+		return;
+	}
+
 	ctrl.hdr.class = VIRTIO_NET_CTRL_RX;
 	ctrl.hdr.cmd = VIRTIO_NET_CTRL_RX_ALLMULTI;
 	ctrl.data[0] = 0;
Signature · 1 line
2.1.4
#5 lore raw

PATCH v3 3/5 virtio: don't set mac table unless negotiated

In reply to Stephen Hemminger

From: Stephen Hemminger <[email protected]>

Don't attempt to set the MAC address table unless the host allows it in feature negotiation. Also, don't return a value from mac_table_set since all callers ignore the return value.

---
 drivers/net/virtio/virtio_ethdev.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/net/virtio/virtio_ethdev.c +6 -3
index 3476ad3..ad49fc1 100644
@@ -668,7 +668,7 @@ virtio_get_hwaddr(struct virtio_hw *hw)
 	}
 }
 
-static int
+static void
 virtio_mac_table_set(struct virtio_hw *hw,
 		     const struct virtio_net_ctrl_mac *uc,
 		     const struct virtio_net_ctrl_mac *mc)
@@ -676,6 +676,11 @@ virtio_mac_table_set(struct virtio_hw *hw,
 	struct virtio_pmd_ctrl ctrl;
 	int err, len[2];
 
+	if (!vtpci_with_feature(hw, VIRTIO_NET_F_CTRL_MAC_ADDR)) {
+		PMD_DRV_LOG(INFO, "host does not support mac table\n");
+		return;
+	}
+
 	ctrl.hdr.class = VIRTIO_NET_CTRL_MAC;
 	ctrl.hdr.cmd = VIRTIO_NET_CTRL_MAC_TABLE_SET;
 
@@ -688,8 +693,6 @@ virtio_mac_table_set(struct virtio_hw *hw,
 	err = virtio_send_command(hw->cvq, &ctrl, len, 2);
 	if (err != 0)
 		PMD_DRV_LOG(NOTICE, "mac table set failed: %d", err);
-
-	return err;
 }
 
 static void
Signature · 1 line
2.1.4
#7 lore raw

PATCH v3 4/5 virtio: clarify feature bit handling

In reply to Stephen Hemminger

From: Stephen Hemminger <[email protected]>

Change the features from bit mask to bit number. This allows the DPDK driver to use the definitions from Linux (yes the header files already use a license compatiable with DPDK). This makes DPDK driver handle future feature bit changes.

Get rid of double negative code in the feature bit intialization. Instead just have a new define with the list of feature bits implemented.

---
 drivers/net/virtio/virtio_ethdev.c | 17 +------
 drivers/net/virtio/virtio_ethdev.h | 27 ++++-------
 drivers/net/virtio/virtio_pci.h    | 96 +++++++++++++++++++-------------------
 drivers/net/virtio/virtqueue.h     |  8 +---
 4 files changed, 61 insertions(+), 87 deletions(-)
drivers/net/virtio/virtio_ethdev.c +2 -15
index ad49fc1..2afa371 100644
@@ -799,23 +799,10 @@ virtio_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
 static void
 virtio_negotiate_features(struct virtio_hw *hw)
 {
-	uint32_t host_features, mask;
-
-	/* checksum offload not implemented */
-	mask = VIRTIO_NET_F_CSUM | VIRTIO_NET_F_GUEST_CSUM;
-
-	/* TSO and LRO are only available when their corresponding
-	 * checksum offload feature is also negotiated.
-	 */
-	mask |= VIRTIO_NET_F_HOST_TSO4 | VIRTIO_NET_F_HOST_TSO6 | VIRTIO_NET_F_HOST_ECN;
-	mask |= VIRTIO_NET_F_GUEST_TSO4 | VIRTIO_NET_F_GUEST_TSO6 | VIRTIO_NET_F_GUEST_ECN;
-	mask |= VTNET_LRO_FEATURES;
-
-	/* not negotiating INDIRECT descriptor table support */
-	mask |= VIRTIO_RING_F_INDIRECT_DESC;
+	uint32_t host_features;
 
 	/* Prepare guest_features: feature that driver wants to support */
-	hw->guest_features = VTNET_FEATURES & ~mask;
+	hw->guest_features = VIRTIO_PMD_GUEST_FEATURES;
 	PMD_INIT_LOG(DEBUG, "guest_features before negotiate = %x",
 		hw->guest_features);
 
drivers/net/virtio/virtio_ethdev.h +9 -18
index e6d4533..df2cb7d 100644
@@ -56,24 +56,15 @@
 #define VIRTIO_MAX_RX_PKTLEN  9728
 
 /* Features desired/implemented by this driver. */
-#define VTNET_FEATURES \
-	(VIRTIO_NET_F_MAC       | \
-	VIRTIO_NET_F_STATUS     | \
-	VIRTIO_NET_F_MQ         | \
-	VIRTIO_NET_F_CTRL_MAC_ADDR | \
-	VIRTIO_NET_F_CTRL_VQ    | \
-	VIRTIO_NET_F_CTRL_RX    | \
-	VIRTIO_NET_F_CTRL_VLAN  | \
-	VIRTIO_NET_F_CSUM       | \
-	VIRTIO_NET_F_HOST_TSO4  | \
-	VIRTIO_NET_F_HOST_TSO6  | \
-	VIRTIO_NET_F_HOST_ECN   | \
-	VIRTIO_NET_F_GUEST_CSUM | \
-	VIRTIO_NET_F_GUEST_TSO4 | \
-	VIRTIO_NET_F_GUEST_TSO6 | \
-	VIRTIO_NET_F_GUEST_ECN  | \
-	VIRTIO_NET_F_MRG_RXBUF  | \
-	VIRTIO_RING_F_INDIRECT_DESC)
+#define VIRTIO_PMD_GUEST_FEATURES		\
+	(1u << VIRTIO_NET_F_MAC		  |	\
+	 1u << VIRTIO_NET_F_STATUS	  |	\
+	 1u << VIRTIO_NET_F_MQ		  |	\
+	 1u << VIRTIO_NET_F_CTRL_MAC_ADDR |	\
+	 1u << VIRTIO_NET_F_CTRL_VQ	  |	\
+	 1u << VIRTIO_NET_F_CTRL_RX	  |	\
+	 1u << VIRTIO_NET_F_CTRL_VLAN	  |	\
+	 1u << VIRTIO_NET_F_MRG_RXBUF)
 
 /*
  * CQ function prototype
drivers/net/virtio/virtio_pci.h +49 -47

117 lines not on this page · raw message

drivers/net/virtio/virtqueue.h +1 -7
index 9d6079e..7789411 100644
@@ -202,18 +202,12 @@ struct virtqueue {
 };
 
 /* If multiqueue is provided by host, then we suppport it. */
-#ifndef VIRTIO_NET_F_MQ
-/* Device supports Receive Flow Steering */
-#define VIRTIO_NET_F_MQ 0x400000
 #define VIRTIO_NET_CTRL_MQ   4
 #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET        0
 #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN        1
 #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX        0x8000
-#endif
-#ifndef VIRTIO_NET_F_CTRL_MAC_ADDR
-#define VIRTIO_NET_F_CTRL_MAC_ADDR 0x800000
+
 #define VIRTIO_NET_CTRL_MAC_ADDR_SET         1
-#endif
 
 /**
  * This is the first element of the scatter-gather list.  If you don't
Signature · 1 line
2.1.4
#9 lore raw

PATCH v3 5/5 virtio: fix ring size negotiation

In reply to Stephen Hemminger

From: Stephen Hemminger <[email protected]>

Negotate the virtio ring size. The host may allow for very large rings but application may only want a smaller ring. Conversely, if the number of descriptors requested exceeds the virtio host queue size, then just silently use the smaller host size.

This fixes issues with virtio in non-QEMU envirionments. For example Google Compute Engine allows up to 16K elements in ring.

---
 drivers/net/virtio/virtio_ethdev.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
drivers/net/virtio/virtio_ethdev.c +13 -5
index 2afa371..befd0bc 100644
@@ -267,13 +267,21 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,
 	if (vq_size == 0) {
 		PMD_INIT_LOG(ERR, "%s: virtqueue does not exist", __func__);
 		return -EINVAL;
-	} else if (!rte_is_power_of_2(vq_size)) {
+	}
+
+	if (!rte_is_power_of_2(vq_size)) {
 		PMD_INIT_LOG(ERR, "%s: virtqueue size is not powerof 2", __func__);
 		return -EINVAL;
-	} else if (nb_desc != vq_size) {
-		PMD_INIT_LOG(ERR, "Warning: nb_desc(%d) is not equal to vq size (%d), fall to vq size",
-			nb_desc, vq_size);
-		nb_desc = vq_size;
+	}
+
+	if (nb_desc < vq_size) {
+		if (!rte_is_power_of_2(nb_desc)) {
+			PMD_INIT_LOG(ERR,
+				     "nb_desc(%u) size is not powerof 2",
+				     nb_desc);
+			return -EINVAL;
+		}
+		vq_size = nb_desc;
 	}
 
 	if (queue_type == VTNET_RQ) {
Signature · 1 line
2.1.4
Acked-by on v3 1/5
#2 lore raw

Re: [PATCH 1/5] virtio: remove blank lines

In reply to Stephen Hemminger
Quoted 9 lines

-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Thursday, June 11, 2015 11:53 PM
To: Ouyang, Changchun
Cc: [email protected]; Stephen Hemminger; Stephen Hemminger
Subject: [PATCH 1/5] virtio: remove blank lines

Quoted 6 lines

From: Stephen Hemminger <[email protected]>

Putting blank line between function and following conditional just wastes screen space, and makes code less obvious.

Acked-by on v3 2/5
#4 lore raw

Re: [PATCH 2/5] virtio: don't enable/disable rx modes unless supported

In reply to Stephen Hemminger
Quoted 9 lines

-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Thursday, June 11, 2015 11:53 PM
To: Ouyang, Changchun
Cc: [email protected]; Stephen Hemminger; Stephen Hemminger
Subject: [PATCH 2/5] virtio: don't enable/disable rx modes unless supported

Quoted 6 lines

From: Stephen Hemminger <[email protected]>

If negotiation with host says that controlling Rx mode is not supported, then don't try.

Acked-by on v3 3/5
#6 lore raw

Re: [PATCH 3/5] virtio: don't set mac table unless negotiated

In reply to Stephen Hemminger
Quoted 9 lines

-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Thursday, June 11, 2015 11:53 PM
To: Ouyang, Changchun
Cc: [email protected]; Stephen Hemminger; Stephen Hemminger
Subject: [PATCH 3/5] virtio: don't set mac table unless negotiated

Quoted 7 lines

From: Stephen Hemminger <[email protected]>

Don't attempt to set the MAC address table unless the host allows it in feature negotiation. Also, don't return a value from mac_table_set since all callers ignore the return value.

Acked-by on v3 4/5
#8 lore raw

Re: [PATCH 4/5] virtio: clarify feature bit handling

In reply to Stephen Hemminger
Quoted 16 lines

-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Thursday, June 11, 2015 11:53 PM
To: Ouyang, Changchun
Cc: [email protected]; Stephen Hemminger; Stephen Hemminger
Subject: [PATCH 4/5] virtio: clarify feature bit handling

From: Stephen Hemminger <[email protected]>

Change the features from bit mask to bit number. This allows the DPDK driver to use the definitions from Linux (yes the header files already use a license compatiable with DPDK). This makes DPDK driver handle future feature bit changes.

Quoted 4 lines

Get rid of double negative code in the feature bit intialization. Instead just have a new define with the list of feature bits implemented.

Acked-by on v3 5/5
#10 lore raw

Re: [PATCH 5/5] virtio: fix ring size negotiation

In reply to Stephen Hemminger
Quoted 16 lines

-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Thursday, June 11, 2015 11:53 PM
To: Ouyang, Changchun
Cc: [email protected]; Stephen Hemminger; Stephen Hemminger
Subject: [PATCH 5/5] virtio: fix ring size negotiation

From: Stephen Hemminger <[email protected]>

Negotate the virtio ring size. The host may allow for very large rings but application may only want a smaller ring.
Conversely, if the number of descriptors requested exceeds the virtio host queue size, then just silently use the smaller host size.

Quoted 4 lines

This fixes issues with virtio in non-QEMU envirionments. For example Google Compute Engine allows up to 16K elements in ring.

#11 lore raw
In reply to Stephen Hemminger

2015-06-11 08:53, Stephen Hemminger:

Quoted 9 lines

This is update to earlier virtio patches, the only change is to handle the rename to drivers/net

Stephen Hemminger (5):
virtio: remove blank lines
virtio: don't enable/disable rx modes unless supported
virtio: don't set mac table unless negotiated
virtio: clarify feature bit handling
virtio: fix ring size negotiation

Applied, thanks