diff mbox series

[net-next,3/5] virtio-net: extract virtqueue coalescig cmd for reuse

Message ID 5b99db97dd4b26636f306f70c8158d9d3297b4a0.1697093455.git.hengqi@linux.alibaba.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series virtio-net: support dynamic coalescing moderation | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit fail Errors and warnings before: 16 this patch: 16
netdev/cc_maintainers success CCed 9 of 9 maintainers
netdev/build_clang fail Errors and warnings before: 21 this patch: 21
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn fail Errors and warnings before: 16 this patch: 16
netdev/checkpatch warning WARNING: line length of 81 exceeds 80 columns WARNING: line length of 90 exceeds 80 columns WARNING: line length of 93 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Heng Qi Oct. 12, 2023, 7:44 a.m. UTC
Extract commands to set virtqueue coalescing parameters for reuse
by ethtool -Q, vq resize and netdim.

Signed-off-by: Heng Qi <hengqi@linux.alibaba.com>
---
 drivers/net/virtio_net.c | 106 +++++++++++++++++++++++----------------
 1 file changed, 64 insertions(+), 42 deletions(-)

Comments

Jason Wang Oct. 25, 2023, 3:03 a.m. UTC | #1
On Thu, Oct 12, 2023 at 3:44 PM Heng Qi <hengqi@linux.alibaba.com> wrote:
>
> Extract commands to set virtqueue coalescing parameters for reuse
> by ethtool -Q, vq resize and netdim.
>
> Signed-off-by: Heng Qi <hengqi@linux.alibaba.com>

Acked-by: Jason Wang <jasowang@redhat.com>

Thanks

