Skip to content

Commit 34cfe87

Browse files
fengidriPaolo Abeni
authored andcommitted
virtio_net: introduce device stats feature and structures
The virtio-net device stats spec: oasis-tcs/virtio-spec@42f3899 We introduce the relative feature and structures. Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com> Acked-by: Jason Wang <jasowang@redhat.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent aff5b0e commit 34cfe87

File tree

1 file changed

+143
-0
lines changed

1 file changed

+143
-0
lines changed

include/uapi/linux/virtio_net.h

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#define VIRTIO_NET_F_MQ 22 /* Device supports Receive Flow
5757
* Steering */
5858
#define VIRTIO_NET_F_CTRL_MAC_ADDR 23 /* Set MAC address */
59+
#define VIRTIO_NET_F_DEVICE_STATS 50 /* Device can provide device-level statistics. */
5960
#define VIRTIO_NET_F_VQ_NOTF_COAL 52 /* Device supports virtqueue notification coalescing */
6061
#define VIRTIO_NET_F_NOTF_COAL 53 /* Device supports notifications coalescing */
6162
#define VIRTIO_NET_F_GUEST_USO4 54 /* Guest can handle USOv4 in. */
@@ -406,4 +407,146 @@ struct virtio_net_ctrl_coal_vq {
406407
struct virtio_net_ctrl_coal coal;
407408
};
408409

410+
/*
411+
* Device Statistics
412+
*/
413+
#define VIRTIO_NET_CTRL_STATS 8
414+
#define VIRTIO_NET_CTRL_STATS_QUERY 0
415+
#define VIRTIO_NET_CTRL_STATS_GET 1
416+
417+
struct virtio_net_stats_capabilities {
418+
419+
#define VIRTIO_NET_STATS_TYPE_CVQ (1ULL << 32)
420+
421+
#define VIRTIO_NET_STATS_TYPE_RX_BASIC (1ULL << 0)
422+
#define VIRTIO_NET_STATS_TYPE_RX_CSUM (1ULL << 1)
423+
#define VIRTIO_NET_STATS_TYPE_RX_GSO (1ULL << 2)
424+
#define VIRTIO_NET_STATS_TYPE_RX_SPEED (1ULL << 3)
425+
426+
#define VIRTIO_NET_STATS_TYPE_TX_BASIC (1ULL << 16)
427+
#define VIRTIO_NET_STATS_TYPE_TX_CSUM (1ULL << 17)
428+
#define VIRTIO_NET_STATS_TYPE_TX_GSO (1ULL << 18)
429+
#define VIRTIO_NET_STATS_TYPE_TX_SPEED (1ULL << 19)
430+
431+
__le64 supported_stats_types[1];
432+
};
433+
434+
struct virtio_net_ctrl_queue_stats {
435+
struct {
436+
__le16 vq_index;
437+
__le16 reserved[3];
438+
__le64 types_bitmap[1];
439+
} stats[1];
440+
};
441+
442+
struct virtio_net_stats_reply_hdr {
443+
#define VIRTIO_NET_STATS_TYPE_REPLY_CVQ 32
444+
445+
#define VIRTIO_NET_STATS_TYPE_REPLY_RX_BASIC 0
446+
#define VIRTIO_NET_STATS_TYPE_REPLY_RX_CSUM 1
447+
#define VIRTIO_NET_STATS_TYPE_REPLY_RX_GSO 2
448+
#define VIRTIO_NET_STATS_TYPE_REPLY_RX_SPEED 3
449+
450+
#define VIRTIO_NET_STATS_TYPE_REPLY_TX_BASIC 16
451+
#define VIRTIO_NET_STATS_TYPE_REPLY_TX_CSUM 17
452+
#define VIRTIO_NET_STATS_TYPE_REPLY_TX_GSO 18
453+
#define VIRTIO_NET_STATS_TYPE_REPLY_TX_SPEED 19
454+
__u8 type;
455+
__u8 reserved;
456+
__le16 vq_index;
457+
__le16 reserved1;
458+
__le16 size;
459+
};
460+
461+
struct virtio_net_stats_cvq {
462+
struct virtio_net_stats_reply_hdr hdr;
463+
464+
__le64 command_num;
465+
__le64 ok_num;
466+
};
467+
468+
struct virtio_net_stats_rx_basic {
469+
struct virtio_net_stats_reply_hdr hdr;
470+
471+
__le64 rx_notifications;
472+
473+
__le64 rx_packets;
474+
__le64 rx_bytes;
475+
476+
__le64 rx_interrupts;
477+
478+
__le64 rx_drops;
479+
__le64 rx_drop_overruns;
480+
};
481+
482+
struct virtio_net_stats_tx_basic {
483+
struct virtio_net_stats_reply_hdr hdr;
484+
485+
__le64 tx_notifications;
486+
487+
__le64 tx_packets;
488+
__le64 tx_bytes;
489+
490+
__le64 tx_interrupts;
491+
492+
__le64 tx_drops;
493+
__le64 tx_drop_malformed;
494+
};
495+
496+
struct virtio_net_stats_rx_csum {
497+
struct virtio_net_stats_reply_hdr hdr;
498+
499+
__le64 rx_csum_valid;
500+
__le64 rx_needs_csum;
501+
__le64 rx_csum_none;
502+
__le64 rx_csum_bad;
503+
};
504+
505+
struct virtio_net_stats_tx_csum {
506+
struct virtio_net_stats_reply_hdr hdr;
507+
508+
__le64 tx_csum_none;
509+
__le64 tx_needs_csum;
510+
};
511+
512+
struct virtio_net_stats_rx_gso {
513+
struct virtio_net_stats_reply_hdr hdr;
514+
515+
__le64 rx_gso_packets;
516+
__le64 rx_gso_bytes;
517+
__le64 rx_gso_packets_coalesced;
518+
__le64 rx_gso_bytes_coalesced;
519+
};
520+
521+
struct virtio_net_stats_tx_gso {
522+
struct virtio_net_stats_reply_hdr hdr;
523+
524+
__le64 tx_gso_packets;
525+
__le64 tx_gso_bytes;
526+
__le64 tx_gso_segments;
527+
__le64 tx_gso_segments_bytes;
528+
__le64 tx_gso_packets_noseg;
529+
__le64 tx_gso_bytes_noseg;
530+
};
531+
532+
struct virtio_net_stats_rx_speed {
533+
struct virtio_net_stats_reply_hdr hdr;
534+
535+
/* rx_{packets,bytes}_allowance_exceeded are too long. So rename to
536+
* short name.
537+
*/
538+
__le64 rx_ratelimit_packets;
539+
__le64 rx_ratelimit_bytes;
540+
};
541+
542+
struct virtio_net_stats_tx_speed {
543+
struct virtio_net_stats_reply_hdr hdr;
544+
545+
/* tx_{packets,bytes}_allowance_exceeded are too long. So rename to
546+
* short name.
547+
*/
548+
__le64 tx_ratelimit_packets;
549+
__le64 tx_ratelimit_bytes;
550+
};
551+
409552
#endif /* _UAPI_LINUX_VIRTIO_NET_H */

0 commit comments

Comments
 (0)