X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fdevices%2Fvirtio%2Fvirtio.h;h=7a5dcd83fe347586aa177f3f3857cdbec11b3d14;hb=379aac395a2cc78847d8f14264a22a3ee99fc1c2;hp=55b6271b3379d4c220d303bb43886c02b7b6b49d;hpb=3f340175aebaf84ed3994799e819e0801c7e3212;p=vpp.git diff --git a/src/vnet/devices/virtio/virtio.h b/src/vnet/devices/virtio/virtio.h index 55b6271b337..7a5dcd83fe3 100644 --- a/src/vnet/devices/virtio/virtio.h +++ b/src/vnet/devices/virtio/virtio.h @@ -22,6 +22,7 @@ #include #include #include +#include #define foreach_virtio_net_features \ _ (VIRTIO_NET_F_CSUM, 0) /* Host handles pkts w/ partial csum */ \ @@ -49,15 +50,14 @@ _ (VIRTIO_NET_F_CTRL_MAC_ADDR, 23) /* Set MAC address */ \ _ (VIRTIO_F_NOTIFY_ON_EMPTY, 24) \ _ (VHOST_F_LOG_ALL, 26) /* Log all write descriptors */ \ - _ (VIRTIO_F_ANY_LAYOUT, 27) /* Can the device handle any descripor layout */ \ + _ (VIRTIO_F_ANY_LAYOUT, 27) /* Can the device handle any descriptor layout */ \ _ (VIRTIO_RING_F_INDIRECT_DESC, 28) /* Support indirect buffer descriptors */ \ _ (VIRTIO_RING_F_EVENT_IDX, 29) /* The Guest publishes the used index for which it expects an interrupt \ * at the end of the avail ring. Host should ignore the avail->flags field. */ \ /* The Host publishes the avail index for which it expects a kick \ * at the end of the used ring. Guest should ignore the used->flags field. */ \ _ (VHOST_USER_F_PROTOCOL_FEATURES, 30) \ - _ (VIRTIO_F_VERSION_1, 32) - + _ (VIRTIO_F_VERSION_1, 32) /* v1.0 compliant. */ \ #define foreach_virtio_if_flag \ _(0, ADMIN_UP, "admin-up") \ @@ -70,9 +70,6 @@ typedef enum #undef _ } virtio_if_flag_t; -#define VIRTIO_NUM_RX_DESC 256 -#define VIRTIO_NUM_TX_DESC 256 - #define VIRTIO_FEATURE(X) (1ULL << X) #define TX_QUEUE(X) ((X*2) + 1) @@ -80,31 +77,31 @@ typedef enum #define TX_QUEUE_ACCESS(X) (X/2) #define RX_QUEUE_ACCESS(X) (X/2) -typedef enum -{ - VIRTIO_IF_TYPE_TAP, - VIRTIO_IF_TYPE_PCI, - VIRTIO_IF_N_TYPES, -} virtio_if_type_t; +#define VIRTIO_NUM_RX_DESC 256 +#define VIRTIO_NUM_TX_DESC 256 +#define foreach_virtio_if_types \ + _ (TAP, 0) \ + _ (TUN, 1) \ + _ (PCI, 2) -typedef struct +typedef enum { - u8 mac[6]; - u16 status; - u16 max_virtqueue_pairs; - u16 mtu; -} virtio_net_config_t; +#define _(a, b) VIRTIO_IF_TYPE_##a = (1 << b), + foreach_virtio_if_types +#undef _ + VIRTIO_IF_N_TYPES = (1 << 3), +} virtio_if_type_t; #define VIRTIO_RING_FLAG_MASK_INT 1 typedef struct { CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); + clib_spinlock_t lockp; struct vring_desc *desc; struct vring_used *used; struct vring_avail *avail; - clib_spinlock_t lockp; u16 desc_in_use; u16 desc_next; int kick_fd; @@ -112,11 +109,13 @@ typedef struct u8 buffer_pool_index; u16 size; u16 queue_id; +#define VRING_TX_OUT_OF_ORDER 1 u16 flags; - u32 call_file_index; u32 *buffers; u16 last_used_idx; u16 last_kick_avail_idx; + u32 call_file_index; + gro_flow_table_t *flow_table; } virtio_vring_t; typedef union @@ -131,57 +130,82 @@ typedef union u32 as_u32; } pci_addr_t; +/* forward declaration */ +typedef struct _virtio_pci_func virtio_pci_func_t; + typedef struct { CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); + u64 features; u32 flags; - - u32 dev_instance; - u32 hw_if_index; - u32 sw_if_index; - u32 numa_node; - u16 virtio_net_hdr_sz; - virtio_if_type_t type; - union - { - u32 id; - pci_addr_t pci_addr; - }; u32 per_interface_next_index; + u16 num_rxqs; + u16 num_txqs; + virtio_vring_t *rxq_vrings; + virtio_vring_t *txq_vrings; + int gso_enabled; + int csum_offload_enabled; union { - int fd; - u32 msix_enabled; - }; - union - { - int tap_fd; - u32 pci_dev_handle; + int *tap_fds; + struct + { + u32 pci_dev_handle; + u32 msix_enabled; + }; }; - virtio_vring_t *rxq_vrings; - virtio_vring_t *txq_vrings; - u64 features, remote_features; + u16 virtio_net_hdr_sz; + virtio_if_type_t type; + + u32 hw_if_index; + u32 sw_if_index; + + CLIB_CACHE_LINE_ALIGN_MARK (cacheline1); + int packet_coalesce; + u32 dev_instance; + u32 numa_node; + u64 remote_features; /* error */ clib_error_t *error; - u8 support_int_mode; /* support interrupt mode */ - u16 max_queue_pairs; - u16 num_rxqs; - u16 num_txqs; - u8 status; u8 mac_addr[6]; - u8 *host_if_name; - u8 *net_ns; - u8 *host_bridge; - u8 host_mac_addr[6]; - ip4_address_t host_ip4_addr; - u8 host_ip4_prefix_len; - ip6_address_t host_ip6_addr; - u8 host_ip6_prefix_len; - u32 tap_file_index; - int gso_enabled; - int ifindex; - virtio_vring_t *cxq_vring; + union + { + struct /* tun/tap interface */ + { + ip6_address_t host_ip6_addr; + int *vhost_fds; + u8 *host_if_name; + u8 *net_ns; + u8 *host_bridge; + u8 host_mac_addr[6]; + u32 id; + u32 host_mtu_size; + u32 tap_flags; + int ifindex; + ip4_address_t host_ip4_addr; + u8 host_ip4_prefix_len; + u8 host_ip6_prefix_len; + }; + struct /* native virtio */ + { + void *bar; + virtio_vring_t *cxq_vring; + pci_addr_t pci_addr; + u32 bar_id; + u32 notify_off_multiplier; + u32 is_modern; + u16 common_offset; + u16 notify_offset; + u16 device_offset; + u16 isr_offset; + u16 max_queue_pairs; + u16 msix_table_size; + u8 support_int_mode; /* support interrupt mode */ + u8 status; + }; + }; + const virtio_pci_func_t *virtio_pci_func; } virtio_if_t; typedef struct @@ -209,15 +233,24 @@ extern void virtio_free_rx_buffers (vlib_main_t * vm, virtio_vring_t * vring); extern void virtio_set_net_hdr_size (virtio_if_t * vif); extern void virtio_show (vlib_main_t * vm, u32 * hw_if_indices, u8 show_descr, u32 type); +extern void virtio_set_packet_coalesce (virtio_if_t * vif); extern void virtio_pci_legacy_notify_queue (vlib_main_t * vm, virtio_if_t * vif, u16 queue_id); +extern void virtio_pci_modern_notify_queue (vlib_main_t * vm, + virtio_if_t * vif, u16 queue_id); format_function_t format_virtio_device_name; +format_function_t format_virtio_log_name; static_always_inline void virtio_kick (vlib_main_t * vm, virtio_vring_t * vring, virtio_if_t * vif) { if (vif->type == VIRTIO_IF_TYPE_PCI) - virtio_pci_legacy_notify_queue (vm, vif, vring->queue_id); + { + if (vif->is_modern) + virtio_pci_modern_notify_queue (vm, vif, vring->queue_id); + else + virtio_pci_legacy_notify_queue (vm, vif, vring->queue_id); + } else { u64 x = 1; @@ -228,6 +261,27 @@ virtio_kick (vlib_main_t * vm, virtio_vring_t * vring, virtio_if_t * vif) } } +#define virtio_log_debug(vif, f, ...) \ +{ \ + vlib_log(VLIB_LOG_LEVEL_DEBUG, virtio_main.log_default, \ + "%U: " f, format_virtio_log_name, vif, \ + ##__VA_ARGS__); \ +}; + +#define virtio_log_warning(vif, f, ...) \ +{ \ + vlib_log(VLIB_LOG_LEVEL_WARNING, virtio_main.log_default, \ + "%U: " f, format_virtio_log_name, vif, \ + ##__VA_ARGS__); \ +}; + +#define virtio_log_error(vif, f, ...) \ +{ \ + vlib_log(VLIB_LOG_LEVEL_ERR, virtio_main.log_default, \ + "%U: " f, format_virtio_log_name, vif, \ + ##__VA_ARGS__); \ +}; + #endif /* _VNET_DEVICES_VIRTIO_VIRTIO_H_ */ /*