> ---
>  drivers/net/virtio_net.c | 106 +++++++++++++++++++++++----------------
>  1 file changed, 64 insertions(+), 42 deletions(-)
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 54b3fb8d0384..caef78bb3963 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -2846,6 +2846,58 @@ static void virtnet_cpu_notif_remove(struct virtnet_info *vi)
>                                             &vi->node_dead);
>  }
>
> +static int virtnet_send_ctrl_coal_vq_cmd(struct virtnet_info *vi,
> +                                        u16 vqn, u32 max_usecs, u32 max_packets)
> +{
> +       struct scatterlist sgs;
> +
> +       vi->ctrl->coal_vq.vqn = cpu_to_le16(vqn);
> +       vi->ctrl->coal_vq.coal.max_usecs = cpu_to_le32(max_usecs);
> +       vi->ctrl->coal_vq.coal.max_packets = cpu_to_le32(max_packets);
> +       sg_init_one(&sgs, &vi->ctrl->coal_vq, sizeof(vi->ctrl->coal_vq));
> +
> +       if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_NOTF_COAL,
> +                                 VIRTIO_NET_CTRL_NOTF_COAL_VQ_SET,
> +                                 &sgs))
> +               return -EINVAL;
> +
> +       return 0;
> +}
> +
> +static int virtnet_send_rx_ctrl_coal_vq_cmd(struct virtnet_info *vi,
> +                                           u16 queue, u32 max_usecs,
> +                                           u32 max_packets)
> +{
> +       int err;
> +
> +       err = virtnet_send_ctrl_coal_vq_cmd(vi, rxq2vq(queue),
> +                                           max_usecs, max_packets);
> +       if (err)
> +               return err;
> +
> +       vi->rq[queue].intr_coal.max_usecs = max_usecs;
> +       vi->rq[queue].intr_coal.max_packets = max_packets;
> +
> +       return 0;
> +}
> +
> +static int virtnet_send_tx_ctrl_coal_vq_cmd(struct virtnet_info *vi,
> +                                           u16 queue, u32 max_usecs,
> +                                           u32 max_packets)
> +{
> +       int err;
> +
> +       err = virtnet_send_ctrl_coal_vq_cmd(vi, txq2vq(queue),
> +                                           max_usecs, max_packets);
> +       if (err)
> +               return err;
> +
> +       vi->sq[queue].intr_coal.max_usecs = max_usecs;
> +       vi->sq[queue].intr_coal.max_packets = max_packets;
> +
> +       return 0;
> +}
> +
>  static void virtnet_get_ringparam(struct net_device *dev,
>                                   struct ethtool_ringparam *ring,
>                                   struct kernel_ethtool_ringparam *kernel_ring,
> @@ -2903,14 +2955,11 @@ static int virtnet_set_ringparam(struct net_device *dev,
>                          * through the VIRTIO_NET_CTRL_NOTF_COAL_TX_SET command, or, if the driver
>                          * did not set any TX coalescing parameters, to 0.
>                          */
> -                       err = virtnet_send_ctrl_coal_vq_cmd(vi, txq2vq(i),
> -                                                           vi->intr_coal_tx.max_usecs,
> -                                                           vi->intr_coal_tx.max_packets);
> +                       err = virtnet_send_tx_ctrl_coal_vq_cmd(vi, i,
> +                                                              vi->intr_coal_tx.max_usecs,
> +                                                              vi->intr_coal_tx.max_packets);
>                         if (err)
>                                 return err;
> -
> -                       vi->sq[i].intr_coal.max_usecs = vi->intr_coal_tx.max_usecs;
> -                       vi->sq[i].intr_coal.max_packets = vi->intr_coal_tx.max_packets;
>                 }
>
>                 if (ring->rx_pending != rx_pending) {
> @@ -2919,14 +2968,11 @@ static int virtnet_set_ringparam(struct net_device *dev,
>                                 return err;
>
>                         /* The reason is same as the transmit virtqueue reset */
> -                       err = virtnet_send_ctrl_coal_vq_cmd(vi, rxq2vq(i),
> -                                                           vi->intr_coal_rx.max_usecs,
> -                                                           vi->intr_coal_rx.max_packets);
> +                       err = virtnet_send_rx_ctrl_coal_vq_cmd(vi, i,
> +                                                              vi->intr_coal_rx.max_usecs,
> +                                                              vi->intr_coal_rx.max_packets);
>                         if (err)
>                                 return err;
> -
> -                       vi->rq[i].intr_coal.max_usecs = vi->intr_coal_rx.max_usecs;
> -                       vi->rq[i].intr_coal.max_packets = vi->intr_coal_rx.max_packets;
>                 }
>         }
>
> @@ -3327,48 +3373,24 @@ static int virtnet_send_notf_coal_cmds(struct virtnet_info *vi,
>         return 0;
>  }
>
> -static int virtnet_send_ctrl_coal_vq_cmd(struct virtnet_info *vi,
> -                                        u16 vqn, u32 max_usecs, u32 max_packets)
> -{
> -       struct scatterlist sgs;
> -
> -       vi->ctrl->coal_vq.vqn = cpu_to_le16(vqn);
> -       vi->ctrl->coal_vq.coal.max_usecs = cpu_to_le32(max_usecs);
> -       vi->ctrl->coal_vq.coal.max_packets = cpu_to_le32(max_packets);
> -       sg_init_one(&sgs, &vi->ctrl->coal_vq, sizeof(vi->ctrl->coal_vq));
> -
> -       if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_NOTF_COAL,
> -                                 VIRTIO_NET_CTRL_NOTF_COAL_VQ_SET,
> -                                 &sgs))
> -               return -EINVAL;
> -
> -       return 0;
> -}
> -
>  static int virtnet_send_notf_coal_vq_cmds(struct virtnet_info *vi,
>                                           struct ethtool_coalesce *ec,
>                                           u16 queue)
>  {
>         int err;
>
> -       err = virtnet_send_ctrl_coal_vq_cmd(vi, rxq2vq(queue),
> -                                           ec->rx_coalesce_usecs,
> -                                           ec->rx_max_coalesced_frames);
> +       err = virtnet_send_rx_ctrl_coal_vq_cmd(vi, queue,
> +                                              ec->rx_coalesce_usecs,
> +                                              ec->rx_max_coalesced_frames);
>         if (err)
>                 return err;
>
> -       vi->rq[queue].intr_coal.max_usecs = ec->rx_coalesce_usecs;
> -       vi->rq[queue].intr_coal.max_packets = ec->rx_max_coalesced_frames;
> -
> -       err = virtnet_send_ctrl_coal_vq_cmd(vi, txq2vq(queue),
> -                                           ec->tx_coalesce_usecs,
> -                                           ec->tx_max_coalesced_frames);
> +       err = virtnet_send_tx_ctrl_coal_vq_cmd(vi, queue,
> +                                              ec->tx_coalesce_usecs,
> +                                              ec->tx_max_coalesced_frames);
>         if (err)
>                 return err;
>
> -       vi->sq[queue].intr_coal.max_usecs = ec->tx_coalesce_usecs;
> -       vi->sq[queue].intr_coal.max_packets = ec->tx_max_coalesced_frames;
> -
>         return 0;
>  }
>
> --
> 2.19.1.6.gb485710b
>
diff mbox series

