Skip to content

Commit aff5b0e

Browse files
fengidriPaolo Abeni
authored andcommitted
virtio_net: introduce ability to get reply info from device
As the spec oasis-tcs/virtio-spec@42f3899 Based on the description provided in the above specification, we have enabled the virtio-net driver to support acquiring some response information from the device via the CVQ (Control Virtqueue). Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent dd1941f commit aff5b0e

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

drivers/net/virtio_net.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2527,11 +2527,12 @@ static int virtnet_tx_resize(struct virtnet_info *vi,
25272527
* supported by the hypervisor, as indicated by feature bits, should
25282528
* never fail unless improperly formatted.
25292529
*/
2530-
static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
2531-
struct scatterlist *out)
2530+
static bool virtnet_send_command_reply(struct virtnet_info *vi, u8 class, u8 cmd,
2531+
struct scatterlist *out,
2532+
struct scatterlist *in)
25322533
{
2533-
struct scatterlist *sgs[4], hdr, stat;
2534-
unsigned out_num = 0, tmp;
2534+
struct scatterlist *sgs[5], hdr, stat;
2535+
u32 out_num = 0, tmp, in_num = 0;
25352536
int ret;
25362537

25372538
/* Caller should know better */
@@ -2549,10 +2550,13 @@ static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
25492550

25502551
/* Add return status. */
25512552
sg_init_one(&stat, &vi->ctrl->status, sizeof(vi->ctrl->status));
2552-
sgs[out_num] = &stat;
2553+
sgs[out_num + in_num++] = &stat;
25532554

2554-
BUG_ON(out_num + 1 > ARRAY_SIZE(sgs));
2555-
ret = virtqueue_add_sgs(vi->cvq, sgs, out_num, 1, vi, GFP_ATOMIC);
2555+
if (in)
2556+
sgs[out_num + in_num++] = in;
2557+
2558+
BUG_ON(out_num + in_num > ARRAY_SIZE(sgs));
2559+
ret = virtqueue_add_sgs(vi->cvq, sgs, out_num, in_num, vi, GFP_ATOMIC);
25562560
if (ret < 0) {
25572561
dev_warn(&vi->vdev->dev,
25582562
"Failed to add sgs for command vq: %d\n.", ret);
@@ -2574,6 +2578,12 @@ static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
25742578
return vi->ctrl->status == VIRTIO_NET_OK;
25752579
}
25762580

2581+
static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
2582+
struct scatterlist *out)
2583+
{
2584+
return virtnet_send_command_reply(vi, class, cmd, out, NULL);
2585+
}
2586+
25772587
static int virtnet_set_mac_address(struct net_device *dev, void *p)
25782588
{
25792589
struct virtnet_info *vi = netdev_priv(dev);

0 commit comments

Comments
 (0)