Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
| 3 | * Copyright (c) 2017 Cisco and/or its affiliates. |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at: |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | *------------------------------------------------------------------ |
| 16 | */ |
| 17 | |
| 18 | #ifndef _VNET_DEVICES_VIRTIO_VIRTIO_H_ |
| 19 | #define _VNET_DEVICES_VIRTIO_VIRTIO_H_ |
| 20 | |
| 21 | #define foreach_virtio_net_features \ |
| 22 | _ (VIRTIO_NET_F_CSUM, 0) /* Host handles pkts w/ partial csum */ \ |
| 23 | _ (VIRTIO_NET_F_GUEST_CSUM, 1) /* Guest handles pkts w/ partial csum */ \ |
| 24 | _ (VIRTIO_NET_F_CTRL_GUEST_OFFLOADS, 2) /* Dynamic offload configuration. */ \ |
| 25 | _ (VIRTIO_NET_F_MTU, 3) /* Initial MTU advice. */ \ |
| 26 | _ (VIRTIO_NET_F_MAC, 5) /* Host has given MAC address. */ \ |
| 27 | _ (VIRTIO_NET_F_GSO, 6) /* Host handles pkts w/ any GSO. */ \ |
| 28 | _ (VIRTIO_NET_F_GUEST_TSO4, 7) /* Guest can handle TSOv4 in. */ \ |
| 29 | _ (VIRTIO_NET_F_GUEST_TSO6, 8) /* Guest can handle TSOv6 in. */ \ |
| 30 | _ (VIRTIO_NET_F_GUEST_ECN, 9) /* Guest can handle TSO[6] w/ ECN in. */ \ |
| 31 | _ (VIRTIO_NET_F_GUEST_UFO, 10) /* Guest can handle UFO in. */ \ |
| 32 | _ (VIRTIO_NET_F_HOST_TSO4, 11) /* Host can handle TSOv4 in. */ \ |
| 33 | _ (VIRTIO_NET_F_HOST_TSO6, 12) /* Host can handle TSOv6 in. */ \ |
| 34 | _ (VIRTIO_NET_F_HOST_ECN, 13) /* Host can handle TSO[6] w/ ECN in. */ \ |
| 35 | _ (VIRTIO_NET_F_HOST_UFO, 14) /* Host can handle UFO in. */ \ |
| 36 | _ (VIRTIO_NET_F_MRG_RXBUF, 15) /* Host can merge receive buffers. */ \ |
| 37 | _ (VIRTIO_NET_F_STATUS, 16) /* virtio_net_config.status available */ \ |
| 38 | _ (VIRTIO_NET_F_CTRL_VQ, 17) /* Control channel available */ \ |
| 39 | _ (VIRTIO_NET_F_CTRL_RX, 18) /* Control channel RX mode support */ \ |
| 40 | _ (VIRTIO_NET_F_CTRL_VLAN, 19) /* Control channel VLAN filtering */ \ |
| 41 | _ (VIRTIO_NET_F_CTRL_RX_EXTRA, 20) /* Extra RX mode control support */ \ |
| 42 | _ (VIRTIO_NET_F_GUEST_ANNOUNCE, 21) /* Guest can announce device on the network */ \ |
| 43 | _ (VIRTIO_NET_F_MQ, 22) /* Device supports Receive Flow Steering */ \ |
| 44 | _ (VIRTIO_NET_F_CTRL_MAC_ADDR, 23) /* Set MAC address */ \ |
| 45 | _ (VIRTIO_F_NOTIFY_ON_EMPTY, 24) \ |
| 46 | _ (VHOST_F_LOG_ALL, 26) /* Log all write descriptors */ \ |
| 47 | _ (VIRTIO_F_ANY_LAYOUT, 27) /* Can the device handle any descripor layout */ \ |
| 48 | _ (VIRTIO_RING_F_INDIRECT_DESC, 28) /* Support indirect buffer descriptors */ \ |
| 49 | _ (VIRTIO_RING_F_EVENT_IDX, 29) /* The Guest publishes the used index for which it expects an interrupt \ |
| 50 | * at the end of the avail ring. Host should ignore the avail->flags field. */ \ |
| 51 | /* The Host publishes the avail index for which it expects a kick \ |
| 52 | * at the end of the used ring. Guest should ignore the used->flags field. */ \ |
| 53 | _ (VHOST_USER_F_PROTOCOL_FEATURES, 30) \ |
| 54 | _ (VIRTIO_F_VERSION_1, 32) |
| 55 | |
| 56 | #define foreach_virtio_if_flag \ |
| 57 | _(0, ADMIN_UP, "admin-up") \ |
| 58 | _(1, DELETING, "deleting") |
| 59 | |
| 60 | typedef enum |
| 61 | { |
| 62 | #define _(a, b, c) VIRTIO_IF_FLAG_##b = (1 << a), |
| 63 | foreach_virtio_if_flag |
| 64 | #undef _ |
| 65 | } virtio_if_flag_t; |
| 66 | |
| 67 | typedef enum |
| 68 | { |
| 69 | VIRTIO_IF_TYPE_TAP, |
| 70 | VIRTIO_IF_N_TYPES, |
| 71 | } virtio_if_type_t; |
| 72 | |
| 73 | |
| 74 | typedef struct |
| 75 | { |
| 76 | struct vring_desc *desc; |
| 77 | struct vring_used *used; |
| 78 | struct vring_avail *avail; |
| 79 | u16 desc_in_use; |
| 80 | u16 desc_next; |
| 81 | int kick_fd; |
| 82 | int call_fd; |
| 83 | u16 size; |
| 84 | #define VIRTIO_RING_FLAG_MASK_INT 1 |
| 85 | u32 flags; |
| 86 | u32 call_file_index; |
| 87 | u32 *buffers; |
| 88 | u16 last_used_idx; |
| 89 | } virtio_vring_t; |
| 90 | |
| 91 | typedef struct |
| 92 | { |
| 93 | u32 flags; |
Damjan Marion | 829ee53 | 2018-02-16 16:13:32 +0100 | [diff] [blame] | 94 | clib_spinlock_t lockp; |
| 95 | |
Damjan Marion | 2df3909 | 2017-12-04 20:03:37 +0100 | [diff] [blame] | 96 | u32 id; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 97 | u32 dev_instance; |
| 98 | u32 hw_if_index; |
| 99 | u32 sw_if_index; |
| 100 | u32 per_interface_next_index; |
| 101 | int fd; |
| 102 | int tap_fd; |
| 103 | virtio_vring_t *vrings; |
| 104 | |
| 105 | u64 features, remote_features; |
| 106 | |
| 107 | virtio_if_type_t type; |
Milan Lenco | 73e7f42 | 2017-12-14 10:04:25 +0100 | [diff] [blame] | 108 | u16 tx_ring_sz; |
| 109 | u16 rx_ring_sz; |
Damjan Marion | 2df3909 | 2017-12-04 20:03:37 +0100 | [diff] [blame] | 110 | u8 *host_if_name; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 111 | u8 *net_ns; |
Milan Lenco | 73e7f42 | 2017-12-14 10:04:25 +0100 | [diff] [blame] | 112 | u8 *host_bridge; |
| 113 | u8 host_mac_addr[6]; |
| 114 | ip4_address_t host_ip4_addr; |
| 115 | u8 host_ip4_prefix_len; |
| 116 | ip6_address_t host_ip6_addr; |
| 117 | u8 host_ip6_prefix_len; |
| 118 | |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 119 | int ifindex; |
| 120 | } virtio_if_t; |
| 121 | |
| 122 | typedef struct |
| 123 | { |
| 124 | virtio_if_t *interfaces; |
| 125 | } virtio_main_t; |
| 126 | |
| 127 | extern virtio_main_t virtio_main; |
| 128 | extern vnet_device_class_t virtio_device_class; |
| 129 | extern vlib_node_registration_t virtio_input_node; |
| 130 | |
| 131 | clib_error_t *virtio_vring_init (vlib_main_t * vm, virtio_if_t * vif, u16 idx, |
| 132 | u16 sz); |
Steven | a624dbe | 2018-01-09 11:13:29 -0800 | [diff] [blame] | 133 | clib_error_t *virtio_vring_free (vlib_main_t * vm, virtio_if_t * vif, |
| 134 | u32 idx); |
| 135 | extern void virtio_free_used_desc (vlib_main_t * vm, virtio_vring_t * vring); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 136 | |
Damjan Marion | ceab788 | 2018-01-19 20:56:12 +0100 | [diff] [blame] | 137 | format_function_t format_virtio_device_name; |
| 138 | |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 139 | #endif /* _VNET_DEVICES_VIRTIO_VIRTIO_H_ */ |
| 140 | |
| 141 | /* |
| 142 | * fd.io coding-style-patch-verification: ON |
| 143 | * |
| 144 | * Local Variables: |
| 145 | * eval: (c-set-style "gnu") |
| 146 | * End: |
| 147 | */ |