1 /* SPDX-License-Identifier: (GPL-2.0 OR MIT)
2 * Google virtual Ethernet (gve) driver
4 * Copyright (C) 2015-2019 Google, Inc.
10 #include <linux/build_bug.h>
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,
26 /* Admin queue status codes */
27 enum gve_adminq_statuses
{
28 GVE_ADMINQ_COMMAND_UNSET
= 0x0,
29 GVE_ADMINQ_COMMAND_PASSED
= 0x1,
30 GVE_ADMINQ_COMMAND_ERROR_ABORTED
= 0xFFFFFFF0,
31 GVE_ADMINQ_COMMAND_ERROR_ALREADY_EXISTS
= 0xFFFFFFF1,
32 GVE_ADMINQ_COMMAND_ERROR_CANCELLED
= 0xFFFFFFF2,
33 GVE_ADMINQ_COMMAND_ERROR_DATALOSS
= 0xFFFFFFF3,
34 GVE_ADMINQ_COMMAND_ERROR_DEADLINE_EXCEEDED
= 0xFFFFFFF4,
35 GVE_ADMINQ_COMMAND_ERROR_FAILED_PRECONDITION
= 0xFFFFFFF5,
36 GVE_ADMINQ_COMMAND_ERROR_INTERNAL_ERROR
= 0xFFFFFFF6,
37 GVE_ADMINQ_COMMAND_ERROR_INVALID_ARGUMENT
= 0xFFFFFFF7,
38 GVE_ADMINQ_COMMAND_ERROR_NOT_FOUND
= 0xFFFFFFF8,
39 GVE_ADMINQ_COMMAND_ERROR_OUT_OF_RANGE
= 0xFFFFFFF9,
40 GVE_ADMINQ_COMMAND_ERROR_PERMISSION_DENIED
= 0xFFFFFFFA,
41 GVE_ADMINQ_COMMAND_ERROR_UNAUTHENTICATED
= 0xFFFFFFFB,
42 GVE_ADMINQ_COMMAND_ERROR_RESOURCE_EXHAUSTED
= 0xFFFFFFFC,
43 GVE_ADMINQ_COMMAND_ERROR_UNAVAILABLE
= 0xFFFFFFFD,
44 GVE_ADMINQ_COMMAND_ERROR_UNIMPLEMENTED
= 0xFFFFFFFE,
45 GVE_ADMINQ_COMMAND_ERROR_UNKNOWN_ERROR
= 0xFFFFFFFF,
48 #define GVE_ADMINQ_DEVICE_DESCRIPTOR_VERSION 1
50 /* All AdminQ command structs should be naturally packed. The static_assert
51 * calls make sure this is the case at compile time.
54 struct gve_adminq_describe_device
{
55 __be64 device_descriptor_addr
;
56 __be32 device_descriptor_version
;
57 __be32 available_length
;
60 static_assert(sizeof(struct gve_adminq_describe_device
) == 16);
62 struct gve_device_descriptor
{
63 __be64 max_registered_pages
;
65 __be16 tx_queue_entries
;
66 __be16 rx_queue_entries
;
67 __be16 default_num_queues
;
70 __be16 tx_pages_per_qpl
;
71 __be16 rx_pages_per_qpl
;
73 __be16 num_device_options
;
78 static_assert(sizeof(struct gve_device_descriptor
) == 40);
80 struct device_option
{
85 static_assert(sizeof(struct device_option
) == 8);
87 struct gve_adminq_configure_device_resources
{
93 __be32 ntfy_blk_msix_base_idx
;
96 static_assert(sizeof(struct gve_adminq_configure_device_resources
) == 32);
98 struct gve_adminq_register_page_list
{
101 __be64 page_address_list_addr
;
104 static_assert(sizeof(struct gve_adminq_register_page_list
) == 16);
106 struct gve_adminq_unregister_page_list
{
110 static_assert(sizeof(struct gve_adminq_unregister_page_list
) == 4);
112 struct gve_adminq_create_tx_queue
{
115 __be64 queue_resources_addr
;
117 __be32 queue_page_list_id
;
121 static_assert(sizeof(struct gve_adminq_create_tx_queue
) == 32);
123 struct gve_adminq_create_rx_queue
{
128 __be64 queue_resources_addr
;
129 __be64 rx_desc_ring_addr
;
130 __be64 rx_data_ring_addr
;
131 __be32 queue_page_list_id
;
135 static_assert(sizeof(struct gve_adminq_create_rx_queue
) == 48);
137 /* Queue resources that are shared with the device */
138 struct gve_queue_resources
{
141 __be32 db_index
; /* Device -> Guest */
142 __be32 counter_index
; /* Device -> Guest */
148 static_assert(sizeof(struct gve_queue_resources
) == 64);
150 struct gve_adminq_destroy_tx_queue
{
154 static_assert(sizeof(struct gve_adminq_destroy_tx_queue
) == 4);
156 struct gve_adminq_destroy_rx_queue
{
160 static_assert(sizeof(struct gve_adminq_destroy_rx_queue
) == 4);
162 /* GVE Set Driver Parameter Types */
163 enum gve_set_driver_param_types
{
164 GVE_SET_PARAM_MTU
= 0x1,
167 struct gve_adminq_set_driver_parameter
{
168 __be32 parameter_type
;
170 __be64 parameter_value
;
173 static_assert(sizeof(struct gve_adminq_set_driver_parameter
) == 16);
175 union gve_adminq_command
{
180 struct gve_adminq_configure_device_resources
181 configure_device_resources
;
182 struct gve_adminq_create_tx_queue create_tx_queue
;
183 struct gve_adminq_create_rx_queue create_rx_queue
;
184 struct gve_adminq_destroy_tx_queue destroy_tx_queue
;
185 struct gve_adminq_destroy_rx_queue destroy_rx_queue
;
186 struct gve_adminq_describe_device describe_device
;
187 struct gve_adminq_register_page_list reg_page_list
;
188 struct gve_adminq_unregister_page_list unreg_page_list
;
189 struct gve_adminq_set_driver_parameter set_driver_param
;
195 static_assert(sizeof(union gve_adminq_command
) == 64);
197 int gve_adminq_alloc(struct device
*dev
, struct gve_priv
*priv
);
198 void gve_adminq_free(struct device
*dev
, struct gve_priv
*priv
);
199 void gve_adminq_release(struct gve_priv
*priv
);
200 int gve_adminq_execute_cmd(struct gve_priv
*priv
,
201 union gve_adminq_command
*cmd_orig
);
202 int gve_adminq_describe_device(struct gve_priv
*priv
);
203 int gve_adminq_configure_device_resources(struct gve_priv
*priv
,
204 dma_addr_t counter_array_bus_addr
,
206 dma_addr_t db_array_bus_addr
,
208 int gve_adminq_deconfigure_device_resources(struct gve_priv
*priv
);
209 int gve_adminq_create_tx_queue(struct gve_priv
*priv
, u32 queue_id
);
210 int gve_adminq_destroy_tx_queue(struct gve_priv
*priv
, u32 queue_id
);
211 int gve_adminq_create_rx_queue(struct gve_priv
*priv
, u32 queue_id
);
212 int gve_adminq_destroy_rx_queue(struct gve_priv
*priv
, u32 queue_id
);
213 int gve_adminq_register_page_list(struct gve_priv
*priv
,
214 struct gve_queue_page_list
*qpl
);
215 int gve_adminq_unregister_page_list(struct gve_priv
*priv
, u32 page_list_id
);
216 int gve_adminq_set_mtu(struct gve_priv
*priv
, u64 mtu
);
217 #endif /* _GVE_ADMINQ_H */