Patch

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 54b3fb8d0384..caef78bb3963 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -2846,6 +2846,58 @@  static void virtnet_cpu_notif_remove(struct virtnet_info *vi)
 					    &vi->node_dead);
 }
 
+static int virtnet_send_ctrl_coal_vq_cmd(struct virtnet_info *vi,
+					 u16 vqn, u32 max_usecs, u32 max_packets)
+{
+	struct scatterlist sgs;
+
+	vi->ctrl->coal_vq.vqn = cpu_to_le16(vqn);
+	vi->ctrl->coal_vq.coal.max_usecs = cpu_to_le32(max_usecs);
+	vi->ctrl->coal_vq.coal.max_packets = cpu_to_le32(max_packets);
+	sg_init_one(&sgs, &vi->ctrl->coal_vq, sizeof(vi->ctrl->coal_vq));
+
+	if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_NOTF_COAL,
+				  VIRTIO_NET_CTRL_NOTF_COAL_VQ_SET,
+				  &sgs))
+		return -EINVAL;
+
+	return 0;
+}
+
+static int virtnet_send_rx_ctrl_coal_vq_cmd(struct virtnet_info *vi,
+					    u16 queue, u32 max_usecs,
+					    u32 max_packets)
+{
+	int err;
+
+	err = virtnet_send_ctrl_coal_vq_cmd(vi, rxq2vq(queue),
+					    max_usecs, max_packets);
+	if (err)
+		return err;
+
+	vi->rq[queue].intr_coal.max_usecs = max_usecs;
+	vi->rq[queue].intr_coal.max_packets = max_packets;
+
+	return 0;
+}
+
+static int virtnet_send_tx_ctrl_coal_vq_cmd(struct virtnet_info *vi,
+					    u16 queue, u32 max_usecs,
+					    u32 max_packets)
+{
+	int err;
+
+	err = virtnet_send_ctrl_coal_vq_cmd(vi, txq2vq(queue),
+					    max_usecs, max_packets);
+	if (err)
+		return err;
+
+	vi->sq[queue].intr_coal.max_usecs = max_usecs;
+	vi->sq[queue].intr_coal.max_packets = max_packets;
+
+	return 0;
+}
+
 static void virtnet_get_ringparam(struct net_device *dev,
 				  struct ethtool_ringparam *ring,
 				  struct kernel_ethtool_ringparam *kernel_ring,
@@ -2903,14 +2955,11 @@  static int virtnet_set_ringparam(struct net_device *dev,
 			 * through the VIRTIO_NET_CTRL_NOTF_COAL_TX_SET command, or, if the driver
 			 * did not set any TX coalescing parameters, to 0.
 			 */
-			err = virtnet_send_ctrl_coal_vq_cmd(vi, txq2vq(i),
-							    vi->intr_coal_tx.max_usecs,
-							    vi->intr_coal_tx.max_packets);
+			err = virtnet_send_tx_ctrl_coal_vq_cmd(vi, i,
+							       vi->intr_coal_tx.max_usecs,
+							       vi->intr_coal_tx.max_packets);
 			if (err)
 				return err;
-
-			vi->sq[i].intr_coal.max_usecs = vi->intr_coal_tx.max_usecs;
-			vi->sq[i].intr_coal.max_packets = vi->intr_coal_tx.max_packets;
 		}
 
 		if (ring->rx_pending != rx_pending) {
@@ -2919,14 +2968,11 @@  static int virtnet_set_ringparam(struct net_device *dev,
 				return err;
 
 			/* The reason is same as the transmit virtqueue reset */
-			err = virtnet_send_ctrl_coal_vq_cmd(vi, rxq2vq(i),
-							    vi->intr_coal_rx.max_usecs,
-							    vi->intr_coal_rx.max_packets);
+			err = virtnet_send_rx_ctrl_coal_vq_cmd(vi, i,
+							       vi->intr_coal_rx.max_usecs,
+							       vi->intr_coal_rx.max_packets);
 			if (err)
 				return err;
-
-			vi->rq[i].intr_coal.max_usecs = vi->intr_coal_rx.max_usecs;
-			vi->rq[i].intr_coal.max_packets = vi->intr_coal_rx.max_packets;
 		}
 	}
 
@@ -3327,48 +3373,24 @@  static int virtnet_send_notf_coal_cmds(struct virtnet_info *vi,
 	return 0;
 }
 
-static int virtnet_send_ctrl_coal_vq_cmd(struct virtnet_info *vi,
-					 u16 vqn, u32 max_usecs, u32 max_packets)
-{
-	struct scatterlist sgs;
-
-	vi->ctrl->coal_vq.vqn = cpu_to_le16(vqn);
-	vi->ctrl->coal_vq.coal.max_usecs = cpu_to_le32(max_usecs);
-	vi->ctrl->coal_vq.coal.max_packets = cpu_to_le32(max_packets);
-	sg_init_one(&sgs, &vi->ctrl->coal_vq, sizeof(vi->ctrl->coal_vq));
-
-	if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_NOTF_COAL,
-				  VIRTIO_NET_CTRL_NOTF_COAL_VQ_SET,
-				  &sgs))
-		return -EINVAL;
-
-	return 0;
-}
-
 static int virtnet_send_notf_coal_vq_cmds(struct virtnet_info *vi,
 					  struct ethtool_coalesce *ec,
 					  u16 queue)
 {
 	int err;
 
-	err = virtnet_send_ctrl_coal_vq_cmd(vi, rxq2vq(queue),
-					    ec->rx_coalesce_usecs,
-					    ec->rx_max_coalesced_frames);
+	err = virtnet_send_rx_ctrl_coal_vq_cmd(vi, queue,
+					       ec->rx_coalesce_usecs,
+					       ec->rx_max_coalesced_frames);
 	if (err)
 		return err;
 
-	vi->rq[queue].intr_coal.max_usecs = ec->rx_coalesce_usecs;
-	vi->rq[queue].intr_coal.max_packets = ec->rx_max_coalesced_frames;
-
-	err = virtnet_send_ctrl_coal_vq_cmd(vi, txq2vq(queue),
-					    ec->tx_coalesce_usecs,
-					    ec->tx_max_coalesced_frames);
+	err = virtnet_send_tx_ctrl_coal_vq_cmd(vi, queue,
+					       ec->tx_coalesce_usecs,
+					       ec->tx_max_coalesced_frames);
 	if (err)
 		return err;
 
-	vi->sq[queue].intr_coal.max_usecs = ec->tx_coalesce_usecs;
-	vi->sq[queue].intr_coal.max_packets = ec->tx_max_coalesced_frames;
-
 	return 0;
 }