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 | |
Mohsin Kazmi | a7a2281 | 2020-08-31 17:17:16 +0200 | [diff] [blame] | 21 | #include <vnet/devices/virtio/virtio_std.h> |
| 22 | #include <vnet/devices/virtio/vhost_std.h> |
Mohsin Kazmi | e347acb | 2020-09-28 10:26:33 +0000 | [diff] [blame] | 23 | #include <vnet/devices/virtio/virtio_buffering.h> |
Mohsin Kazmi | 9e2a785 | 2020-08-13 18:57:26 +0200 | [diff] [blame] | 24 | #include <vnet/gso/gro.h> |
Neale Ranns | f7040f0 | 2022-02-15 09:02:27 +0000 | [diff] [blame] | 25 | #include <vnet/interface.h> |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 26 | |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 27 | #define foreach_virtio_if_flag \ |
| 28 | _(0, ADMIN_UP, "admin-up") \ |
| 29 | _(1, DELETING, "deleting") |
| 30 | |
| 31 | typedef enum |
| 32 | { |
| 33 | #define _(a, b, c) VIRTIO_IF_FLAG_##b = (1 << a), |
| 34 | foreach_virtio_if_flag |
| 35 | #undef _ |
| 36 | } virtio_if_flag_t; |
| 37 | |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 38 | #define TX_QUEUE(X) ((X*2) + 1) |
| 39 | #define RX_QUEUE(X) (X*2) |
| 40 | #define TX_QUEUE_ACCESS(X) (X/2) |
| 41 | #define RX_QUEUE_ACCESS(X) (X/2) |
| 42 | |
Mohsin Kazmi | a0a6833 | 2020-07-16 12:55:42 +0000 | [diff] [blame] | 43 | #define VIRTIO_NUM_RX_DESC 256 |
| 44 | #define VIRTIO_NUM_TX_DESC 256 |
| 45 | |
Mohsin Kazmi | 206acf8 | 2020-04-06 14:19:54 +0200 | [diff] [blame] | 46 | #define foreach_virtio_if_types \ |
Mohsin Kazmi | d88fc0f | 2020-04-30 19:05:56 +0200 | [diff] [blame] | 47 | _ (TAP, 0) \ |
| 48 | _ (TUN, 1) \ |
| 49 | _ (PCI, 2) |
Mohsin Kazmi | 206acf8 | 2020-04-06 14:19:54 +0200 | [diff] [blame] | 50 | |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 51 | typedef enum |
| 52 | { |
Mohsin Kazmi | 206acf8 | 2020-04-06 14:19:54 +0200 | [diff] [blame] | 53 | #define _(a, b) VIRTIO_IF_TYPE_##a = (1 << b), |
| 54 | foreach_virtio_if_types |
| 55 | #undef _ |
Mohsin Kazmi | d88fc0f | 2020-04-30 19:05:56 +0200 | [diff] [blame] | 56 | VIRTIO_IF_N_TYPES = (1 << 3), |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 57 | } virtio_if_type_t; |
| 58 | |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 59 | #define VIRTIO_RING_FLAG_MASK_INT 1 |
| 60 | |
Mohsin Kazmi | a5203b5 | 2020-10-12 13:01:24 +0200 | [diff] [blame] | 61 | #define VIRTIO_EVENT_START_TIMER 1 |
| 62 | #define VIRTIO_EVENT_STOP_TIMER 2 |
| 63 | |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 64 | typedef struct |
| 65 | { |
David Johnson | d9818dd | 2018-12-14 14:53:41 -0500 | [diff] [blame] | 66 | CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); |
Mohsin Kazmi | 38b0968 | 2020-06-03 18:20:17 +0200 | [diff] [blame] | 67 | clib_spinlock_t lockp; |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 68 | union |
| 69 | { |
| 70 | struct |
| 71 | { |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 72 | vnet_virtio_vring_desc_t *desc; |
| 73 | vnet_virtio_vring_used_t *used; |
| 74 | vnet_virtio_vring_avail_t *avail; |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 75 | }; |
| 76 | struct |
| 77 | { |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 78 | vnet_virtio_vring_packed_desc_t *packed_desc; |
| 79 | vnet_virtio_vring_desc_event_t *driver_event; |
| 80 | vnet_virtio_vring_desc_event_t *device_event; |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 81 | }; |
| 82 | }; |
| 83 | u32 *buffers; |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 84 | u16 queue_size; |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 85 | u16 queue_id; |
Damjan Marion | 9410053 | 2020-11-06 23:25:57 +0100 | [diff] [blame] | 86 | u32 queue_index; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 87 | u16 desc_in_use; |
| 88 | u16 desc_next; |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 89 | u16 last_used_idx; |
| 90 | u16 last_kick_avail_idx; |
Mohsin Kazmi | 162a296 | 2020-09-29 10:01:25 +0000 | [diff] [blame] | 91 | union |
| 92 | { |
| 93 | struct |
| 94 | { |
| 95 | int kick_fd; |
| 96 | int call_fd; |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 97 | u32 call_file_index; |
Mohsin Kazmi | 162a296 | 2020-09-29 10:01:25 +0000 | [diff] [blame] | 98 | }; |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 99 | struct |
| 100 | { |
| 101 | u16 avail_wrap_counter; |
| 102 | u16 used_wrap_counter; |
| 103 | u16 queue_notify_offset; |
| 104 | }; |
Mohsin Kazmi | 162a296 | 2020-09-29 10:01:25 +0000 | [diff] [blame] | 105 | }; |
Mohsin Kazmi | 7f6d145 | 2020-02-27 11:49:21 +0100 | [diff] [blame] | 106 | #define VRING_TX_OUT_OF_ORDER 1 |
Mohsin Kazmi | b7e4e6d | 2021-12-13 18:32:42 +0000 | [diff] [blame] | 107 | #define VRING_TX_SCHEDULED 2 |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 108 | u16 flags; |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 109 | u8 buffer_pool_index; |
Mohsin Kazmi | a5203b5 | 2020-10-12 13:01:24 +0200 | [diff] [blame] | 110 | vnet_hw_if_rx_mode mode; |
Mohsin Kazmi | e347acb | 2020-09-28 10:26:33 +0000 | [diff] [blame] | 111 | virtio_vring_buffering_t *buffering; |
Mohsin Kazmi | 9e2a785 | 2020-08-13 18:57:26 +0200 | [diff] [blame] | 112 | gro_flow_table_t *flow_table; |
Mohsin Kazmi | dd0144a | 2022-09-14 11:25:54 +0000 | [diff] [blame] | 113 | u64 total_packets; |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 114 | } vnet_virtio_vring_t; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 115 | |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 116 | typedef union |
| 117 | { |
| 118 | struct |
| 119 | { |
| 120 | u16 domain; |
| 121 | u8 bus; |
| 122 | u8 slot:5; |
| 123 | u8 function:3; |
| 124 | }; |
| 125 | u32 as_u32; |
| 126 | } pci_addr_t; |
| 127 | |
Mohsin Kazmi | 379aac3 | 2020-08-20 10:25:12 +0200 | [diff] [blame] | 128 | /* forward declaration */ |
Mohsin Kazmi | a0a6833 | 2020-07-16 12:55:42 +0000 | [diff] [blame] | 129 | typedef struct _virtio_pci_func virtio_pci_func_t; |
| 130 | |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 131 | typedef struct |
| 132 | { |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 133 | CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); |
Mohsin Kazmi | 38b0968 | 2020-06-03 18:20:17 +0200 | [diff] [blame] | 134 | u64 features; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 135 | u32 flags; |
Mohsin Kazmi | 38b0968 | 2020-06-03 18:20:17 +0200 | [diff] [blame] | 136 | u32 per_interface_next_index; |
| 137 | u16 num_rxqs; |
| 138 | u16 num_txqs; |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 139 | vnet_virtio_vring_t *rxq_vrings; |
| 140 | vnet_virtio_vring_t *txq_vrings; |
Mohsin Kazmi | 38b0968 | 2020-06-03 18:20:17 +0200 | [diff] [blame] | 141 | int gso_enabled; |
| 142 | int csum_offload_enabled; |
| 143 | union |
| 144 | { |
| 145 | int *tap_fds; |
| 146 | struct |
| 147 | { |
| 148 | u32 pci_dev_handle; |
| 149 | u32 msix_enabled; |
| 150 | }; |
| 151 | }; |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 152 | u16 virtio_net_hdr_sz; |
| 153 | virtio_if_type_t type; |
Mohsin Kazmi | 38b0968 | 2020-06-03 18:20:17 +0200 | [diff] [blame] | 154 | |
| 155 | u32 hw_if_index; |
| 156 | u32 sw_if_index; |
| 157 | |
| 158 | CLIB_CACHE_LINE_ALIGN_MARK (cacheline1); |
Mohsin Kazmi | 9e2a785 | 2020-08-13 18:57:26 +0200 | [diff] [blame] | 159 | int packet_coalesce; |
Mohsin Kazmi | e347acb | 2020-09-28 10:26:33 +0000 | [diff] [blame] | 160 | int packet_buffering; |
Mohsin Kazmi | 38b0968 | 2020-06-03 18:20:17 +0200 | [diff] [blame] | 161 | u32 dev_instance; |
| 162 | u32 numa_node; |
| 163 | u64 remote_features; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 164 | |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 165 | /* error */ |
| 166 | clib_error_t *error; |
Benoît Ganne | 3f0ae66 | 2020-09-09 12:50:07 +0200 | [diff] [blame] | 167 | union |
| 168 | { |
| 169 | struct |
| 170 | { |
| 171 | u32 mac_addr32; |
| 172 | u16 mac_addr16; |
| 173 | }; |
| 174 | u8 mac_addr[6]; |
| 175 | }; |
Mohsin Kazmi | 379aac3 | 2020-08-20 10:25:12 +0200 | [diff] [blame] | 176 | union |
| 177 | { |
| 178 | struct /* tun/tap interface */ |
| 179 | { |
| 180 | ip6_address_t host_ip6_addr; |
| 181 | int *vhost_fds; |
| 182 | u8 *host_if_name; |
| 183 | u8 *net_ns; |
| 184 | u8 *host_bridge; |
| 185 | u8 host_mac_addr[6]; |
| 186 | u32 id; |
| 187 | u32 host_mtu_size; |
| 188 | u32 tap_flags; |
| 189 | int ifindex; |
| 190 | ip4_address_t host_ip4_addr; |
| 191 | u8 host_ip4_prefix_len; |
| 192 | u8 host_ip6_prefix_len; |
Matthew Smith | bd50ed1 | 2020-07-24 13:38:03 -0500 | [diff] [blame] | 193 | u8 host_carrier_up; /* host tun/tap driver link carrier state */ |
Mohsin Kazmi | 379aac3 | 2020-08-20 10:25:12 +0200 | [diff] [blame] | 194 | }; |
| 195 | struct /* native virtio */ |
| 196 | { |
| 197 | void *bar; |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 198 | vnet_virtio_vring_t *cxq_vring; |
Mohsin Kazmi | 379aac3 | 2020-08-20 10:25:12 +0200 | [diff] [blame] | 199 | pci_addr_t pci_addr; |
| 200 | u32 bar_id; |
| 201 | u32 notify_off_multiplier; |
| 202 | u32 is_modern; |
| 203 | u16 common_offset; |
| 204 | u16 notify_offset; |
| 205 | u16 device_offset; |
| 206 | u16 isr_offset; |
| 207 | u16 max_queue_pairs; |
| 208 | u16 msix_table_size; |
| 209 | u8 support_int_mode; /* support interrupt mode */ |
| 210 | u8 status; |
| 211 | }; |
| 212 | }; |
Mohsin Kazmi | a0a6833 | 2020-07-16 12:55:42 +0000 | [diff] [blame] | 213 | const virtio_pci_func_t *virtio_pci_func; |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 214 | int is_packed; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 215 | } virtio_if_t; |
| 216 | |
| 217 | typedef struct |
| 218 | { |
Mohsin Kazmi | b7e4e6d | 2021-12-13 18:32:42 +0000 | [diff] [blame] | 219 | u32 gro_or_buffering_if_count; |
Mohsin Kazmi | 33cc5cf | 2019-01-21 15:19:39 +0000 | [diff] [blame] | 220 | /* logging */ |
| 221 | vlib_log_class_t log_default; |
| 222 | |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 223 | virtio_if_t *interfaces; |
Filip Tehlar | 9f562cd | 2021-06-23 00:23:05 +0000 | [diff] [blame] | 224 | u16 msg_id_base; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 225 | } virtio_main_t; |
| 226 | |
| 227 | extern virtio_main_t virtio_main; |
| 228 | extern vnet_device_class_t virtio_device_class; |
| 229 | extern vlib_node_registration_t virtio_input_node; |
| 230 | |
| 231 | clib_error_t *virtio_vring_init (vlib_main_t * vm, virtio_if_t * vif, u16 idx, |
| 232 | u16 sz); |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 233 | clib_error_t *virtio_vring_free_rx (vlib_main_t * vm, virtio_if_t * vif, |
| 234 | u32 idx); |
| 235 | clib_error_t *virtio_vring_free_tx (vlib_main_t * vm, virtio_if_t * vif, |
| 236 | u32 idx); |
Damjan Marion | 9410053 | 2020-11-06 23:25:57 +0100 | [diff] [blame] | 237 | void virtio_vring_set_rx_queues (vlib_main_t *vm, virtio_if_t *vif); |
Mohsin Kazmi | b7e4e6d | 2021-12-13 18:32:42 +0000 | [diff] [blame] | 238 | void virtio_vring_set_tx_queues (vlib_main_t *vm, virtio_if_t *vif); |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 239 | extern void virtio_free_buffers (vlib_main_t *vm, vnet_virtio_vring_t *vring); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 240 | extern void virtio_set_net_hdr_size (virtio_if_t * vif); |
Mohsin Kazmi | e4efbe7 | 2021-09-22 18:56:05 +0000 | [diff] [blame] | 241 | extern void virtio_show (vlib_main_t *vm, u32 *hw_if_indices, u8 show_descr, |
| 242 | virtio_if_type_t type); |
Mohsin Kazmi | 9e2a785 | 2020-08-13 18:57:26 +0200 | [diff] [blame] | 243 | extern void virtio_set_packet_coalesce (virtio_if_t * vif); |
Mohsin Kazmi | e347acb | 2020-09-28 10:26:33 +0000 | [diff] [blame] | 244 | clib_error_t *virtio_set_packet_buffering (virtio_if_t * vif, u16 size); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 245 | extern void virtio_pci_legacy_notify_queue (vlib_main_t * vm, |
Mohsin Kazmi | 162a296 | 2020-09-29 10:01:25 +0000 | [diff] [blame] | 246 | virtio_if_t * vif, u16 queue_id, |
| 247 | u16 queue_notify_offset); |
Mohsin Kazmi | 379aac3 | 2020-08-20 10:25:12 +0200 | [diff] [blame] | 248 | extern void virtio_pci_modern_notify_queue (vlib_main_t * vm, |
Mohsin Kazmi | 162a296 | 2020-09-29 10:01:25 +0000 | [diff] [blame] | 249 | virtio_if_t * vif, u16 queue_id, |
| 250 | u16 queue_notify_offset); |
Mohsin Kazmi | b7e4e6d | 2021-12-13 18:32:42 +0000 | [diff] [blame] | 251 | extern void virtio_pre_input_node_enable (vlib_main_t *vm, virtio_if_t *vif); |
| 252 | extern void virtio_pre_input_node_disable (vlib_main_t *vm, virtio_if_t *vif); |
| 253 | |
Damjan Marion | ceab788 | 2018-01-19 20:56:12 +0100 | [diff] [blame] | 254 | format_function_t format_virtio_device_name; |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame] | 255 | format_function_t format_virtio_log_name; |
Damjan Marion | ceab788 | 2018-01-19 20:56:12 +0100 | [diff] [blame] | 256 | |
Damjan Marion | e40231b | 2018-12-20 10:44:47 +0100 | [diff] [blame] | 257 | static_always_inline void |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 258 | virtio_kick (vlib_main_t *vm, vnet_virtio_vring_t *vring, virtio_if_t *vif) |
Damjan Marion | e40231b | 2018-12-20 10:44:47 +0100 | [diff] [blame] | 259 | { |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 260 | if (vif->type == VIRTIO_IF_TYPE_PCI) |
Mohsin Kazmi | 379aac3 | 2020-08-20 10:25:12 +0200 | [diff] [blame] | 261 | { |
| 262 | if (vif->is_modern) |
Mohsin Kazmi | 162a296 | 2020-09-29 10:01:25 +0000 | [diff] [blame] | 263 | virtio_pci_modern_notify_queue (vm, vif, vring->queue_id, |
| 264 | vring->queue_notify_offset); |
Mohsin Kazmi | 379aac3 | 2020-08-20 10:25:12 +0200 | [diff] [blame] | 265 | else |
Mohsin Kazmi | 162a296 | 2020-09-29 10:01:25 +0000 | [diff] [blame] | 266 | virtio_pci_legacy_notify_queue (vm, vif, vring->queue_id, |
| 267 | vring->queue_notify_offset); |
Mohsin Kazmi | 379aac3 | 2020-08-20 10:25:12 +0200 | [diff] [blame] | 268 | } |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 269 | else |
| 270 | { |
| 271 | u64 x = 1; |
| 272 | int __clib_unused r; |
Damjan Marion | e40231b | 2018-12-20 10:44:47 +0100 | [diff] [blame] | 273 | |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 274 | r = write (vring->kick_fd, &x, sizeof (x)); |
| 275 | vring->last_kick_avail_idx = vring->avail->idx; |
| 276 | } |
Damjan Marion | e40231b | 2018-12-20 10:44:47 +0100 | [diff] [blame] | 277 | } |
| 278 | |
Mohsin Kazmi | b7e4e6d | 2021-12-13 18:32:42 +0000 | [diff] [blame] | 279 | static_always_inline u8 |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 280 | virtio_txq_is_scheduled (vnet_virtio_vring_t *vring) |
Mohsin Kazmi | b7e4e6d | 2021-12-13 18:32:42 +0000 | [diff] [blame] | 281 | { |
| 282 | if (vring) |
| 283 | return (vring->flags & VRING_TX_SCHEDULED); |
| 284 | return 1; |
| 285 | } |
| 286 | |
| 287 | static_always_inline void |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 288 | virtio_txq_set_scheduled (vnet_virtio_vring_t *vring) |
Mohsin Kazmi | b7e4e6d | 2021-12-13 18:32:42 +0000 | [diff] [blame] | 289 | { |
| 290 | if (vring) |
| 291 | vring->flags |= VRING_TX_SCHEDULED; |
| 292 | } |
| 293 | |
| 294 | static_always_inline void |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 295 | virtio_txq_clear_scheduled (vnet_virtio_vring_t *vring) |
Mohsin Kazmi | b7e4e6d | 2021-12-13 18:32:42 +0000 | [diff] [blame] | 296 | { |
| 297 | if (vring) |
| 298 | vring->flags &= ~VRING_TX_SCHEDULED; |
| 299 | } |
| 300 | |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 301 | static_always_inline void |
| 302 | vnet_virtio_vring_init (vnet_virtio_vring_t *vring, u16 queue_size, void *p, |
| 303 | u32 align) |
| 304 | { |
| 305 | vring->queue_size = queue_size; |
| 306 | vring->desc = p; |
| 307 | vring->avail = |
| 308 | (vnet_virtio_vring_avail_t *) ((char *) p + |
| 309 | queue_size * |
| 310 | sizeof (vnet_virtio_vring_desc_t)); |
| 311 | vring->used = |
| 312 | (vnet_virtio_vring_used_t |
| 313 | *) ((char *) p + ((sizeof (vnet_virtio_vring_desc_t) * queue_size + |
| 314 | sizeof (u16) * (3 + queue_size) + align - 1) & |
| 315 | ~(align - 1))); |
| 316 | vring->avail->flags = VIRTIO_RING_FLAG_MASK_INT; |
| 317 | } |
| 318 | |
| 319 | static_always_inline u16 |
| 320 | vnet_virtio_vring_size (u16 queue_size, u32 align) |
| 321 | { |
| 322 | return ((sizeof (vnet_virtio_vring_desc_t) * queue_size + |
| 323 | sizeof (u16) * (3 + queue_size) + align - 1) & |
| 324 | ~(align - 1)) + |
| 325 | sizeof (u16) * 3 + |
| 326 | sizeof (vnet_virtio_vring_used_elem_t) * queue_size; |
| 327 | } |
| 328 | |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame] | 329 | #define virtio_log_debug(vif, f, ...) \ |
| 330 | { \ |
| 331 | vlib_log(VLIB_LOG_LEVEL_DEBUG, virtio_main.log_default, \ |
| 332 | "%U: " f, format_virtio_log_name, vif, \ |
| 333 | ##__VA_ARGS__); \ |
| 334 | }; |
| 335 | |
| 336 | #define virtio_log_warning(vif, f, ...) \ |
| 337 | { \ |
| 338 | vlib_log(VLIB_LOG_LEVEL_WARNING, virtio_main.log_default, \ |
| 339 | "%U: " f, format_virtio_log_name, vif, \ |
| 340 | ##__VA_ARGS__); \ |
| 341 | }; |
| 342 | |
| 343 | #define virtio_log_error(vif, f, ...) \ |
| 344 | { \ |
| 345 | vlib_log(VLIB_LOG_LEVEL_ERR, virtio_main.log_default, \ |
| 346 | "%U: " f, format_virtio_log_name, vif, \ |
| 347 | ##__VA_ARGS__); \ |
| 348 | }; |
| 349 | |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 350 | #endif /* _VNET_DEVICES_VIRTIO_VIRTIO_H_ */ |
| 351 | |
| 352 | /* |
| 353 | * fd.io coding-style-patch-verification: ON |
| 354 | * |
| 355 | * Local Variables: |
| 356 | * eval: (c-set-style "gnu") |
| 357 | * End: |
| 358 | */ |