Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | #include <fcntl.h> |
| 17 | #include <sys/ioctl.h> |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 18 | |
| 19 | #include <vppinfra/types.h> |
| 20 | #include <vlib/vlib.h> |
| 21 | #include <vlib/pci/pci.h> |
| 22 | #include <vnet/ethernet/ethernet.h> |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 23 | #include <vnet/ip/ip4_packet.h> |
| 24 | #include <vnet/ip/ip6_packet.h> |
| 25 | #include <vnet/devices/virtio/virtio.h> |
| 26 | #include <vnet/devices/virtio/pci.h> |
| 27 | |
| 28 | #define PCI_VENDOR_ID_VIRTIO 0x1af4 |
| 29 | #define PCI_DEVICE_ID_VIRTIO_NIC 0x1000 |
| 30 | /* Doesn't support modern device */ |
| 31 | #define PCI_DEVICE_ID_VIRTIO_NIC_MODERN 0x1041 |
| 32 | |
| 33 | #define PCI_CAPABILITY_LIST 0x34 |
| 34 | #define PCI_CAP_ID_VNDR 0x09 |
| 35 | #define PCI_CAP_ID_MSIX 0x11 |
| 36 | |
| 37 | #define PCI_MSIX_ENABLE 0x8000 |
| 38 | |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 39 | #define PCI_CONFIG_SIZE(vif) ((vif->msix_enabled == VIRTIO_MSIX_ENABLED) ? \ |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 40 | 24 : 20) |
| 41 | |
| 42 | static pci_device_id_t virtio_pci_device_ids[] = { |
| 43 | { |
| 44 | .vendor_id = PCI_VENDOR_ID_VIRTIO, |
| 45 | .device_id = PCI_DEVICE_ID_VIRTIO_NIC}, |
| 46 | { |
| 47 | .vendor_id = PCI_VENDOR_ID_VIRTIO, |
| 48 | .device_id = PCI_DEVICE_ID_VIRTIO_NIC_MODERN}, |
| 49 | {0}, |
| 50 | }; |
| 51 | |
| 52 | static void |
| 53 | virtio_pci_legacy_read_config (vlib_main_t * vm, virtio_if_t * vif, void *dst, |
| 54 | int len, u32 addr) |
| 55 | { |
| 56 | u32 size = 0; |
| 57 | vlib_pci_dev_handle_t h = vif->pci_dev_handle; |
| 58 | |
| 59 | while (len > 0) |
| 60 | { |
| 61 | if (len >= 4) |
| 62 | { |
| 63 | size = 4; |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 64 | vlib_pci_read_io_u32 (vm, h, PCI_CONFIG_SIZE (vif) + addr, dst); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 65 | } |
| 66 | else if (len >= 2) |
| 67 | { |
| 68 | size = 2; |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 69 | vlib_pci_read_io_u16 (vm, h, PCI_CONFIG_SIZE (vif) + addr, dst); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 70 | } |
| 71 | else |
| 72 | { |
| 73 | size = 1; |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 74 | vlib_pci_read_io_u8 (vm, h, PCI_CONFIG_SIZE (vif) + addr, dst); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 75 | } |
| 76 | dst = (u8 *) dst + size; |
| 77 | addr += size; |
| 78 | len -= size; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | static void |
| 83 | virtio_pci_legacy_write_config (vlib_main_t * vm, virtio_if_t * vif, |
| 84 | void *src, int len, u32 addr) |
| 85 | { |
| 86 | u32 size = 0; |
| 87 | vlib_pci_dev_handle_t h = vif->pci_dev_handle; |
| 88 | |
| 89 | while (len > 0) |
| 90 | { |
| 91 | if (len >= 4) |
| 92 | { |
| 93 | size = 4; |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 94 | vlib_pci_write_io_u32 (vm, h, PCI_CONFIG_SIZE (vif) + addr, src); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 95 | } |
| 96 | else if (len >= 2) |
| 97 | { |
| 98 | size = 2; |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 99 | vlib_pci_write_io_u16 (vm, h, PCI_CONFIG_SIZE (vif) + addr, src); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 100 | } |
| 101 | else |
| 102 | { |
| 103 | size = 1; |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 104 | vlib_pci_write_io_u8 (vm, h, PCI_CONFIG_SIZE (vif) + addr, src); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 105 | } |
| 106 | src = (u8 *) src + size; |
| 107 | addr += size; |
| 108 | len -= size; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | static u64 |
| 113 | virtio_pci_legacy_get_features (vlib_main_t * vm, virtio_if_t * vif) |
| 114 | { |
| 115 | u32 features; |
| 116 | vlib_pci_read_io_u32 (vm, vif->pci_dev_handle, VIRTIO_PCI_HOST_FEATURES, |
| 117 | &features); |
| 118 | return features; |
| 119 | } |
| 120 | |
| 121 | static u32 |
| 122 | virtio_pci_legacy_set_features (vlib_main_t * vm, virtio_if_t * vif, |
| 123 | u64 features) |
| 124 | { |
| 125 | if ((features >> 32) != 0) |
| 126 | { |
| 127 | clib_warning ("only 32 bit features are allowed for legacy virtio!"); |
| 128 | } |
| 129 | u32 feature = 0, guest_features = (u32) features; |
| 130 | vlib_pci_write_io_u32 (vm, vif->pci_dev_handle, VIRTIO_PCI_GUEST_FEATURES, |
| 131 | &guest_features); |
| 132 | vlib_pci_read_io_u32 (vm, vif->pci_dev_handle, VIRTIO_PCI_GUEST_FEATURES, |
| 133 | &feature); |
| 134 | return feature; |
| 135 | } |
| 136 | |
| 137 | static u8 |
| 138 | virtio_pci_legacy_get_status (vlib_main_t * vm, virtio_if_t * vif) |
| 139 | { |
| 140 | u8 status = 0; |
| 141 | vlib_pci_read_io_u8 (vm, vif->pci_dev_handle, VIRTIO_PCI_STATUS, &status); |
| 142 | return status; |
| 143 | } |
| 144 | |
| 145 | static void |
| 146 | virtio_pci_legacy_set_status (vlib_main_t * vm, virtio_if_t * vif, u8 status) |
| 147 | { |
| 148 | if (status != VIRTIO_CONFIG_STATUS_RESET) |
| 149 | status |= virtio_pci_legacy_get_status (vm, vif); |
| 150 | vlib_pci_write_io_u8 (vm, vif->pci_dev_handle, VIRTIO_PCI_STATUS, &status); |
| 151 | } |
| 152 | |
| 153 | static u8 |
| 154 | virtio_pci_legacy_reset (vlib_main_t * vm, virtio_if_t * vif) |
| 155 | { |
| 156 | virtio_pci_legacy_set_status (vm, vif, VIRTIO_CONFIG_STATUS_RESET); |
| 157 | return virtio_pci_legacy_get_status (vm, vif); |
| 158 | } |
| 159 | |
| 160 | static u8 |
| 161 | virtio_pci_legacy_get_isr (vlib_main_t * vm, virtio_if_t * vif) |
| 162 | { |
| 163 | u8 isr = 0; |
| 164 | vlib_pci_read_io_u8 (vm, vif->pci_dev_handle, VIRTIO_PCI_ISR, &isr); |
| 165 | return isr; |
| 166 | } |
| 167 | |
| 168 | static u16 |
| 169 | virtio_pci_legacy_get_queue_num (vlib_main_t * vm, virtio_if_t * vif, |
| 170 | u16 queue_id) |
| 171 | { |
| 172 | u16 queue_num = 0; |
| 173 | vlib_pci_write_io_u16 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_SEL, |
| 174 | &queue_id); |
| 175 | vlib_pci_read_io_u16 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_NUM, |
| 176 | &queue_num); |
| 177 | return queue_num; |
| 178 | } |
| 179 | |
Mohsin Kazmi | 43b512c | 2019-04-30 17:25:26 +0200 | [diff] [blame] | 180 | static int |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 181 | virtio_pci_legacy_setup_queue (vlib_main_t * vm, virtio_if_t * vif, |
| 182 | u16 queue_id, void *p) |
| 183 | { |
| 184 | u64 addr = vlib_physmem_get_pa (vm, p) >> VIRTIO_PCI_QUEUE_ADDR_SHIFT; |
Mohsin Kazmi | 43b512c | 2019-04-30 17:25:26 +0200 | [diff] [blame] | 185 | u32 addr2 = 0; |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 186 | vlib_pci_write_io_u16 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_SEL, |
| 187 | &queue_id); |
| 188 | vlib_pci_write_io_u32 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_PFN, |
| 189 | (u32 *) & addr); |
Mohsin Kazmi | 43b512c | 2019-04-30 17:25:26 +0200 | [diff] [blame] | 190 | vlib_pci_read_io_u32 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_PFN, |
| 191 | &addr2); |
| 192 | if ((u32) addr == addr2) |
| 193 | return 0; |
| 194 | return 1; |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | static void |
| 198 | virtio_pci_legacy_del_queue (vlib_main_t * vm, virtio_if_t * vif, |
| 199 | u16 queue_id) |
| 200 | { |
| 201 | u32 src = 0; |
| 202 | vlib_pci_write_io_u16 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_SEL, |
| 203 | &queue_id); |
| 204 | vlib_pci_write_io_u32 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_PFN, &src); |
| 205 | } |
| 206 | |
| 207 | inline void |
| 208 | virtio_pci_legacy_notify_queue (vlib_main_t * vm, virtio_if_t * vif, |
| 209 | u16 queue_id) |
| 210 | { |
| 211 | vlib_pci_write_io_u16 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_NOTIFY, |
| 212 | &queue_id); |
| 213 | } |
| 214 | |
| 215 | /* Enable one vector (0) for Link State Intrerrupt */ |
| 216 | static u16 |
| 217 | virtio_pci_legacy_set_config_irq (vlib_main_t * vm, virtio_if_t * vif, |
| 218 | u16 vec) |
| 219 | { |
| 220 | vlib_pci_write_io_u16 (vm, vif->pci_dev_handle, VIRTIO_MSI_CONFIG_VECTOR, |
| 221 | &vec); |
| 222 | vlib_pci_read_io_u16 (vm, vif->pci_dev_handle, VIRTIO_MSI_CONFIG_VECTOR, |
| 223 | &vec); |
| 224 | return vec; |
| 225 | } |
| 226 | |
| 227 | static u16 |
| 228 | virtio_pci_legacy_set_queue_irq (vlib_main_t * vm, virtio_if_t * vif, u16 vec, |
| 229 | u16 queue_id) |
| 230 | { |
| 231 | vlib_pci_write_io_u16 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_SEL, |
| 232 | &queue_id); |
| 233 | vlib_pci_write_io_u16 (vm, vif->pci_dev_handle, VIRTIO_MSI_QUEUE_VECTOR, |
| 234 | &vec); |
| 235 | vlib_pci_read_io_u16 (vm, vif->pci_dev_handle, VIRTIO_MSI_QUEUE_VECTOR, |
| 236 | &vec); |
| 237 | return vec; |
| 238 | } |
| 239 | |
| 240 | static u32 |
| 241 | virtio_pci_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hw, |
| 242 | u32 flags) |
| 243 | { |
| 244 | return 0; |
| 245 | } |
| 246 | |
| 247 | static clib_error_t * |
| 248 | virtio_pci_get_max_virtqueue_pairs (vlib_main_t * vm, virtio_if_t * vif) |
| 249 | { |
| 250 | virtio_net_config_t config; |
| 251 | clib_error_t *error = 0; |
| 252 | u16 max_queue_pairs = 1; |
| 253 | |
| 254 | if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_MQ)) |
| 255 | { |
| 256 | virtio_pci_legacy_read_config (vm, vif, &config.max_virtqueue_pairs, |
Mohsin Kazmi | 46f877e | 2019-04-08 10:36:18 +0200 | [diff] [blame] | 257 | sizeof (config.max_virtqueue_pairs), |
| 258 | STRUCT_OFFSET_OF (virtio_net_config_t, |
| 259 | max_virtqueue_pairs)); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 260 | max_queue_pairs = config.max_virtqueue_pairs; |
| 261 | } |
| 262 | |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 263 | virtio_log_debug (vif, "max queue pair is %x", max_queue_pairs); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 264 | if (max_queue_pairs < 1 || max_queue_pairs > 0x8000) |
Mohsin Kazmi | 46f877e | 2019-04-08 10:36:18 +0200 | [diff] [blame] | 265 | return clib_error_return (error, "max queue pair is %x", max_queue_pairs); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 266 | |
| 267 | vif->max_queue_pairs = max_queue_pairs; |
| 268 | return error; |
| 269 | } |
| 270 | |
| 271 | static void |
| 272 | virtio_pci_set_mac (vlib_main_t * vm, virtio_if_t * vif) |
| 273 | { |
| 274 | virtio_pci_legacy_write_config (vm, vif, vif->mac_addr, |
| 275 | sizeof (vif->mac_addr), 0); |
| 276 | } |
| 277 | |
| 278 | static u32 |
| 279 | virtio_pci_get_mac (vlib_main_t * vm, virtio_if_t * vif) |
| 280 | { |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 281 | if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_MAC)) |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 282 | { |
| 283 | virtio_pci_legacy_read_config (vm, vif, vif->mac_addr, |
| 284 | sizeof (vif->mac_addr), 0); |
| 285 | return 0; |
| 286 | } |
| 287 | return 1; |
| 288 | } |
| 289 | |
| 290 | static u16 |
| 291 | virtio_pci_is_link_up (vlib_main_t * vm, virtio_if_t * vif) |
| 292 | { |
| 293 | /* |
| 294 | * Minimal driver: assumes link is up |
| 295 | */ |
| 296 | u16 status = 1; |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 297 | if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_STATUS)) |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 298 | virtio_pci_legacy_read_config (vm, vif, &status, sizeof (status), /* mac */ |
Mohsin Kazmi | 46f877e | 2019-04-08 10:36:18 +0200 | [diff] [blame] | 299 | STRUCT_OFFSET_OF (virtio_net_config_t, |
| 300 | status)); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 301 | return status; |
| 302 | } |
| 303 | |
| 304 | static void |
| 305 | virtio_pci_irq_0_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h, u16 line) |
| 306 | { |
| 307 | vnet_main_t *vnm = vnet_get_main (); |
Mohsin Kazmi | 33cc5cf | 2019-01-21 15:19:39 +0000 | [diff] [blame] | 308 | virtio_main_t *vim = &virtio_main; |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 309 | uword pd = vlib_pci_get_private_data (vm, h); |
Mohsin Kazmi | 33cc5cf | 2019-01-21 15:19:39 +0000 | [diff] [blame] | 310 | virtio_if_t *vif = pool_elt_at_index (vim->interfaces, pd); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 311 | u16 qid = line; |
| 312 | |
| 313 | vnet_device_input_set_interrupt_pending (vnm, vif->hw_if_index, qid); |
| 314 | } |
| 315 | |
| 316 | static void |
| 317 | virtio_pci_irq_1_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h, u16 line) |
| 318 | { |
| 319 | vnet_main_t *vnm = vnet_get_main (); |
Mohsin Kazmi | 33cc5cf | 2019-01-21 15:19:39 +0000 | [diff] [blame] | 320 | virtio_main_t *vim = &virtio_main; |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 321 | uword pd = vlib_pci_get_private_data (vm, h); |
Mohsin Kazmi | 33cc5cf | 2019-01-21 15:19:39 +0000 | [diff] [blame] | 322 | virtio_if_t *vif = pool_elt_at_index (vim->interfaces, pd); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 323 | |
| 324 | if (virtio_pci_is_link_up (vm, vif) & VIRTIO_NET_S_LINK_UP) |
| 325 | { |
| 326 | vif->flags |= VIRTIO_IF_FLAG_ADMIN_UP; |
| 327 | vnet_hw_interface_set_flags (vnm, vif->hw_if_index, |
| 328 | VNET_HW_INTERFACE_FLAG_LINK_UP); |
| 329 | } |
| 330 | else |
| 331 | { |
| 332 | vif->flags &= ~VIRTIO_IF_FLAG_ADMIN_UP; |
| 333 | vnet_hw_interface_set_flags (vnm, vif->hw_if_index, 0); |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | static void |
| 338 | virtio_pci_irq_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h) |
| 339 | { |
Mohsin Kazmi | 33cc5cf | 2019-01-21 15:19:39 +0000 | [diff] [blame] | 340 | virtio_main_t *vim = &virtio_main; |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 341 | uword pd = vlib_pci_get_private_data (vm, h); |
Mohsin Kazmi | 33cc5cf | 2019-01-21 15:19:39 +0000 | [diff] [blame] | 342 | virtio_if_t *vif = pool_elt_at_index (vim->interfaces, pd); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 343 | u8 isr = 0; |
| 344 | u16 line = 0; |
| 345 | |
| 346 | isr = virtio_pci_legacy_get_isr (vm, vif); |
| 347 | |
| 348 | /* |
| 349 | * If the lower bit is set: look through the used rings of |
| 350 | * all virtqueues for the device, to see if any progress has |
| 351 | * been made by the device which requires servicing. |
| 352 | */ |
| 353 | if (isr & VIRTIO_PCI_ISR_INTR) |
| 354 | virtio_pci_irq_0_handler (vm, h, line); |
| 355 | |
| 356 | if (isr & VIRTIO_PCI_ISR_CONFIG) |
| 357 | virtio_pci_irq_1_handler (vm, h, line); |
| 358 | } |
| 359 | |
| 360 | inline void |
| 361 | device_status (vlib_main_t * vm, virtio_if_t * vif) |
| 362 | { |
| 363 | struct status_struct |
| 364 | { |
| 365 | u8 bit; |
| 366 | char *str; |
| 367 | }; |
| 368 | struct status_struct *status_entry; |
| 369 | static struct status_struct status_array[] = { |
| 370 | #define _(s,b) { .str = #s, .bit = b, }, |
| 371 | foreach_virtio_config_status_flags |
| 372 | #undef _ |
| 373 | {.str = NULL} |
| 374 | }; |
| 375 | |
| 376 | vlib_cli_output (vm, " status 0x%x", vif->status); |
| 377 | |
| 378 | status_entry = (struct status_struct *) &status_array; |
| 379 | while (status_entry->str) |
| 380 | { |
| 381 | if (vif->status & status_entry->bit) |
| 382 | vlib_cli_output (vm, " %s (%x)", status_entry->str, |
| 383 | status_entry->bit); |
| 384 | status_entry++; |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | inline void |
| 389 | debug_device_config_space (vlib_main_t * vm, virtio_if_t * vif) |
| 390 | { |
| 391 | u32 data_u32; |
| 392 | u16 data_u16; |
| 393 | u8 data_u8; |
| 394 | vlib_pci_read_io_u32 (vm, vif->pci_dev_handle, VIRTIO_PCI_HOST_FEATURES, |
| 395 | &data_u32); |
| 396 | vlib_cli_output (vm, "remote features 0x%lx", data_u32); |
| 397 | vlib_pci_read_io_u32 (vm, vif->pci_dev_handle, VIRTIO_PCI_GUEST_FEATURES, |
| 398 | &data_u32); |
| 399 | vlib_cli_output (vm, "guest features 0x%lx", data_u32); |
| 400 | vlib_pci_read_io_u32 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_PFN, |
| 401 | &data_u32); |
| 402 | vlib_cli_output (vm, "queue address 0x%lx", data_u32); |
| 403 | vlib_pci_read_io_u16 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_NUM, |
| 404 | &data_u16); |
| 405 | vlib_cli_output (vm, "queue size 0x%x", data_u16); |
| 406 | vlib_pci_read_io_u16 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_SEL, |
| 407 | &data_u16); |
| 408 | vlib_cli_output (vm, "queue select 0x%x", data_u16); |
| 409 | vlib_pci_read_io_u16 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_NOTIFY, |
| 410 | &data_u16); |
| 411 | vlib_cli_output (vm, "queue notify 0x%x", data_u16); |
| 412 | vlib_pci_read_io_u8 (vm, vif->pci_dev_handle, VIRTIO_PCI_STATUS, &data_u8); |
| 413 | vlib_cli_output (vm, "status 0x%x", data_u8); |
| 414 | vlib_pci_read_io_u8 (vm, vif->pci_dev_handle, VIRTIO_PCI_ISR, &data_u8); |
| 415 | vlib_cli_output (vm, "isr 0x%x", data_u8); |
| 416 | |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 417 | if (vif->msix_enabled == VIRTIO_MSIX_ENABLED) |
| 418 | { |
| 419 | vlib_pci_read_io_u16 (vm, vif->pci_dev_handle, VIRTIO_MSI_CONFIG_VECTOR, |
| 420 | &data_u16); |
| 421 | vlib_cli_output (vm, "config vector 0x%x", data_u16); |
| 422 | u16 queue_id = 0; |
| 423 | vlib_pci_write_io_u16 (vm, vif->pci_dev_handle, VIRTIO_PCI_QUEUE_SEL, |
| 424 | &queue_id); |
| 425 | vlib_pci_read_io_u16 (vm, vif->pci_dev_handle, VIRTIO_MSI_QUEUE_VECTOR, |
| 426 | &data_u16); |
| 427 | vlib_cli_output (vm, "queue vector for queue (0) 0x%x", data_u16); |
| 428 | } |
| 429 | |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 430 | u8 mac[6]; |
| 431 | virtio_pci_legacy_read_config (vm, vif, mac, sizeof (mac), 0); |
| 432 | vlib_cli_output (vm, "mac %U", format_ethernet_address, mac); |
| 433 | virtio_pci_legacy_read_config (vm, vif, &data_u16, sizeof (u16), /* offset to status */ |
| 434 | 6); |
| 435 | vlib_cli_output (vm, "link up/down status 0x%x", data_u16); |
| 436 | virtio_pci_legacy_read_config (vm, vif, &data_u16, sizeof (u16), |
| 437 | /* offset to max_virtqueue */ 8); |
| 438 | vlib_cli_output (vm, "num of virtqueue 0x%x", data_u16); |
| 439 | virtio_pci_legacy_read_config (vm, vif, &data_u16, sizeof (u16), /* offset to mtu */ |
| 440 | 10); |
| 441 | vlib_cli_output (vm, "mtu 0x%x", data_u16); |
| 442 | |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 443 | u32 i = PCI_CONFIG_SIZE (vif) + 12, a = 4; |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 444 | i += a; |
| 445 | i &= ~a; |
| 446 | for (; i < 64; i += 4) |
| 447 | { |
| 448 | u32 data = 0; |
| 449 | vlib_pci_read_io_u32 (vm, vif->pci_dev_handle, i, &data); |
| 450 | vlib_cli_output (vm, "0x%lx", data); |
| 451 | } |
| 452 | } |
| 453 | |
Mohsin Kazmi | 0549378 | 2019-05-01 14:26:17 +0200 | [diff] [blame] | 454 | struct virtio_ctrl_msg |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 455 | { |
| 456 | struct virtio_net_ctrl_hdr ctrl; |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 457 | virtio_net_ctrl_ack status; |
Mohsin Kazmi | 0549378 | 2019-05-01 14:26:17 +0200 | [diff] [blame] | 458 | u8 data[1024]; |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 459 | }; |
| 460 | |
| 461 | static int |
Mohsin Kazmi | 0549378 | 2019-05-01 14:26:17 +0200 | [diff] [blame] | 462 | virtio_pci_send_ctrl_msg (vlib_main_t * vm, virtio_if_t * vif, |
| 463 | struct virtio_ctrl_msg *data, u32 len) |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 464 | { |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 465 | virtio_vring_t *vring = vif->cxq_vring; |
Mohsin Kazmi | 0549378 | 2019-05-01 14:26:17 +0200 | [diff] [blame] | 466 | virtio_net_ctrl_ack status = VIRTIO_NET_ERR; |
| 467 | struct virtio_ctrl_msg result; |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 468 | u32 buffer_index; |
| 469 | vlib_buffer_t *b; |
| 470 | u16 used, next, avail; |
| 471 | u16 sz = vring->size; |
| 472 | u16 mask = sz - 1; |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 473 | |
| 474 | used = vring->desc_in_use; |
| 475 | next = vring->desc_next; |
| 476 | avail = vring->avail->idx; |
| 477 | struct vring_desc *d = &vring->desc[next]; |
| 478 | |
| 479 | if (vlib_buffer_alloc (vm, &buffer_index, 1)) |
| 480 | b = vlib_get_buffer (vm, buffer_index); |
| 481 | else |
| 482 | return VIRTIO_NET_ERR; |
| 483 | /* |
| 484 | * current_data may not be initialized with 0 and may contain |
| 485 | * previous offset. |
| 486 | */ |
| 487 | b->current_data = 0; |
Mohsin Kazmi | 0549378 | 2019-05-01 14:26:17 +0200 | [diff] [blame] | 488 | clib_memcpy (vlib_buffer_get_current (b), data, |
| 489 | sizeof (struct virtio_ctrl_msg)); |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 490 | d->flags = VRING_DESC_F_NEXT; |
| 491 | d->addr = vlib_buffer_get_current_pa (vm, b); |
| 492 | d->len = sizeof (struct virtio_net_ctrl_hdr); |
| 493 | vring->avail->ring[avail & mask] = next; |
| 494 | avail++; |
| 495 | next = (next + 1) & mask; |
| 496 | d->next = next; |
| 497 | used++; |
| 498 | |
| 499 | d = &vring->desc[next]; |
| 500 | d->flags = VRING_DESC_F_NEXT; |
| 501 | d->addr = vlib_buffer_get_current_pa (vm, b) + |
Mohsin Kazmi | 0549378 | 2019-05-01 14:26:17 +0200 | [diff] [blame] | 502 | STRUCT_OFFSET_OF (struct virtio_ctrl_msg, data); |
| 503 | d->len = len; |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 504 | next = (next + 1) & mask; |
| 505 | d->next = next; |
| 506 | used++; |
| 507 | |
| 508 | d = &vring->desc[next]; |
| 509 | d->flags = VRING_DESC_F_WRITE; |
| 510 | d->addr = vlib_buffer_get_current_pa (vm, b) + |
Mohsin Kazmi | 0549378 | 2019-05-01 14:26:17 +0200 | [diff] [blame] | 511 | STRUCT_OFFSET_OF (struct virtio_ctrl_msg, status); |
| 512 | d->len = sizeof (data->status); |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 513 | next = (next + 1) & mask; |
| 514 | used++; |
| 515 | |
| 516 | CLIB_MEMORY_STORE_BARRIER (); |
| 517 | vring->avail->idx = avail; |
| 518 | vring->desc_next = next; |
| 519 | vring->desc_in_use = used; |
| 520 | |
| 521 | if ((vring->used->flags & VIRTIO_RING_FLAG_MASK_INT) == 0) |
| 522 | { |
| 523 | virtio_kick (vm, vring, vif); |
| 524 | } |
| 525 | |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 526 | u16 last = vring->last_used_idx, n_left = 0; |
| 527 | n_left = vring->used->idx - last; |
| 528 | |
| 529 | while (n_left) |
| 530 | { |
| 531 | struct vring_used_elem *e = &vring->used->ring[last & mask]; |
| 532 | u16 slot = e->id; |
| 533 | |
| 534 | d = &vring->desc[slot]; |
| 535 | while (d->flags & VRING_DESC_F_NEXT) |
| 536 | { |
| 537 | used--; |
| 538 | slot = d->next; |
| 539 | d = &vring->desc[slot]; |
| 540 | } |
| 541 | used--; |
| 542 | last++; |
| 543 | n_left--; |
| 544 | } |
| 545 | vring->desc_in_use = used; |
| 546 | vring->last_used_idx = last; |
| 547 | |
| 548 | CLIB_MEMORY_BARRIER (); |
| 549 | clib_memcpy (&result, vlib_buffer_get_current (b), |
Mohsin Kazmi | 0549378 | 2019-05-01 14:26:17 +0200 | [diff] [blame] | 550 | sizeof (struct virtio_ctrl_msg)); |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 551 | virtio_log_debug (vif, "ctrl-queue: status %u", result.status); |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 552 | status = result.status; |
| 553 | vlib_buffer_free (vm, &buffer_index, 1); |
| 554 | return status; |
| 555 | } |
| 556 | |
Mohsin Kazmi | 0549378 | 2019-05-01 14:26:17 +0200 | [diff] [blame] | 557 | static int |
Mohsin Kazmi | bbd6b74 | 2019-05-02 13:54:59 +0200 | [diff] [blame] | 558 | virtio_pci_enable_gso (vlib_main_t * vm, virtio_if_t * vif) |
| 559 | { |
Mohsin Kazmi | bbd6b74 | 2019-05-02 13:54:59 +0200 | [diff] [blame] | 560 | struct virtio_ctrl_msg gso_hdr; |
| 561 | virtio_net_ctrl_ack status = VIRTIO_NET_ERR; |
| 562 | |
| 563 | gso_hdr.ctrl.class = VIRTIO_NET_CTRL_GUEST_OFFLOADS; |
| 564 | gso_hdr.ctrl.cmd = VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET; |
| 565 | gso_hdr.status = VIRTIO_NET_ERR; |
| 566 | u64 offloads = VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_CSUM) |
| 567 | | VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_TSO4) |
| 568 | | VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_TSO6) |
| 569 | | VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_UFO); |
| 570 | clib_memcpy (gso_hdr.data, &offloads, sizeof (offloads)); |
| 571 | |
| 572 | status = virtio_pci_send_ctrl_msg (vm, vif, &gso_hdr, sizeof (offloads)); |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 573 | virtio_log_debug (vif, "enable gso"); |
Mohsin Kazmi | bbd6b74 | 2019-05-02 13:54:59 +0200 | [diff] [blame] | 574 | return status; |
| 575 | } |
| 576 | |
| 577 | static int |
Mohsin Kazmi | 0549378 | 2019-05-01 14:26:17 +0200 | [diff] [blame] | 578 | virtio_pci_enable_multiqueue (vlib_main_t * vm, virtio_if_t * vif, |
| 579 | u16 num_queues) |
| 580 | { |
Mohsin Kazmi | 0549378 | 2019-05-01 14:26:17 +0200 | [diff] [blame] | 581 | struct virtio_ctrl_msg mq_hdr; |
| 582 | virtio_net_ctrl_ack status = VIRTIO_NET_ERR; |
| 583 | |
| 584 | mq_hdr.ctrl.class = VIRTIO_NET_CTRL_MQ; |
| 585 | mq_hdr.ctrl.cmd = VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET; |
| 586 | mq_hdr.status = VIRTIO_NET_ERR; |
| 587 | clib_memcpy (mq_hdr.data, &num_queues, sizeof (num_queues)); |
| 588 | |
| 589 | status = virtio_pci_send_ctrl_msg (vm, vif, &mq_hdr, sizeof (num_queues)); |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 590 | virtio_log_debug (vif, "multi-queue enable %u queues", num_queues); |
Mohsin Kazmi | 0549378 | 2019-05-01 14:26:17 +0200 | [diff] [blame] | 591 | return status; |
| 592 | } |
| 593 | |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 594 | static u8 |
| 595 | virtio_pci_queue_size_valid (u16 qsz) |
| 596 | { |
| 597 | if (qsz < 64 || qsz > 4096) |
| 598 | return 0; |
| 599 | if ((qsz % 64) != 0) |
| 600 | return 0; |
| 601 | return 1; |
| 602 | } |
| 603 | |
| 604 | clib_error_t * |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 605 | virtio_pci_control_vring_init (vlib_main_t * vm, virtio_if_t * vif, |
| 606 | u16 queue_num) |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 607 | { |
| 608 | clib_error_t *error = 0; |
| 609 | u16 queue_size = 0; |
| 610 | virtio_vring_t *vring; |
| 611 | struct vring vr; |
| 612 | u32 i = 0; |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 613 | void *ptr = NULL; |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 614 | |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 615 | queue_size = virtio_pci_legacy_get_queue_num (vm, vif, queue_num); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 616 | if (!virtio_pci_queue_size_valid (queue_size)) |
| 617 | clib_warning ("queue size is not valid"); |
| 618 | |
| 619 | if (!is_pow2 (queue_size)) |
| 620 | return clib_error_return (0, "ring size must be power of 2"); |
| 621 | |
| 622 | if (queue_size > 32768) |
| 623 | return clib_error_return (0, "ring size must be 32768 or lower"); |
| 624 | |
| 625 | if (queue_size == 0) |
| 626 | queue_size = 256; |
| 627 | |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 628 | vec_validate_aligned (vif->cxq_vring, 0, CLIB_CACHE_LINE_BYTES); |
| 629 | vring = vec_elt_at_index (vif->cxq_vring, 0); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 630 | i = vring_size (queue_size, VIRTIO_PCI_VRING_ALIGN); |
| 631 | i = round_pow2 (i, VIRTIO_PCI_VRING_ALIGN); |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 632 | ptr = |
| 633 | vlib_physmem_alloc_aligned_on_numa (vm, i, VIRTIO_PCI_VRING_ALIGN, |
| 634 | vif->numa_node); |
| 635 | if (!ptr) |
| 636 | return vlib_physmem_last_error (vm); |
| 637 | clib_memset (ptr, 0, i); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 638 | vring_init (&vr, queue_size, ptr, VIRTIO_PCI_VRING_ALIGN); |
| 639 | vring->desc = vr.desc; |
| 640 | vring->avail = vr.avail; |
| 641 | vring->used = vr.used; |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 642 | vring->queue_id = queue_num; |
| 643 | vring->avail->flags = VIRTIO_RING_FLAG_MASK_INT; |
| 644 | |
| 645 | ASSERT (vring->buffers == 0); |
| 646 | |
| 647 | vring->size = queue_size; |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 648 | virtio_log_debug (vif, "control-queue: number %u, size %u", queue_num, |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 649 | queue_size); |
| 650 | virtio_pci_legacy_setup_queue (vm, vif, queue_num, ptr); |
| 651 | vring->kick_fd = -1; |
| 652 | |
| 653 | return error; |
| 654 | } |
| 655 | |
| 656 | clib_error_t * |
| 657 | virtio_pci_vring_init (vlib_main_t * vm, virtio_if_t * vif, u16 queue_num) |
| 658 | { |
| 659 | clib_error_t *error = 0; |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 660 | vlib_thread_main_t *vtm = vlib_get_thread_main (); |
| 661 | u16 queue_size = 0; |
| 662 | virtio_vring_t *vring; |
| 663 | struct vring vr; |
| 664 | u32 i = 0; |
| 665 | void *ptr = NULL; |
| 666 | |
| 667 | queue_size = virtio_pci_legacy_get_queue_num (vm, vif, queue_num); |
| 668 | if (!virtio_pci_queue_size_valid (queue_size)) |
| 669 | clib_warning ("queue size is not valid"); |
| 670 | |
| 671 | if (!is_pow2 (queue_size)) |
| 672 | return clib_error_return (0, "ring size must be power of 2"); |
| 673 | |
| 674 | if (queue_size > 32768) |
| 675 | return clib_error_return (0, "ring size must be 32768 or lower"); |
| 676 | |
| 677 | if (queue_size == 0) |
| 678 | queue_size = 256; |
| 679 | |
| 680 | if (queue_num % 2) |
| 681 | { |
| 682 | if (TX_QUEUE_ACCESS (queue_num) > vtm->n_vlib_mains) |
| 683 | return error; |
| 684 | vec_validate_aligned (vif->txq_vrings, TX_QUEUE_ACCESS (queue_num), |
| 685 | CLIB_CACHE_LINE_BYTES); |
| 686 | vring = vec_elt_at_index (vif->txq_vrings, TX_QUEUE_ACCESS (queue_num)); |
| 687 | clib_spinlock_init (&vring->lockp); |
| 688 | } |
| 689 | else |
| 690 | { |
| 691 | vec_validate_aligned (vif->rxq_vrings, RX_QUEUE_ACCESS (queue_num), |
| 692 | CLIB_CACHE_LINE_BYTES); |
| 693 | vring = vec_elt_at_index (vif->rxq_vrings, RX_QUEUE_ACCESS (queue_num)); |
| 694 | } |
| 695 | i = vring_size (queue_size, VIRTIO_PCI_VRING_ALIGN); |
| 696 | i = round_pow2 (i, VIRTIO_PCI_VRING_ALIGN); |
| 697 | ptr = |
| 698 | vlib_physmem_alloc_aligned_on_numa (vm, i, VIRTIO_PCI_VRING_ALIGN, |
| 699 | vif->numa_node); |
| 700 | if (!ptr) |
| 701 | return vlib_physmem_last_error (vm); |
| 702 | clib_memset (ptr, 0, i); |
| 703 | vring_init (&vr, queue_size, ptr, VIRTIO_PCI_VRING_ALIGN); |
| 704 | vring->desc = vr.desc; |
| 705 | vring->avail = vr.avail; |
| 706 | vring->used = vr.used; |
| 707 | vring->queue_id = queue_num; |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 708 | vring->avail->flags = VIRTIO_RING_FLAG_MASK_INT; |
| 709 | |
| 710 | ASSERT (vring->buffers == 0); |
| 711 | vec_validate_aligned (vring->buffers, queue_size, CLIB_CACHE_LINE_BYTES); |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 712 | if (queue_num % 2) |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 713 | { |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 714 | virtio_log_debug (vif, "tx-queue: number %u, size %u", queue_num, |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 715 | queue_size); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 716 | } |
| 717 | else |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 718 | { |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 719 | virtio_log_debug (vif, "rx-queue: number %u, size %u", queue_num, |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 720 | queue_size); |
| 721 | } |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 722 | vring->size = queue_size; |
Mohsin Kazmi | 43b512c | 2019-04-30 17:25:26 +0200 | [diff] [blame] | 723 | if (virtio_pci_legacy_setup_queue (vm, vif, queue_num, ptr)) |
| 724 | return clib_error_return (0, "error in queue address setup"); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 725 | |
Mohsin Kazmi | 43b512c | 2019-04-30 17:25:26 +0200 | [diff] [blame] | 726 | vring->kick_fd = -1; |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 727 | return error; |
| 728 | } |
| 729 | |
| 730 | static void |
| 731 | virtio_negotiate_features (vlib_main_t * vm, virtio_if_t * vif, |
| 732 | u64 req_features) |
| 733 | { |
| 734 | /* |
| 735 | * if features are not requested |
| 736 | * default: all supported features |
| 737 | */ |
Mohsin Kazmi | bbd6b74 | 2019-05-02 13:54:59 +0200 | [diff] [blame] | 738 | u64 supported_features = VIRTIO_FEATURE (VIRTIO_NET_F_CSUM) |
| 739 | | VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_CSUM) |
| 740 | | VIRTIO_FEATURE (VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) |
| 741 | | VIRTIO_FEATURE (VIRTIO_NET_F_MTU) |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 742 | | VIRTIO_FEATURE (VIRTIO_NET_F_MAC) |
Mohsin Kazmi | bbd6b74 | 2019-05-02 13:54:59 +0200 | [diff] [blame] | 743 | | VIRTIO_FEATURE (VIRTIO_NET_F_GSO) |
| 744 | | VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_TSO4) |
| 745 | | VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_TSO6) |
| 746 | | VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_UFO) |
| 747 | | VIRTIO_FEATURE (VIRTIO_NET_F_HOST_TSO4) |
| 748 | | VIRTIO_FEATURE (VIRTIO_NET_F_HOST_TSO6) |
| 749 | | VIRTIO_FEATURE (VIRTIO_NET_F_HOST_UFO) |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 750 | | VIRTIO_FEATURE (VIRTIO_NET_F_MRG_RXBUF) |
| 751 | | VIRTIO_FEATURE (VIRTIO_NET_F_STATUS) |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 752 | | VIRTIO_FEATURE (VIRTIO_NET_F_CTRL_VQ) |
| 753 | | VIRTIO_FEATURE (VIRTIO_NET_F_MQ) |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 754 | | VIRTIO_FEATURE (VIRTIO_F_NOTIFY_ON_EMPTY) |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 755 | | VIRTIO_FEATURE (VIRTIO_F_ANY_LAYOUT) |
| 756 | | VIRTIO_FEATURE (VIRTIO_RING_F_INDIRECT_DESC); |
| 757 | |
| 758 | if (req_features == 0) |
| 759 | { |
| 760 | req_features = supported_features; |
| 761 | } |
| 762 | |
| 763 | vif->features = req_features & vif->remote_features & supported_features; |
| 764 | |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 765 | if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_MTU)) |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 766 | { |
| 767 | virtio_net_config_t config; |
| 768 | virtio_pci_legacy_read_config (vm, vif, &config.mtu, |
Mohsin Kazmi | 46f877e | 2019-04-08 10:36:18 +0200 | [diff] [blame] | 769 | sizeof (config.mtu), |
| 770 | STRUCT_OFFSET_OF (virtio_net_config_t, |
| 771 | mtu)); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 772 | if (config.mtu < 64) |
| 773 | vif->features &= ~VIRTIO_FEATURE (VIRTIO_NET_F_MTU); |
| 774 | } |
| 775 | |
| 776 | vif->features = virtio_pci_legacy_set_features (vm, vif, vif->features); |
| 777 | } |
| 778 | |
| 779 | void |
| 780 | virtio_pci_read_device_feature (vlib_main_t * vm, virtio_if_t * vif) |
| 781 | { |
| 782 | vif->remote_features = virtio_pci_legacy_get_features (vm, vif); |
| 783 | } |
| 784 | |
| 785 | int |
| 786 | virtio_pci_reset_device (vlib_main_t * vm, virtio_if_t * vif) |
| 787 | { |
| 788 | u8 status = 0; |
| 789 | |
| 790 | /* |
| 791 | * Reset the device |
| 792 | */ |
| 793 | status = virtio_pci_legacy_reset (vm, vif); |
| 794 | |
| 795 | /* |
| 796 | * Set the Acknowledge status bit |
| 797 | */ |
| 798 | virtio_pci_legacy_set_status (vm, vif, VIRTIO_CONFIG_STATUS_ACK); |
| 799 | |
| 800 | /* |
| 801 | * Set the Driver status bit |
| 802 | */ |
| 803 | virtio_pci_legacy_set_status (vm, vif, VIRTIO_CONFIG_STATUS_DRIVER); |
| 804 | |
| 805 | /* |
| 806 | * Read the status and verify it |
| 807 | */ |
| 808 | status = virtio_pci_legacy_get_status (vm, vif); |
| 809 | if (! |
| 810 | ((status & VIRTIO_CONFIG_STATUS_ACK) |
| 811 | && (status & VIRTIO_CONFIG_STATUS_DRIVER))) |
| 812 | return -1; |
| 813 | vif->status = status; |
| 814 | |
| 815 | return 0; |
| 816 | } |
| 817 | |
| 818 | clib_error_t * |
| 819 | virtio_pci_read_caps (vlib_main_t * vm, virtio_if_t * vif) |
| 820 | { |
| 821 | clib_error_t *error = 0; |
| 822 | struct virtio_pci_cap cap; |
Mohsin Kazmi | 22c0ece | 2019-01-28 19:30:21 +0000 | [diff] [blame] | 823 | u8 pos, common_cfg = 0, notify_base = 0, dev_cfg = 0, isr = 0, pci_cfg = 0; |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 824 | vlib_pci_dev_handle_t h = vif->pci_dev_handle; |
| 825 | |
| 826 | if ((error = vlib_pci_read_config_u8 (vm, h, PCI_CAPABILITY_LIST, &pos))) |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 827 | { |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 828 | virtio_log_error (vif, "error in reading capabilty list position"); |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 829 | clib_error_return (error, "error in reading capabilty list position"); |
| 830 | } |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 831 | while (pos) |
| 832 | { |
| 833 | if ((error = |
| 834 | vlib_pci_read_write_config (vm, h, VLIB_READ, pos, &cap, |
| 835 | sizeof (cap)))) |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 836 | { |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 837 | virtio_log_error (vif, "%s [%2x]", |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 838 | "error in reading the capability at", pos); |
| 839 | clib_error_return (error, |
| 840 | "error in reading the capability at [%2x]", pos); |
| 841 | } |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 842 | |
| 843 | if (cap.cap_vndr == PCI_CAP_ID_MSIX) |
| 844 | { |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 845 | u16 flags, table_size, table_size_mask = 0x07FF; |
| 846 | |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 847 | if ((error = |
| 848 | vlib_pci_read_write_config (vm, h, VLIB_READ, pos + 2, &flags, |
| 849 | sizeof (flags)))) |
| 850 | clib_error_return (error, |
| 851 | "error in reading the capability at [%2x]", |
| 852 | pos + 2); |
| 853 | |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 854 | table_size = flags & table_size_mask; |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 855 | virtio_log_debug (vif, "flags:0x%x %s 0x%x", flags, |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 856 | "msix interrupt vector table-size", table_size); |
| 857 | |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 858 | if (flags & PCI_MSIX_ENABLE) |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 859 | { |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 860 | virtio_log_debug (vif, "msix interrupt enabled"); |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 861 | vif->msix_enabled = VIRTIO_MSIX_ENABLED; |
| 862 | } |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 863 | else |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 864 | { |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 865 | virtio_log_debug (vif, "msix interrupt disabled"); |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 866 | vif->msix_enabled = VIRTIO_MSIX_DISABLED; |
| 867 | } |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | if (cap.cap_vndr != PCI_CAP_ID_VNDR) |
| 871 | { |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 872 | virtio_log_debug (vif, "[%2x] %s %2x ", pos, |
Mohsin Kazmi | 33cc5cf | 2019-01-21 15:19:39 +0000 | [diff] [blame] | 873 | "skipping non VNDR cap id:", cap.cap_vndr); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 874 | goto next; |
| 875 | } |
| 876 | |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 877 | virtio_log_debug (vif, |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 878 | "[%4x] cfg type: %u, bar: %u, offset: %04x, len: %u", |
| 879 | pos, cap.cfg_type, cap.bar, cap.offset, cap.length); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 880 | switch (cap.cfg_type) |
| 881 | { |
| 882 | case VIRTIO_PCI_CAP_COMMON_CFG: |
| 883 | common_cfg = 1; |
| 884 | break; |
| 885 | case VIRTIO_PCI_CAP_NOTIFY_CFG: |
| 886 | notify_base = 1; |
| 887 | break; |
| 888 | case VIRTIO_PCI_CAP_DEVICE_CFG: |
| 889 | dev_cfg = 1; |
| 890 | break; |
| 891 | case VIRTIO_PCI_CAP_ISR_CFG: |
| 892 | isr = 1; |
| 893 | break; |
Mohsin Kazmi | 22c0ece | 2019-01-28 19:30:21 +0000 | [diff] [blame] | 894 | case VIRTIO_PCI_CAP_PCI_CFG: |
| 895 | if (cap.bar == 0) |
| 896 | pci_cfg = 1; |
| 897 | break; |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 898 | } |
| 899 | next: |
| 900 | pos = cap.cap_next; |
| 901 | } |
| 902 | |
| 903 | if (common_cfg == 0 || notify_base == 0 || dev_cfg == 0 || isr == 0) |
| 904 | { |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 905 | virtio_log_debug (vif, "legacy virtio pci device found"); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 906 | return error; |
| 907 | } |
| 908 | |
Mohsin Kazmi | 0e2bc63 | 2019-01-30 13:36:57 +0000 | [diff] [blame] | 909 | if (!pci_cfg) |
| 910 | clib_error_return (error, "modern virtio pci device found"); |
| 911 | |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 912 | virtio_log_debug (vif, "transitional virtio pci device found"); |
Mohsin Kazmi | 33cc5cf | 2019-01-21 15:19:39 +0000 | [diff] [blame] | 913 | return error; |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | static clib_error_t * |
| 917 | virtio_pci_device_init (vlib_main_t * vm, virtio_if_t * vif, |
| 918 | virtio_pci_create_if_args_t * args) |
| 919 | { |
| 920 | clib_error_t *error = 0; |
| 921 | u8 status = 0; |
| 922 | |
Mohsin Kazmi | 22c0ece | 2019-01-28 19:30:21 +0000 | [diff] [blame] | 923 | if ((error = virtio_pci_read_caps (vm, vif))) |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 924 | clib_error_return (error, "Device is not supported"); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 925 | |
| 926 | if (virtio_pci_reset_device (vm, vif) < 0) |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 927 | { |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 928 | virtio_log_error (vif, "Failed to reset the device"); |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 929 | clib_error_return (error, "Failed to reset the device"); |
| 930 | } |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 931 | /* |
| 932 | * read device features and negotiate (user) requested features |
| 933 | */ |
| 934 | virtio_pci_read_device_feature (vm, vif); |
| 935 | virtio_negotiate_features (vm, vif, args->features); |
| 936 | |
| 937 | /* |
| 938 | * After FEATURE_OK, driver should not accept new feature bits |
| 939 | */ |
| 940 | virtio_pci_legacy_set_status (vm, vif, VIRTIO_CONFIG_STATUS_FEATURES_OK); |
| 941 | status = virtio_pci_legacy_get_status (vm, vif); |
| 942 | if (!(status & VIRTIO_CONFIG_STATUS_FEATURES_OK)) |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 943 | { |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 944 | virtio_log_error (vif, |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 945 | "error encountered: Device doesn't support requested features"); |
| 946 | clib_error_return (error, "Device doesn't support requested features"); |
| 947 | } |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 948 | vif->status = status; |
| 949 | |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 950 | /* |
| 951 | * get or set the mac address |
| 952 | */ |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 953 | if (virtio_pci_get_mac (vm, vif)) |
| 954 | { |
| 955 | f64 now = vlib_time_now (vm); |
| 956 | u32 rnd; |
| 957 | rnd = (u32) (now * 1e6); |
| 958 | rnd = random_u32 (&rnd); |
| 959 | |
| 960 | memcpy (vif->mac_addr + 2, &rnd, sizeof (rnd)); |
| 961 | vif->mac_addr[0] = 2; |
| 962 | vif->mac_addr[1] = 0xfe; |
| 963 | virtio_pci_set_mac (vm, vif); |
| 964 | } |
| 965 | |
| 966 | virtio_set_net_hdr_size (vif); |
| 967 | |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 968 | /* |
| 969 | * Initialize the virtqueues |
| 970 | */ |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 971 | if ((error = virtio_pci_get_max_virtqueue_pairs (vm, vif))) |
Mohsin Kazmi | 46f877e | 2019-04-08 10:36:18 +0200 | [diff] [blame] | 972 | goto err; |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 973 | |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 974 | for (int i = 0; i < vif->max_queue_pairs; i++) |
| 975 | { |
| 976 | if ((error = virtio_pci_vring_init (vm, vif, RX_QUEUE (i)))) |
Mohsin Kazmi | 43b512c | 2019-04-30 17:25:26 +0200 | [diff] [blame] | 977 | { |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 978 | virtio_log_warning (vif, "%s (%u) %s", "error in rxq-queue", |
Mohsin Kazmi | 43b512c | 2019-04-30 17:25:26 +0200 | [diff] [blame] | 979 | RX_QUEUE (i), "initialization"); |
| 980 | } |
| 981 | else |
| 982 | { |
| 983 | vif->num_rxqs++; |
| 984 | } |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 985 | |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 986 | if ((error = virtio_pci_vring_init (vm, vif, TX_QUEUE (i)))) |
Mohsin Kazmi | 43b512c | 2019-04-30 17:25:26 +0200 | [diff] [blame] | 987 | { |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 988 | virtio_log_warning (vif, "%s (%u) %s", "error in txq-queue", |
Mohsin Kazmi | 43b512c | 2019-04-30 17:25:26 +0200 | [diff] [blame] | 989 | TX_QUEUE (i), "initialization"); |
| 990 | } |
| 991 | else |
| 992 | { |
| 993 | vif->num_txqs++; |
| 994 | } |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 995 | } |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 996 | |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 997 | if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_CTRL_VQ)) |
| 998 | { |
| 999 | if ((error = |
| 1000 | virtio_pci_control_vring_init (vm, vif, vif->max_queue_pairs * 2))) |
| 1001 | { |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 1002 | virtio_log_warning (vif, "%s (%u) %s", "error in control-queue", |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 1003 | vif->max_queue_pairs * 2, "initialization"); |
| 1004 | if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_MQ)) |
| 1005 | vif->features &= ~VIRTIO_FEATURE (VIRTIO_NET_F_MQ); |
| 1006 | } |
| 1007 | } |
| 1008 | else |
| 1009 | { |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 1010 | virtio_log_debug (vif, "control queue is not available"); |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 1011 | vif->cxq_vring = NULL; |
| 1012 | } |
| 1013 | |
| 1014 | /* |
| 1015 | * set the msix interrupts |
| 1016 | */ |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 1017 | if (vif->msix_enabled == VIRTIO_MSIX_ENABLED) |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1018 | { |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 1019 | if (virtio_pci_legacy_set_config_irq (vm, vif, 1) == |
| 1020 | VIRTIO_MSI_NO_VECTOR) |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 1021 | virtio_log_warning (vif, "config vector 1 is not set"); |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 1022 | if (virtio_pci_legacy_set_queue_irq (vm, vif, 0, 0) == |
| 1023 | VIRTIO_MSI_NO_VECTOR) |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 1024 | virtio_log_warning (vif, "queue vector 0 is not set"); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1025 | } |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 1026 | |
| 1027 | /* |
| 1028 | * set the driver status OK |
| 1029 | */ |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1030 | virtio_pci_legacy_set_status (vm, vif, VIRTIO_CONFIG_STATUS_DRIVER_OK); |
| 1031 | vif->status = virtio_pci_legacy_get_status (vm, vif); |
Mohsin Kazmi | 46f877e | 2019-04-08 10:36:18 +0200 | [diff] [blame] | 1032 | err: |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1033 | return error; |
| 1034 | } |
| 1035 | |
| 1036 | void |
| 1037 | virtio_pci_create_if (vlib_main_t * vm, virtio_pci_create_if_args_t * args) |
| 1038 | { |
| 1039 | vnet_main_t *vnm = vnet_get_main (); |
Mohsin Kazmi | 33cc5cf | 2019-01-21 15:19:39 +0000 | [diff] [blame] | 1040 | virtio_main_t *vim = &virtio_main; |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1041 | virtio_if_t *vif; |
| 1042 | vlib_pci_dev_handle_t h; |
| 1043 | clib_error_t *error = 0; |
| 1044 | |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1045 | /* *INDENT-OFF* */ |
Mohsin Kazmi | 33cc5cf | 2019-01-21 15:19:39 +0000 | [diff] [blame] | 1046 | pool_foreach (vif, vim->interfaces, ({ |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1047 | if (vif->pci_addr.as_u32 == args->addr) |
| 1048 | { |
| 1049 | args->rv = VNET_API_ERROR_INVALID_VALUE; |
| 1050 | args->error = |
| 1051 | clib_error_return (error, "PCI address in use"); |
Mohsin Kazmi | 33cc5cf | 2019-01-21 15:19:39 +0000 | [diff] [blame] | 1052 | vlib_log (VLIB_LOG_LEVEL_ERR, vim->log_default, "%U: %s", |
| 1053 | format_vlib_pci_addr, &args->addr, |
| 1054 | " PCI address in use"); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1055 | return; |
| 1056 | } |
| 1057 | })); |
| 1058 | /* *INDENT-ON* */ |
| 1059 | |
Mohsin Kazmi | 33cc5cf | 2019-01-21 15:19:39 +0000 | [diff] [blame] | 1060 | pool_get (vim->interfaces, vif); |
| 1061 | vif->dev_instance = vif - vim->interfaces; |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1062 | vif->per_interface_next_index = ~0; |
| 1063 | vif->pci_addr.as_u32 = args->addr; |
| 1064 | |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1065 | if ((error = |
| 1066 | vlib_pci_device_open (vm, (vlib_pci_addr_t *) & vif->pci_addr, |
| 1067 | virtio_pci_device_ids, &h))) |
| 1068 | { |
Mohsin Kazmi | 33cc5cf | 2019-01-21 15:19:39 +0000 | [diff] [blame] | 1069 | pool_put (vim->interfaces, vif); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1070 | args->rv = VNET_API_ERROR_INVALID_INTERFACE; |
| 1071 | args->error = |
| 1072 | clib_error_return (error, "pci-addr %U", format_vlib_pci_addr, |
| 1073 | &vif->pci_addr); |
Mohsin Kazmi | 33cc5cf | 2019-01-21 15:19:39 +0000 | [diff] [blame] | 1074 | vlib_log (VLIB_LOG_LEVEL_ERR, vim->log_default, "%U: %s", |
| 1075 | format_vlib_pci_addr, &vif->pci_addr, |
| 1076 | "error encountered on pci device open"); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1077 | return; |
| 1078 | } |
| 1079 | vif->pci_dev_handle = h; |
| 1080 | vlib_pci_set_private_data (vm, h, vif->dev_instance); |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 1081 | vif->numa_node = vlib_pci_get_numa_node (vm, h); |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 1082 | vif->type = VIRTIO_IF_TYPE_PCI; |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1083 | |
| 1084 | if ((error = vlib_pci_bus_master_enable (vm, h))) |
Mohsin Kazmi | 33cc5cf | 2019-01-21 15:19:39 +0000 | [diff] [blame] | 1085 | { |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 1086 | virtio_log_error (vif, "error encountered on pci bus master enable"); |
Mohsin Kazmi | 33cc5cf | 2019-01-21 15:19:39 +0000 | [diff] [blame] | 1087 | goto error; |
| 1088 | } |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1089 | |
| 1090 | if ((error = vlib_pci_io_region (vm, h, 0))) |
Mohsin Kazmi | 33cc5cf | 2019-01-21 15:19:39 +0000 | [diff] [blame] | 1091 | { |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 1092 | virtio_log_error (vif, "error encountered on pci io region"); |
Mohsin Kazmi | 33cc5cf | 2019-01-21 15:19:39 +0000 | [diff] [blame] | 1093 | goto error; |
| 1094 | } |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1095 | |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 1096 | if (vlib_pci_get_num_msix_interrupts (vm, h) > 1) |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1097 | { |
| 1098 | if ((error = vlib_pci_register_msix_handler (vm, h, 0, 1, |
| 1099 | &virtio_pci_irq_0_handler))) |
Mohsin Kazmi | 33cc5cf | 2019-01-21 15:19:39 +0000 | [diff] [blame] | 1100 | { |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 1101 | virtio_log_error (vif, |
Mohsin Kazmi | 33cc5cf | 2019-01-21 15:19:39 +0000 | [diff] [blame] | 1102 | "error encountered on pci register msix handler 0"); |
| 1103 | goto error; |
| 1104 | } |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1105 | if ((error = vlib_pci_register_msix_handler (vm, h, 1, 1, |
| 1106 | &virtio_pci_irq_1_handler))) |
Mohsin Kazmi | 33cc5cf | 2019-01-21 15:19:39 +0000 | [diff] [blame] | 1107 | { |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 1108 | virtio_log_error (vif, |
Mohsin Kazmi | 33cc5cf | 2019-01-21 15:19:39 +0000 | [diff] [blame] | 1109 | "error encountered on pci register msix handler 1"); |
| 1110 | goto error; |
| 1111 | } |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1112 | |
| 1113 | if ((error = vlib_pci_enable_msix_irq (vm, h, 0, 2))) |
Mohsin Kazmi | 33cc5cf | 2019-01-21 15:19:39 +0000 | [diff] [blame] | 1114 | { |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 1115 | virtio_log_error (vif, "error encountered on pci enable msix irq"); |
Mohsin Kazmi | 33cc5cf | 2019-01-21 15:19:39 +0000 | [diff] [blame] | 1116 | goto error; |
| 1117 | } |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 1118 | vif->support_int_mode = 1; |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 1119 | virtio_log_debug (vif, "device supports msix interrupts"); |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 1120 | } |
| 1121 | else if (vlib_pci_get_num_msix_interrupts (vm, h) == 1) |
| 1122 | { |
| 1123 | /* |
| 1124 | * if msix table-size is 1, fall back to intX. |
| 1125 | */ |
| 1126 | if ((error = |
| 1127 | vlib_pci_register_intx_handler (vm, h, &virtio_pci_irq_handler))) |
| 1128 | { |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 1129 | virtio_log_error (vif, |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 1130 | "error encountered on pci register interrupt handler"); |
| 1131 | goto error; |
| 1132 | } |
| 1133 | vif->support_int_mode = 1; |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 1134 | virtio_log_debug (vif, "pci register interrupt handler"); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1135 | } |
| 1136 | else |
| 1137 | { |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 1138 | /* |
| 1139 | * WARN: intX is showing some weird behaviour. |
| 1140 | * Please don't use interrupt mode with UIO driver. |
| 1141 | */ |
| 1142 | vif->support_int_mode = 0; |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 1143 | virtio_log_debug (vif, "driver is configured in poll mode only"); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1144 | } |
| 1145 | |
| 1146 | if ((error = vlib_pci_intr_enable (vm, h))) |
Mohsin Kazmi | 33cc5cf | 2019-01-21 15:19:39 +0000 | [diff] [blame] | 1147 | { |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 1148 | virtio_log_error (vif, "error encountered on pci interrupt enable"); |
Mohsin Kazmi | 33cc5cf | 2019-01-21 15:19:39 +0000 | [diff] [blame] | 1149 | goto error; |
| 1150 | } |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1151 | |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 1152 | if ((error = virtio_pci_device_init (vm, vif, args))) |
| 1153 | { |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 1154 | virtio_log_error (vif, "error encountered on device init"); |
Mohsin Kazmi | b74fe32 | 2019-01-31 13:50:56 +0000 | [diff] [blame] | 1155 | goto error; |
| 1156 | } |
| 1157 | |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1158 | /* create interface */ |
| 1159 | error = ethernet_register_interface (vnm, virtio_device_class.index, |
| 1160 | vif->dev_instance, vif->mac_addr, |
| 1161 | &vif->hw_if_index, |
| 1162 | virtio_pci_flag_change); |
| 1163 | |
| 1164 | if (error) |
Mohsin Kazmi | 33cc5cf | 2019-01-21 15:19:39 +0000 | [diff] [blame] | 1165 | { |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 1166 | virtio_log_error (vif, |
Mohsin Kazmi | 33cc5cf | 2019-01-21 15:19:39 +0000 | [diff] [blame] | 1167 | "error encountered on ethernet register interface"); |
| 1168 | goto error; |
| 1169 | } |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1170 | |
| 1171 | vnet_sw_interface_t *sw = vnet_get_hw_sw_interface (vnm, vif->hw_if_index); |
| 1172 | vif->sw_if_index = sw->sw_if_index; |
| 1173 | args->sw_if_index = sw->sw_if_index; |
| 1174 | |
| 1175 | vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, vif->hw_if_index); |
| 1176 | hw->flags |= VNET_HW_INTERFACE_FLAG_SUPPORTS_INT_MODE; |
| 1177 | vnet_hw_interface_set_input_node (vnm, vif->hw_if_index, |
| 1178 | virtio_input_node.index); |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 1179 | u32 i = 0; |
| 1180 | vec_foreach_index (i, vif->rxq_vrings) |
| 1181 | { |
| 1182 | vnet_hw_interface_assign_rx_thread (vnm, vif->hw_if_index, i, ~0); |
| 1183 | virtio_vring_set_numa_node (vm, vif, RX_QUEUE (i)); |
| 1184 | /* Set default rx mode to POLLING */ |
| 1185 | vnet_hw_interface_set_rx_mode (vnm, vif->hw_if_index, i, |
| 1186 | VNET_HW_INTERFACE_RX_MODE_POLLING); |
| 1187 | } |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1188 | if (virtio_pci_is_link_up (vm, vif) & VIRTIO_NET_S_LINK_UP) |
| 1189 | { |
| 1190 | vif->flags |= VIRTIO_IF_FLAG_ADMIN_UP; |
| 1191 | vnet_hw_interface_set_flags (vnm, vif->hw_if_index, |
| 1192 | VNET_HW_INTERFACE_FLAG_LINK_UP); |
| 1193 | } |
| 1194 | else |
| 1195 | vnet_hw_interface_set_flags (vnm, vif->hw_if_index, 0); |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 1196 | |
Mohsin Kazmi | bbd6b74 | 2019-05-02 13:54:59 +0200 | [diff] [blame] | 1197 | if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_CTRL_VQ)) |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 1198 | { |
Mohsin Kazmi | bbd6b74 | 2019-05-02 13:54:59 +0200 | [diff] [blame] | 1199 | if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) && |
| 1200 | args->gso_enabled) |
| 1201 | { |
| 1202 | if (virtio_pci_enable_gso (vm, vif)) |
| 1203 | { |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 1204 | virtio_log_warning (vif, "gso is not enabled"); |
Mohsin Kazmi | bbd6b74 | 2019-05-02 13:54:59 +0200 | [diff] [blame] | 1205 | } |
| 1206 | else |
| 1207 | { |
| 1208 | vif->gso_enabled = 1; |
| 1209 | hw->flags |= VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO; |
| 1210 | vnm->interface_main.gso_interface_count++; |
| 1211 | } |
| 1212 | } |
| 1213 | if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_MQ)) |
| 1214 | { |
| 1215 | if (virtio_pci_enable_multiqueue (vm, vif, vif->max_queue_pairs)) |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame^] | 1216 | virtio_log_warning (vif, "multiqueue is not set"); |
Mohsin Kazmi | bbd6b74 | 2019-05-02 13:54:59 +0200 | [diff] [blame] | 1217 | } |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 1218 | } |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1219 | return; |
| 1220 | |
Mohsin Kazmi | bbd6b74 | 2019-05-02 13:54:59 +0200 | [diff] [blame] | 1221 | |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1222 | error: |
| 1223 | virtio_pci_delete_if (vm, vif); |
| 1224 | args->rv = VNET_API_ERROR_INVALID_INTERFACE; |
| 1225 | args->error = error; |
| 1226 | } |
| 1227 | |
| 1228 | int |
| 1229 | virtio_pci_delete_if (vlib_main_t * vm, virtio_if_t * vif) |
| 1230 | { |
| 1231 | vnet_main_t *vnm = vnet_get_main (); |
Mohsin Kazmi | 33cc5cf | 2019-01-21 15:19:39 +0000 | [diff] [blame] | 1232 | virtio_main_t *vim = &virtio_main; |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1233 | u32 i = 0; |
| 1234 | |
| 1235 | if (vif->type != VIRTIO_IF_TYPE_PCI) |
| 1236 | return VNET_API_ERROR_INVALID_INTERFACE; |
| 1237 | |
| 1238 | vlib_pci_intr_disable (vm, vif->pci_dev_handle); |
| 1239 | |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 1240 | for (i = 0; i < vif->max_queue_pairs; i++) |
| 1241 | { |
| 1242 | virtio_pci_legacy_del_queue (vm, vif, RX_QUEUE (i)); |
| 1243 | virtio_pci_legacy_del_queue (vm, vif, TX_QUEUE (i)); |
| 1244 | } |
| 1245 | |
| 1246 | if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_CTRL_VQ)) |
| 1247 | virtio_pci_legacy_del_queue (vm, vif, vif->max_queue_pairs * 2); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1248 | |
| 1249 | virtio_pci_legacy_reset (vm, vif); |
| 1250 | |
Mohsin Kazmi | bbd6b74 | 2019-05-02 13:54:59 +0200 | [diff] [blame] | 1251 | if (vif->gso_enabled) |
| 1252 | vnm->interface_main.gso_interface_count--; |
| 1253 | |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1254 | if (vif->hw_if_index) |
| 1255 | { |
| 1256 | vnet_hw_interface_set_flags (vnm, vif->hw_if_index, 0); |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 1257 | vec_foreach_index (i, vif->rxq_vrings) |
| 1258 | { |
| 1259 | vnet_hw_interface_unassign_rx_thread (vnm, vif->hw_if_index, i); |
| 1260 | } |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1261 | ethernet_delete_interface (vnm, vif->hw_if_index); |
| 1262 | } |
| 1263 | |
| 1264 | vlib_pci_device_close (vm, vif->pci_dev_handle); |
| 1265 | |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 1266 | vec_foreach_index (i, vif->rxq_vrings) |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1267 | { |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 1268 | virtio_vring_t *vring = vec_elt_at_index (vif->rxq_vrings, i); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1269 | if (vring->kick_fd != -1) |
| 1270 | close (vring->kick_fd); |
| 1271 | if (vring->used) |
| 1272 | { |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 1273 | virtio_free_rx_buffers (vm, vring); |
| 1274 | } |
| 1275 | vec_free (vring->buffers); |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 1276 | vlib_physmem_free (vm, vring->desc); |
| 1277 | } |
| 1278 | |
| 1279 | vec_foreach_index (i, vif->txq_vrings) |
| 1280 | { |
| 1281 | virtio_vring_t *vring = vec_elt_at_index (vif->txq_vrings, i); |
| 1282 | if (vring->kick_fd != -1) |
| 1283 | close (vring->kick_fd); |
| 1284 | if (vring->used) |
| 1285 | { |
| 1286 | virtio_free_used_desc (vm, vring); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1287 | } |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1288 | vec_free (vring->buffers); |
Steven Luong | e558496 | 2019-06-25 13:47:06 -0700 | [diff] [blame] | 1289 | clib_spinlock_free (&vring->lockp); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1290 | vlib_physmem_free (vm, vring->desc); |
| 1291 | } |
| 1292 | |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 1293 | if (vif->cxq_vring != NULL) |
| 1294 | { |
| 1295 | u16 last = vif->cxq_vring->last_used_idx; |
| 1296 | u16 n_left = vif->cxq_vring->used->idx - last; |
| 1297 | while (n_left) |
| 1298 | { |
| 1299 | last++; |
| 1300 | n_left--; |
| 1301 | } |
| 1302 | |
| 1303 | vif->cxq_vring->last_used_idx = last; |
| 1304 | vlib_physmem_free (vm, vif->cxq_vring->desc); |
| 1305 | } |
| 1306 | |
| 1307 | vec_free (vif->rxq_vrings); |
| 1308 | vec_free (vif->txq_vrings); |
| 1309 | vec_free (vif->cxq_vring); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1310 | |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1311 | clib_error_free (vif->error); |
| 1312 | memset (vif, 0, sizeof (*vif)); |
Mohsin Kazmi | 33cc5cf | 2019-01-21 15:19:39 +0000 | [diff] [blame] | 1313 | pool_put (vim->interfaces, vif); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 1314 | |
| 1315 | return 0; |
| 1316 | } |
| 1317 | |
| 1318 | /* |
| 1319 | * fd.io coding-style-patch-verification: ON |
| 1320 | * |
| 1321 | * Local Variables: |
| 1322 | * eval: (c-set-style "gnu") |
| 1323 | * End: |
| 1324 | */ |