1 /* SPDX-License-Identifier: (GPL-2.0 OR MIT) 2 * Google virtual Ethernet (gve) driver 3 * 4 * Copyright (C) 2015-2019 Google, Inc. 5 */ 6 7 #ifndef _GVE_ADMINQ_H 8 #define _GVE_ADMINQ_H 9 10 #include <linux/build_bug.h> 11 12 /* Admin queue opcodes */ 13 enum gve_adminq_opcodes { 14 GVE_ADMINQ_DESCRIBE_DEVICE = 0x1, 15 GVE_ADMINQ_CONFIGURE_DEVICE_RESOURCES = 0x2, 16 GVE_ADMINQ_REGISTER_PAGE_LIST = 0x3, 17 GVE_ADMINQ_UNREGISTER_PAGE_LIST = 0x4, 18 GVE_ADMINQ_CREATE_TX_QUEUE = 0x5, 19 GVE_ADMINQ_CREATE_RX_QUEUE = 0x6, 20 GVE_ADMINQ_DESTROY_TX_QUEUE = 0x7, 21 GVE_ADMINQ_DESTROY_RX_QUEUE = 0x8, 22 GVE_ADMINQ_DECONFIGURE_DEVICE_RESOURCES = 0x9, 23 GVE_ADMINQ_SET_DRIVER_PARAMETER = 0xB, 24 GVE_ADMINQ_REPORT_STATS = 0xC, 25 GVE_ADMINQ_REPORT_LINK_SPEED = 0xD 26 }; 27 28 /* Admin queue status codes */ 29 enum gve_adminq_statuses { 30 GVE_ADMINQ_COMMAND_UNSET = 0x0, 31 GVE_ADMINQ_COMMAND_PASSED = 0x1, 32 GVE_ADMINQ_COMMAND_ERROR_ABORTED = 0xFFFFFFF0, 33 GVE_ADMINQ_COMMAND_ERROR_ALREADY_EXISTS = 0xFFFFFFF1, 34 GVE_ADMINQ_COMMAND_ERROR_CANCELLED = 0xFFFFFFF2, 35 GVE_ADMINQ_COMMAND_ERROR_DATALOSS = 0xFFFFFFF3, 36 GVE_ADMINQ_COMMAND_ERROR_DEADLINE_EXCEEDED = 0xFFFFFFF4, 37 GVE_ADMINQ_COMMAND_ERROR_FAILED_PRECONDITION = 0xFFFFFFF5, 38 GVE_ADMINQ_COMMAND_ERROR_INTERNAL_ERROR = 0xFFFFFFF6, 39 GVE_ADMINQ_COMMAND_ERROR_INVALID_ARGUMENT = 0xFFFFFFF7, 40 GVE_ADMINQ_COMMAND_ERROR_NOT_FOUND = 0xFFFFFFF8, 41 GVE_ADMINQ_COMMAND_ERROR_OUT_OF_RANGE = 0xFFFFFFF9, 42 GVE_ADMINQ_COMMAND_ERROR_PERMISSION_DENIED = 0xFFFFFFFA, 43 GVE_ADMINQ_COMMAND_ERROR_UNAUTHENTICATED = 0xFFFFFFFB, 44 GVE_ADMINQ_COMMAND_ERROR_RESOURCE_EXHAUSTED = 0xFFFFFFFC, 45 GVE_ADMINQ_COMMAND_ERROR_UNAVAILABLE = 0xFFFFFFFD, 46 GVE_ADMINQ_COMMAND_ERROR_UNIMPLEMENTED = 0xFFFFFFFE, 47 GVE_ADMINQ_COMMAND_ERROR_UNKNOWN_ERROR = 0xFFFFFFFF, 48 }; 49 50 #define GVE_ADMINQ_DEVICE_DESCRIPTOR_VERSION 1 51 52 /* All AdminQ command structs should be naturally packed. The static_assert 53 * calls make sure this is the case at compile time. 54 */ 55 56 struct gve_adminq_describe_device { 57 __be64 device_descriptor_addr; 58 __be32 device_descriptor_version; 59 __be32 available_length; 60 }; 61 62 static_assert(sizeof(struct gve_adminq_describe_device) == 16); 63 64 struct gve_device_descriptor { 65 __be64 max_registered_pages; 66 __be16 reserved1; 67 __be16 tx_queue_entries; 68 __be16 rx_queue_entries; 69 __be16 default_num_queues; 70 __be16 mtu; 71 __be16 counters; 72 __be16 tx_pages_per_qpl; 73 __be16 rx_pages_per_qpl; 74 u8 mac[ETH_ALEN]; 75 __be16 num_device_options; 76 __be16 total_length; 77 u8 reserved2[6]; 78 }; 79 80 static_assert(sizeof(struct gve_device_descriptor) == 40); 81 82 struct gve_device_option { 83 __be16 option_id; 84 __be16 option_length; 85 __be32 feat_mask; 86 }; 87 88 static_assert(sizeof(struct gve_device_option) == 8); 89 90 #define GVE_DEV_OPT_ID_RAW_ADDRESSING 0x1 91 #define GVE_DEV_OPT_LEN_RAW_ADDRESSING 0x0 92 #define GVE_DEV_OPT_FEAT_MASK_RAW_ADDRESSING 0x0 93 94 struct gve_adminq_configure_device_resources { 95 __be64 counter_array; 96 __be64 irq_db_addr; 97 __be32 num_counters; 98 __be32 num_irq_dbs; 99 __be32 irq_db_stride; 100 __be32 ntfy_blk_msix_base_idx; 101 }; 102 103 static_assert(sizeof(struct gve_adminq_configure_device_resources) == 32); 104 105 struct gve_adminq_register_page_list { 106 __be32 page_list_id; 107 __be32 num_pages; 108 __be64 page_address_list_addr; 109 }; 110 111 static_assert(sizeof(struct gve_adminq_register_page_list) == 16); 112 113 struct gve_adminq_unregister_page_list { 114 __be32 page_list_id; 115 }; 116 117 static_assert(sizeof(struct gve_adminq_unregister_page_list) == 4); 118 119 #define GVE_RAW_ADDRESSING_QPL_ID 0xFFFFFFFF 120 121 struct gve_adminq_create_tx_queue { 122 __be32 queue_id; 123 __be32 reserved; 124 __be64 queue_resources_addr; 125 __be64 tx_ring_addr; 126 __be32 queue_page_list_id; 127 __be32 ntfy_id; 128 }; 129 130 static_assert(sizeof(struct gve_adminq_create_tx_queue) == 32); 131 132 struct gve_adminq_create_rx_queue { 133 __be32 queue_id; 134 __be32 index; 135 __be32 reserved; 136 __be32 ntfy_id; 137 __be64 queue_resources_addr; 138 __be64 rx_desc_ring_addr; 139 __be64 rx_data_ring_addr; 140 __be32 queue_page_list_id; 141 u8 padding[4]; 142 }; 143 144 static_assert(sizeof(struct gve_adminq_create_rx_queue) == 48); 145 146 /* Queue resources that are shared with the device */ 147 struct gve_queue_resources { 148 union { 149 struct { 150 __be32 db_index; /* Device -> Guest */ 151 __be32 counter_index; /* Device -> Guest */ 152 }; 153 u8 reserved[64]; 154 }; 155 }; 156 157 static_assert(sizeof(struct gve_queue_resources) == 64); 158 159 struct gve_adminq_destroy_tx_queue { 160 __be32 queue_id; 161 }; 162 163 static_assert(sizeof(struct gve_adminq_destroy_tx_queue) == 4); 164 165 struct gve_adminq_destroy_rx_queue { 166 __be32 queue_id; 167 }; 168 169 static_assert(sizeof(struct gve_adminq_destroy_rx_queue) == 4); 170 171 /* GVE Set Driver Parameter Types */ 172 enum gve_set_driver_param_types { 173 GVE_SET_PARAM_MTU = 0x1, 174 }; 175 176 struct gve_adminq_set_driver_parameter { 177 __be32 parameter_type; 178 u8 reserved[4]; 179 __be64 parameter_value; 180 }; 181 182 static_assert(sizeof(struct gve_adminq_set_driver_parameter) == 16); 183 184 struct gve_adminq_report_stats { 185 __be64 stats_report_len; 186 __be64 stats_report_addr; 187 __be64 interval; 188 }; 189 190 static_assert(sizeof(struct gve_adminq_report_stats) == 24); 191 192 struct gve_adminq_report_link_speed { 193 __be64 link_speed_address; 194 }; 195 196 static_assert(sizeof(struct gve_adminq_report_link_speed) == 8); 197 198 struct stats { 199 __be32 stat_name; 200 __be32 queue_id; 201 __be64 value; 202 }; 203 204 static_assert(sizeof(struct stats) == 16); 205 206 struct gve_stats_report { 207 __be64 written_count; 208 struct stats stats[]; 209 }; 210 211 static_assert(sizeof(struct gve_stats_report) == 8); 212 213 enum gve_stat_names { 214 // stats from gve 215 TX_WAKE_CNT = 1, 216 TX_STOP_CNT = 2, 217 TX_FRAMES_SENT = 3, 218 TX_BYTES_SENT = 4, 219 TX_LAST_COMPLETION_PROCESSED = 5, 220 RX_NEXT_EXPECTED_SEQUENCE = 6, 221 RX_BUFFERS_POSTED = 7, 222 // stats from NIC 223 RX_QUEUE_DROP_CNT = 65, 224 RX_NO_BUFFERS_POSTED = 66, 225 RX_DROPS_PACKET_OVER_MRU = 67, 226 RX_DROPS_INVALID_CHECKSUM = 68, 227 }; 228 229 union gve_adminq_command { 230 struct { 231 __be32 opcode; 232 __be32 status; 233 union { 234 struct gve_adminq_configure_device_resources 235 configure_device_resources; 236 struct gve_adminq_create_tx_queue create_tx_queue; 237 struct gve_adminq_create_rx_queue create_rx_queue; 238 struct gve_adminq_destroy_tx_queue destroy_tx_queue; 239 struct gve_adminq_destroy_rx_queue destroy_rx_queue; 240 struct gve_adminq_describe_device describe_device; 241 struct gve_adminq_register_page_list reg_page_list; 242 struct gve_adminq_unregister_page_list unreg_page_list; 243 struct gve_adminq_set_driver_parameter set_driver_param; 244 struct gve_adminq_report_stats report_stats; 245 struct gve_adminq_report_link_speed report_link_speed; 246 }; 247 }; 248 u8 reserved[64]; 249 }; 250 251 static_assert(sizeof(union gve_adminq_command) == 64); 252 253 int gve_adminq_alloc(struct device *dev, struct gve_priv *priv); 254 void gve_adminq_free(struct device *dev, struct gve_priv *priv); 255 void gve_adminq_release(struct gve_priv *priv); 256 int gve_adminq_describe_device(struct gve_priv *priv); 257 int gve_adminq_configure_device_resources(struct gve_priv *priv, 258 dma_addr_t counter_array_bus_addr, 259 u32 num_counters, 260 dma_addr_t db_array_bus_addr, 261 u32 num_ntfy_blks); 262 int gve_adminq_deconfigure_device_resources(struct gve_priv *priv); 263 int gve_adminq_create_tx_queues(struct gve_priv *priv, u32 num_queues); 264 int gve_adminq_destroy_tx_queues(struct gve_priv *priv, u32 queue_id); 265 int gve_adminq_create_rx_queues(struct gve_priv *priv, u32 num_queues); 266 int gve_adminq_destroy_rx_queues(struct gve_priv *priv, u32 queue_id); 267 int gve_adminq_register_page_list(struct gve_priv *priv, 268 struct gve_queue_page_list *qpl); 269 int gve_adminq_unregister_page_list(struct gve_priv *priv, u32 page_list_id); 270 int gve_adminq_set_mtu(struct gve_priv *priv, u64 mtu); 271 int gve_adminq_report_stats(struct gve_priv *priv, u64 stats_report_len, 272 dma_addr_t stats_report_addr, u64 interval); 273 int gve_adminq_report_link_speed(struct gve_priv *priv); 274 #endif /* _GVE_ADMINQ_H */ 275