xref: /linux/drivers/net/ethernet/google/gve/gve_adminq.h (revision 6fdcba32711044c35c0e1b094cbd8f3f0b4472c9)
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 };
25 
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,
46 };
47 
48 #define GVE_ADMINQ_DEVICE_DESCRIPTOR_VERSION 1
49 
50 /* All AdminQ command structs should be naturally packed. The static_assert
51  * calls make sure this is the case at compile time.
52  */
53 
54 struct gve_adminq_describe_device {
55 	__be64 device_descriptor_addr;
56 	__be32 device_descriptor_version;
57 	__be32 available_length;
58 };
59 
60 static_assert(sizeof(struct gve_adminq_describe_device) == 16);
61 
62 struct gve_device_descriptor {
63 	__be64 max_registered_pages;
64 	__be16 reserved1;
65 	__be16 tx_queue_entries;
66 	__be16 rx_queue_entries;
67 	__be16 default_num_queues;
68 	__be16 mtu;
69 	__be16 counters;
70 	__be16 tx_pages_per_qpl;
71 	__be16 rx_pages_per_qpl;
72 	u8  mac[ETH_ALEN];
73 	__be16 num_device_options;
74 	__be16 total_length;
75 	u8  reserved2[6];
76 };
77 
78 static_assert(sizeof(struct gve_device_descriptor) == 40);
79 
80 struct device_option {
81 	__be32 option_id;
82 	__be32 option_length;
83 };
84 
85 static_assert(sizeof(struct device_option) == 8);
86 
87 struct gve_adminq_configure_device_resources {
88 	__be64 counter_array;
89 	__be64 irq_db_addr;
90 	__be32 num_counters;
91 	__be32 num_irq_dbs;
92 	__be32 irq_db_stride;
93 	__be32 ntfy_blk_msix_base_idx;
94 };
95 
96 static_assert(sizeof(struct gve_adminq_configure_device_resources) == 32);
97 
98 struct gve_adminq_register_page_list {
99 	__be32 page_list_id;
100 	__be32 num_pages;
101 	__be64 page_address_list_addr;
102 };
103 
104 static_assert(sizeof(struct gve_adminq_register_page_list) == 16);
105 
106 struct gve_adminq_unregister_page_list {
107 	__be32 page_list_id;
108 };
109 
110 static_assert(sizeof(struct gve_adminq_unregister_page_list) == 4);
111 
112 struct gve_adminq_create_tx_queue {
113 	__be32 queue_id;
114 	__be32 reserved;
115 	__be64 queue_resources_addr;
116 	__be64 tx_ring_addr;
117 	__be32 queue_page_list_id;
118 	__be32 ntfy_id;
119 };
120 
121 static_assert(sizeof(struct gve_adminq_create_tx_queue) == 32);
122 
123 struct gve_adminq_create_rx_queue {
124 	__be32 queue_id;
125 	__be32 index;
126 	__be32 reserved;
127 	__be32 ntfy_id;
128 	__be64 queue_resources_addr;
129 	__be64 rx_desc_ring_addr;
130 	__be64 rx_data_ring_addr;
131 	__be32 queue_page_list_id;
132 	u8 padding[4];
133 };
134 
135 static_assert(sizeof(struct gve_adminq_create_rx_queue) == 48);
136 
137 /* Queue resources that are shared with the device */
138 struct gve_queue_resources {
139 	union {
140 		struct {
141 			__be32 db_index;	/* Device -> Guest */
142 			__be32 counter_index;	/* Device -> Guest */
143 		};
144 		u8 reserved[64];
145 	};
146 };
147 
148 static_assert(sizeof(struct gve_queue_resources) == 64);
149 
150 struct gve_adminq_destroy_tx_queue {
151 	__be32 queue_id;
152 };
153 
154 static_assert(sizeof(struct gve_adminq_destroy_tx_queue) == 4);
155 
156 struct gve_adminq_destroy_rx_queue {
157 	__be32 queue_id;
158 };
159 
160 static_assert(sizeof(struct gve_adminq_destroy_rx_queue) == 4);
161 
162 /* GVE Set Driver Parameter Types */
163 enum gve_set_driver_param_types {
164 	GVE_SET_PARAM_MTU	= 0x1,
165 };
166 
167 struct gve_adminq_set_driver_parameter {
168 	__be32 parameter_type;
169 	u8 reserved[4];
170 	__be64 parameter_value;
171 };
172 
173 static_assert(sizeof(struct gve_adminq_set_driver_parameter) == 16);
174 
175 union gve_adminq_command {
176 	struct {
177 		__be32 opcode;
178 		__be32 status;
179 		union {
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;
190 		};
191 	};
192 	u8 reserved[64];
193 };
194 
195 static_assert(sizeof(union gve_adminq_command) == 64);
196 
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,
205 					  u32 num_counters,
206 					  dma_addr_t db_array_bus_addr,
207 					  u32 num_ntfy_blks);
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 */
218