Branch data Line data Source code
1 : : /* SPDX-License-Identifier: MIT
2 : : * Google Virtual Ethernet (gve) driver
3 : : * Copyright (C) 2015-2022 Google, Inc.
4 : : */
5 : :
6 : : #include <rte_common.h>
7 : :
8 : : #include "../gve_ethdev.h"
9 : : #include "gve_adminq.h"
10 : : #include "gve_register.h"
11 : : #include "gve_rss.h"
12 : :
13 : : #define GVE_MAX_ADMINQ_RELEASE_CHECK 500
14 : : #define GVE_ADMINQ_SLEEP_LEN 20
15 : : #define GVE_MAX_ADMINQ_EVENT_COUNTER_CHECK 100
16 : :
17 : : #define GVE_DEVICE_OPTION_ERROR_FMT "%s option error: Expected: length=%d, feature_mask=%x. Actual: length=%d, feature_mask=%x."
18 : :
19 : : #define GVE_DEVICE_OPTION_TOO_BIG_FMT "Length of %s option larger than expected. Possible older version of guest driver."
20 : :
21 : : static void gve_set_min_desc_cnt(struct gve_priv *priv,
22 : : struct gve_device_option_modify_ring *dev_op_modify_ring);
23 : :
24 : : static
25 : : struct gve_device_option *gve_get_next_option(struct gve_device_descriptor *descriptor,
26 : : struct gve_device_option *option)
27 : : {
28 : : uintptr_t option_end, descriptor_end;
29 : :
30 [ # # ]: 0 : option_end = (uintptr_t)option + sizeof(*option) + be16_to_cpu(option->option_length);
31 [ # # ]: 0 : descriptor_end = (uintptr_t)descriptor + be16_to_cpu(descriptor->total_length);
32 : :
33 [ # # ]: 0 : return option_end > descriptor_end ? NULL : (struct gve_device_option *)option_end;
34 : : }
35 : :
36 : : static
37 : 0 : void gve_parse_device_option(struct gve_priv *priv,
38 : : struct gve_device_option *option,
39 : : struct gve_device_option_gqi_rda **dev_op_gqi_rda,
40 : : struct gve_device_option_gqi_qpl **dev_op_gqi_qpl,
41 : : struct gve_device_option_dqo_rda **dev_op_dqo_rda,
42 : : struct gve_device_option_flow_steering **dev_op_flow_steering,
43 : : struct gve_device_option_modify_ring **dev_op_modify_ring,
44 : : struct gve_device_option_jumbo_frames **dev_op_jumbo_frames,
45 : : struct gve_device_option_nic_timestamp **dev_op_nic_timestamp)
46 : : {
47 [ # # ]: 0 : u32 req_feat_mask = be32_to_cpu(option->required_features_mask);
48 [ # # ]: 0 : u16 option_length = be16_to_cpu(option->option_length);
49 [ # # ]: 0 : u16 option_id = be16_to_cpu(option->option_id);
50 : :
51 : : /* If the length or feature mask doesn't match, continue without
52 : : * enabling the feature.
53 : : */
54 [ # # # # : 0 : switch (option_id) {
# # # #
# ]
55 : 0 : case GVE_DEV_OPT_ID_GQI_RAW_ADDRESSING:
56 : 0 : if (option_length != GVE_DEV_OPT_LEN_GQI_RAW_ADDRESSING ||
57 [ # # ]: 0 : req_feat_mask != GVE_DEV_OPT_REQ_FEAT_MASK_GQI_RAW_ADDRESSING) {
58 : 0 : PMD_DRV_LOG(WARNING, GVE_DEVICE_OPTION_ERROR_FMT,
59 : : "Raw Addressing",
60 : : GVE_DEV_OPT_LEN_GQI_RAW_ADDRESSING,
61 : : GVE_DEV_OPT_REQ_FEAT_MASK_GQI_RAW_ADDRESSING,
62 : : option_length, req_feat_mask);
63 : 0 : break;
64 : : }
65 : :
66 : 0 : PMD_DRV_LOG(INFO, "Gqi raw addressing device option enabled.");
67 : 0 : priv->queue_format = GVE_GQI_RDA_FORMAT;
68 : 0 : break;
69 : 0 : case GVE_DEV_OPT_ID_GQI_RDA:
70 : 0 : if (option_length < sizeof(**dev_op_gqi_rda) ||
71 [ # # ]: 0 : req_feat_mask != GVE_DEV_OPT_REQ_FEAT_MASK_GQI_RDA) {
72 : 0 : PMD_DRV_LOG(WARNING, GVE_DEVICE_OPTION_ERROR_FMT,
73 : : "GQI RDA", (int)sizeof(**dev_op_gqi_rda),
74 : : GVE_DEV_OPT_REQ_FEAT_MASK_GQI_RDA,
75 : : option_length, req_feat_mask);
76 : 0 : break;
77 : : }
78 : :
79 [ # # ]: 0 : if (option_length > sizeof(**dev_op_gqi_rda)) {
80 : 0 : PMD_DRV_LOG(WARNING,
81 : : GVE_DEVICE_OPTION_TOO_BIG_FMT, "GQI RDA");
82 : : }
83 : 0 : *dev_op_gqi_rda = RTE_PTR_ADD(option, sizeof(*option));
84 : 0 : break;
85 : 0 : case GVE_DEV_OPT_ID_GQI_QPL:
86 : 0 : if (option_length < sizeof(**dev_op_gqi_qpl) ||
87 [ # # ]: 0 : req_feat_mask != GVE_DEV_OPT_REQ_FEAT_MASK_GQI_QPL) {
88 : 0 : PMD_DRV_LOG(WARNING, GVE_DEVICE_OPTION_ERROR_FMT,
89 : : "GQI QPL", (int)sizeof(**dev_op_gqi_qpl),
90 : : GVE_DEV_OPT_REQ_FEAT_MASK_GQI_QPL,
91 : : option_length, req_feat_mask);
92 : 0 : break;
93 : : }
94 : :
95 [ # # ]: 0 : if (option_length > sizeof(**dev_op_gqi_qpl)) {
96 : 0 : PMD_DRV_LOG(WARNING,
97 : : GVE_DEVICE_OPTION_TOO_BIG_FMT, "GQI QPL");
98 : : }
99 : 0 : *dev_op_gqi_qpl = RTE_PTR_ADD(option, sizeof(*option));
100 : 0 : break;
101 : 0 : case GVE_DEV_OPT_ID_DQO_RDA:
102 : 0 : if (option_length < sizeof(**dev_op_dqo_rda) ||
103 [ # # ]: 0 : req_feat_mask != GVE_DEV_OPT_REQ_FEAT_MASK_DQO_RDA) {
104 : 0 : PMD_DRV_LOG(WARNING, GVE_DEVICE_OPTION_ERROR_FMT,
105 : : "DQO RDA", (int)sizeof(**dev_op_dqo_rda),
106 : : GVE_DEV_OPT_REQ_FEAT_MASK_DQO_RDA,
107 : : option_length, req_feat_mask);
108 : 0 : break;
109 : : }
110 : :
111 [ # # ]: 0 : if (option_length > sizeof(**dev_op_dqo_rda)) {
112 : 0 : PMD_DRV_LOG(WARNING,
113 : : GVE_DEVICE_OPTION_TOO_BIG_FMT, "DQO RDA");
114 : : }
115 : 0 : *dev_op_dqo_rda = RTE_PTR_ADD(option, sizeof(*option));
116 : 0 : break;
117 : 0 : case GVE_DEV_OPT_ID_FLOW_STEERING:
118 : 0 : if (option_length < sizeof(**dev_op_flow_steering) ||
119 [ # # ]: 0 : req_feat_mask != GVE_DEV_OPT_REQ_FEAT_MASK_FLOW_STEERING) {
120 : 0 : PMD_DRV_LOG(WARNING, GVE_DEVICE_OPTION_ERROR_FMT,
121 : : "Flow Steering", (int)sizeof(**dev_op_flow_steering),
122 : : GVE_DEV_OPT_REQ_FEAT_MASK_FLOW_STEERING,
123 : : option_length, req_feat_mask);
124 : 0 : break;
125 : : }
126 : :
127 [ # # ]: 0 : if (option_length > sizeof(**dev_op_flow_steering)) {
128 : 0 : PMD_DRV_LOG(WARNING,
129 : : GVE_DEVICE_OPTION_TOO_BIG_FMT, "Flow Steering");
130 : : }
131 : 0 : *dev_op_flow_steering = RTE_PTR_ADD(option, sizeof(*option));
132 : 0 : break;
133 : 0 : case GVE_DEV_OPT_ID_MODIFY_RING:
134 : : /* Min ring size bound is optional. */
135 : 0 : if (option_length < (sizeof(**dev_op_modify_ring) -
136 : 0 : sizeof(struct gve_ring_size_bound)) ||
137 [ # # ]: 0 : req_feat_mask != GVE_DEV_OPT_REQ_FEAT_MASK_MODIFY_RING) {
138 : 0 : PMD_DRV_LOG(WARNING, GVE_DEVICE_OPTION_ERROR_FMT,
139 : : "Modify Ring",
140 : : (int)sizeof(**dev_op_modify_ring),
141 : : GVE_DEV_OPT_REQ_FEAT_MASK_MODIFY_RING,
142 : : option_length, req_feat_mask);
143 : 0 : break;
144 : : }
145 : :
146 [ # # ]: 0 : if (option_length > sizeof(**dev_op_modify_ring)) {
147 : 0 : PMD_DRV_LOG(WARNING,
148 : : GVE_DEVICE_OPTION_TOO_BIG_FMT,
149 : : "Modify Ring");
150 : : }
151 : 0 : *dev_op_modify_ring = RTE_PTR_ADD(option, sizeof(*option));
152 : :
153 : : /* Min ring size included; set the minimum ring size. */
154 [ # # ]: 0 : if (option_length == sizeof(**dev_op_modify_ring))
155 : : gve_set_min_desc_cnt(priv, *dev_op_modify_ring);
156 : : break;
157 : 0 : case GVE_DEV_OPT_ID_JUMBO_FRAMES:
158 : 0 : if (option_length < sizeof(**dev_op_jumbo_frames) ||
159 [ # # ]: 0 : req_feat_mask != GVE_DEV_OPT_REQ_FEAT_MASK_JUMBO_FRAMES) {
160 : 0 : PMD_DRV_LOG(WARNING, GVE_DEVICE_OPTION_ERROR_FMT,
161 : : "Jumbo Frames",
162 : : (int)sizeof(**dev_op_jumbo_frames),
163 : : GVE_DEV_OPT_REQ_FEAT_MASK_JUMBO_FRAMES,
164 : : option_length, req_feat_mask);
165 : 0 : break;
166 : : }
167 : :
168 [ # # ]: 0 : if (option_length > sizeof(**dev_op_jumbo_frames)) {
169 : 0 : PMD_DRV_LOG(WARNING,
170 : : GVE_DEVICE_OPTION_TOO_BIG_FMT,
171 : : "Jumbo Frames");
172 : : }
173 : 0 : *dev_op_jumbo_frames = RTE_PTR_ADD(option, sizeof(*option));
174 : 0 : break;
175 : 0 : case GVE_DEV_OPT_ID_NIC_TIMESTAMP:
176 : 0 : if (option_length < sizeof(**dev_op_nic_timestamp) ||
177 [ # # ]: 0 : req_feat_mask != GVE_DEV_OPT_REQ_FEAT_MASK_NIC_TIMESTAMP) {
178 : 0 : PMD_DRV_LOG(WARNING, GVE_DEVICE_OPTION_ERROR_FMT,
179 : : "Nic Timestamp",
180 : : (int)sizeof(**dev_op_nic_timestamp),
181 : : GVE_DEV_OPT_REQ_FEAT_MASK_NIC_TIMESTAMP,
182 : : option_length, req_feat_mask);
183 : 0 : break;
184 : : }
185 : :
186 [ # # ]: 0 : if (option_length > sizeof(**dev_op_nic_timestamp)) {
187 : 0 : PMD_DRV_LOG(WARNING,
188 : : GVE_DEVICE_OPTION_TOO_BIG_FMT,
189 : : "Nic Timestamp");
190 : : }
191 : 0 : *dev_op_nic_timestamp = RTE_PTR_ADD(option, sizeof(*option));
192 : 0 : break;
193 : 0 : default:
194 : : /* If we don't recognize the option just continue
195 : : * without doing anything.
196 : : */
197 : 0 : PMD_DRV_LOG(DEBUG, "Unrecognized device option 0x%hx not enabled.",
198 : : option_id);
199 : : }
200 : 0 : }
201 : :
202 : : /* Process all device options for a given describe device call. */
203 : : static int
204 : 0 : gve_process_device_options(struct gve_priv *priv,
205 : : struct gve_device_descriptor *descriptor,
206 : : struct gve_device_option_gqi_rda **dev_op_gqi_rda,
207 : : struct gve_device_option_gqi_qpl **dev_op_gqi_qpl,
208 : : struct gve_device_option_dqo_rda **dev_op_dqo_rda,
209 : : struct gve_device_option_flow_steering **dev_op_flow_steering,
210 : : struct gve_device_option_modify_ring **dev_op_modify_ring,
211 : : struct gve_device_option_jumbo_frames **dev_op_jumbo_frames,
212 : : struct gve_device_option_nic_timestamp **dev_op_nic_timestamp)
213 : : {
214 [ # # ]: 0 : const int num_options = be16_to_cpu(descriptor->num_device_options);
215 : : struct gve_device_option *dev_opt;
216 : : int i;
217 : :
218 : : /* The options struct directly follows the device descriptor. */
219 : 0 : dev_opt = RTE_PTR_ADD(descriptor, sizeof(*descriptor));
220 [ # # ]: 0 : for (i = 0; i < num_options; i++) {
221 : : struct gve_device_option *next_opt;
222 : :
223 : : next_opt = gve_get_next_option(descriptor, dev_opt);
224 [ # # ]: 0 : if (!next_opt) {
225 : 0 : PMD_DRV_LOG(ERR,
226 : : "options exceed device_descriptor's total length.");
227 : 0 : return -EINVAL;
228 : : }
229 : :
230 : 0 : gve_parse_device_option(priv, dev_opt,
231 : : dev_op_gqi_rda, dev_op_gqi_qpl,
232 : : dev_op_dqo_rda, dev_op_flow_steering,
233 : : dev_op_modify_ring, dev_op_jumbo_frames,
234 : : dev_op_nic_timestamp);
235 : : dev_opt = next_opt;
236 : : }
237 : :
238 : : return 0;
239 : : }
240 : :
241 : 0 : int gve_adminq_alloc(struct gve_priv *priv)
242 : : {
243 : : pthread_mutexattr_t mutexattr;
244 : : uint8_t pci_rev_id;
245 : :
246 : 0 : priv->adminq = gve_alloc_dma_mem(&priv->adminq_dma_mem, PAGE_SIZE);
247 [ # # ]: 0 : if (unlikely(!priv->adminq))
248 : : return -ENOMEM;
249 : :
250 : 0 : priv->adminq_mask = (PAGE_SIZE / sizeof(union gve_adminq_command)) - 1;
251 : 0 : priv->adminq_prod_cnt = 0;
252 : 0 : priv->adminq_cmd_fail = 0;
253 : 0 : priv->adminq_timeouts = 0;
254 : 0 : priv->adminq_describe_device_cnt = 0;
255 : 0 : priv->adminq_cfg_device_resources_cnt = 0;
256 : 0 : priv->adminq_register_page_list_cnt = 0;
257 : 0 : priv->adminq_unregister_page_list_cnt = 0;
258 : 0 : priv->adminq_create_tx_queue_cnt = 0;
259 : 0 : priv->adminq_create_rx_queue_cnt = 0;
260 : 0 : priv->adminq_destroy_tx_queue_cnt = 0;
261 : 0 : priv->adminq_destroy_rx_queue_cnt = 0;
262 : 0 : priv->adminq_dcfg_device_resources_cnt = 0;
263 : 0 : priv->adminq_set_driver_parameter_cnt = 0;
264 : 0 : priv->adminq_report_stats_cnt = 0;
265 : 0 : priv->adminq_report_link_speed_cnt = 0;
266 : 0 : priv->adminq_get_ptype_map_cnt = 0;
267 : 0 : priv->adminq_cfg_flow_rule_cnt = 0;
268 : :
269 : 0 : priv->adminq_report_nic_timestamp_cnt = 0;
270 : :
271 : 0 : pthread_mutexattr_init(&mutexattr);
272 : 0 : pthread_mutexattr_setpshared(&mutexattr, PTHREAD_PROCESS_SHARED);
273 : 0 : pthread_mutex_init(&priv->adminq_lock, &mutexattr);
274 : 0 : pthread_mutexattr_destroy(&mutexattr);
275 : :
276 : : /* Setup Admin queue with the device */
277 : 0 : rte_pci_read_config(priv->pci_dev, &pci_rev_id, sizeof(pci_rev_id),
278 : : RTE_PCI_REVISION_ID);
279 [ # # ]: 0 : if (pci_rev_id < 0x1) { /* Use AQ PFN. */
280 : 0 : iowrite32be(priv->adminq_dma_mem.pa / PAGE_SIZE,
281 [ # # ]: 0 : &priv->reg_bar0->adminq_pfn);
282 : : } else { /* Use full AQ address. */
283 : : iowrite16be(GVE_ADMINQ_BUFFER_SIZE,
284 : 0 : &priv->reg_bar0->adminq_length);
285 : 0 : iowrite32be(priv->adminq_dma_mem.pa >> 32,
286 [ # # ]: 0 : &priv->reg_bar0->adminq_base_address_hi);
287 : 0 : iowrite32be(priv->adminq_dma_mem.pa,
288 [ # # ]: 0 : &priv->reg_bar0->adminq_base_address_lo);
289 : : iowrite32be(GVE_DRIVER_STATUS_RUN_MASK,
290 : 0 : &priv->reg_bar0->driver_status);
291 : : }
292 : :
293 : : gve_set_admin_queue_ok(priv);
294 : 0 : return 0;
295 : : }
296 : :
297 : 0 : void gve_adminq_release(struct gve_priv *priv)
298 : : {
299 : : uint8_t pci_rev_id;
300 : : int i = 0;
301 : :
302 : : /* Tell the device the adminq is leaving */
303 : 0 : rte_pci_read_config(priv->pci_dev, &pci_rev_id, sizeof(pci_rev_id),
304 : : RTE_PCI_REVISION_ID);
305 [ # # ]: 0 : if (pci_rev_id < 0x1) {
306 : 0 : iowrite32be(0x0, &priv->reg_bar0->adminq_pfn);
307 [ # # ]: 0 : while (ioread32be(&priv->reg_bar0->adminq_pfn)) {
308 : : /* If this is reached the device is unrecoverable and still
309 : : * holding memory. Continue looping to avoid memory corruption,
310 : : * but WARN so it is visible what is going on.
311 : : */
312 [ # # ]: 0 : if (i == GVE_MAX_ADMINQ_RELEASE_CHECK)
313 : 0 : PMD_DRV_LOG(WARNING,
314 : : "Unrecoverable platform error!");
315 : 0 : i++;
316 : : msleep(GVE_ADMINQ_SLEEP_LEN);
317 : : }
318 : : } else {
319 : : iowrite32be(GVE_DRIVER_STATUS_RESET_MASK,
320 : 0 : &priv->reg_bar0->driver_status);
321 : 0 : while (!(ioread32be(&priv->reg_bar0->device_status)
322 [ # # ]: 0 : & GVE_DEVICE_STATUS_DEVICE_IS_RESET)) {
323 [ # # ]: 0 : if (i == GVE_MAX_ADMINQ_RELEASE_CHECK)
324 : 0 : PMD_DRV_LOG(WARNING,
325 : : "Unrecoverable platform error!");
326 : 0 : i++;
327 : : msleep(GVE_ADMINQ_SLEEP_LEN);
328 : : }
329 : : }
330 : : gve_clear_admin_queue_ok(priv);
331 : 0 : }
332 : :
333 [ # # ]: 0 : void gve_adminq_free(struct gve_priv *priv)
334 : : {
335 [ # # ]: 0 : if (!gve_get_admin_queue_ok(priv))
336 : : return;
337 : 0 : gve_adminq_release(priv);
338 : 0 : gve_free_dma_mem(&priv->adminq_dma_mem);
339 : 0 : pthread_mutex_destroy(&priv->adminq_lock);
340 : : gve_clear_admin_queue_ok(priv);
341 : : }
342 : :
343 : : static void gve_adminq_kick_cmd(struct gve_priv *priv, u32 prod_cnt)
344 : : {
345 : 0 : iowrite32be(prod_cnt, &priv->reg_bar0->adminq_doorbell);
346 : 0 : }
347 : :
348 : : static bool gve_adminq_wait_for_cmd(struct gve_priv *priv, u32 prod_cnt)
349 : : {
350 : : int i;
351 : :
352 [ # # ]: 0 : for (i = 0; i < GVE_MAX_ADMINQ_EVENT_COUNTER_CHECK; i++) {
353 [ # # ]: 0 : if (ioread32be(&priv->reg_bar0->adminq_event_counter)
354 : : == prod_cnt)
355 : : return true;
356 : : msleep(GVE_ADMINQ_SLEEP_LEN);
357 : : }
358 : :
359 : : return false;
360 : : }
361 : :
362 : 0 : static int gve_adminq_parse_err(struct gve_priv *priv, u32 status)
363 : : {
364 [ # # ]: 0 : if (status != GVE_ADMINQ_COMMAND_PASSED &&
365 : : status != GVE_ADMINQ_COMMAND_UNSET) {
366 : 0 : PMD_DRV_LOG(ERR, "AQ command failed with status %d", status);
367 : 0 : priv->adminq_cmd_fail++;
368 : : }
369 [ # # # # : 0 : switch (status) {
# # # #
# ]
370 : : case GVE_ADMINQ_COMMAND_PASSED:
371 : : return 0;
372 : 0 : case GVE_ADMINQ_COMMAND_UNSET:
373 : 0 : PMD_DRV_LOG(ERR, "parse_aq_err: err and status both unset, this should not be possible.");
374 : 0 : return -EINVAL;
375 : 0 : case GVE_ADMINQ_COMMAND_ERROR_ABORTED:
376 : : case GVE_ADMINQ_COMMAND_ERROR_CANCELLED:
377 : : case GVE_ADMINQ_COMMAND_ERROR_DATALOSS:
378 : : case GVE_ADMINQ_COMMAND_ERROR_FAILED_PRECONDITION:
379 : : case GVE_ADMINQ_COMMAND_ERROR_UNAVAILABLE:
380 : 0 : return -EAGAIN;
381 : 0 : case GVE_ADMINQ_COMMAND_ERROR_ALREADY_EXISTS:
382 : : case GVE_ADMINQ_COMMAND_ERROR_INTERNAL_ERROR:
383 : : case GVE_ADMINQ_COMMAND_ERROR_INVALID_ARGUMENT:
384 : : case GVE_ADMINQ_COMMAND_ERROR_NOT_FOUND:
385 : : case GVE_ADMINQ_COMMAND_ERROR_OUT_OF_RANGE:
386 : : case GVE_ADMINQ_COMMAND_ERROR_UNKNOWN_ERROR:
387 : 0 : return -EINVAL;
388 : 0 : case GVE_ADMINQ_COMMAND_ERROR_DEADLINE_EXCEEDED:
389 : 0 : return -ETIMEDOUT;
390 : 0 : case GVE_ADMINQ_COMMAND_ERROR_PERMISSION_DENIED:
391 : : case GVE_ADMINQ_COMMAND_ERROR_UNAUTHENTICATED:
392 : 0 : return -EACCES;
393 : 0 : case GVE_ADMINQ_COMMAND_ERROR_RESOURCE_EXHAUSTED:
394 : 0 : return -ENOMEM;
395 : 0 : case GVE_ADMINQ_COMMAND_ERROR_UNIMPLEMENTED:
396 : 0 : return -ENOTSUP;
397 : 0 : default:
398 : 0 : PMD_DRV_LOG(ERR, "parse_aq_err: unknown status code %d",
399 : : status);
400 : 0 : return -EINVAL;
401 : : }
402 : : }
403 : :
404 : : /* Flushes all AQ commands currently queued and waits for them to complete.
405 : : * If there are failures, it will return the first error.
406 : : */
407 : 0 : static int gve_adminq_kick_and_wait(struct gve_priv *priv)
408 : : {
409 : : u32 tail, head;
410 : : u32 i;
411 : :
412 : 0 : tail = ioread32be(&priv->reg_bar0->adminq_event_counter);
413 [ # # ]: 0 : head = priv->adminq_prod_cnt;
414 : :
415 : : gve_adminq_kick_cmd(priv, head);
416 [ # # ]: 0 : if (!gve_adminq_wait_for_cmd(priv, head)) {
417 : 0 : PMD_DRV_LOG(ERR, "AQ commands timed out, need to reset AQ");
418 : 0 : priv->adminq_timeouts++;
419 : 0 : return -ENOTRECOVERABLE;
420 : : }
421 : :
422 [ # # ]: 0 : for (i = tail; i < head; i++) {
423 : : union gve_adminq_command *cmd;
424 : : u32 status, err;
425 : :
426 : 0 : cmd = &priv->adminq[i & priv->adminq_mask];
427 : : status = be32_to_cpu(READ_ONCE32(cmd->status));
428 : 0 : err = gve_adminq_parse_err(priv, status);
429 [ # # ]: 0 : if (err)
430 : : /* Return the first error if we failed. */
431 : 0 : return err;
432 : : }
433 : :
434 : : return 0;
435 : : }
436 : :
437 : : /* This function is not threadsafe - the caller is responsible for any
438 : : * necessary locks.
439 : : */
440 : 0 : static int gve_adminq_issue_cmd(struct gve_priv *priv,
441 : : union gve_adminq_command *cmd_orig)
442 : : {
443 : : union gve_adminq_command *cmd;
444 : : u32 opcode;
445 : : u32 tail;
446 : :
447 : 0 : tail = ioread32be(&priv->reg_bar0->adminq_event_counter);
448 : :
449 : : /* Check if next command will overflow the buffer. */
450 [ # # ]: 0 : if (((priv->adminq_prod_cnt + 1) & priv->adminq_mask) ==
451 : : (tail & priv->adminq_mask)) {
452 : : int err;
453 : :
454 : : /* Flush existing commands to make room.
455 : : * Note: This kicks the doorbell for all staged commands.
456 : : * Any failure here means we failed after attempting to kick.
457 : : */
458 : 0 : err = gve_adminq_kick_and_wait(priv);
459 [ # # ]: 0 : if (err)
460 : : return err;
461 : :
462 : : /* Retry. */
463 : 0 : tail = ioread32be(&priv->reg_bar0->adminq_event_counter);
464 [ # # ]: 0 : if (((priv->adminq_prod_cnt + 1) & priv->adminq_mask) ==
465 : : (tail & priv->adminq_mask)) {
466 : : /* This should never happen. We just flushed the
467 : : * command queue so there should be enough space.
468 : : */
469 : : return -ENOMEM;
470 : : }
471 : : }
472 : :
473 : 0 : cmd = &priv->adminq[priv->adminq_prod_cnt & priv->adminq_mask];
474 : 0 : priv->adminq_prod_cnt++;
475 : :
476 : : memcpy(cmd, cmd_orig, sizeof(*cmd_orig));
477 : : opcode = be32_to_cpu(READ_ONCE32(cmd->opcode));
478 [ # # ]: 0 : if (opcode == GVE_ADMINQ_EXTENDED_COMMAND)
479 : : opcode = be32_to_cpu(READ_ONCE32(cmd->extended_command.inner_opcode));
480 : :
481 [ # # # # : 0 : switch (opcode) {
# # # # #
# # # # #
# # # # ]
482 : 0 : case GVE_ADMINQ_DESCRIBE_DEVICE:
483 : 0 : priv->adminq_describe_device_cnt++;
484 : 0 : break;
485 : 0 : case GVE_ADMINQ_CONFIGURE_DEVICE_RESOURCES:
486 : 0 : priv->adminq_cfg_device_resources_cnt++;
487 : 0 : break;
488 : 0 : case GVE_ADMINQ_REGISTER_PAGE_LIST:
489 : 0 : priv->adminq_register_page_list_cnt++;
490 : 0 : break;
491 : 0 : case GVE_ADMINQ_UNREGISTER_PAGE_LIST:
492 : 0 : priv->adminq_unregister_page_list_cnt++;
493 : 0 : break;
494 : 0 : case GVE_ADMINQ_CREATE_TX_QUEUE:
495 : 0 : priv->adminq_create_tx_queue_cnt++;
496 : 0 : break;
497 : 0 : case GVE_ADMINQ_CREATE_RX_QUEUE:
498 : 0 : priv->adminq_create_rx_queue_cnt++;
499 : 0 : break;
500 : 0 : case GVE_ADMINQ_DESTROY_TX_QUEUE:
501 : 0 : priv->adminq_destroy_tx_queue_cnt++;
502 : 0 : break;
503 : 0 : case GVE_ADMINQ_DESTROY_RX_QUEUE:
504 : 0 : priv->adminq_destroy_rx_queue_cnt++;
505 : 0 : break;
506 : 0 : case GVE_ADMINQ_DECONFIGURE_DEVICE_RESOURCES:
507 : 0 : priv->adminq_dcfg_device_resources_cnt++;
508 : 0 : break;
509 : 0 : case GVE_ADMINQ_CONFIGURE_RSS:
510 : 0 : priv->adminq_cfg_rss_cnt++;
511 : 0 : break;
512 : 0 : case GVE_ADMINQ_SET_DRIVER_PARAMETER:
513 : 0 : priv->adminq_set_driver_parameter_cnt++;
514 : 0 : break;
515 : 0 : case GVE_ADMINQ_REPORT_STATS:
516 : 0 : priv->adminq_report_stats_cnt++;
517 : 0 : break;
518 : 0 : case GVE_ADMINQ_REPORT_LINK_SPEED:
519 : 0 : priv->adminq_report_link_speed_cnt++;
520 : 0 : break;
521 : 0 : case GVE_ADMINQ_GET_PTYPE_MAP:
522 : 0 : priv->adminq_get_ptype_map_cnt++;
523 : 0 : break;
524 : 0 : case GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY:
525 : 0 : priv->adminq_verify_driver_compatibility_cnt++;
526 : 0 : break;
527 : 0 : case GVE_ADMINQ_CONFIGURE_FLOW_RULE:
528 : 0 : priv->adminq_cfg_flow_rule_cnt++;
529 : 0 : break;
530 : 0 : case GVE_ADMINQ_REPORT_NIC_TIMESTAMP:
531 : 0 : priv->adminq_report_nic_timestamp_cnt++;
532 : 0 : break;
533 : :
534 : 0 : default:
535 : 0 : PMD_DRV_LOG(ERR, "unknown AQ command opcode %d", opcode);
536 : : }
537 : :
538 : : return 0;
539 : : }
540 : :
541 : : /* This function is not threadsafe - the caller is responsible for any
542 : : * necessary locks.
543 : : * The caller is also responsible for making sure there are no commands
544 : : * waiting to be executed.
545 : : */
546 : 0 : static int gve_adminq_execute_cmd(struct gve_priv *priv,
547 : : union gve_adminq_command *cmd_orig)
548 : : {
549 : : u32 tail, head;
550 : : int err;
551 : :
552 : 0 : pthread_mutex_lock(&priv->adminq_lock);
553 : 0 : tail = ioread32be(&priv->reg_bar0->adminq_event_counter);
554 : 0 : head = priv->adminq_prod_cnt;
555 [ # # ]: 0 : if (tail != head) {
556 : : /* This is not a valid path */
557 : : err = -EINVAL;
558 : 0 : goto unlock_and_return;
559 : : }
560 : :
561 : 0 : err = gve_adminq_issue_cmd(priv, cmd_orig);
562 [ # # ]: 0 : if (err)
563 : 0 : goto unlock_and_return;
564 : :
565 : 0 : err = gve_adminq_kick_and_wait(priv);
566 : :
567 : 0 : unlock_and_return:
568 : 0 : pthread_mutex_unlock(&priv->adminq_lock);
569 : 0 : return err;
570 : : }
571 : :
572 : 0 : static int gve_adminq_execute_extended_cmd(struct gve_priv *priv, u32 opcode,
573 : : size_t cmd_size, void *cmd_orig)
574 : : {
575 : : union gve_adminq_command cmd;
576 : : struct gve_dma_mem inner_cmd_dma_mem;
577 : : void *inner_cmd;
578 : : int err;
579 : :
580 : 0 : inner_cmd = gve_alloc_dma_mem(&inner_cmd_dma_mem, cmd_size);
581 [ # # ]: 0 : if (!inner_cmd)
582 : : return -ENOMEM;
583 : :
584 : : memcpy(inner_cmd, cmd_orig, cmd_size);
585 : :
586 : : memset(&cmd, 0, sizeof(cmd));
587 : 0 : cmd.opcode = cpu_to_be32(GVE_ADMINQ_EXTENDED_COMMAND);
588 : 0 : cmd.extended_command = (struct gve_adminq_extended_command) {
589 [ # # ]: 0 : .inner_opcode = cpu_to_be32(opcode),
590 [ # # ]: 0 : .inner_length = cpu_to_be32(cmd_size),
591 [ # # ]: 0 : .inner_command_addr = cpu_to_be64(inner_cmd_dma_mem.pa),
592 : : };
593 : :
594 : 0 : err = gve_adminq_execute_cmd(priv, &cmd);
595 : :
596 : 0 : gve_free_dma_mem(&inner_cmd_dma_mem);
597 : 0 : return err;
598 : : }
599 : :
600 : : static int
601 : : gve_adminq_configure_flow_rule(struct gve_priv *priv,
602 : : struct gve_adminq_configure_flow_rule *flow_rule_cmd)
603 : : {
604 : 0 : int err = gve_adminq_execute_extended_cmd(priv,
605 : : GVE_ADMINQ_CONFIGURE_FLOW_RULE,
606 : : sizeof(struct gve_adminq_configure_flow_rule),
607 : : flow_rule_cmd);
608 : :
609 : : return err;
610 : : }
611 : :
612 : 0 : int gve_adminq_add_flow_rule(struct gve_priv *priv,
613 : : struct gve_flow_rule_params *rule, u32 loc)
614 : : {
615 : 0 : struct gve_adminq_configure_flow_rule flow_rule_cmd = {
616 : : .opcode = cpu_to_be16(GVE_FLOW_RULE_CFG_ADD),
617 [ # # ]: 0 : .location = cpu_to_be32(loc),
618 : : .rule = {
619 [ # # ]: 0 : .flow_type = cpu_to_be16(rule->flow_type),
620 [ # # ]: 0 : .action = cpu_to_be16(rule->action),
621 : : .key = rule->key,
622 : : .mask = rule->mask,
623 : : },
624 : : };
625 : :
626 : 0 : return gve_adminq_configure_flow_rule(priv, &flow_rule_cmd);
627 : : }
628 : :
629 : 0 : int gve_adminq_del_flow_rule(struct gve_priv *priv, u32 loc)
630 : : {
631 : 0 : struct gve_adminq_configure_flow_rule flow_rule_cmd = {
632 : : .opcode = cpu_to_be16(GVE_FLOW_RULE_CFG_DEL),
633 [ # # ]: 0 : .location = cpu_to_be32(loc),
634 : : };
635 : :
636 : 0 : return gve_adminq_configure_flow_rule(priv, &flow_rule_cmd);
637 : : }
638 : :
639 : 0 : int gve_adminq_reset_flow_rules(struct gve_priv *priv)
640 : : {
641 : 0 : struct gve_adminq_configure_flow_rule flow_rule_cmd = {
642 : : .opcode = cpu_to_be16(GVE_FLOW_RULE_CFG_RESET),
643 : : };
644 : :
645 : 0 : return gve_adminq_configure_flow_rule(priv, &flow_rule_cmd);
646 : : }
647 : :
648 [ # # ]: 0 : int gve_adminq_report_nic_timestamp(struct gve_priv *priv, dma_addr_t nic_ts_report_addr)
649 : : {
650 : : union gve_adminq_command cmd;
651 : :
652 : : memset(&cmd, 0, sizeof(cmd));
653 : 0 : cmd.opcode = cpu_to_be32(GVE_ADMINQ_REPORT_NIC_TIMESTAMP);
654 : 0 : cmd.report_nic_timestamp = (struct gve_adminq_report_nic_timestamp) {
655 : : .nic_ts_report_len = cpu_to_be64(sizeof(struct gve_nic_ts_report)),
656 [ # # ]: 0 : .nic_timestamp_addr = cpu_to_be64(nic_ts_report_addr),
657 : : };
658 : :
659 : 0 : return gve_adminq_execute_cmd(priv, &cmd);
660 : : }
661 : :
662 : : /* The device specifies that the management vector can either be the first irq
663 : : * or the last irq. ntfy_blk_msix_base_idx indicates the first irq assigned to
664 : : * the ntfy blks. It if is 0 then the management vector is last, if it is 1 then
665 : : * the management vector is first.
666 : : *
667 : : * gve arranges the msix vectors so that the management vector is last.
668 : : */
669 : : #define GVE_NTFY_BLK_BASE_MSIX_IDX 0
670 [ # # ]: 0 : int gve_adminq_configure_device_resources(struct gve_priv *priv)
671 : : {
672 : : union gve_adminq_command cmd;
673 : :
674 : : memset(&cmd, 0, sizeof(cmd));
675 : 0 : cmd.opcode = cpu_to_be32(GVE_ADMINQ_CONFIGURE_DEVICE_RESOURCES);
676 : 0 : cmd.configure_device_resources =
677 : : (struct gve_adminq_configure_device_resources) {
678 [ # # ]: 0 : .counter_array = cpu_to_be64(priv->cnt_array_mz->iova),
679 [ # # ]: 0 : .num_counters = cpu_to_be32(priv->num_event_counters),
680 [ # # ]: 0 : .irq_db_addr = cpu_to_be64(priv->irq_dbs_mz->iova),
681 [ # # ]: 0 : .num_irq_dbs = cpu_to_be32(priv->num_ntfy_blks),
682 : : .irq_db_stride = cpu_to_be32(sizeof(*priv->irq_dbs)),
683 : : .ntfy_blk_msix_base_idx =
684 : : cpu_to_be32(GVE_NTFY_BLK_BASE_MSIX_IDX),
685 : 0 : .queue_format = priv->queue_format,
686 : : };
687 : :
688 : 0 : return gve_adminq_execute_cmd(priv, &cmd);
689 : : }
690 : :
691 [ # # ]: 0 : int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
692 : : u64 driver_info_len,
693 : : dma_addr_t driver_info_addr)
694 : : {
695 : : union gve_adminq_command cmd;
696 : :
697 : : memset(&cmd, 0, sizeof(cmd));
698 : 0 : cmd.opcode = cpu_to_be32(GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY);
699 : 0 : cmd.verify_driver_compatibility = (struct gve_adminq_verify_driver_compatibility) {
700 [ # # ]: 0 : .driver_info_len = cpu_to_be64(driver_info_len),
701 [ # # ]: 0 : .driver_info_addr = cpu_to_be64(driver_info_addr),
702 : : };
703 : :
704 : 0 : return gve_adminq_execute_cmd(priv, &cmd);
705 : : }
706 : :
707 : 0 : int gve_adminq_deconfigure_device_resources(struct gve_priv *priv)
708 : : {
709 : : union gve_adminq_command cmd;
710 : :
711 : : memset(&cmd, 0, sizeof(cmd));
712 : 0 : cmd.opcode = cpu_to_be32(GVE_ADMINQ_DECONFIGURE_DEVICE_RESOURCES);
713 : :
714 : 0 : return gve_adminq_execute_cmd(priv, &cmd);
715 : : }
716 : :
717 : 0 : static int gve_adminq_create_tx_queue(struct gve_priv *priv, u32 queue_index)
718 : : {
719 [ # # ]: 0 : struct gve_tx_queue *txq = priv->txqs[queue_index];
720 : : union gve_adminq_command cmd;
721 : :
722 : : memset(&cmd, 0, sizeof(cmd));
723 : 0 : cmd.opcode = cpu_to_be32(GVE_ADMINQ_CREATE_TX_QUEUE);
724 [ # # ]: 0 : cmd.create_tx_queue = (struct gve_adminq_create_tx_queue) {
725 [ # # ]: 0 : .queue_id = cpu_to_be32(queue_index),
726 : : .queue_resources_addr =
727 [ # # ]: 0 : cpu_to_be64(txq->qres_mz->iova),
728 [ # # ]: 0 : .tx_ring_addr = cpu_to_be64(txq->tx_ring_phys_addr),
729 [ # # ]: 0 : .ntfy_id = cpu_to_be32(txq->ntfy_id),
730 [ # # ]: 0 : .tx_ring_size = cpu_to_be16(txq->nb_tx_desc),
731 : : };
732 : :
733 [ # # ]: 0 : if (gve_is_gqi(priv)) {
734 : : u32 qpl_id = priv->queue_format == GVE_GQI_RDA_FORMAT ?
735 [ # # ]: 0 : GVE_RAW_ADDRESSING_QPL_ID : txq->qpl->id;
736 : :
737 [ # # ]: 0 : cmd.create_tx_queue.queue_page_list_id = cpu_to_be32(qpl_id);
738 : : } else {
739 : 0 : cmd.create_tx_queue.tx_comp_ring_addr =
740 [ # # ]: 0 : cpu_to_be64(txq->compl_ring_phys_addr);
741 : 0 : cmd.create_tx_queue.tx_comp_ring_size =
742 [ # # ]: 0 : cpu_to_be16(txq->nb_complq_desc);
743 : : }
744 : :
745 : 0 : return gve_adminq_issue_cmd(priv, &cmd);
746 : : }
747 : :
748 : 0 : int gve_adminq_create_tx_queues(struct gve_priv *priv, u32 num_queues)
749 : : {
750 : : int err;
751 : : u32 i;
752 : :
753 : 0 : pthread_mutex_lock(&priv->adminq_lock);
754 : :
755 [ # # ]: 0 : for (i = 0; i < num_queues; i++) {
756 : 0 : err = gve_adminq_create_tx_queue(priv, i);
757 [ # # ]: 0 : if (err)
758 : 0 : goto unlock_and_return;
759 : : }
760 : :
761 : 0 : err = gve_adminq_kick_and_wait(priv);
762 : :
763 : 0 : unlock_and_return:
764 : 0 : pthread_mutex_unlock(&priv->adminq_lock);
765 : 0 : return err;
766 : : }
767 : :
768 : 0 : static int gve_adminq_create_rx_queue(struct gve_priv *priv, u32 queue_index)
769 : : {
770 [ # # ]: 0 : struct gve_rx_queue *rxq = priv->rxqs[queue_index];
771 : : union gve_adminq_command cmd;
772 : :
773 : : memset(&cmd, 0, sizeof(cmd));
774 : 0 : cmd.opcode = cpu_to_be32(GVE_ADMINQ_CREATE_RX_QUEUE);
775 [ # # ]: 0 : cmd.create_rx_queue = (struct gve_adminq_create_rx_queue) {
776 [ # # ]: 0 : .queue_id = cpu_to_be32(queue_index),
777 [ # # ]: 0 : .ntfy_id = cpu_to_be32(rxq->ntfy_id),
778 [ # # ]: 0 : .queue_resources_addr = cpu_to_be64(rxq->qres_mz->iova),
779 [ # # ]: 0 : .rx_ring_size = cpu_to_be16(rxq->nb_rx_desc),
780 : : };
781 : :
782 [ # # ]: 0 : if (gve_is_gqi(priv)) {
783 : : u32 qpl_id = priv->queue_format == GVE_GQI_RDA_FORMAT ?
784 [ # # ]: 0 : GVE_RAW_ADDRESSING_QPL_ID : rxq->qpl->id;
785 : :
786 : 0 : cmd.create_rx_queue.rx_desc_ring_addr =
787 [ # # ]: 0 : cpu_to_be64(rxq->mz->iova);
788 : 0 : cmd.create_rx_queue.rx_data_ring_addr =
789 [ # # ]: 0 : cpu_to_be64(rxq->data_mz->iova);
790 [ # # ]: 0 : cmd.create_rx_queue.index = cpu_to_be32(queue_index);
791 [ # # ]: 0 : cmd.create_rx_queue.queue_page_list_id = cpu_to_be32(qpl_id);
792 [ # # ]: 0 : cmd.create_rx_queue.packet_buffer_size = cpu_to_be16(rxq->rx_buf_len);
793 : : } else {
794 : 0 : cmd.create_rx_queue.rx_desc_ring_addr =
795 [ # # ]: 0 : cpu_to_be64(rxq->compl_ring_phys_addr);
796 : 0 : cmd.create_rx_queue.rx_data_ring_addr =
797 [ # # ]: 0 : cpu_to_be64(rxq->rx_ring_phys_addr);
798 : 0 : cmd.create_rx_queue.packet_buffer_size =
799 [ # # ]: 0 : cpu_to_be16(rxq->rx_buf_len);
800 : 0 : cmd.create_rx_queue.rx_buff_ring_size =
801 [ # # ]: 0 : cpu_to_be16(rxq->nb_rx_desc);
802 : 0 : cmd.create_rx_queue.enable_rsc = !!(priv->enable_rsc);
803 : : }
804 : :
805 : 0 : return gve_adminq_issue_cmd(priv, &cmd);
806 : : }
807 : :
808 : 0 : int gve_adminq_create_rx_queues(struct gve_priv *priv, u32 num_queues)
809 : : {
810 : : int err;
811 : : u32 i;
812 : :
813 : 0 : pthread_mutex_lock(&priv->adminq_lock);
814 : :
815 [ # # ]: 0 : for (i = 0; i < num_queues; i++) {
816 : 0 : err = gve_adminq_create_rx_queue(priv, i);
817 [ # # ]: 0 : if (err)
818 : 0 : goto unlock_and_return;
819 : : }
820 : :
821 : 0 : err = gve_adminq_kick_and_wait(priv);
822 : :
823 : 0 : unlock_and_return:
824 : 0 : pthread_mutex_unlock(&priv->adminq_lock);
825 : 0 : return err;
826 : : }
827 : :
828 [ # # ]: 0 : static int gve_adminq_destroy_tx_queue(struct gve_priv *priv, u32 queue_index)
829 : : {
830 : : union gve_adminq_command cmd;
831 : : int err;
832 : :
833 : : memset(&cmd, 0, sizeof(cmd));
834 : 0 : cmd.opcode = cpu_to_be32(GVE_ADMINQ_DESTROY_TX_QUEUE);
835 : 0 : cmd.destroy_tx_queue = (struct gve_adminq_destroy_tx_queue) {
836 [ # # ]: 0 : .queue_id = cpu_to_be32(queue_index),
837 : : };
838 : :
839 : 0 : err = gve_adminq_issue_cmd(priv, &cmd);
840 [ # # ]: 0 : if (err)
841 : 0 : return err;
842 : :
843 : : return 0;
844 : : }
845 : :
846 : 0 : int gve_adminq_destroy_tx_queues(struct gve_priv *priv, u32 num_queues)
847 : : {
848 : : int err;
849 : : u32 i;
850 : :
851 : 0 : pthread_mutex_lock(&priv->adminq_lock);
852 : :
853 [ # # ]: 0 : for (i = 0; i < num_queues; i++) {
854 : 0 : err = gve_adminq_destroy_tx_queue(priv, i);
855 [ # # ]: 0 : if (err)
856 : 0 : goto unlock_and_return;
857 : : }
858 : :
859 : 0 : err = gve_adminq_kick_and_wait(priv);
860 : :
861 : 0 : unlock_and_return:
862 : 0 : pthread_mutex_unlock(&priv->adminq_lock);
863 : 0 : return err;
864 : : }
865 : :
866 [ # # ]: 0 : static int gve_adminq_destroy_rx_queue(struct gve_priv *priv, u32 queue_index)
867 : : {
868 : : union gve_adminq_command cmd;
869 : : int err;
870 : :
871 : : memset(&cmd, 0, sizeof(cmd));
872 : 0 : cmd.opcode = cpu_to_be32(GVE_ADMINQ_DESTROY_RX_QUEUE);
873 : 0 : cmd.destroy_rx_queue = (struct gve_adminq_destroy_rx_queue) {
874 [ # # ]: 0 : .queue_id = cpu_to_be32(queue_index),
875 : : };
876 : :
877 : 0 : err = gve_adminq_issue_cmd(priv, &cmd);
878 [ # # ]: 0 : if (err)
879 : 0 : return err;
880 : :
881 : : return 0;
882 : : }
883 : :
884 : 0 : int gve_adminq_destroy_rx_queues(struct gve_priv *priv, u32 num_queues)
885 : : {
886 : : int err;
887 : : u32 i;
888 : :
889 : 0 : pthread_mutex_lock(&priv->adminq_lock);
890 : :
891 [ # # ]: 0 : for (i = 0; i < num_queues; i++) {
892 : 0 : err = gve_adminq_destroy_rx_queue(priv, i);
893 [ # # ]: 0 : if (err)
894 : 0 : goto unlock_and_return;
895 : : }
896 : :
897 : 0 : err = gve_adminq_kick_and_wait(priv);
898 : :
899 : 0 : unlock_and_return:
900 : 0 : pthread_mutex_unlock(&priv->adminq_lock);
901 : 0 : return err;
902 : : }
903 : :
904 : 0 : static int gve_set_desc_cnt(struct gve_priv *priv,
905 : : struct gve_device_descriptor *descriptor)
906 : : {
907 [ # # ]: 0 : priv->default_tx_desc_cnt = be16_to_cpu(descriptor->tx_queue_entries);
908 [ # # ]: 0 : if (priv->default_tx_desc_cnt * sizeof(priv->txqs[0]->tx_desc_ring[0])
909 : : < PAGE_SIZE) {
910 : 0 : PMD_DRV_LOG(ERR, "Tx desc count %d too low",
911 : : priv->default_tx_desc_cnt);
912 : 0 : return -EINVAL;
913 : : }
914 [ # # ]: 0 : priv->default_rx_desc_cnt = be16_to_cpu(descriptor->rx_queue_entries);
915 [ # # ]: 0 : if (priv->default_rx_desc_cnt * sizeof(priv->rxqs[0]->rx_desc_ring[0])
916 : : < PAGE_SIZE) {
917 : 0 : PMD_DRV_LOG(ERR, "Rx desc count %d too low", priv->default_rx_desc_cnt);
918 : 0 : return -EINVAL;
919 : : }
920 : : return 0;
921 : : }
922 : :
923 : : static int
924 : 0 : gve_set_desc_cnt_dqo(struct gve_priv *priv,
925 : : const struct gve_device_descriptor *descriptor,
926 : : const struct gve_device_option_dqo_rda *dev_op_dqo_rda)
927 : : {
928 [ # # ]: 0 : priv->default_tx_desc_cnt = be16_to_cpu(descriptor->tx_queue_entries);
929 [ # # ]: 0 : priv->tx_compq_size = be16_to_cpu(dev_op_dqo_rda->tx_comp_ring_entries);
930 [ # # ]: 0 : priv->default_rx_desc_cnt = be16_to_cpu(descriptor->rx_queue_entries);
931 [ # # ]: 0 : priv->rx_bufq_size = be16_to_cpu(dev_op_dqo_rda->rx_buff_ring_entries);
932 : :
933 : 0 : return 0;
934 : : }
935 : :
936 : : static void
937 : : gve_set_min_desc_cnt(struct gve_priv *priv,
938 : : struct gve_device_option_modify_ring *modify_ring)
939 : : {
940 [ # # ]: 0 : priv->min_rx_desc_cnt = be16_to_cpu(modify_ring->min_ring_size.rx);
941 [ # # ]: 0 : priv->min_tx_desc_cnt = be16_to_cpu(modify_ring->min_ring_size.tx);
942 : 0 : }
943 : :
944 : : static void
945 : 0 : gve_set_max_desc_cnt(struct gve_priv *priv,
946 : : const struct gve_device_option_modify_ring *modify_ring)
947 : : {
948 [ # # ]: 0 : priv->max_rx_desc_cnt = be16_to_cpu(modify_ring->max_ring_size.rx);
949 [ # # ]: 0 : priv->max_tx_desc_cnt = be16_to_cpu(modify_ring->max_ring_size.tx);
950 : :
951 [ # # ]: 0 : if (priv->queue_format == GVE_DQO_RDA_FORMAT) {
952 : 0 : PMD_DRV_LOG(DEBUG, "Overriding max ring size from device for DQ "
953 : : "queue format to 4096.");
954 : 0 : priv->max_rx_desc_cnt = GVE_MAX_QUEUE_SIZE_DQO;
955 : 0 : priv->max_tx_desc_cnt = GVE_MAX_QUEUE_SIZE_DQO;
956 [ # # ]: 0 : } else if (priv->queue_format == GVE_GQI_QPL_FORMAT) {
957 : 0 : priv->max_rx_desc_cnt = RTE_MIN(priv->max_rx_desc_cnt,
958 : : GVE_MAX_RING_SIZE_GQ_QPL);
959 : 0 : priv->max_tx_desc_cnt = RTE_MIN(priv->max_tx_desc_cnt,
960 : : GVE_MAX_RING_SIZE_GQ_QPL);
961 : : }
962 : 0 : }
963 : :
964 : 0 : static void gve_enable_supported_features(struct gve_priv *priv,
965 : : u32 supported_features_mask,
966 : : const struct gve_device_option_flow_steering *dev_op_flow_steering,
967 : : const struct gve_device_option_modify_ring *dev_op_modify_ring,
968 : : const struct gve_device_option_jumbo_frames *dev_op_jumbo_frames,
969 : : const struct gve_device_option_nic_timestamp *dev_op_nic_timestamp)
970 : : {
971 [ # # ]: 0 : if (dev_op_flow_steering &&
972 [ # # ]: 0 : (supported_features_mask & GVE_SUP_FLOW_STEERING_MASK) &&
973 [ # # ]: 0 : dev_op_flow_steering->max_flow_rules) {
974 : 0 : priv->max_flow_rules =
975 [ # # ]: 0 : be32_to_cpu(dev_op_flow_steering->max_flow_rules);
976 : 0 : PMD_DRV_LOG(INFO,
977 : : "FLOW STEERING device option enabled with max rule limit of %u.",
978 : : priv->max_flow_rules);
979 : : }
980 [ # # ]: 0 : if (dev_op_modify_ring &&
981 [ # # ]: 0 : (supported_features_mask & GVE_SUP_MODIFY_RING_MASK)) {
982 : 0 : PMD_DRV_LOG(INFO, "MODIFY RING device option enabled.");
983 : : /* Min ring size set separately by virtue of it being optional. */
984 : 0 : gve_set_max_desc_cnt(priv, dev_op_modify_ring);
985 : : }
986 : :
987 : : /* Before control reaches this point, the page-size-capped max MTU from
988 : : * the gve_device_descriptor field has already been stored in
989 : : * priv->dev->max_mtu. We overwrite it with the true max MTU below.
990 : : */
991 [ # # ]: 0 : if (dev_op_jumbo_frames &&
992 [ # # ]: 0 : (supported_features_mask & GVE_SUP_JUMBO_FRAMES_MASK)) {
993 : 0 : PMD_DRV_LOG(INFO, "JUMBO FRAMES device option enabled.");
994 [ # # ]: 0 : priv->max_mtu = be16_to_cpu(dev_op_jumbo_frames->max_mtu);
995 : : }
996 [ # # ]: 0 : if (dev_op_nic_timestamp &&
997 [ # # # # ]: 0 : (supported_features_mask & GVE_SUP_NIC_TIMESTAMP_MASK) &&
998 : : !gve_is_gqi(priv)) {
999 : 0 : PMD_DRV_LOG(INFO, "NIC TIMESTAMP device option enabled.");
1000 : 0 : priv->clk_read_type = GVE_DEV_CLK_CMD;
1001 : : }
1002 : 0 : }
1003 : :
1004 : 0 : int gve_adminq_describe_device(struct gve_priv *priv)
1005 : : {
1006 : 0 : struct gve_device_option_jumbo_frames *dev_op_jumbo_frames = NULL;
1007 : 0 : struct gve_device_option_modify_ring *dev_op_modify_ring = NULL;
1008 : 0 : struct gve_device_option_flow_steering *dev_op_flow_steering = NULL;
1009 : 0 : struct gve_device_option_nic_timestamp *dev_op_nic_timestamp = NULL;
1010 : 0 : struct gve_device_option_gqi_rda *dev_op_gqi_rda = NULL;
1011 : 0 : struct gve_device_option_gqi_qpl *dev_op_gqi_qpl = NULL;
1012 : 0 : struct gve_device_option_dqo_rda *dev_op_dqo_rda = NULL;
1013 : : struct gve_device_descriptor *descriptor;
1014 : : struct gve_dma_mem descriptor_dma_mem;
1015 : : u32 supported_features_mask = 0;
1016 : : union gve_adminq_command cmd;
1017 : : int err = 0;
1018 : : u16 mtu;
1019 : :
1020 : : memset(&cmd, 0, sizeof(cmd));
1021 : 0 : descriptor = gve_alloc_dma_mem(&descriptor_dma_mem, PAGE_SIZE);
1022 [ # # ]: 0 : if (!descriptor)
1023 : : return -ENOMEM;
1024 : 0 : cmd.opcode = cpu_to_be32(GVE_ADMINQ_DESCRIBE_DEVICE);
1025 : 0 : cmd.describe_device.device_descriptor_addr =
1026 [ # # ]: 0 : cpu_to_be64(descriptor_dma_mem.pa);
1027 : 0 : cmd.describe_device.device_descriptor_version =
1028 : : cpu_to_be32(GVE_ADMINQ_DEVICE_DESCRIPTOR_VERSION);
1029 : 0 : cmd.describe_device.available_length = cpu_to_be32(PAGE_SIZE);
1030 : :
1031 : 0 : err = gve_adminq_execute_cmd(priv, &cmd);
1032 [ # # ]: 0 : if (err)
1033 : 0 : goto free_device_descriptor;
1034 : :
1035 : 0 : err = gve_process_device_options(priv, descriptor, &dev_op_gqi_rda,
1036 : : &dev_op_gqi_qpl, &dev_op_dqo_rda,
1037 : : &dev_op_flow_steering,
1038 : : &dev_op_modify_ring,
1039 : : &dev_op_jumbo_frames,
1040 : : &dev_op_nic_timestamp);
1041 [ # # ]: 0 : if (err)
1042 : 0 : goto free_device_descriptor;
1043 : :
1044 : : /* If the GQI_RAW_ADDRESSING option is not enabled and the queue format
1045 : : * is not set to GqiRda, choose the queue format in a priority order:
1046 : : * DqoRda, GqiRda, GqiQpl. Use GqiQpl as default.
1047 : : */
1048 [ # # ]: 0 : if (dev_op_dqo_rda) {
1049 : 0 : priv->queue_format = GVE_DQO_RDA_FORMAT;
1050 : 0 : PMD_DRV_LOG(INFO, "Driver is running with DQO RDA queue format.");
1051 : : supported_features_mask =
1052 [ # # ]: 0 : be32_to_cpu(dev_op_dqo_rda->supported_features_mask);
1053 [ # # ]: 0 : } else if (dev_op_gqi_rda) {
1054 : 0 : priv->queue_format = GVE_GQI_RDA_FORMAT;
1055 : 0 : PMD_DRV_LOG(INFO, "Driver is running with GQI RDA queue format.");
1056 : : supported_features_mask =
1057 [ # # ]: 0 : be32_to_cpu(dev_op_gqi_rda->supported_features_mask);
1058 [ # # ]: 0 : } else if (priv->queue_format == GVE_GQI_RDA_FORMAT) {
1059 : 0 : PMD_DRV_LOG(INFO, "Driver is running with GQI RDA queue format.");
1060 : : } else {
1061 : 0 : priv->queue_format = GVE_GQI_QPL_FORMAT;
1062 [ # # ]: 0 : if (dev_op_gqi_qpl)
1063 : : supported_features_mask =
1064 [ # # ]: 0 : be32_to_cpu(dev_op_gqi_qpl->supported_features_mask);
1065 : 0 : PMD_DRV_LOG(INFO, "Driver is running with GQI QPL queue format.");
1066 : : }
1067 [ # # ]: 0 : if (gve_is_gqi(priv)) {
1068 : 0 : err = gve_set_desc_cnt(priv, descriptor);
1069 : : } else {
1070 : : /* DQO supports LRO. */
1071 : 0 : err = gve_set_desc_cnt_dqo(priv, descriptor, dev_op_dqo_rda);
1072 : : }
1073 [ # # ]: 0 : if (err)
1074 : 0 : goto free_device_descriptor;
1075 : :
1076 : 0 : priv->max_registered_pages =
1077 [ # # ]: 0 : be64_to_cpu(descriptor->max_registered_pages);
1078 [ # # ]: 0 : mtu = be16_to_cpu(descriptor->mtu);
1079 [ # # ]: 0 : if (mtu < ETH_MIN_MTU) {
1080 : 0 : PMD_DRV_LOG(ERR, "MTU %d below minimum MTU", mtu);
1081 : : err = -EINVAL;
1082 : 0 : goto free_device_descriptor;
1083 : : }
1084 : 0 : priv->max_mtu = mtu;
1085 [ # # ]: 0 : priv->num_event_counters = be16_to_cpu(descriptor->counters);
1086 : : rte_memcpy(priv->dev_addr.addr_bytes, descriptor->mac, ETH_ALEN);
1087 : 0 : PMD_DRV_LOG(INFO, "MAC addr: " RTE_ETHER_ADDR_PRT_FMT,
1088 : : RTE_ETHER_ADDR_BYTES(&priv->dev_addr));
1089 [ # # ]: 0 : priv->tx_pages_per_qpl = be16_to_cpu(descriptor->tx_pages_per_qpl);
1090 [ # # ]: 0 : priv->default_tx_num_queues = be16_to_cpu(descriptor->default_num_queues);
1091 [ # # ]: 0 : priv->default_rx_num_queues = be16_to_cpu(descriptor->default_num_queues);
1092 : :
1093 : 0 : gve_enable_supported_features(priv, supported_features_mask,
1094 : : dev_op_flow_steering, dev_op_modify_ring,
1095 : : dev_op_jumbo_frames, dev_op_nic_timestamp);
1096 : :
1097 : 0 : free_device_descriptor:
1098 : 0 : gve_free_dma_mem(&descriptor_dma_mem);
1099 : 0 : return err;
1100 : : }
1101 : :
1102 : 0 : int gve_adminq_register_page_list(struct gve_priv *priv,
1103 : : struct gve_queue_page_list *qpl)
1104 : : {
1105 : : struct gve_dma_mem page_list_dma_mem;
1106 : 0 : u32 num_entries = qpl->num_entries;
1107 : 0 : u32 size = num_entries * sizeof(qpl->page_buses[0]);
1108 : : union gve_adminq_command cmd;
1109 : : __be64 *page_list;
1110 : : int err;
1111 : : u32 i;
1112 : :
1113 : : memset(&cmd, 0, sizeof(cmd));
1114 : 0 : page_list = gve_alloc_dma_mem(&page_list_dma_mem, size);
1115 [ # # ]: 0 : if (!page_list)
1116 : : return -ENOMEM;
1117 : :
1118 [ # # ]: 0 : for (i = 0; i < num_entries; i++)
1119 [ # # ]: 0 : page_list[i] = cpu_to_be64(qpl->page_buses[i]);
1120 : :
1121 : 0 : cmd.opcode = cpu_to_be32(GVE_ADMINQ_REGISTER_PAGE_LIST);
1122 : 0 : cmd.reg_page_list = (struct gve_adminq_register_page_list) {
1123 [ # # ]: 0 : .page_list_id = cpu_to_be32(qpl->id),
1124 [ # # ]: 0 : .num_pages = cpu_to_be32(num_entries),
1125 [ # # ]: 0 : .page_address_list_addr = cpu_to_be64(page_list_dma_mem.pa),
1126 : : };
1127 : :
1128 : 0 : err = gve_adminq_execute_cmd(priv, &cmd);
1129 : 0 : gve_free_dma_mem(&page_list_dma_mem);
1130 : 0 : return err;
1131 : : }
1132 : :
1133 [ # # ]: 0 : int gve_adminq_unregister_page_list(struct gve_priv *priv, u32 page_list_id)
1134 : : {
1135 : : union gve_adminq_command cmd;
1136 : :
1137 : : memset(&cmd, 0, sizeof(cmd));
1138 : 0 : cmd.opcode = cpu_to_be32(GVE_ADMINQ_UNREGISTER_PAGE_LIST);
1139 : 0 : cmd.unreg_page_list = (struct gve_adminq_unregister_page_list) {
1140 [ # # ]: 0 : .page_list_id = cpu_to_be32(page_list_id),
1141 : : };
1142 : :
1143 : 0 : return gve_adminq_execute_cmd(priv, &cmd);
1144 : : }
1145 : :
1146 [ # # ]: 0 : int gve_adminq_set_mtu(struct gve_priv *priv, u64 mtu)
1147 : : {
1148 : : union gve_adminq_command cmd;
1149 : :
1150 : : memset(&cmd, 0, sizeof(cmd));
1151 : 0 : cmd.opcode = cpu_to_be32(GVE_ADMINQ_SET_DRIVER_PARAMETER);
1152 : 0 : cmd.set_driver_param = (struct gve_adminq_set_driver_parameter) {
1153 : : .parameter_type = cpu_to_be32(GVE_SET_PARAM_MTU),
1154 [ # # ]: 0 : .parameter_value = cpu_to_be64(mtu),
1155 : : };
1156 : :
1157 : 0 : return gve_adminq_execute_cmd(priv, &cmd);
1158 : : }
1159 : :
1160 [ # # ]: 0 : int gve_adminq_report_stats(struct gve_priv *priv, u64 stats_report_len,
1161 : : dma_addr_t stats_report_addr, u64 interval)
1162 : : {
1163 : : union gve_adminq_command cmd;
1164 : :
1165 : : memset(&cmd, 0, sizeof(cmd));
1166 : 0 : cmd.opcode = cpu_to_be32(GVE_ADMINQ_REPORT_STATS);
1167 : 0 : cmd.report_stats = (struct gve_adminq_report_stats) {
1168 [ # # ]: 0 : .stats_report_len = cpu_to_be64(stats_report_len),
1169 [ # # ]: 0 : .stats_report_addr = cpu_to_be64(stats_report_addr),
1170 [ # # ]: 0 : .interval = cpu_to_be64(interval),
1171 : : };
1172 : :
1173 : 0 : return gve_adminq_execute_cmd(priv, &cmd);
1174 : : }
1175 : :
1176 : 0 : int gve_adminq_report_link_speed(struct gve_priv *priv)
1177 : : {
1178 : : struct gve_dma_mem link_speed_region_dma_mem;
1179 : : union gve_adminq_command gvnic_cmd;
1180 : : u64 *link_speed_region;
1181 : : int err;
1182 : :
1183 : 0 : link_speed_region = gve_alloc_dma_mem(&link_speed_region_dma_mem,
1184 : : sizeof(*link_speed_region));
1185 : :
1186 [ # # ]: 0 : if (!link_speed_region)
1187 : : return -ENOMEM;
1188 : :
1189 : : memset(&gvnic_cmd, 0, sizeof(gvnic_cmd));
1190 : 0 : gvnic_cmd.opcode = cpu_to_be32(GVE_ADMINQ_REPORT_LINK_SPEED);
1191 : 0 : gvnic_cmd.report_link_speed.link_speed_address =
1192 [ # # ]: 0 : cpu_to_be64(link_speed_region_dma_mem.pa);
1193 : :
1194 : 0 : err = gve_adminq_execute_cmd(priv, &gvnic_cmd);
1195 : :
1196 [ # # ]: 0 : priv->link_speed = be64_to_cpu(*link_speed_region);
1197 : 0 : gve_free_dma_mem(&link_speed_region_dma_mem);
1198 : 0 : return err;
1199 : : }
1200 : :
1201 : 0 : int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv)
1202 : : {
1203 : 0 : struct gve_ptype_lut *ptype_lut = priv->ptype_lut_dqo;
1204 : : struct gve_dma_mem ptype_map_dma_mem;
1205 : : struct gve_ptype_map *ptype_map;
1206 : : union gve_adminq_command cmd;
1207 : : int err = 0;
1208 : : int i;
1209 : :
1210 : : memset(&cmd, 0, sizeof(cmd));
1211 : 0 : ptype_map = gve_alloc_dma_mem(&ptype_map_dma_mem, sizeof(*ptype_map));
1212 [ # # ]: 0 : if (!ptype_map)
1213 : : return -ENOMEM;
1214 : :
1215 : 0 : cmd.opcode = cpu_to_be32(GVE_ADMINQ_GET_PTYPE_MAP);
1216 : 0 : cmd.get_ptype_map = (struct gve_adminq_get_ptype_map) {
1217 : : .ptype_map_len = cpu_to_be64(sizeof(*ptype_map)),
1218 [ # # ]: 0 : .ptype_map_addr = cpu_to_be64(ptype_map_dma_mem.pa),
1219 : : };
1220 : :
1221 : 0 : err = gve_adminq_execute_cmd(priv, &cmd);
1222 [ # # ]: 0 : if (err)
1223 : 0 : goto err;
1224 : :
1225 : : /* Populate ptype_lut. */
1226 [ # # ]: 0 : for (i = 0; i < GVE_NUM_PTYPES; i++) {
1227 : 0 : ptype_lut->ptypes[i].l3_type =
1228 : 0 : ptype_map->ptypes[i].l3_type;
1229 : 0 : ptype_lut->ptypes[i].l4_type =
1230 : 0 : ptype_map->ptypes[i].l4_type;
1231 : : }
1232 : 0 : err:
1233 : 0 : gve_free_dma_mem(&ptype_map_dma_mem);
1234 : 0 : return err;
1235 : : }
1236 : :
1237 : 0 : int gve_adminq_configure_rss(struct gve_priv *priv,
1238 : : struct gve_rss_config *rss_config)
1239 : : {
1240 : : struct gve_dma_mem indirection_table_dma_mem;
1241 : : struct gve_dma_mem rss_key_dma_mem;
1242 : : union gve_adminq_command cmd;
1243 : : __be32 *indir = NULL;
1244 : : u8 *key = NULL;
1245 : : int err = 0;
1246 : : int i;
1247 : :
1248 [ # # # # ]: 0 : if (!rss_config->indir_size || !rss_config->key_size)
1249 : : return -EINVAL;
1250 : :
1251 : 0 : indir = gve_alloc_dma_mem(&indirection_table_dma_mem,
1252 : 0 : rss_config->indir_size *
1253 : : sizeof(*rss_config->indir));
1254 [ # # ]: 0 : if (!indir) {
1255 : : err = -ENOMEM;
1256 : 0 : goto out;
1257 : : }
1258 [ # # ]: 0 : for (i = 0; i < rss_config->indir_size; i++)
1259 [ # # ]: 0 : indir[i] = cpu_to_be32(rss_config->indir[i]);
1260 : :
1261 : 0 : key = gve_alloc_dma_mem(&rss_key_dma_mem,
1262 : 0 : rss_config->key_size *
1263 : : sizeof(*rss_config->key));
1264 [ # # ]: 0 : if (!key) {
1265 : : err = -ENOMEM;
1266 : 0 : goto out;
1267 : : }
1268 [ # # ]: 0 : memcpy(key, rss_config->key, rss_config->key_size);
1269 : :
1270 : : memset(&cmd, 0, sizeof(cmd));
1271 : 0 : cmd.opcode = cpu_to_be32(GVE_ADMINQ_CONFIGURE_RSS);
1272 : 0 : cmd.configure_rss = (struct gve_adminq_configure_rss) {
1273 [ # # ]: 0 : .hash_types = cpu_to_be16(rss_config->hash_types),
1274 : 0 : .halg = rss_config->alg,
1275 [ # # ]: 0 : .hkey_len = cpu_to_be16(rss_config->key_size),
1276 [ # # ]: 0 : .indir_len = cpu_to_be16(rss_config->indir_size),
1277 [ # # ]: 0 : .hkey_addr = cpu_to_be64(rss_key_dma_mem.pa),
1278 [ # # ]: 0 : .indir_addr = cpu_to_be64(indirection_table_dma_mem.pa),
1279 : : };
1280 : :
1281 : 0 : err = gve_adminq_execute_cmd(priv, &cmd);
1282 [ # # ]: 0 : if (err == 0)
1283 : 0 : gve_update_priv_rss_config(priv, rss_config);
1284 : :
1285 : 0 : out:
1286 [ # # ]: 0 : if (indir)
1287 : 0 : gve_free_dma_mem(&indirection_table_dma_mem);
1288 [ # # ]: 0 : if (key)
1289 : 0 : gve_free_dma_mem(&rss_key_dma_mem);
1290 : : return err;
1291 : : }
|