diff mbox series

[09/10] net/virtio: add ctrl vq helper for split ring

Message ID 20190319064312.13743-10-tiwei.bie@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Maxime Coquelin
Headers show
Series net/virtio: cleanups and fixes for packed/split ring | expand

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Tiwei Bie March 19, 2019, 6:43 a.m. UTC
Add a helper for sending commands in split ring to make the
code consistent with the corresponding code in packed ring.

Signed-off-by: Tiwei Bie <tiwei.bie@intel.com>
---
 drivers/net/virtio/virtio_ethdev.c | 76 +++++++++++++++++-------------
 1 file changed, 43 insertions(+), 33 deletions(-)

Comments

Jens Freimann March 19, 2019, 9:54 a.m. UTC | #1
On Tue, Mar 19, 2019 at 02:43:11PM +0800, Tiwei Bie wrote:
>Add a helper for sending commands in split ring to make the
>code consistent with the corresponding code in packed ring.
>
>Signed-off-by: Tiwei Bie <tiwei.bie@intel.com>
>---
> drivers/net/virtio/virtio_ethdev.c | 76 +++++++++++++++++-------------
> 1 file changed, 43 insertions(+), 33 deletions(-)
>

Reviewed-by: Jens Freimann <jfreimann@redhat.com>
Maxime Coquelin March 19, 2019, 1:54 p.m. UTC | #2
On 3/19/19 7:43 AM, Tiwei Bie wrote:
> Add a helper for sending commands in split ring to make the
> code consistent with the corresponding code in packed ring.
> 
> Signed-off-by: Tiwei Bie <tiwei.bie@intel.com>
> ---
>   drivers/net/virtio/virtio_ethdev.c | 76 +++++++++++++++++-------------
>   1 file changed, 43 insertions(+), 33 deletions(-)
>

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime
diff mbox series

Patch

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 8aa250997..85b223451 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -237,44 +237,18 @@  virtio_send_command_packed(struct virtnet_ctl *cvq,
 	return result;
 }
 
-static int
-virtio_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl,
-		int *dlen, int pkt_num)
+static struct virtio_pmd_ctrl *
+virtio_send_command_split(struct virtnet_ctl *cvq,
+			  struct virtio_pmd_ctrl *ctrl,
+			  int *dlen, int pkt_num)
 {
+	struct virtio_pmd_ctrl *result;
+	struct virtqueue *vq = cvq->vq;
 	uint32_t head, i;
 	int k, sum = 0;
-	virtio_net_ctrl_ack status = ~0;
-	struct virtio_pmd_ctrl *result;
-	struct virtqueue *vq;
 
-	ctrl->status = status;
-
-	if (!cvq || !cvq->vq) {
-		PMD_INIT_LOG(ERR, "Control queue is not supported.");
-		return -1;
-	}
-
-	rte_spinlock_lock(&cvq->lock);
-	vq = cvq->vq;
 	head = vq->vq_desc_head_idx;
 
-	PMD_INIT_LOG(DEBUG, "vq->vq_desc_head_idx = %d, status = %d, "
-		"vq->hw->cvq = %p vq = %p",
-		vq->vq_desc_head_idx, status, vq->hw->cvq, vq);
-
-	if (vq->vq_free_cnt < pkt_num + 2 || pkt_num < 1) {
-		rte_spinlock_unlock(&cvq->lock);
-		return -1;
-	}
-
-	memcpy(cvq->virtio_net_hdr_mz->addr, ctrl,
-		sizeof(struct virtio_pmd_ctrl));
-
-	if (vtpci_packed_queue(vq->hw)) {
-		result = virtio_send_command_packed(cvq, ctrl, dlen, pkt_num);
-		goto out_unlock;
-	}
-
 	/*
 	 * Format is enforced in qemu code:
 	 * One TX packet for header;
@@ -346,8 +320,44 @@  virtio_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl,
 			vq->vq_free_cnt, vq->vq_desc_head_idx);
 
 	result = cvq->virtio_net_hdr_mz->addr;
+	return result;
+}
+
+static int
+virtio_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl,
+		    int *dlen, int pkt_num)
+{
+	virtio_net_ctrl_ack status = ~0;
+	struct virtio_pmd_ctrl *result;
+	struct virtqueue *vq;
+
+	ctrl->status = status;
+
+	if (!cvq || !cvq->vq) {
+		PMD_INIT_LOG(ERR, "Control queue is not supported.");
+		return -1;
+	}
+
+	rte_spinlock_lock(&cvq->lock);
+	vq = cvq->vq;
+
+	PMD_INIT_LOG(DEBUG, "vq->vq_desc_head_idx = %d, status = %d, "
+		"vq->hw->cvq = %p vq = %p",
+		vq->vq_desc_head_idx, status, vq->hw->cvq, vq);
+
+	if (vq->vq_free_cnt < pkt_num + 2 || pkt_num < 1) {
+		rte_spinlock_unlock(&cvq->lock);
+		return -1;
+	}
+
+	memcpy(cvq->virtio_net_hdr_mz->addr, ctrl,
+		sizeof(struct virtio_pmd_ctrl));
+
+	if (vtpci_packed_queue(vq->hw))
+		result = virtio_send_command_packed(cvq, ctrl, dlen, pkt_num);
+	else
+		result = virtio_send_command_split(cvq, ctrl, dlen, pkt_num);
 
-out_unlock:
 	rte_spinlock_unlock(&cvq->lock);
 	return result->status;
 }