1 /*- 2 * SPDX-License-Identifier: BSD-3-Clause 3 * 4 * Copyright (c) 2023 Google LLC 5 * 6 * Redistribution and use in source and binary forms, with or without modification, 7 * are permitted provided that the following conditions are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright notice, this 10 * list of conditions and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright notice, 13 * this list of conditions and the following disclaimer in the documentation 14 * and/or other materials provided with the distribution. 15 * 16 * 3. Neither the name of the copyright holder nor the names of its contributors 17 * may be used to endorse or promote products derived from this software without 18 * specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 #ifndef _GVE_AQ_H_ 32 #define _GVE_AQ_H_ 1 33 34 #include <sys/types.h> 35 #include <net/if.h> 36 #include <net/iflib.h> 37 #include <machine/bus.h> 38 #include <machine/resource.h> 39 40 /* Admin queue opcodes */ 41 enum gve_adminq_opcodes { 42 GVE_ADMINQ_DESCRIBE_DEVICE = 0x1, 43 GVE_ADMINQ_CONFIGURE_DEVICE_RESOURCES = 0x2, 44 GVE_ADMINQ_REGISTER_PAGE_LIST = 0x3, 45 GVE_ADMINQ_UNREGISTER_PAGE_LIST = 0x4, 46 GVE_ADMINQ_CREATE_TX_QUEUE = 0x5, 47 GVE_ADMINQ_CREATE_RX_QUEUE = 0x6, 48 GVE_ADMINQ_DESTROY_TX_QUEUE = 0x7, 49 GVE_ADMINQ_DESTROY_RX_QUEUE = 0x8, 50 GVE_ADMINQ_DECONFIGURE_DEVICE_RESOURCES = 0x9, 51 GVE_ADMINQ_SET_DRIVER_PARAMETER = 0xB, 52 GVE_ADMINQ_REPORT_STATS = 0xC, 53 GVE_ADMINQ_REPORT_LINK_SPEED = 0xD, 54 GVE_ADMINQ_GET_PTYPE_MAP = 0xE, 55 GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY = 0xF, 56 }; 57 58 /* Admin queue status codes */ 59 enum gve_adminq_statuses { 60 GVE_ADMINQ_COMMAND_UNSET = 0x0, 61 GVE_ADMINQ_COMMAND_PASSED = 0x1, 62 GVE_ADMINQ_COMMAND_ERROR_ABORTED = 0xFFFFFFF0, 63 GVE_ADMINQ_COMMAND_ERROR_ALREADY_EXISTS = 0xFFFFFFF1, 64 GVE_ADMINQ_COMMAND_ERROR_CANCELLED = 0xFFFFFFF2, 65 GVE_ADMINQ_COMMAND_ERROR_DATALOSS = 0xFFFFFFF3, 66 GVE_ADMINQ_COMMAND_ERROR_DEADLINE_EXCEEDED = 0xFFFFFFF4, 67 GVE_ADMINQ_COMMAND_ERROR_FAILED_PRECONDITION = 0xFFFFFFF5, 68 GVE_ADMINQ_COMMAND_ERROR_INTERNAL_ERROR = 0xFFFFFFF6, 69 GVE_ADMINQ_COMMAND_ERROR_INVALID_ARGUMENT = 0xFFFFFFF7, 70 GVE_ADMINQ_COMMAND_ERROR_NOT_FOUND = 0xFFFFFFF8, 71 GVE_ADMINQ_COMMAND_ERROR_OUT_OF_RANGE = 0xFFFFFFF9, 72 GVE_ADMINQ_COMMAND_ERROR_PERMISSION_DENIED = 0xFFFFFFFA, 73 GVE_ADMINQ_COMMAND_ERROR_UNAUTHENTICATED = 0xFFFFFFFB, 74 GVE_ADMINQ_COMMAND_ERROR_RESOURCE_EXHAUSTED = 0xFFFFFFFC, 75 GVE_ADMINQ_COMMAND_ERROR_UNAVAILABLE = 0xFFFFFFFD, 76 GVE_ADMINQ_COMMAND_ERROR_UNIMPLEMENTED = 0xFFFFFFFE, 77 GVE_ADMINQ_COMMAND_ERROR_UNKNOWN_ERROR = 0xFFFFFFFF, 78 }; 79 80 #define GVE_ADMINQ_DEVICE_DESCRIPTOR_VERSION 1 81 82 /* 83 * All AdminQ command structs should be naturally packed. The static_assert 84 * calls make sure this is the case at compile time. 85 */ 86 87 struct gve_adminq_describe_device { 88 __be64 device_descriptor_addr; 89 __be32 device_descriptor_version; 90 __be32 available_length; 91 }; 92 93 _Static_assert(sizeof(struct gve_adminq_describe_device) == 16, 94 "gve: bad admin queue struct length"); 95 96 struct gve_device_descriptor { 97 __be64 max_registered_pages; 98 __be16 reserved1; 99 __be16 tx_queue_entries; 100 __be16 rx_queue_entries; 101 __be16 default_num_queues; 102 __be16 mtu; 103 __be16 counters; 104 __be16 reserved2; 105 __be16 rx_pages_per_qpl; 106 uint8_t mac[ETHER_ADDR_LEN]; 107 __be16 num_device_options; 108 __be16 total_length; 109 uint8_t reserved3[6]; 110 }; 111 112 _Static_assert(sizeof(struct gve_device_descriptor) == 40, 113 "gve: bad admin queue struct length"); 114 115 struct gve_device_option { 116 __be16 option_id; 117 __be16 option_length; 118 __be32 required_features_mask; 119 }; 120 121 _Static_assert(sizeof(struct gve_device_option) == 8, 122 "gve: bad admin queue struct length"); 123 124 struct gve_device_option_gqi_rda { 125 __be32 supported_features_mask; 126 }; 127 128 _Static_assert(sizeof(struct gve_device_option_gqi_rda) == 4, 129 "gve: bad admin queue struct length"); 130 131 struct gve_device_option_gqi_qpl { 132 __be32 supported_features_mask; 133 }; 134 135 _Static_assert(sizeof(struct gve_device_option_gqi_qpl) == 4, 136 "gve: bad admin queue struct length"); 137 138 struct gve_device_option_dqo_rda { 139 __be32 supported_features_mask; 140 }; 141 142 _Static_assert(sizeof(struct gve_device_option_dqo_rda) == 4, 143 "gve: bad admin queue struct length"); 144 145 struct gve_device_option_modify_ring { 146 __be32 supported_features_mask; 147 __be16 max_rx_ring_size; 148 __be16 max_tx_ring_size; 149 }; 150 151 _Static_assert(sizeof(struct gve_device_option_modify_ring) == 8, 152 "gve: bad admin queue struct length"); 153 154 struct gve_device_option_jumbo_frames { 155 __be32 supported_features_mask; 156 __be16 max_mtu; 157 uint8_t padding[2]; 158 }; 159 160 _Static_assert(sizeof(struct gve_device_option_jumbo_frames) == 8, 161 "gve: bad admin queue struct length"); 162 163 enum gve_dev_opt_id { 164 GVE_DEV_OPT_ID_GQI_RAW_ADDRESSING = 0x1, 165 GVE_DEV_OPT_ID_GQI_RDA = 0x2, 166 GVE_DEV_OPT_ID_GQI_QPL = 0x3, 167 GVE_DEV_OPT_ID_DQO_RDA = 0x4, 168 GVE_DEV_OPT_ID_MODIFY_RING = 0x6, 169 GVE_DEV_OPT_ID_JUMBO_FRAMES = 0x8, 170 }; 171 172 /* 173 * These masks are way to predicate the use of a particular option on the driver 174 * having particular bug fixes represented by each bit position in the mask. 175 * Currently they are all zero because there are no known bugs preventing the 176 * use of any option. 177 */ 178 enum gve_dev_opt_req_feat_mask { 179 GVE_DEV_OPT_REQ_FEAT_MASK_GQI_RAW_ADDRESSING = 0x0, 180 GVE_DEV_OPT_REQ_FEAT_MASK_GQI_RDA = 0x0, 181 GVE_DEV_OPT_REQ_FEAT_MASK_GQI_QPL = 0x0, 182 GVE_DEV_OPT_REQ_FEAT_MASK_DQO_RDA = 0x0, 183 GVE_DEV_OPT_REQ_FEAT_MASK_MODIFY_RING = 0x0, 184 GVE_DEV_OPT_REQ_FEAT_MASK_JUMBO_FRAMES = 0x0, 185 }; 186 187 enum gve_sup_feature_mask { 188 GVE_SUP_MODIFY_RING_MASK = 1 << 0, 189 GVE_SUP_JUMBO_FRAMES_MASK = 1 << 2, 190 }; 191 192 #define GVE_VERSION_STR_LEN 128 193 194 enum gve_driver_capability { 195 gve_driver_capability_gqi_qpl = 0, 196 gve_driver_capability_gqi_rda = 1, 197 gve_driver_capability_dqo_qpl = 2, /* reserved for future use */ 198 gve_driver_capability_dqo_rda = 3, 199 gve_driver_capability_alt_miss_compl = 4, 200 }; 201 202 #define GVE_CAP1(a) BIT((int) a) 203 #define GVE_CAP2(a) BIT(((int) a) - 64) 204 #define GVE_CAP3(a) BIT(((int) a) - 128) 205 #define GVE_CAP4(a) BIT(((int) a) - 192) 206 207 /* 208 * The following four defines describe 256 compatibility bits. 209 * Only a few bits (as shown in `gve_driver_compatibility`) are currently 210 * defined. The rest are reserved for future use. 211 */ 212 #define GVE_DRIVER_CAPABILITY_FLAGS1 (GVE_CAP1(gve_driver_capability_gqi_qpl)) 213 #define GVE_DRIVER_CAPABILITY_FLAGS2 0x0 214 #define GVE_DRIVER_CAPABILITY_FLAGS3 0x0 215 #define GVE_DRIVER_CAPABILITY_FLAGS4 0x0 216 217 struct gve_driver_info { 218 uint8_t os_type; 219 uint8_t driver_major; 220 uint8_t driver_minor; 221 uint8_t driver_sub; 222 __be32 os_version_major; 223 __be32 os_version_minor; 224 __be32 os_version_sub; 225 __be64 driver_capability_flags[4]; 226 uint8_t os_version_str1[GVE_VERSION_STR_LEN]; 227 uint8_t os_version_str2[GVE_VERSION_STR_LEN]; 228 }; 229 230 struct gve_adminq_verify_driver_compatibility { 231 __be64 driver_info_len; 232 __be64 driver_info_addr; 233 }; 234 235 _Static_assert(sizeof(struct gve_adminq_verify_driver_compatibility) == 16, 236 "gve: bad admin queue struct length"); 237 238 struct gve_adminq_configure_device_resources { 239 __be64 counter_array; 240 __be64 irq_db_addr; 241 __be32 num_counters; 242 __be32 num_irq_dbs; 243 __be32 irq_db_stride; 244 __be32 ntfy_blk_msix_base_idx; 245 uint8_t queue_format; 246 uint8_t padding[7]; 247 }; 248 249 _Static_assert(sizeof(struct gve_adminq_configure_device_resources) == 40, 250 "gve: bad admin queue struct length"); 251 252 struct gve_adminq_register_page_list { 253 __be32 page_list_id; 254 __be32 num_pages; 255 __be64 page_address_list_addr; 256 __be64 page_size; 257 }; 258 259 _Static_assert(sizeof(struct gve_adminq_register_page_list) == 24, 260 "gve: bad admin queue struct length"); 261 262 struct gve_adminq_unregister_page_list { 263 __be32 page_list_id; 264 }; 265 266 _Static_assert(sizeof(struct gve_adminq_unregister_page_list) == 4, 267 "gve: bad admin queue struct length"); 268 269 struct gve_adminq_create_tx_queue { 270 __be32 queue_id; 271 __be32 reserved; 272 __be64 queue_resources_addr; 273 __be64 tx_ring_addr; 274 __be32 queue_page_list_id; 275 __be32 ntfy_id; 276 __be64 tx_comp_ring_addr; 277 __be16 tx_ring_size; 278 __be16 tx_comp_ring_size; 279 uint8_t padding[4]; 280 }; 281 282 _Static_assert(sizeof(struct gve_adminq_create_tx_queue) == 48, 283 "gve: bad admin queue struct length"); 284 285 struct gve_adminq_create_rx_queue { 286 __be32 queue_id; 287 __be32 index; 288 __be32 reserved; 289 __be32 ntfy_id; 290 __be64 queue_resources_addr; 291 __be64 rx_desc_ring_addr; 292 __be64 rx_data_ring_addr; 293 __be32 queue_page_list_id; 294 __be16 rx_ring_size; 295 __be16 packet_buffer_size; 296 __be16 rx_buff_ring_size; 297 uint8_t enable_rsc; 298 uint8_t padding[5]; 299 }; 300 301 _Static_assert(sizeof(struct gve_adminq_create_rx_queue) == 56, 302 "gve: bad admin queue struct length"); 303 304 /* Queue resources that are shared with the device */ 305 struct gve_queue_resources { 306 union { 307 struct { 308 __be32 db_index; /* Device -> Guest */ 309 __be32 counter_index; /* Device -> Guest */ 310 }; 311 uint8_t reserved[64]; 312 }; 313 }; 314 315 _Static_assert(sizeof(struct gve_queue_resources) == 64, 316 "gve: bad admin queue struct length"); 317 318 struct gve_adminq_destroy_tx_queue { 319 __be32 queue_id; 320 }; 321 322 _Static_assert(sizeof(struct gve_adminq_destroy_tx_queue) == 4, 323 "gve: bad admin queue struct length"); 324 325 struct gve_adminq_destroy_rx_queue { 326 __be32 queue_id; 327 }; 328 329 _Static_assert(sizeof(struct gve_adminq_destroy_rx_queue) == 4, 330 "gve: bad admin queue struct length"); 331 332 /* GVE Set Driver Parameter Types */ 333 enum gve_set_driver_param_types { 334 GVE_SET_PARAM_MTU = 0x1, 335 }; 336 337 struct gve_adminq_set_driver_parameter { 338 __be32 parameter_type; 339 uint8_t reserved[4]; 340 __be64 parameter_value; 341 }; 342 343 _Static_assert(sizeof(struct gve_adminq_set_driver_parameter) == 16, 344 "gve: bad admin queue struct length"); 345 346 struct stats { 347 __be32 stat_name; 348 __be32 queue_id; 349 __be64 value; 350 }; 351 352 _Static_assert(sizeof(struct stats) == 16, 353 "gve: bad admin queue struct length"); 354 355 struct gve_adminq_command { 356 __be32 opcode; 357 __be32 status; 358 union { 359 struct gve_adminq_configure_device_resources 360 configure_device_resources; 361 struct gve_adminq_create_tx_queue create_tx_queue; 362 struct gve_adminq_create_rx_queue create_rx_queue; 363 struct gve_adminq_destroy_tx_queue destroy_tx_queue; 364 struct gve_adminq_destroy_rx_queue destroy_rx_queue; 365 struct gve_adminq_describe_device describe_device; 366 struct gve_adminq_register_page_list reg_page_list; 367 struct gve_adminq_unregister_page_list unreg_page_list; 368 struct gve_adminq_set_driver_parameter set_driver_param; 369 struct gve_adminq_verify_driver_compatibility 370 verify_driver_compatibility; 371 uint8_t reserved[56]; 372 }; 373 }; 374 375 _Static_assert(sizeof(struct gve_adminq_command) == 64, 376 "gve: bad admin queue struct length"); 377 378 int gve_adminq_create_rx_queues(struct gve_priv *priv, uint32_t num_queues); 379 int gve_adminq_create_tx_queues(struct gve_priv *priv, uint32_t num_queues); 380 int gve_adminq_destroy_tx_queues(struct gve_priv *priv, uint32_t num_queues); 381 int gve_adminq_destroy_rx_queues(struct gve_priv *priv, uint32_t num_queues); 382 int gve_adminq_set_mtu(struct gve_priv *priv, uint32_t mtu); 383 int gve_adminq_alloc(struct gve_priv *priv); 384 void gve_reset_adminq(struct gve_priv *priv); 385 int gve_adminq_describe_device(struct gve_priv *priv); 386 int gve_adminq_configure_device_resources(struct gve_priv *priv); 387 int gve_adminq_deconfigure_device_resources(struct gve_priv *priv); 388 void gve_release_adminq(struct gve_priv *priv); 389 int gve_adminq_register_page_list(struct gve_priv *priv, 390 struct gve_queue_page_list *qpl); 391 int gve_adminq_unregister_page_list(struct gve_priv *priv, uint32_t page_list_id); 392 int gve_adminq_verify_driver_compatibility(struct gve_priv *priv, 393 uint64_t driver_info_len, vm_paddr_t driver_info_addr); 394 #endif /* _GVE_AQ_H_ */ 395