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 "../gve_ethdev.h"
7 : : #include "gve_adminq.h"
8 : : #include "gve_register.h"
9 : :
10 : : #define GVE_MAX_ADMINQ_RELEASE_CHECK 500
11 : : #define GVE_ADMINQ_SLEEP_LEN 20
12 : : #define GVE_MAX_ADMINQ_EVENT_COUNTER_CHECK 100
13 : :
14 : : #define GVE_DEVICE_OPTION_ERROR_FMT "%s option error:\n Expected: length=%d, feature_mask=%x.\n Actual: length=%d, feature_mask=%x."
15 : :
16 : : #define GVE_DEVICE_OPTION_TOO_BIG_FMT "Length of %s option larger than expected. Possible older version of guest driver."
17 : :
18 : : static
19 : : struct gve_device_option *gve_get_next_option(struct gve_device_descriptor *descriptor,
20 : : struct gve_device_option *option)
21 : : {
22 : : uintptr_t option_end, descriptor_end;
23 : :
24 [ # # ]: 0 : option_end = (uintptr_t)option + sizeof(*option) + be16_to_cpu(option->option_length);
25 [ # # ]: 0 : descriptor_end = (uintptr_t)descriptor + be16_to_cpu(descriptor->total_length);
26 : :
27 [ # # ]: 0 : return option_end > descriptor_end ? NULL : (struct gve_device_option *)option_end;
28 : : }
29 : :
30 : : static
31 : 0 : void gve_parse_device_option(struct gve_priv *priv,
32 : : struct gve_device_option *option,
33 : : struct gve_device_option_gqi_rda **dev_op_gqi_rda,
34 : : struct gve_device_option_gqi_qpl **dev_op_gqi_qpl,
35 : : struct gve_device_option_dqo_rda **dev_op_dqo_rda,
36 : : struct gve_device_option_jumbo_frames **dev_op_jumbo_frames)
37 : : {
38 [ # # ]: 0 : u32 req_feat_mask = be32_to_cpu(option->required_features_mask);
39 [ # # ]: 0 : u16 option_length = be16_to_cpu(option->option_length);
40 [ # # ]: 0 : u16 option_id = be16_to_cpu(option->option_id);
41 : :
42 : : /* If the length or feature mask doesn't match, continue without
43 : : * enabling the feature.
44 : : */
45 [ # # # # : 0 : switch (option_id) {
# # ]
46 : 0 : case GVE_DEV_OPT_ID_GQI_RAW_ADDRESSING:
47 : 0 : if (option_length != GVE_DEV_OPT_LEN_GQI_RAW_ADDRESSING ||
48 [ # # ]: 0 : req_feat_mask != GVE_DEV_OPT_REQ_FEAT_MASK_GQI_RAW_ADDRESSING) {
49 : 0 : PMD_DRV_LOG(WARNING, GVE_DEVICE_OPTION_ERROR_FMT,
50 : : "Raw Addressing",
51 : : GVE_DEV_OPT_LEN_GQI_RAW_ADDRESSING,
52 : : GVE_DEV_OPT_REQ_FEAT_MASK_GQI_RAW_ADDRESSING,
53 : : option_length, req_feat_mask);
54 : 0 : break;
55 : : }
56 : :
57 : 0 : PMD_DRV_LOG(INFO, "Gqi raw addressing device option enabled.");
58 : 0 : priv->queue_format = GVE_GQI_RDA_FORMAT;
59 : 0 : break;
60 : 0 : case GVE_DEV_OPT_ID_GQI_RDA:
61 : 0 : if (option_length < sizeof(**dev_op_gqi_rda) ||
62 [ # # ]: 0 : req_feat_mask != GVE_DEV_OPT_REQ_FEAT_MASK_GQI_RDA) {
63 : 0 : PMD_DRV_LOG(WARNING, GVE_DEVICE_OPTION_ERROR_FMT,
64 : : "GQI RDA", (int)sizeof(**dev_op_gqi_rda),
65 : : GVE_DEV_OPT_REQ_FEAT_MASK_GQI_RDA,
66 : : option_length, req_feat_mask);
67 : 0 : break;
68 : : }
69 : :
70 [ # # ]: 0 : if (option_length > sizeof(**dev_op_gqi_rda)) {
71 : 0 : PMD_DRV_LOG(WARNING,
72 : : GVE_DEVICE_OPTION_TOO_BIG_FMT, "GQI RDA");
73 : : }
74 : 0 : *dev_op_gqi_rda = RTE_PTR_ADD(option, sizeof(*option));
75 : 0 : break;
76 : 0 : case GVE_DEV_OPT_ID_GQI_QPL:
77 : 0 : if (option_length < sizeof(**dev_op_gqi_qpl) ||
78 [ # # ]: 0 : req_feat_mask != GVE_DEV_OPT_REQ_FEAT_MASK_GQI_QPL) {
79 : 0 : PMD_DRV_LOG(WARNING, GVE_DEVICE_OPTION_ERROR_FMT,
80 : : "GQI QPL", (int)sizeof(**dev_op_gqi_qpl),
81 : : GVE_DEV_OPT_REQ_FEAT_MASK_GQI_QPL,
82 : : option_length, req_feat_mask);
83 : 0 : break;
84 : : }
85 : :
86 [ # # ]: 0 : if (option_length > sizeof(**dev_op_gqi_qpl)) {
87 : 0 : PMD_DRV_LOG(WARNING,
88 : : GVE_DEVICE_OPTION_TOO_BIG_FMT, "GQI QPL");
89 : : }
90 : 0 : *dev_op_gqi_qpl = RTE_PTR_ADD(option, sizeof(*option));
91 : 0 : break;
92 : 0 : case GVE_DEV_OPT_ID_DQO_RDA:
93 : 0 : if (option_length < sizeof(**dev_op_dqo_rda) ||
94 [ # # ]: 0 : req_feat_mask != GVE_DEV_OPT_REQ_FEAT_MASK_DQO_RDA) {
95 : 0 : PMD_DRV_LOG(WARNING, GVE_DEVICE_OPTION_ERROR_FMT,
96 : : "DQO RDA", (int)sizeof(**dev_op_dqo_rda),
97 : : GVE_DEV_OPT_REQ_FEAT_MASK_DQO_RDA,
98 : : option_length, req_feat_mask);
99 : 0 : break;
100 : : }
101 : :
102 [ # # ]: 0 : if (option_length > sizeof(**dev_op_dqo_rda)) {
103 : 0 : PMD_DRV_LOG(WARNING,
104 : : GVE_DEVICE_OPTION_TOO_BIG_FMT, "DQO RDA");
105 : : }
106 : 0 : *dev_op_dqo_rda = RTE_PTR_ADD(option, sizeof(*option));
107 : 0 : break;
108 : 0 : case GVE_DEV_OPT_ID_JUMBO_FRAMES:
109 : 0 : if (option_length < sizeof(**dev_op_jumbo_frames) ||
110 [ # # ]: 0 : req_feat_mask != GVE_DEV_OPT_REQ_FEAT_MASK_JUMBO_FRAMES) {
111 : 0 : PMD_DRV_LOG(WARNING, GVE_DEVICE_OPTION_ERROR_FMT,
112 : : "Jumbo Frames",
113 : : (int)sizeof(**dev_op_jumbo_frames),
114 : : GVE_DEV_OPT_REQ_FEAT_MASK_JUMBO_FRAMES,
115 : : option_length, req_feat_mask);
116 : 0 : break;
117 : : }
118 : :
119 [ # # ]: 0 : if (option_length > sizeof(**dev_op_jumbo_frames)) {
120 : 0 : PMD_DRV_LOG(WARNING,
121 : : GVE_DEVICE_OPTION_TOO_BIG_FMT,
122 : : "Jumbo Frames");
123 : : }
124 : 0 : *dev_op_jumbo_frames = RTE_PTR_ADD(option, sizeof(*option));
125 : 0 : break;
126 : 0 : default:
127 : : /* If we don't recognize the option just continue
128 : : * without doing anything.
129 : : */
130 : 0 : PMD_DRV_LOG(DEBUG, "Unrecognized device option 0x%hx not enabled.",
131 : : option_id);
132 : : }
133 : 0 : }
134 : :
135 : : /* Process all device options for a given describe device call. */
136 : : static int
137 : 0 : gve_process_device_options(struct gve_priv *priv,
138 : : struct gve_device_descriptor *descriptor,
139 : : struct gve_device_option_gqi_rda **dev_op_gqi_rda,
140 : : struct gve_device_option_gqi_qpl **dev_op_gqi_qpl,
141 : : struct gve_device_option_dqo_rda **dev_op_dqo_rda,
142 : : struct gve_device_option_jumbo_frames **dev_op_jumbo_frames)
143 : : {
144 [ # # ]: 0 : const int num_options = be16_to_cpu(descriptor->num_device_options);
145 : : struct gve_device_option *dev_opt;
146 : : int i;
147 : :
148 : : /* The options struct directly follows the device descriptor. */
149 : 0 : dev_opt = RTE_PTR_ADD(descriptor, sizeof(*descriptor));
150 [ # # ]: 0 : for (i = 0; i < num_options; i++) {
151 : : struct gve_device_option *next_opt;
152 : :
153 : : next_opt = gve_get_next_option(descriptor, dev_opt);
154 [ # # ]: 0 : if (!next_opt) {
155 : 0 : PMD_DRV_LOG(ERR,
156 : : "options exceed device_descriptor's total length.");
157 : 0 : return -EINVAL;
158 : : }
159 : :
160 : 0 : gve_parse_device_option(priv, dev_opt,
161 : : dev_op_gqi_rda, dev_op_gqi_qpl,
162 : : dev_op_dqo_rda, dev_op_jumbo_frames);
163 : : dev_opt = next_opt;
164 : : }
165 : :
166 : : return 0;
167 : : }
168 : :
169 : 0 : int gve_adminq_alloc(struct gve_priv *priv)
170 : : {
171 : 0 : priv->adminq = gve_alloc_dma_mem(&priv->adminq_dma_mem, PAGE_SIZE);
172 [ # # ]: 0 : if (unlikely(!priv->adminq))
173 : : return -ENOMEM;
174 : :
175 : 0 : priv->adminq_mask = (PAGE_SIZE / sizeof(union gve_adminq_command)) - 1;
176 : 0 : priv->adminq_prod_cnt = 0;
177 : 0 : priv->adminq_cmd_fail = 0;
178 : 0 : priv->adminq_timeouts = 0;
179 : 0 : priv->adminq_describe_device_cnt = 0;
180 : 0 : priv->adminq_cfg_device_resources_cnt = 0;
181 : 0 : priv->adminq_register_page_list_cnt = 0;
182 : 0 : priv->adminq_unregister_page_list_cnt = 0;
183 : 0 : priv->adminq_create_tx_queue_cnt = 0;
184 : 0 : priv->adminq_create_rx_queue_cnt = 0;
185 : 0 : priv->adminq_destroy_tx_queue_cnt = 0;
186 : 0 : priv->adminq_destroy_rx_queue_cnt = 0;
187 : 0 : priv->adminq_dcfg_device_resources_cnt = 0;
188 : 0 : priv->adminq_set_driver_parameter_cnt = 0;
189 : 0 : priv->adminq_report_stats_cnt = 0;
190 : 0 : priv->adminq_report_link_speed_cnt = 0;
191 : 0 : priv->adminq_get_ptype_map_cnt = 0;
192 : :
193 : : /* Setup Admin queue with the device */
194 : 0 : iowrite32be(priv->adminq_dma_mem.pa / PAGE_SIZE,
195 [ # # ]: 0 : &priv->reg_bar0->adminq_pfn);
196 : :
197 : : gve_set_admin_queue_ok(priv);
198 : 0 : return 0;
199 : : }
200 : :
201 : 0 : void gve_adminq_release(struct gve_priv *priv)
202 : : {
203 : : int i = 0;
204 : :
205 : : /* Tell the device the adminq is leaving */
206 : 0 : iowrite32be(0x0, &priv->reg_bar0->adminq_pfn);
207 [ # # ]: 0 : while (ioread32be(&priv->reg_bar0->adminq_pfn)) {
208 : : /* If this is reached the device is unrecoverable and still
209 : : * holding memory. Continue looping to avoid memory corruption,
210 : : * but WARN so it is visible what is going on.
211 : : */
212 [ # # ]: 0 : if (i == GVE_MAX_ADMINQ_RELEASE_CHECK)
213 : 0 : PMD_DRV_LOG(WARNING, "Unrecoverable platform error!");
214 : 0 : i++;
215 : : msleep(GVE_ADMINQ_SLEEP_LEN);
216 : : }
217 : : gve_clear_device_rings_ok(priv);
218 : : gve_clear_device_resources_ok(priv);
219 : : gve_clear_admin_queue_ok(priv);
220 : 0 : }
221 : :
222 [ # # ]: 0 : void gve_adminq_free(struct gve_priv *priv)
223 : : {
224 [ # # ]: 0 : if (!gve_get_admin_queue_ok(priv))
225 : : return;
226 : 0 : gve_adminq_release(priv);
227 : 0 : gve_free_dma_mem(&priv->adminq_dma_mem);
228 : : gve_clear_admin_queue_ok(priv);
229 : : }
230 : :
231 : : static void gve_adminq_kick_cmd(struct gve_priv *priv, u32 prod_cnt)
232 : : {
233 : 0 : iowrite32be(prod_cnt, &priv->reg_bar0->adminq_doorbell);
234 : 0 : }
235 : :
236 : : static bool gve_adminq_wait_for_cmd(struct gve_priv *priv, u32 prod_cnt)
237 : : {
238 : : int i;
239 : :
240 [ # # ]: 0 : for (i = 0; i < GVE_MAX_ADMINQ_EVENT_COUNTER_CHECK; i++) {
241 [ # # ]: 0 : if (ioread32be(&priv->reg_bar0->adminq_event_counter)
242 : : == prod_cnt)
243 : : return true;
244 : : msleep(GVE_ADMINQ_SLEEP_LEN);
245 : : }
246 : :
247 : : return false;
248 : : }
249 : :
250 : 0 : static int gve_adminq_parse_err(struct gve_priv *priv, u32 status)
251 : : {
252 [ # # ]: 0 : if (status != GVE_ADMINQ_COMMAND_PASSED &&
253 : : status != GVE_ADMINQ_COMMAND_UNSET) {
254 : 0 : PMD_DRV_LOG(ERR, "AQ command failed with status %d", status);
255 : 0 : priv->adminq_cmd_fail++;
256 : : }
257 [ # # # # : 0 : switch (status) {
# # # #
# ]
258 : : case GVE_ADMINQ_COMMAND_PASSED:
259 : : return 0;
260 : 0 : case GVE_ADMINQ_COMMAND_UNSET:
261 : 0 : PMD_DRV_LOG(ERR, "parse_aq_err: err and status both unset, this should not be possible.");
262 : 0 : return -EINVAL;
263 : 0 : case GVE_ADMINQ_COMMAND_ERROR_ABORTED:
264 : : case GVE_ADMINQ_COMMAND_ERROR_CANCELLED:
265 : : case GVE_ADMINQ_COMMAND_ERROR_DATALOSS:
266 : : case GVE_ADMINQ_COMMAND_ERROR_FAILED_PRECONDITION:
267 : : case GVE_ADMINQ_COMMAND_ERROR_UNAVAILABLE:
268 : 0 : return -EAGAIN;
269 : 0 : case GVE_ADMINQ_COMMAND_ERROR_ALREADY_EXISTS:
270 : : case GVE_ADMINQ_COMMAND_ERROR_INTERNAL_ERROR:
271 : : case GVE_ADMINQ_COMMAND_ERROR_INVALID_ARGUMENT:
272 : : case GVE_ADMINQ_COMMAND_ERROR_NOT_FOUND:
273 : : case GVE_ADMINQ_COMMAND_ERROR_OUT_OF_RANGE:
274 : : case GVE_ADMINQ_COMMAND_ERROR_UNKNOWN_ERROR:
275 : 0 : return -EINVAL;
276 : 0 : case GVE_ADMINQ_COMMAND_ERROR_DEADLINE_EXCEEDED:
277 : 0 : return -ETIMEDOUT;
278 : 0 : case GVE_ADMINQ_COMMAND_ERROR_PERMISSION_DENIED:
279 : : case GVE_ADMINQ_COMMAND_ERROR_UNAUTHENTICATED:
280 : 0 : return -EACCES;
281 : 0 : case GVE_ADMINQ_COMMAND_ERROR_RESOURCE_EXHAUSTED:
282 : 0 : return -ENOMEM;
283 : 0 : case GVE_ADMINQ_COMMAND_ERROR_UNIMPLEMENTED:
284 : 0 : return -ENOTSUP;
285 : 0 : default:
286 : 0 : PMD_DRV_LOG(ERR, "parse_aq_err: unknown status code %d",
287 : : status);
288 : 0 : return -EINVAL;
289 : : }
290 : : }
291 : :
292 : : /* Flushes all AQ commands currently queued and waits for them to complete.
293 : : * If there are failures, it will return the first error.
294 : : */
295 : 0 : static int gve_adminq_kick_and_wait(struct gve_priv *priv)
296 : : {
297 : : u32 tail, head;
298 : : u32 i;
299 : :
300 : 0 : tail = ioread32be(&priv->reg_bar0->adminq_event_counter);
301 [ # # ]: 0 : head = priv->adminq_prod_cnt;
302 : :
303 : : gve_adminq_kick_cmd(priv, head);
304 [ # # ]: 0 : if (!gve_adminq_wait_for_cmd(priv, head)) {
305 : 0 : PMD_DRV_LOG(ERR, "AQ commands timed out, need to reset AQ");
306 : 0 : priv->adminq_timeouts++;
307 : 0 : return -ENOTRECOVERABLE;
308 : : }
309 : :
310 [ # # ]: 0 : for (i = tail; i < head; i++) {
311 : : union gve_adminq_command *cmd;
312 : : u32 status, err;
313 : :
314 : 0 : cmd = &priv->adminq[i & priv->adminq_mask];
315 : : status = be32_to_cpu(READ_ONCE32(cmd->status));
316 : 0 : err = gve_adminq_parse_err(priv, status);
317 [ # # ]: 0 : if (err)
318 : : /* Return the first error if we failed. */
319 : 0 : return err;
320 : : }
321 : :
322 : : return 0;
323 : : }
324 : :
325 : : /* This function is not threadsafe - the caller is responsible for any
326 : : * necessary locks.
327 : : */
328 : 0 : static int gve_adminq_issue_cmd(struct gve_priv *priv,
329 : : union gve_adminq_command *cmd_orig)
330 : : {
331 : : union gve_adminq_command *cmd;
332 : : u32 opcode;
333 : : u32 tail;
334 : :
335 : 0 : tail = ioread32be(&priv->reg_bar0->adminq_event_counter);
336 : :
337 : : /* Check if next command will overflow the buffer. */
338 : 0 : if (((priv->adminq_prod_cnt + 1) & priv->adminq_mask) ==
339 [ # # ]: 0 : (tail & priv->adminq_mask)) {
340 : : int err;
341 : :
342 : : /* Flush existing commands to make room. */
343 : 0 : err = gve_adminq_kick_and_wait(priv);
344 [ # # ]: 0 : if (err)
345 : : return err;
346 : :
347 : : /* Retry. */
348 : 0 : tail = ioread32be(&priv->reg_bar0->adminq_event_counter);
349 : 0 : if (((priv->adminq_prod_cnt + 1) & priv->adminq_mask) ==
350 [ # # ]: 0 : (tail & priv->adminq_mask)) {
351 : : /* This should never happen. We just flushed the
352 : : * command queue so there should be enough space.
353 : : */
354 : : return -ENOMEM;
355 : : }
356 : : }
357 : :
358 : 0 : cmd = &priv->adminq[priv->adminq_prod_cnt & priv->adminq_mask];
359 : 0 : priv->adminq_prod_cnt++;
360 : :
361 : : memcpy(cmd, cmd_orig, sizeof(*cmd_orig));
362 : : opcode = be32_to_cpu(READ_ONCE32(cmd->opcode));
363 : :
364 [ # # # # : 0 : switch (opcode) {
# # # # #
# # # # #
# # ]
365 : 0 : case GVE_ADMINQ_DESCRIBE_DEVICE:
366 : 0 : priv->adminq_describe_device_cnt++;
367 : 0 : break;
368 : 0 : case GVE_ADMINQ_CONFIGURE_DEVICE_RESOURCES:
369 : 0 : priv->adminq_cfg_device_resources_cnt++;
370 : 0 : break;
371 : 0 : case GVE_ADMINQ_REGISTER_PAGE_LIST:
372 : 0 : priv->adminq_register_page_list_cnt++;
373 : 0 : break;
374 : 0 : case GVE_ADMINQ_UNREGISTER_PAGE_LIST:
375 : 0 : priv->adminq_unregister_page_list_cnt++;
376 : 0 : break;
377 : 0 : case GVE_ADMINQ_CREATE_TX_QUEUE:
378 : 0 : priv->adminq_create_tx_queue_cnt++;
379 : 0 : break;
380 : 0 : case GVE_ADMINQ_CREATE_RX_QUEUE:
381 : 0 : priv->adminq_create_rx_queue_cnt++;
382 : 0 : break;
383 : 0 : case GVE_ADMINQ_DESTROY_TX_QUEUE:
384 : 0 : priv->adminq_destroy_tx_queue_cnt++;
385 : 0 : break;
386 : 0 : case GVE_ADMINQ_DESTROY_RX_QUEUE:
387 : 0 : priv->adminq_destroy_rx_queue_cnt++;
388 : 0 : break;
389 : 0 : case GVE_ADMINQ_DECONFIGURE_DEVICE_RESOURCES:
390 : 0 : priv->adminq_dcfg_device_resources_cnt++;
391 : 0 : break;
392 : 0 : case GVE_ADMINQ_CONFIGURE_RSS:
393 : 0 : priv->adminq_cfg_rss_cnt++;
394 : 0 : break;
395 : 0 : case GVE_ADMINQ_SET_DRIVER_PARAMETER:
396 : 0 : priv->adminq_set_driver_parameter_cnt++;
397 : 0 : break;
398 : 0 : case GVE_ADMINQ_REPORT_STATS:
399 : 0 : priv->adminq_report_stats_cnt++;
400 : 0 : break;
401 : 0 : case GVE_ADMINQ_REPORT_LINK_SPEED:
402 : 0 : priv->adminq_report_link_speed_cnt++;
403 : 0 : break;
404 : 0 : case GVE_ADMINQ_GET_PTYPE_MAP:
405 : 0 : priv->adminq_get_ptype_map_cnt++;
406 : 0 : break;
407 : 0 : case GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY:
408 : 0 : priv->adminq_verify_driver_compatibility_cnt++;
409 : 0 : break;
410 : 0 : default:
411 : 0 : PMD_DRV_LOG(ERR, "unknown AQ command opcode %d", opcode);
412 : : }
413 : :
414 : : return 0;
415 : : }
416 : :
417 : : /* This function is not threadsafe - the caller is responsible for any
418 : : * necessary locks.
419 : : * The caller is also responsible for making sure there are no commands
420 : : * waiting to be executed.
421 : : */
422 : 0 : static int gve_adminq_execute_cmd(struct gve_priv *priv,
423 : : union gve_adminq_command *cmd_orig)
424 : : {
425 : : u32 tail, head;
426 : : int err;
427 : :
428 : 0 : tail = ioread32be(&priv->reg_bar0->adminq_event_counter);
429 : 0 : head = priv->adminq_prod_cnt;
430 [ # # ]: 0 : if (tail != head)
431 : : /* This is not a valid path */
432 : : return -EINVAL;
433 : :
434 : 0 : err = gve_adminq_issue_cmd(priv, cmd_orig);
435 [ # # ]: 0 : if (err)
436 : : return err;
437 : :
438 : 0 : return gve_adminq_kick_and_wait(priv);
439 : : }
440 : :
441 : : /* The device specifies that the management vector can either be the first irq
442 : : * or the last irq. ntfy_blk_msix_base_idx indicates the first irq assigned to
443 : : * the ntfy blks. It if is 0 then the management vector is last, if it is 1 then
444 : : * the management vector is first.
445 : : *
446 : : * gve arranges the msix vectors so that the management vector is last.
447 : : */
448 : : #define GVE_NTFY_BLK_BASE_MSIX_IDX 0
449 [ # # ]: 0 : int gve_adminq_configure_device_resources(struct gve_priv *priv,
450 : : dma_addr_t counter_array_bus_addr,
451 : : u32 num_counters,
452 : : dma_addr_t db_array_bus_addr,
453 : : u32 num_ntfy_blks)
454 : : {
455 : : union gve_adminq_command cmd;
456 : :
457 : : memset(&cmd, 0, sizeof(cmd));
458 : 0 : cmd.opcode = cpu_to_be32(GVE_ADMINQ_CONFIGURE_DEVICE_RESOURCES);
459 : 0 : cmd.configure_device_resources =
460 : : (struct gve_adminq_configure_device_resources) {
461 [ # # ]: 0 : .counter_array = cpu_to_be64(counter_array_bus_addr),
462 [ # # ]: 0 : .num_counters = cpu_to_be32(num_counters),
463 [ # # ]: 0 : .irq_db_addr = cpu_to_be64(db_array_bus_addr),
464 [ # # ]: 0 : .num_irq_dbs = cpu_to_be32(num_ntfy_blks),
465 : : .irq_db_stride = cpu_to_be32(sizeof(*priv->irq_dbs)),
466 : : .ntfy_blk_msix_base_idx =
467 : : cpu_to_be32(GVE_NTFY_BLK_BASE_MSIX_IDX),
468 : 0 : .queue_format = priv->queue_format,
469 : : };
470 : :
471 : 0 : return gve_adminq_execute_cmd(priv, &cmd);
472 : : }
473 : :
474 [ # # ]: 0 : int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
475 : : u64 driver_info_len,
476 : : dma_addr_t driver_info_addr)
477 : : {
478 : : union gve_adminq_command cmd;
479 : :
480 : : memset(&cmd, 0, sizeof(cmd));
481 : 0 : cmd.opcode = cpu_to_be32(GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY);
482 : 0 : cmd.verify_driver_compatibility = (struct gve_adminq_verify_driver_compatibility) {
483 [ # # ]: 0 : .driver_info_len = cpu_to_be64(driver_info_len),
484 [ # # ]: 0 : .driver_info_addr = cpu_to_be64(driver_info_addr),
485 : : };
486 : :
487 : 0 : return gve_adminq_execute_cmd(priv, &cmd);
488 : : }
489 : :
490 : 0 : int gve_adminq_deconfigure_device_resources(struct gve_priv *priv)
491 : : {
492 : : union gve_adminq_command cmd;
493 : :
494 : : memset(&cmd, 0, sizeof(cmd));
495 : 0 : cmd.opcode = cpu_to_be32(GVE_ADMINQ_DECONFIGURE_DEVICE_RESOURCES);
496 : :
497 : 0 : return gve_adminq_execute_cmd(priv, &cmd);
498 : : }
499 : :
500 : 0 : static int gve_adminq_create_tx_queue(struct gve_priv *priv, u32 queue_index)
501 : : {
502 [ # # ]: 0 : struct gve_tx_queue *txq = priv->txqs[queue_index];
503 : : union gve_adminq_command cmd;
504 : :
505 : : memset(&cmd, 0, sizeof(cmd));
506 : 0 : cmd.opcode = cpu_to_be32(GVE_ADMINQ_CREATE_TX_QUEUE);
507 [ # # ]: 0 : cmd.create_tx_queue = (struct gve_adminq_create_tx_queue) {
508 [ # # ]: 0 : .queue_id = cpu_to_be32(queue_index),
509 : : .queue_resources_addr =
510 [ # # ]: 0 : cpu_to_be64(txq->qres_mz->iova),
511 [ # # ]: 0 : .tx_ring_addr = cpu_to_be64(txq->tx_ring_phys_addr),
512 [ # # ]: 0 : .ntfy_id = cpu_to_be32(txq->ntfy_id),
513 : : };
514 : :
515 [ # # ]: 0 : if (gve_is_gqi(priv)) {
516 : : u32 qpl_id = priv->queue_format == GVE_GQI_RDA_FORMAT ?
517 [ # # ]: 0 : GVE_RAW_ADDRESSING_QPL_ID : txq->qpl->id;
518 : :
519 [ # # ]: 0 : cmd.create_tx_queue.queue_page_list_id = cpu_to_be32(qpl_id);
520 : : } else {
521 : 0 : cmd.create_tx_queue.tx_ring_size =
522 [ # # ]: 0 : cpu_to_be16(txq->nb_tx_desc);
523 : 0 : cmd.create_tx_queue.tx_comp_ring_addr =
524 [ # # ]: 0 : cpu_to_be64(txq->compl_ring_phys_addr);
525 : 0 : cmd.create_tx_queue.tx_comp_ring_size =
526 [ # # ]: 0 : cpu_to_be16(txq->sw_size);
527 : : }
528 : :
529 : 0 : return gve_adminq_issue_cmd(priv, &cmd);
530 : : }
531 : :
532 : 0 : int gve_adminq_create_tx_queues(struct gve_priv *priv, u32 num_queues)
533 : : {
534 : : int err;
535 : : u32 i;
536 : :
537 [ # # ]: 0 : for (i = 0; i < num_queues; i++) {
538 : 0 : err = gve_adminq_create_tx_queue(priv, i);
539 [ # # ]: 0 : if (err)
540 : 0 : return err;
541 : : }
542 : :
543 : 0 : return gve_adminq_kick_and_wait(priv);
544 : : }
545 : :
546 : 0 : static int gve_adminq_create_rx_queue(struct gve_priv *priv, u32 queue_index)
547 : : {
548 [ # # ]: 0 : struct gve_rx_queue *rxq = priv->rxqs[queue_index];
549 : : union gve_adminq_command cmd;
550 : :
551 : : memset(&cmd, 0, sizeof(cmd));
552 : 0 : cmd.opcode = cpu_to_be32(GVE_ADMINQ_CREATE_RX_QUEUE);
553 [ # # ]: 0 : cmd.create_rx_queue = (struct gve_adminq_create_rx_queue) {
554 [ # # ]: 0 : .queue_id = cpu_to_be32(queue_index),
555 [ # # ]: 0 : .ntfy_id = cpu_to_be32(rxq->ntfy_id),
556 [ # # ]: 0 : .queue_resources_addr = cpu_to_be64(rxq->qres_mz->iova),
557 : : };
558 : :
559 [ # # ]: 0 : if (gve_is_gqi(priv)) {
560 : : u32 qpl_id = priv->queue_format == GVE_GQI_RDA_FORMAT ?
561 [ # # ]: 0 : GVE_RAW_ADDRESSING_QPL_ID : rxq->qpl->id;
562 : :
563 : 0 : cmd.create_rx_queue.rx_desc_ring_addr =
564 [ # # ]: 0 : cpu_to_be64(rxq->mz->iova),
565 : 0 : cmd.create_rx_queue.rx_data_ring_addr =
566 [ # # ]: 0 : cpu_to_be64(rxq->data_mz->iova),
567 [ # # ]: 0 : cmd.create_rx_queue.index = cpu_to_be32(queue_index);
568 [ # # ]: 0 : cmd.create_rx_queue.queue_page_list_id = cpu_to_be32(qpl_id);
569 [ # # ]: 0 : cmd.create_rx_queue.packet_buffer_size = cpu_to_be16(rxq->rx_buf_len);
570 : : } else {
571 : 0 : cmd.create_rx_queue.rx_ring_size =
572 [ # # ]: 0 : cpu_to_be16(rxq->nb_rx_desc);
573 : 0 : cmd.create_rx_queue.rx_desc_ring_addr =
574 [ # # ]: 0 : cpu_to_be64(rxq->compl_ring_phys_addr);
575 : 0 : cmd.create_rx_queue.rx_data_ring_addr =
576 [ # # ]: 0 : cpu_to_be64(rxq->rx_ring_phys_addr);
577 : 0 : cmd.create_rx_queue.packet_buffer_size =
578 [ # # ]: 0 : cpu_to_be16(rxq->rx_buf_len);
579 : 0 : cmd.create_rx_queue.rx_buff_ring_size =
580 [ # # ]: 0 : cpu_to_be16(rxq->nb_rx_desc);
581 : 0 : cmd.create_rx_queue.enable_rsc = !!(priv->enable_rsc);
582 : : }
583 : :
584 : 0 : return gve_adminq_issue_cmd(priv, &cmd);
585 : : }
586 : :
587 : 0 : int gve_adminq_create_rx_queues(struct gve_priv *priv, u32 num_queues)
588 : : {
589 : : int err;
590 : : u32 i;
591 : :
592 [ # # ]: 0 : for (i = 0; i < num_queues; i++) {
593 : 0 : err = gve_adminq_create_rx_queue(priv, i);
594 [ # # ]: 0 : if (err)
595 : 0 : return err;
596 : : }
597 : :
598 : 0 : return gve_adminq_kick_and_wait(priv);
599 : : }
600 : :
601 [ # # ]: 0 : static int gve_adminq_destroy_tx_queue(struct gve_priv *priv, u32 queue_index)
602 : : {
603 : : union gve_adminq_command cmd;
604 : : int err;
605 : :
606 : : memset(&cmd, 0, sizeof(cmd));
607 : 0 : cmd.opcode = cpu_to_be32(GVE_ADMINQ_DESTROY_TX_QUEUE);
608 : 0 : cmd.destroy_tx_queue = (struct gve_adminq_destroy_tx_queue) {
609 [ # # ]: 0 : .queue_id = cpu_to_be32(queue_index),
610 : : };
611 : :
612 : 0 : err = gve_adminq_issue_cmd(priv, &cmd);
613 [ # # ]: 0 : if (err)
614 : 0 : return err;
615 : :
616 : : return 0;
617 : : }
618 : :
619 : 0 : int gve_adminq_destroy_tx_queues(struct gve_priv *priv, u32 num_queues)
620 : : {
621 : : int err;
622 : : u32 i;
623 : :
624 [ # # ]: 0 : for (i = 0; i < num_queues; i++) {
625 : 0 : err = gve_adminq_destroy_tx_queue(priv, i);
626 [ # # ]: 0 : if (err)
627 : 0 : return err;
628 : : }
629 : :
630 : 0 : return gve_adminq_kick_and_wait(priv);
631 : : }
632 : :
633 [ # # ]: 0 : static int gve_adminq_destroy_rx_queue(struct gve_priv *priv, u32 queue_index)
634 : : {
635 : : union gve_adminq_command cmd;
636 : : int err;
637 : :
638 : : memset(&cmd, 0, sizeof(cmd));
639 : 0 : cmd.opcode = cpu_to_be32(GVE_ADMINQ_DESTROY_RX_QUEUE);
640 : 0 : cmd.destroy_rx_queue = (struct gve_adminq_destroy_rx_queue) {
641 [ # # ]: 0 : .queue_id = cpu_to_be32(queue_index),
642 : : };
643 : :
644 : 0 : err = gve_adminq_issue_cmd(priv, &cmd);
645 [ # # ]: 0 : if (err)
646 : 0 : return err;
647 : :
648 : : return 0;
649 : : }
650 : :
651 : 0 : int gve_adminq_destroy_rx_queues(struct gve_priv *priv, u32 num_queues)
652 : : {
653 : : int err;
654 : : u32 i;
655 : :
656 [ # # ]: 0 : for (i = 0; i < num_queues; i++) {
657 : 0 : err = gve_adminq_destroy_rx_queue(priv, i);
658 [ # # ]: 0 : if (err)
659 : 0 : return err;
660 : : }
661 : :
662 : 0 : return gve_adminq_kick_and_wait(priv);
663 : : }
664 : :
665 : 0 : static int gve_set_desc_cnt(struct gve_priv *priv,
666 : : struct gve_device_descriptor *descriptor)
667 : : {
668 [ # # ]: 0 : priv->tx_desc_cnt = be16_to_cpu(descriptor->tx_queue_entries);
669 [ # # ]: 0 : if (priv->tx_desc_cnt * sizeof(priv->txqs[0]->tx_desc_ring[0])
670 : : < PAGE_SIZE) {
671 : 0 : PMD_DRV_LOG(ERR, "Tx desc count %d too low", priv->tx_desc_cnt);
672 : 0 : return -EINVAL;
673 : : }
674 [ # # ]: 0 : priv->rx_desc_cnt = be16_to_cpu(descriptor->rx_queue_entries);
675 [ # # ]: 0 : if (priv->rx_desc_cnt * sizeof(priv->rxqs[0]->rx_desc_ring[0])
676 : : < PAGE_SIZE) {
677 : 0 : PMD_DRV_LOG(ERR, "Rx desc count %d too low", priv->rx_desc_cnt);
678 : 0 : return -EINVAL;
679 : : }
680 : : return 0;
681 : : }
682 : :
683 : : static int
684 : 0 : gve_set_desc_cnt_dqo(struct gve_priv *priv,
685 : : const struct gve_device_descriptor *descriptor,
686 : : const struct gve_device_option_dqo_rda *dev_op_dqo_rda)
687 : : {
688 [ # # ]: 0 : priv->tx_desc_cnt = be16_to_cpu(descriptor->tx_queue_entries);
689 [ # # ]: 0 : priv->tx_compq_size = be16_to_cpu(dev_op_dqo_rda->tx_comp_ring_entries);
690 [ # # ]: 0 : priv->rx_desc_cnt = be16_to_cpu(descriptor->rx_queue_entries);
691 [ # # ]: 0 : priv->rx_bufq_size = be16_to_cpu(dev_op_dqo_rda->rx_buff_ring_entries);
692 : :
693 : 0 : return 0;
694 : : }
695 : :
696 : 0 : static void gve_enable_supported_features(struct gve_priv *priv,
697 : : u32 supported_features_mask,
698 : : const struct gve_device_option_jumbo_frames
699 : : *dev_op_jumbo_frames)
700 : : {
701 : : /* Before control reaches this point, the page-size-capped max MTU from
702 : : * the gve_device_descriptor field has already been stored in
703 : : * priv->dev->max_mtu. We overwrite it with the true max MTU below.
704 : : */
705 [ # # ]: 0 : if (dev_op_jumbo_frames &&
706 [ # # ]: 0 : (supported_features_mask & GVE_SUP_JUMBO_FRAMES_MASK)) {
707 : 0 : PMD_DRV_LOG(INFO, "JUMBO FRAMES device option enabled.");
708 [ # # ]: 0 : priv->max_mtu = be16_to_cpu(dev_op_jumbo_frames->max_mtu);
709 : : }
710 : 0 : }
711 : :
712 : 0 : int gve_adminq_describe_device(struct gve_priv *priv)
713 : : {
714 : 0 : struct gve_device_option_jumbo_frames *dev_op_jumbo_frames = NULL;
715 : 0 : struct gve_device_option_gqi_rda *dev_op_gqi_rda = NULL;
716 : 0 : struct gve_device_option_gqi_qpl *dev_op_gqi_qpl = NULL;
717 : 0 : struct gve_device_option_dqo_rda *dev_op_dqo_rda = NULL;
718 : : struct gve_device_descriptor *descriptor;
719 : : struct gve_dma_mem descriptor_dma_mem;
720 : : u32 supported_features_mask = 0;
721 : : union gve_adminq_command cmd;
722 : : int err = 0;
723 : : u16 mtu;
724 : :
725 : : memset(&cmd, 0, sizeof(cmd));
726 : 0 : descriptor = gve_alloc_dma_mem(&descriptor_dma_mem, PAGE_SIZE);
727 [ # # ]: 0 : if (!descriptor)
728 : : return -ENOMEM;
729 : 0 : cmd.opcode = cpu_to_be32(GVE_ADMINQ_DESCRIBE_DEVICE);
730 : 0 : cmd.describe_device.device_descriptor_addr =
731 [ # # ]: 0 : cpu_to_be64(descriptor_dma_mem.pa);
732 : 0 : cmd.describe_device.device_descriptor_version =
733 : : cpu_to_be32(GVE_ADMINQ_DEVICE_DESCRIPTOR_VERSION);
734 : 0 : cmd.describe_device.available_length = cpu_to_be32(PAGE_SIZE);
735 : :
736 : 0 : err = gve_adminq_execute_cmd(priv, &cmd);
737 [ # # ]: 0 : if (err)
738 : 0 : goto free_device_descriptor;
739 : :
740 : 0 : err = gve_process_device_options(priv, descriptor, &dev_op_gqi_rda,
741 : : &dev_op_gqi_qpl, &dev_op_dqo_rda,
742 : : &dev_op_jumbo_frames);
743 [ # # ]: 0 : if (err)
744 : 0 : goto free_device_descriptor;
745 : :
746 : : /* If the GQI_RAW_ADDRESSING option is not enabled and the queue format
747 : : * is not set to GqiRda, choose the queue format in a priority order:
748 : : * DqoRda, GqiRda, GqiQpl. Use GqiQpl as default.
749 : : */
750 [ # # ]: 0 : if (dev_op_dqo_rda) {
751 : 0 : priv->queue_format = GVE_DQO_RDA_FORMAT;
752 : 0 : PMD_DRV_LOG(INFO, "Driver is running with DQO RDA queue format.");
753 : : supported_features_mask =
754 [ # # ]: 0 : be32_to_cpu(dev_op_dqo_rda->supported_features_mask);
755 [ # # ]: 0 : } else if (dev_op_gqi_rda) {
756 : 0 : priv->queue_format = GVE_GQI_RDA_FORMAT;
757 : 0 : PMD_DRV_LOG(INFO, "Driver is running with GQI RDA queue format.");
758 : : supported_features_mask =
759 [ # # ]: 0 : be32_to_cpu(dev_op_gqi_rda->supported_features_mask);
760 [ # # ]: 0 : } else if (priv->queue_format == GVE_GQI_RDA_FORMAT) {
761 : 0 : PMD_DRV_LOG(INFO, "Driver is running with GQI RDA queue format.");
762 : : } else {
763 : 0 : priv->queue_format = GVE_GQI_QPL_FORMAT;
764 [ # # ]: 0 : if (dev_op_gqi_qpl)
765 : : supported_features_mask =
766 [ # # ]: 0 : be32_to_cpu(dev_op_gqi_qpl->supported_features_mask);
767 : 0 : PMD_DRV_LOG(INFO, "Driver is running with GQI QPL queue format.");
768 : : }
769 [ # # ]: 0 : if (gve_is_gqi(priv)) {
770 : 0 : err = gve_set_desc_cnt(priv, descriptor);
771 : : } else {
772 : : /* DQO supports LRO. */
773 : 0 : err = gve_set_desc_cnt_dqo(priv, descriptor, dev_op_dqo_rda);
774 : : }
775 [ # # ]: 0 : if (err)
776 : 0 : goto free_device_descriptor;
777 : :
778 : 0 : priv->max_registered_pages =
779 [ # # ]: 0 : be64_to_cpu(descriptor->max_registered_pages);
780 [ # # ]: 0 : mtu = be16_to_cpu(descriptor->mtu);
781 [ # # ]: 0 : if (mtu < ETH_MIN_MTU) {
782 : 0 : PMD_DRV_LOG(ERR, "MTU %d below minimum MTU", mtu);
783 : : err = -EINVAL;
784 : 0 : goto free_device_descriptor;
785 : : }
786 : 0 : priv->max_mtu = mtu;
787 [ # # ]: 0 : priv->num_event_counters = be16_to_cpu(descriptor->counters);
788 [ # # ]: 0 : rte_memcpy(priv->dev_addr.addr_bytes, descriptor->mac, ETH_ALEN);
789 : 0 : PMD_DRV_LOG(INFO, "MAC addr: " RTE_ETHER_ADDR_PRT_FMT,
790 : : RTE_ETHER_ADDR_BYTES(&priv->dev_addr));
791 [ # # ]: 0 : priv->tx_pages_per_qpl = be16_to_cpu(descriptor->tx_pages_per_qpl);
792 [ # # # # ]: 0 : priv->rx_data_slot_cnt = be16_to_cpu(descriptor->rx_pages_per_qpl);
793 : :
794 [ # # # # ]: 0 : if (gve_is_gqi(priv) && priv->rx_data_slot_cnt < priv->rx_desc_cnt) {
795 : 0 : PMD_DRV_LOG(ERR,
796 : : "rx_data_slot_cnt cannot be smaller than rx_desc_cnt, setting rx_desc_cnt down to %d",
797 : : priv->rx_data_slot_cnt);
798 : 0 : priv->rx_desc_cnt = priv->rx_data_slot_cnt;
799 : : }
800 [ # # ]: 0 : priv->default_num_queues = be16_to_cpu(descriptor->default_num_queues);
801 : :
802 : 0 : gve_enable_supported_features(priv, supported_features_mask,
803 : : dev_op_jumbo_frames);
804 : :
805 : 0 : free_device_descriptor:
806 : 0 : gve_free_dma_mem(&descriptor_dma_mem);
807 : 0 : return err;
808 : : }
809 : :
810 : 0 : int gve_adminq_register_page_list(struct gve_priv *priv,
811 : : struct gve_queue_page_list *qpl)
812 : : {
813 : : struct gve_dma_mem page_list_dma_mem;
814 : 0 : u32 num_entries = qpl->num_entries;
815 : 0 : u32 size = num_entries * sizeof(qpl->page_buses[0]);
816 : : union gve_adminq_command cmd;
817 : : __be64 *page_list;
818 : : int err;
819 : : u32 i;
820 : :
821 : : memset(&cmd, 0, sizeof(cmd));
822 : 0 : page_list = gve_alloc_dma_mem(&page_list_dma_mem, size);
823 [ # # ]: 0 : if (!page_list)
824 : : return -ENOMEM;
825 : :
826 [ # # ]: 0 : for (i = 0; i < num_entries; i++)
827 [ # # ]: 0 : page_list[i] = cpu_to_be64(qpl->page_buses[i]);
828 : :
829 : 0 : cmd.opcode = cpu_to_be32(GVE_ADMINQ_REGISTER_PAGE_LIST);
830 : 0 : cmd.reg_page_list = (struct gve_adminq_register_page_list) {
831 [ # # ]: 0 : .page_list_id = cpu_to_be32(qpl->id),
832 [ # # ]: 0 : .num_pages = cpu_to_be32(num_entries),
833 [ # # ]: 0 : .page_address_list_addr = cpu_to_be64(page_list_dma_mem.pa),
834 : : };
835 : :
836 : 0 : err = gve_adminq_execute_cmd(priv, &cmd);
837 : 0 : gve_free_dma_mem(&page_list_dma_mem);
838 : 0 : return err;
839 : : }
840 : :
841 [ # # ]: 0 : int gve_adminq_unregister_page_list(struct gve_priv *priv, u32 page_list_id)
842 : : {
843 : : union gve_adminq_command cmd;
844 : :
845 : : memset(&cmd, 0, sizeof(cmd));
846 : 0 : cmd.opcode = cpu_to_be32(GVE_ADMINQ_UNREGISTER_PAGE_LIST);
847 : 0 : cmd.unreg_page_list = (struct gve_adminq_unregister_page_list) {
848 [ # # ]: 0 : .page_list_id = cpu_to_be32(page_list_id),
849 : : };
850 : :
851 : 0 : return gve_adminq_execute_cmd(priv, &cmd);
852 : : }
853 : :
854 [ # # ]: 0 : int gve_adminq_set_mtu(struct gve_priv *priv, u64 mtu)
855 : : {
856 : : union gve_adminq_command cmd;
857 : :
858 : : memset(&cmd, 0, sizeof(cmd));
859 : 0 : cmd.opcode = cpu_to_be32(GVE_ADMINQ_SET_DRIVER_PARAMETER);
860 : 0 : cmd.set_driver_param = (struct gve_adminq_set_driver_parameter) {
861 : : .parameter_type = cpu_to_be32(GVE_SET_PARAM_MTU),
862 [ # # ]: 0 : .parameter_value = cpu_to_be64(mtu),
863 : : };
864 : :
865 : 0 : return gve_adminq_execute_cmd(priv, &cmd);
866 : : }
867 : :
868 [ # # ]: 0 : int gve_adminq_report_stats(struct gve_priv *priv, u64 stats_report_len,
869 : : dma_addr_t stats_report_addr, u64 interval)
870 : : {
871 : : union gve_adminq_command cmd;
872 : :
873 : : memset(&cmd, 0, sizeof(cmd));
874 : 0 : cmd.opcode = cpu_to_be32(GVE_ADMINQ_REPORT_STATS);
875 : 0 : cmd.report_stats = (struct gve_adminq_report_stats) {
876 [ # # ]: 0 : .stats_report_len = cpu_to_be64(stats_report_len),
877 [ # # ]: 0 : .stats_report_addr = cpu_to_be64(stats_report_addr),
878 [ # # ]: 0 : .interval = cpu_to_be64(interval),
879 : : };
880 : :
881 : 0 : return gve_adminq_execute_cmd(priv, &cmd);
882 : : }
883 : :
884 : 0 : int gve_adminq_report_link_speed(struct gve_priv *priv)
885 : : {
886 : : struct gve_dma_mem link_speed_region_dma_mem;
887 : : union gve_adminq_command gvnic_cmd;
888 : : u64 *link_speed_region;
889 : : int err;
890 : :
891 : 0 : link_speed_region = gve_alloc_dma_mem(&link_speed_region_dma_mem,
892 : : sizeof(*link_speed_region));
893 : :
894 [ # # ]: 0 : if (!link_speed_region)
895 : : return -ENOMEM;
896 : :
897 : : memset(&gvnic_cmd, 0, sizeof(gvnic_cmd));
898 : 0 : gvnic_cmd.opcode = cpu_to_be32(GVE_ADMINQ_REPORT_LINK_SPEED);
899 : 0 : gvnic_cmd.report_link_speed.link_speed_address =
900 [ # # ]: 0 : cpu_to_be64(link_speed_region_dma_mem.pa);
901 : :
902 : 0 : err = gve_adminq_execute_cmd(priv, &gvnic_cmd);
903 : :
904 [ # # ]: 0 : priv->link_speed = be64_to_cpu(*link_speed_region);
905 : 0 : gve_free_dma_mem(&link_speed_region_dma_mem);
906 : 0 : return err;
907 : : }
908 : :
909 : 0 : int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv,
910 : : struct gve_ptype_lut *ptype_lut)
911 : : {
912 : : struct gve_dma_mem ptype_map_dma_mem;
913 : : struct gve_ptype_map *ptype_map;
914 : : union gve_adminq_command cmd;
915 : : int err = 0;
916 : : int i;
917 : :
918 : : memset(&cmd, 0, sizeof(cmd));
919 : 0 : ptype_map = gve_alloc_dma_mem(&ptype_map_dma_mem, sizeof(*ptype_map));
920 [ # # ]: 0 : if (!ptype_map)
921 : : return -ENOMEM;
922 : :
923 : 0 : cmd.opcode = cpu_to_be32(GVE_ADMINQ_GET_PTYPE_MAP);
924 : 0 : cmd.get_ptype_map = (struct gve_adminq_get_ptype_map) {
925 : : .ptype_map_len = cpu_to_be64(sizeof(*ptype_map)),
926 [ # # ]: 0 : .ptype_map_addr = cpu_to_be64(ptype_map_dma_mem.pa),
927 : : };
928 : :
929 : 0 : err = gve_adminq_execute_cmd(priv, &cmd);
930 [ # # ]: 0 : if (err)
931 : 0 : goto err;
932 : :
933 : : /* Populate ptype_lut. */
934 [ # # ]: 0 : for (i = 0; i < GVE_NUM_PTYPES; i++) {
935 : 0 : ptype_lut->ptypes[i].l3_type =
936 : 0 : ptype_map->ptypes[i].l3_type;
937 : 0 : ptype_lut->ptypes[i].l4_type =
938 : 0 : ptype_map->ptypes[i].l4_type;
939 : : }
940 : 0 : err:
941 : 0 : gve_free_dma_mem(&ptype_map_dma_mem);
942 : 0 : return err;
943 : : }
944 : :
945 : 0 : int gve_adminq_configure_rss(struct gve_priv *priv,
946 : : struct gve_rss_config *rss_config)
947 : : {
948 : : struct gve_dma_mem indirection_table_dma_mem;
949 : : struct gve_dma_mem rss_key_dma_mem;
950 : : union gve_adminq_command cmd;
951 : : __be32 *indir = NULL;
952 : : u8 *key = NULL;
953 : : int err = 0;
954 : : int i;
955 : :
956 [ # # # # ]: 0 : if (!rss_config->indir_size || !rss_config->key_size)
957 : : return -EINVAL;
958 : :
959 : 0 : indir = gve_alloc_dma_mem(&indirection_table_dma_mem,
960 : 0 : rss_config->indir_size *
961 : : sizeof(*rss_config->indir));
962 [ # # ]: 0 : if (!indir) {
963 : : err = -ENOMEM;
964 : 0 : goto out;
965 : : }
966 [ # # ]: 0 : for (i = 0; i < rss_config->indir_size; i++)
967 [ # # ]: 0 : indir[i] = cpu_to_be32(rss_config->indir[i]);
968 : :
969 : 0 : key = gve_alloc_dma_mem(&rss_key_dma_mem,
970 : 0 : rss_config->key_size *
971 : : sizeof(*rss_config->key));
972 [ # # ]: 0 : if (!key) {
973 : : err = -ENOMEM;
974 : 0 : goto out;
975 : : }
976 [ # # ]: 0 : memcpy(key, rss_config->key, rss_config->key_size);
977 : :
978 : : memset(&cmd, 0, sizeof(cmd));
979 : 0 : cmd.opcode = cpu_to_be32(GVE_ADMINQ_CONFIGURE_RSS);
980 : 0 : cmd.configure_rss = (struct gve_adminq_configure_rss) {
981 [ # # ]: 0 : .hash_types = cpu_to_be16(rss_config->hash_types),
982 : 0 : .halg = rss_config->alg,
983 [ # # ]: 0 : .hkey_len = cpu_to_be16(rss_config->key_size),
984 [ # # ]: 0 : .indir_len = cpu_to_be16(rss_config->indir_size),
985 [ # # ]: 0 : .hkey_addr = cpu_to_be64(rss_key_dma_mem.pa),
986 [ # # ]: 0 : .indir_addr = cpu_to_be64(indirection_table_dma_mem.pa),
987 : : };
988 : :
989 : 0 : err = gve_adminq_execute_cmd(priv, &cmd);
990 : :
991 : 0 : out:
992 [ # # ]: 0 : if (indir)
993 : 0 : gve_free_dma_mem(&indirection_table_dma_mem);
994 [ # # ]: 0 : if (key)
995 : 0 : gve_free_dma_mem(&rss_key_dma_mem);
996 : : return err;
997 : : }
998 : :
|