Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2017 Intel Corporation
3 : : */
4 : :
5 : : #include <fcntl.h>
6 : : #include <stdio.h>
7 : : #include <errno.h>
8 : : #include <stdint.h>
9 : : #include <string.h>
10 : : #include <unistd.h>
11 : : #include <stdarg.h>
12 : : #include <inttypes.h>
13 : : #include <rte_byteorder.h>
14 : : #include <rte_common.h>
15 : : #include <rte_os_shim.h>
16 : :
17 : : #include <rte_debug.h>
18 : : #include <rte_alarm.h>
19 : : #include <rte_atomic.h>
20 : : #include <rte_eal.h>
21 : : #include <rte_ether.h>
22 : : #include <ethdev_driver.h>
23 : : #include <ethdev_pci.h>
24 : : #include <dev_driver.h>
25 : :
26 : : #include "iavf.h"
27 : : #include "iavf_rxtx.h"
28 : :
29 : : #define MAX_TRY_TIMES 2000
30 : : #define ASQ_DELAY_MS 1
31 : :
32 : : #define MAX_EVENT_PENDING 16
33 : :
34 : : struct iavf_event_element {
35 : : TAILQ_ENTRY(iavf_event_element) next;
36 : : struct rte_eth_dev *dev;
37 : : enum rte_eth_event_type event;
38 : : void *param;
39 : : size_t param_alloc_size;
40 : : uint8_t param_alloc_data[0];
41 : : };
42 : :
43 : : struct iavf_event_handler {
44 : : RTE_ATOMIC(uint32_t) ndev;
45 : : rte_thread_t tid;
46 : : int fd[2];
47 : : pthread_mutex_t lock;
48 : : TAILQ_HEAD(event_list, iavf_event_element) pending;
49 : : };
50 : :
51 : : static struct iavf_event_handler event_handler = {
52 : : .fd = {-1, -1},
53 : : };
54 : :
55 : : #ifndef TAILQ_FOREACH_SAFE
56 : : #define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
57 : : for ((var) = TAILQ_FIRST((head)); \
58 : : (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \
59 : : (var) = (tvar))
60 : : #endif
61 : :
62 : : static uint32_t
63 : 0 : iavf_dev_event_handle(void *param __rte_unused)
64 : : {
65 : : struct iavf_event_handler *handler = &event_handler;
66 : : TAILQ_HEAD(event_list, iavf_event_element) pending;
67 : :
68 : 0 : while (true) {
69 : : char unused[MAX_EVENT_PENDING];
70 : 0 : ssize_t nr = read(handler->fd[0], &unused, sizeof(unused));
71 [ # # ]: 0 : if (nr <= 0)
72 : : break;
73 : :
74 : 0 : TAILQ_INIT(&pending);
75 : 0 : pthread_mutex_lock(&handler->lock);
76 [ # # ]: 0 : TAILQ_CONCAT(&pending, &handler->pending, next);
77 : 0 : pthread_mutex_unlock(&handler->lock);
78 : :
79 : : struct iavf_event_element *pos, *save_next;
80 [ # # ]: 0 : TAILQ_FOREACH_SAFE(pos, &pending, next, save_next) {
81 [ # # ]: 0 : TAILQ_REMOVE(&pending, pos, next);
82 : :
83 : 0 : struct iavf_adapter *adapter = pos->dev->data->dev_private;
84 [ # # ]: 0 : if (pos->event == RTE_ETH_EVENT_INTR_RESET &&
85 [ # # ]: 0 : adapter->devargs.auto_reset) {
86 : 0 : iavf_handle_hw_reset(pos->dev, false);
87 : 0 : rte_free(pos);
88 : 0 : continue;
89 : : }
90 : :
91 : 0 : rte_eth_dev_callback_process(pos->dev, pos->event, pos->param);
92 : 0 : rte_free(pos);
93 : : }
94 : : }
95 : :
96 : 0 : return 0;
97 : : }
98 : :
99 : : void
100 : 0 : iavf_dev_event_post(struct rte_eth_dev *dev,
101 : : enum rte_eth_event_type event,
102 : : void *param, size_t param_alloc_size)
103 : : {
104 : : struct iavf_event_handler *handler = &event_handler;
105 : 0 : char notify_byte = 0;
106 : 0 : struct iavf_event_element *elem = rte_malloc(NULL, sizeof(*elem) + param_alloc_size, 0);
107 [ # # ]: 0 : if (!elem)
108 : 0 : return;
109 : :
110 : 0 : elem->dev = dev;
111 : 0 : elem->event = event;
112 : 0 : elem->param = param;
113 : 0 : elem->param_alloc_size = param_alloc_size;
114 [ # # ]: 0 : if (param && param_alloc_size) {
115 : 0 : memcpy(elem->param_alloc_data, param, param_alloc_size);
116 : 0 : elem->param = elem->param_alloc_data;
117 : : }
118 : :
119 : 0 : pthread_mutex_lock(&handler->lock);
120 : 0 : TAILQ_INSERT_TAIL(&handler->pending, elem, next);
121 : 0 : pthread_mutex_unlock(&handler->lock);
122 : :
123 : 0 : ssize_t nw = write(handler->fd[1], ¬ify_byte, 1);
124 : : RTE_SET_USED(nw);
125 : : }
126 : :
127 : : int
128 : 0 : iavf_dev_event_handler_init(void)
129 : : {
130 : : struct iavf_event_handler *handler = &event_handler;
131 : :
132 [ # # ]: 0 : if (rte_atomic_fetch_add_explicit(&handler->ndev, 1, rte_memory_order_relaxed) + 1 != 1)
133 : : return 0;
134 : : #if defined(RTE_EXEC_ENV_IS_WINDOWS) && RTE_EXEC_ENV_IS_WINDOWS != 0
135 : : int err = _pipe(handler->fd, MAX_EVENT_PENDING, O_BINARY);
136 : : #else
137 : 0 : int err = pipe(handler->fd);
138 : : #endif
139 [ # # ]: 0 : if (err != 0) {
140 : 0 : rte_atomic_fetch_sub_explicit(&handler->ndev, 1, rte_memory_order_relaxed);
141 : 0 : return -1;
142 : : }
143 : :
144 : 0 : TAILQ_INIT(&handler->pending);
145 : 0 : pthread_mutex_init(&handler->lock, NULL);
146 : :
147 [ # # ]: 0 : if (rte_thread_create_internal_control(&handler->tid, "iavf-event",
148 : : iavf_dev_event_handle, NULL)) {
149 : 0 : rte_atomic_fetch_sub_explicit(&handler->ndev, 1, rte_memory_order_relaxed);
150 : 0 : return -1;
151 : : }
152 : :
153 : : return 0;
154 : : }
155 : :
156 : : void
157 : 0 : iavf_dev_event_handler_fini(void)
158 : : {
159 : : struct iavf_event_handler *handler = &event_handler;
160 : :
161 [ # # ]: 0 : if (rte_atomic_fetch_sub_explicit(&handler->ndev, 1, rte_memory_order_relaxed) - 1 != 0)
162 : : return;
163 : :
164 : 0 : int unused = pthread_cancel((pthread_t)handler->tid.opaque_id);
165 : : RTE_SET_USED(unused);
166 : 0 : close(handler->fd[0]);
167 : 0 : close(handler->fd[1]);
168 : 0 : handler->fd[0] = -1;
169 : 0 : handler->fd[1] = -1;
170 : :
171 : 0 : rte_thread_join(handler->tid, NULL);
172 : 0 : pthread_mutex_destroy(&handler->lock);
173 : :
174 : : struct iavf_event_element *pos, *save_next;
175 [ # # ]: 0 : TAILQ_FOREACH_SAFE(pos, &handler->pending, next, save_next) {
176 [ # # ]: 0 : TAILQ_REMOVE(&handler->pending, pos, next);
177 : 0 : rte_free(pos);
178 : : }
179 : : }
180 : :
181 : : static uint32_t
182 : 0 : iavf_convert_link_speed(enum virtchnl_link_speed virt_link_speed)
183 : : {
184 : : uint32_t speed;
185 : :
186 [ # # # # : 0 : switch (virt_link_speed) {
# # # #
# ]
187 : : case VIRTCHNL_LINK_SPEED_100MB:
188 : : speed = 100;
189 : : break;
190 : 0 : case VIRTCHNL_LINK_SPEED_1GB:
191 : : speed = 1000;
192 : 0 : break;
193 : 0 : case VIRTCHNL_LINK_SPEED_10GB:
194 : : speed = 10000;
195 : 0 : break;
196 : 0 : case VIRTCHNL_LINK_SPEED_40GB:
197 : : speed = 40000;
198 : 0 : break;
199 : 0 : case VIRTCHNL_LINK_SPEED_20GB:
200 : : speed = 20000;
201 : 0 : break;
202 : 0 : case VIRTCHNL_LINK_SPEED_25GB:
203 : : speed = 25000;
204 : 0 : break;
205 : 0 : case VIRTCHNL_LINK_SPEED_2_5GB:
206 : : speed = 2500;
207 : 0 : break;
208 : 0 : case VIRTCHNL_LINK_SPEED_5GB:
209 : : speed = 5000;
210 : 0 : break;
211 : 0 : default:
212 : : speed = 0;
213 : 0 : break;
214 : : }
215 : :
216 : 0 : return speed;
217 : : }
218 : :
219 : : /*
220 : : * iavf_handle_link_change_event: common handler for VIRTCHNL link change events
221 : : *
222 : : * @dev: pointer to rte_eth_dev for this VF
223 : : * @vpe: pointer to the virtchnl_pf_event payload received from the PF
224 : : *
225 : : * Handle PF link-change event: decode adv/legacy link info, update VF
226 : : * link state, sync no-poll/watchdog behavior & notify app via LSC event.
227 : : */
228 : : static void
229 : 0 : iavf_handle_link_change_event(struct rte_eth_dev *dev,
230 : : struct virtchnl_pf_event *vpe)
231 : : {
232 : 0 : struct iavf_adapter *adapter =
233 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
234 : : struct iavf_info *vf = &adapter->vf;
235 : : bool adv_link_speed;
236 : :
237 [ # # ]: 0 : adv_link_speed = (vf->vf_res != NULL) &&
238 [ # # ]: 0 : ((vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_ADV_LINK_SPEED) != 0);
239 : :
240 [ # # ]: 0 : if (adv_link_speed) {
241 : 0 : vf->link_up = vpe->event_data.link_event_adv.link_status;
242 : 0 : vf->link_speed = vpe->event_data.link_event_adv.link_speed;
243 : : } else {
244 : : enum virtchnl_link_speed speed;
245 : :
246 : 0 : vf->link_up = vpe->event_data.link_event.link_status;
247 : 0 : speed = vpe->event_data.link_event.link_speed;
248 : 0 : vf->link_speed = iavf_convert_link_speed(speed);
249 : : }
250 : :
251 : 0 : iavf_dev_link_update(dev, 0);
252 : :
253 : : /*
254 : : * Update watchdog/no_poll state BEFORE notifying the application via
255 : : * the LSC event. Otherwise the application's link-up callback could
256 : : * race with stale (link-down) no_poll/watchdog state and either
257 : : * continue to drop traffic or trigger a spurious reset detection.
258 : : *
259 : : * Keeping the watchdog enabled whenever the link cannot be trusted
260 : : * (link is down or a VF reset is in progress); the watchdog drives
261 : : * auto-reset recovery, so it must remain armed in those cases.
262 : : */
263 [ # # # # : 0 : if (vf->link_up && !vf->vf_reset && !vf->in_reset_recovery)
# # ]
264 : 0 : iavf_dev_watchdog_disable(adapter);
265 : : else
266 : 0 : iavf_dev_watchdog_enable(adapter);
267 : :
268 [ # # ]: 0 : if (adapter->devargs.no_poll_on_link_down) {
269 : 0 : iavf_set_no_poll(adapter, true);
270 [ # # ]: 0 : PMD_DRV_LOG(DEBUG, "VF no poll turned %s",
271 : : rte_atomic_load_explicit(&adapter->no_poll,
272 : : rte_memory_order_relaxed) ?
273 : : "on" : "off");
274 : : }
275 : :
276 : : /* Retry a dev_start deferred by reset recovery, before the LSC post. */
277 : 0 : iavf_resume_pending_start(dev);
278 : :
279 : 0 : iavf_dev_event_post(dev, RTE_ETH_EVENT_INTR_LSC, NULL, 0);
280 : :
281 [ # # ]: 0 : PMD_DRV_LOG(INFO, "Link status update:%s",
282 : : vf->link_up ? "up" : "down");
283 : 0 : }
284 : :
285 : : /* Read data in admin queue to get msg from pf driver */
286 : : static enum iavf_aq_result
287 : 0 : iavf_read_msg_from_pf(struct iavf_adapter *adapter, uint16_t buf_len,
288 : : uint8_t *buf)
289 : : {
290 : 0 : struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
291 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
292 : : struct iavf_arq_event_info event;
293 : : enum iavf_aq_result result = IAVF_MSG_NON;
294 : : enum virtchnl_ops opcode;
295 : : int ret;
296 : :
297 : 0 : event.buf_len = buf_len;
298 : 0 : event.msg_buf = buf;
299 : 0 : ret = iavf_clean_arq_element(hw, &event, NULL);
300 : : /* Can't read any msg from adminQ */
301 [ # # ]: 0 : if (ret) {
302 : 0 : PMD_DRV_LOG(DEBUG, "Can't read msg from AQ");
303 [ # # ]: 0 : if (ret != IAVF_ERR_ADMIN_QUEUE_NO_WORK)
304 : : result = IAVF_MSG_ERR;
305 : 0 : return result;
306 : : }
307 : :
308 : 0 : opcode = (enum virtchnl_ops)rte_le_to_cpu_32(event.desc.cookie_high);
309 : 0 : vf->cmd_retval = (enum virtchnl_status_code)rte_le_to_cpu_32(
310 : : event.desc.cookie_low);
311 : :
312 : 0 : PMD_DRV_LOG(DEBUG, "AQ from pf carries opcode %u, retval %d",
313 : : opcode, vf->cmd_retval);
314 : :
315 [ # # ]: 0 : if (opcode == VIRTCHNL_OP_EVENT) {
316 : 0 : struct virtchnl_pf_event *vpe =
317 : : (struct virtchnl_pf_event *)event.msg_buf;
318 : :
319 : : result = IAVF_MSG_SYS;
320 [ # # # # ]: 0 : switch (vpe->event) {
321 : 0 : case VIRTCHNL_EVENT_LINK_CHANGE:
322 : 0 : iavf_handle_link_change_event(vf->eth_dev, vpe);
323 : 0 : break;
324 : 0 : case VIRTCHNL_EVENT_RESET_IMPENDING:
325 : : /*
326 : : * Force link down on impending reset to drop
327 : : * the cached link-up state; a fresh LSC up
328 : : * event will be re-issued by the PF once the
329 : : * VF is reinitialised.
330 : : */
331 : 0 : vf->link_up = false;
332 [ # # ]: 0 : if (!vf->vf_reset) {
333 : 0 : vf->vf_reset = true;
334 : 0 : iavf_set_no_poll(adapter, false);
335 : 0 : iavf_dev_watchdog_enable(adapter);
336 [ # # ]: 0 : if (adapter->devargs.no_poll_on_link_down)
337 : 0 : iavf_dev_tx_drain(vf->eth_dev);
338 : 0 : iavf_dev_event_post(vf->eth_dev,
339 : : RTE_ETH_EVENT_INTR_RESET,
340 : : NULL, 0);
341 : : }
342 : 0 : PMD_DRV_LOG(DEBUG, "VF is resetting");
343 : 0 : break;
344 : 0 : case VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
345 : 0 : vf->dev_closed = true;
346 : 0 : PMD_DRV_LOG(INFO, "PF driver closed");
347 : 0 : break;
348 : 0 : default:
349 : 0 : PMD_DRV_LOG(ERR, "%s: Unknown event %d from pf",
350 : : __func__, vpe->event);
351 : : }
352 : : } else {
353 : : /* async reply msg on command issued by vf previously */
354 : : result = IAVF_MSG_CMD;
355 [ # # ]: 0 : if (opcode != vf->pend_cmd) {
356 [ # # ]: 0 : if (opcode == VIRTCHNL_OP_UNKNOWN)
357 : 0 : PMD_DRV_LOG(DEBUG,
358 : : "Spurious msg with opcode 0, pending cmd %u",
359 : : vf->pend_cmd);
360 : : else
361 : 0 : PMD_DRV_LOG(WARNING,
362 : : "command mismatch, expect %u, get %u",
363 : : vf->pend_cmd, opcode);
364 : :
365 : : result = IAVF_MSG_ERR;
366 : : }
367 : : }
368 : :
369 : : return result;
370 : : }
371 : :
372 : : static int
373 : 0 : iavf_set_pending_cmd(struct iavf_info *vf, enum virtchnl_ops ops,
374 : : uint32_t resp_count)
375 : : {
376 : : enum virtchnl_ops op_unk = VIRTCHNL_OP_UNKNOWN;
377 : 0 : int ret = rte_atomic_compare_exchange_strong_explicit(&vf->pend_cmd,
378 : : &op_unk, ops, rte_memory_order_acquire,
379 : : rte_memory_order_acquire);
380 : :
381 [ # # ]: 0 : if (ret == 0) {
382 : 0 : PMD_DRV_LOG(ERR, "There is incomplete cmd %d", vf->pend_cmd);
383 : 0 : return -1;
384 : : }
385 : :
386 : 0 : rte_atomic_store_explicit(&vf->pend_cmd_count, resp_count,
387 : : rte_memory_order_relaxed);
388 : :
389 : 0 : return 0;
390 : : }
391 : :
392 : : static inline void
393 : : iavf_clear_pending_cmd(struct iavf_info *vf)
394 : : {
395 : : rte_wmb();
396 : 0 : vf->pend_cmd = VIRTCHNL_OP_UNKNOWN;
397 : 0 : vf->cmd_retval = VIRTCHNL_STATUS_SUCCESS;
398 : : }
399 : :
400 : : static inline void
401 : : iavf_notify_pending_cmd(struct iavf_info *vf, int msg_ret)
402 : : {
403 : 0 : vf->cmd_retval = msg_ret;
404 : : rte_wmb();
405 : 0 : vf->pend_cmd = VIRTCHNL_OP_UNKNOWN;
406 : 0 : }
407 : :
408 : : static int
409 : : iavf_get_cmd_resp_count(enum virtchnl_ops op)
410 : : {
411 : 0 : switch (op) {
412 : : case VIRTCHNL_OP_RESET_VF:
413 : : case VIRTCHNL_OP_REQUEST_QUEUES:
414 : : /* These commands trigger reset and are not waited for */
415 : : return 0;
416 : 0 : case VIRTCHNL_OP_INLINE_IPSEC_CRYPTO:
417 : : /* IPsec crypto commands generate two responses */
418 : 0 : return 2;
419 : 0 : default:
420 : : /* All other commands generate one response */
421 : 0 : return 1;
422 : : }
423 : : }
424 : :
425 : : static int
426 : : iavf_op_needs_poll(struct iavf_info *vf)
427 : : {
428 : : /* Poll if interrupts disabled or we are in interrupt thread */
429 [ # # ]: 0 : return !vf->aq_intr_enabled || rte_thread_is_intr();
430 : : }
431 : :
432 : : static int
433 : 0 : iavf_wait_for_msg(struct iavf_adapter *adapter, struct iavf_cmd_info *args,
434 : : bool poll)
435 : : {
436 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
437 : : int err = 0;
438 : : int i = 0;
439 : :
440 [ # # ]: 0 : if (args->out_buffer == NULL) {
441 : 0 : PMD_DRV_LOG(ERR, "Invalid buffer for cmd %d response", args->ops);
442 : 0 : return -EINVAL;
443 : : }
444 : :
445 : : /* Wait for command completion */
446 : : do {
447 [ # # ]: 0 : if (poll) {
448 : : enum iavf_aq_result result;
449 : 0 : result = iavf_read_msg_from_pf(adapter, args->out_size,
450 : : args->out_buffer);
451 [ # # ]: 0 : if (result == IAVF_MSG_CMD)
452 : : break;
453 : : } else {
454 : : /* check if interrupt thread has erased pending cmd */
455 [ # # ]: 0 : if (vf->pend_cmd == VIRTCHNL_OP_UNKNOWN)
456 : : break;
457 : : }
458 : 0 : iavf_msec_delay(ASQ_DELAY_MS);
459 [ # # ]: 0 : } while (i++ < MAX_TRY_TIMES);
460 : :
461 [ # # ]: 0 : if (i >= MAX_TRY_TIMES) {
462 : 0 : PMD_DRV_LOG(ERR, "No response for cmd %d", args->ops);
463 : : err = -EIO;
464 [ # # ]: 0 : } else if (vf->cmd_retval == VIRTCHNL_STATUS_ERR_NOT_SUPPORTED) {
465 : 0 : PMD_DRV_LOG(ERR, "Cmd %d not supported", args->ops);
466 : : err = -ENOTSUP;
467 [ # # ]: 0 : } else if (vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
468 : 0 : PMD_DRV_LOG(ERR, "Return failure %d for cmd %d",
469 : : vf->cmd_retval, args->ops);
470 : : err = -EINVAL;
471 : : }
472 : :
473 : : return err;
474 : : }
475 : :
476 : : static int
477 : 0 : iavf_execute_vf_cmd(struct iavf_adapter *adapter, struct iavf_cmd_info *args)
478 : : {
479 : 0 : struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
480 [ # # ]: 0 : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
481 : : enum iavf_status status;
482 : : uint32_t resp_count;
483 : : bool poll = iavf_op_needs_poll(vf);
484 : : int err;
485 : :
486 [ # # ]: 0 : if (vf->vf_reset)
487 : : return -EIO;
488 : :
489 [ # # # ]: 0 : resp_count = iavf_get_cmd_resp_count(args->ops);
490 : :
491 : : /*
492 : : * For some commands, we are not waiting for responses because they
493 : : * produce a reset event. However, we still need to set pending command
494 : : * to avoid sending commands while another one is already in progress.
495 : : */
496 [ # # ]: 0 : if (iavf_set_pending_cmd(vf, args->ops, RTE_MAX(1U, resp_count)) != 0)
497 : : return -1;
498 : :
499 : 0 : status = iavf_aq_send_msg_to_pf(hw, args->ops, IAVF_SUCCESS,
500 : 0 : args->in_args, args->in_args_size, NULL);
501 [ # # ]: 0 : if (status != IAVF_SUCCESS) {
502 : 0 : PMD_DRV_LOG(ERR, "fail to send cmd %d", args->ops);
503 : : err = (int)status;
504 : 0 : goto clear_cmd;
505 [ # # ]: 0 : } else if (resp_count == 0) {
506 : : /* we're not waiting on responses */
507 : : err = 0;
508 : 0 : goto clear_cmd;
509 : : }
510 : :
511 : 0 : err = iavf_wait_for_msg(adapter, args, poll);
512 : :
513 : : /*
514 : : * messages received through interrupts store their response in global
515 : : * buffer, so we need to copy it if we received the message.
516 : : */
517 [ # # ]: 0 : if (!poll && err == 0)
518 : 0 : memcpy(args->out_buffer, vf->aq_resp, args->out_size);
519 : :
520 : : /* in interrupt success case, pending cmd is cleared by intr thread */
521 [ # # ]: 0 : if (err != 0 || poll)
522 : 0 : goto clear_cmd;
523 : :
524 : : return err;
525 : 0 : clear_cmd:
526 : : iavf_clear_pending_cmd(vf);
527 : 0 : return err;
528 : : }
529 : :
530 : : static int
531 : 0 : iavf_execute_vf_cmd_safe(struct iavf_adapter *adapter,
532 : : struct iavf_cmd_info *args)
533 : : {
534 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
535 : : int ret;
536 : 0 : int is_intr_thread = rte_thread_is_intr();
537 : :
538 [ # # ]: 0 : if (is_intr_thread) {
539 [ # # ]: 0 : if (!rte_spinlock_trylock(&vf->aq_lock))
540 : : return -EIO;
541 : : } else {
542 : 0 : rte_spinlock_lock(&vf->aq_lock);
543 : : }
544 : 0 : ret = iavf_execute_vf_cmd(adapter, args);
545 : 0 : rte_spinlock_unlock(&vf->aq_lock);
546 : :
547 : 0 : return ret;
548 : : }
549 : :
550 : : static void
551 : 0 : iavf_handle_pf_event_msg(struct rte_eth_dev *dev, uint8_t *msg,
552 : : uint16_t msglen)
553 : : {
554 : 0 : struct iavf_adapter *adapter =
555 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
556 : : struct iavf_info *vf = &adapter->vf;
557 : : struct virtchnl_pf_event *pf_msg =
558 : : (struct virtchnl_pf_event *)msg;
559 : :
560 [ # # ]: 0 : if (adapter->closed) {
561 : 0 : PMD_DRV_LOG(DEBUG, "Port closed");
562 : 0 : return;
563 : : }
564 : :
565 [ # # ]: 0 : if (msglen < sizeof(struct virtchnl_pf_event)) {
566 : 0 : PMD_DRV_LOG(DEBUG, "Error event");
567 : 0 : return;
568 : : }
569 [ # # # # ]: 0 : switch (pf_msg->event) {
570 : 0 : case VIRTCHNL_EVENT_RESET_IMPENDING:
571 : 0 : PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_RESET_IMPENDING event");
572 : 0 : vf->link_up = false;
573 [ # # ]: 0 : if (!vf->vf_reset) {
574 : 0 : vf->vf_reset = true;
575 : 0 : iavf_set_no_poll(adapter, false);
576 : 0 : iavf_dev_watchdog_enable(adapter);
577 [ # # ]: 0 : if (adapter->devargs.no_poll_on_link_down)
578 : 0 : iavf_dev_tx_drain(dev);
579 : 0 : iavf_dev_event_post(dev, RTE_ETH_EVENT_INTR_RESET,
580 : : NULL, 0);
581 : : }
582 : : break;
583 : 0 : case VIRTCHNL_EVENT_LINK_CHANGE:
584 : 0 : PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_LINK_CHANGE event");
585 : 0 : iavf_handle_link_change_event(dev, pf_msg);
586 : 0 : break;
587 : 0 : case VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
588 : 0 : PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_PF_DRIVER_CLOSE event");
589 : 0 : break;
590 : 0 : default:
591 : 0 : PMD_DRV_LOG(ERR, " unknown event received %u", pf_msg->event);
592 : 0 : break;
593 : : }
594 : : }
595 : :
596 : : void
597 : 0 : iavf_handle_virtchnl_msg(struct rte_eth_dev *dev)
598 : : {
599 : 0 : struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
600 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
601 : : struct iavf_arq_event_info info;
602 : : uint16_t pending, aq_opc;
603 : : enum virtchnl_ops msg_opc;
604 : : enum iavf_status msg_ret;
605 : : int ret;
606 : :
607 : 0 : info.buf_len = IAVF_AQ_BUF_SZ;
608 : 0 : info.msg_buf = vf->aq_resp;
609 : :
610 : 0 : pending = 1;
611 [ # # ]: 0 : while (pending) {
612 : 0 : ret = iavf_clean_arq_element(hw, &info, &pending);
613 : :
614 [ # # ]: 0 : if (ret != IAVF_SUCCESS) {
615 : : /*
616 : : * IAVF_ERR_ADMIN_QUEUE_NO_WORK (-57) means AQ is empty
617 : : * and is a normal way to terminate the drain loop.
618 : : * Log error only for genuine other failure codes.
619 : : * Incorrect logging like this during VF resets might
620 : : * mislead into chasing a non-existent AQ failure.
621 : : */
622 [ # # ]: 0 : if (ret != IAVF_ERR_ADMIN_QUEUE_NO_WORK)
623 : 0 : PMD_DRV_LOG(INFO, "Failed to read msg from AdminQ,"
624 : : "ret: %d", ret);
625 : : break;
626 : : }
627 : 0 : aq_opc = rte_le_to_cpu_16(info.desc.opcode);
628 : :
629 : : /* opcode 0 means the descriptor is empty/zeroed, skip it */
630 [ # # ]: 0 : if (aq_opc == 0)
631 : 0 : continue;
632 : :
633 : : /* For the message sent from pf to vf, opcode is stored in
634 : : * cookie_high of struct iavf_aq_desc, while return error code
635 : : * are stored in cookie_low, Which is done by PF driver.
636 : : */
637 : 0 : msg_opc = (enum virtchnl_ops)rte_le_to_cpu_32(
638 : : info.desc.cookie_high);
639 : 0 : msg_ret = (enum iavf_status)rte_le_to_cpu_32(
640 : : info.desc.cookie_low);
641 [ # # ]: 0 : switch (aq_opc) {
642 : 0 : case iavf_aqc_opc_send_msg_to_vf:
643 [ # # ]: 0 : if (msg_opc == VIRTCHNL_OP_EVENT) {
644 : 0 : iavf_handle_pf_event_msg(dev, info.msg_buf,
645 : 0 : info.msg_len);
646 : : } else {
647 : : /* check for unsolicited messages i.e. events */
648 [ # # ]: 0 : if (info.msg_len > 0) {
649 : : switch (msg_opc) {
650 : 0 : case VIRTCHNL_OP_INLINE_IPSEC_CRYPTO: {
651 : 0 : struct inline_ipsec_msg *imsg =
652 : : (struct inline_ipsec_msg *)info.msg_buf;
653 [ # # ]: 0 : if (imsg->ipsec_opcode
654 : 0 : == INLINE_IPSEC_OP_EVENT) {
655 : : struct rte_eth_event_ipsec_desc desc;
656 : : struct virtchnl_ipsec_event *ev =
657 : : imsg->ipsec_data.event;
658 : 0 : desc.subtype =
659 : : RTE_ETH_EVENT_IPSEC_UNKNOWN;
660 : 0 : desc.metadata =
661 : 0 : ev->ipsec_event_data;
662 : 0 : iavf_dev_event_post(dev,
663 : : RTE_ETH_EVENT_IPSEC,
664 : : &desc, sizeof(desc));
665 : : continue;
666 : : }
667 : : }
668 : : break;
669 : : default:
670 : : break;
671 : : }
672 : :
673 : : }
674 : :
675 : : /* read message and it's expected one */
676 [ # # ]: 0 : if (msg_opc == vf->pend_cmd) {
677 : : uint32_t cmd_count =
678 : 0 : rte_atomic_fetch_sub_explicit(&vf->pend_cmd_count,
679 : : 1, rte_memory_order_relaxed) - 1;
680 [ # # ]: 0 : if (cmd_count == 0)
681 : : iavf_notify_pending_cmd(vf, msg_ret);
682 : : } else {
683 : 0 : PMD_DRV_LOG(ERR,
684 : : "command mismatch, expect %u, get %u",
685 : : vf->pend_cmd, msg_opc);
686 : : }
687 : 0 : PMD_DRV_LOG(DEBUG,
688 : : "adminq response is received, opcode = %d",
689 : : msg_opc);
690 : : }
691 : : break;
692 : 0 : default:
693 : 0 : PMD_DRV_LOG(DEBUG, "Request %u is not supported yet",
694 : : aq_opc);
695 : 0 : break;
696 : : }
697 : : }
698 : 0 : }
699 : :
700 : : int
701 : 0 : iavf_enable_vlan_strip(struct iavf_adapter *adapter)
702 : : {
703 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
704 : : struct iavf_cmd_info args;
705 : : int ret;
706 : :
707 : : memset(&args, 0, sizeof(args));
708 : 0 : args.ops = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
709 : : args.in_args = NULL;
710 : : args.in_args_size = 0;
711 : 0 : args.out_buffer = msg_buf;
712 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
713 : 0 : ret = iavf_execute_vf_cmd_safe(adapter, &args);
714 [ # # ]: 0 : if (ret)
715 : 0 : PMD_DRV_LOG(ERR, "Failed to execute command of"
716 : : " OP_ENABLE_VLAN_STRIPPING");
717 : :
718 : 0 : return ret;
719 : : }
720 : :
721 : : int
722 : 0 : iavf_disable_vlan_strip(struct iavf_adapter *adapter)
723 : : {
724 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
725 : : struct iavf_cmd_info args;
726 : : int ret;
727 : :
728 : : memset(&args, 0, sizeof(args));
729 : 0 : args.ops = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
730 : : args.in_args = NULL;
731 : : args.in_args_size = 0;
732 : 0 : args.out_buffer = msg_buf;
733 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
734 : 0 : ret = iavf_execute_vf_cmd_safe(adapter, &args);
735 [ # # ]: 0 : if (ret)
736 : 0 : PMD_DRV_LOG(ERR, "Failed to execute command of"
737 : : " OP_DISABLE_VLAN_STRIPPING");
738 : :
739 : 0 : return ret;
740 : : }
741 : :
742 : : #define VIRTCHNL_VERSION_MAJOR_START 1
743 : : #define VIRTCHNL_VERSION_MINOR_START 1
744 : :
745 : : /* Check API version with sync wait until version read from admin queue */
746 : : int
747 : 0 : iavf_check_api_version(struct iavf_adapter *adapter)
748 : : {
749 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
750 : : struct virtchnl_version_info version, *pver;
751 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
752 : : struct iavf_cmd_info args;
753 : : int err;
754 : :
755 : 0 : version.major = VIRTCHNL_VERSION_MAJOR;
756 : 0 : version.minor = VIRTCHNL_VERSION_MINOR;
757 : :
758 : 0 : args.ops = VIRTCHNL_OP_VERSION;
759 : 0 : args.in_args = (uint8_t *)&version;
760 : 0 : args.in_args_size = sizeof(version);
761 : 0 : args.out_buffer = msg_buf;
762 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
763 : :
764 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
765 [ # # ]: 0 : if (err) {
766 : 0 : PMD_INIT_LOG(ERR, "Fail to execute command of OP_VERSION");
767 : 0 : return err;
768 : : }
769 : :
770 : 0 : pver = (struct virtchnl_version_info *)args.out_buffer;
771 : 0 : vf->virtchnl_version = *pver;
772 : :
773 [ # # ]: 0 : if (vf->virtchnl_version.major < VIRTCHNL_VERSION_MAJOR_START ||
774 [ # # ]: 0 : (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR_START &&
775 : : vf->virtchnl_version.minor < VIRTCHNL_VERSION_MINOR_START)) {
776 : 0 : PMD_INIT_LOG(ERR, "VIRTCHNL API version should not be lower"
777 : : " than (%u.%u) to support Adaptive VF",
778 : : VIRTCHNL_VERSION_MAJOR_START,
779 : : VIRTCHNL_VERSION_MAJOR_START);
780 : 0 : return -1;
781 [ # # ]: 0 : } else if (vf->virtchnl_version.major > VIRTCHNL_VERSION_MAJOR ||
782 : 0 : (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR &&
783 [ # # ]: 0 : vf->virtchnl_version.minor > VIRTCHNL_VERSION_MINOR)) {
784 : 0 : PMD_INIT_LOG(ERR, "PF/VF API version mismatch:(%u.%u)-(%u.%u)",
785 : : vf->virtchnl_version.major,
786 : : vf->virtchnl_version.minor,
787 : : VIRTCHNL_VERSION_MAJOR,
788 : : VIRTCHNL_VERSION_MINOR);
789 : 0 : return -1;
790 : : }
791 : :
792 : 0 : PMD_DRV_LOG(DEBUG, "Peer is supported PF host");
793 : 0 : return 0;
794 : : }
795 : :
796 : : int
797 : 0 : iavf_get_vf_resource(struct iavf_adapter *adapter)
798 : : {
799 : 0 : struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
800 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
801 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
802 : : struct iavf_cmd_info args;
803 : : uint32_t caps, len;
804 : : int err, i;
805 : :
806 : 0 : args.ops = VIRTCHNL_OP_GET_VF_RESOURCES;
807 : 0 : args.out_buffer = msg_buf;
808 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
809 : :
810 : 0 : caps = IAVF_BASIC_OFFLOAD_CAPS | VIRTCHNL_VF_CAP_ADV_LINK_SPEED |
811 : : VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC |
812 : : VIRTCHNL_VF_OFFLOAD_FDIR_PF |
813 : : VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF |
814 : : VIRTCHNL_VF_OFFLOAD_FSUB_PF |
815 : : VIRTCHNL_VF_OFFLOAD_REQ_QUEUES |
816 : : VIRTCHNL_VF_OFFLOAD_USO |
817 : : VIRTCHNL_VF_OFFLOAD_CRC |
818 : : VIRTCHNL_VF_OFFLOAD_VLAN_V2 |
819 : : VIRTCHNL_VF_LARGE_NUM_QPAIRS |
820 : : VIRTCHNL_VF_OFFLOAD_QOS |
821 : : VIRTCHNL_VF_OFFLOAD_INLINE_IPSEC_CRYPTO |
822 : : VIRTCHNL_VF_CAP_PTP;
823 : :
824 : 0 : args.in_args = (uint8_t *)∩︀
825 : 0 : args.in_args_size = sizeof(caps);
826 : :
827 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
828 : :
829 [ # # ]: 0 : if (err) {
830 : 0 : PMD_DRV_LOG(ERR,
831 : : "Failed to execute command of OP_GET_VF_RESOURCE");
832 : 0 : return -1;
833 : : }
834 : :
835 : : len = sizeof(struct virtchnl_vf_resource) +
836 : : IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
837 : :
838 : 0 : memcpy(vf->vf_res, args.out_buffer,
839 : 0 : RTE_MIN(args.out_size, len));
840 : : /* parse VF config message back from PF*/
841 : 0 : iavf_vf_parse_hw_config(hw, vf->vf_res);
842 [ # # ]: 0 : for (i = 0; i < vf->vf_res->num_vsis; i++) {
843 [ # # ]: 0 : if (vf->vf_res->vsi_res[i].vsi_type == VIRTCHNL_VSI_SRIOV)
844 : 0 : vf->vsi_res = &vf->vf_res->vsi_res[i];
845 : : }
846 : :
847 [ # # ]: 0 : if (!vf->vsi_res) {
848 : 0 : PMD_INIT_LOG(ERR, "no LAN VSI found");
849 : 0 : return -1;
850 : : }
851 : :
852 : 0 : vf->vsi.vsi_id = vf->vsi_res->vsi_id;
853 : 0 : vf->vsi.nb_qps = vf->vsi_res->num_queue_pairs;
854 : 0 : vf->vsi.adapter = adapter;
855 : :
856 : 0 : return 0;
857 : : }
858 : :
859 : : int
860 : 0 : iavf_get_supported_rxdid(struct iavf_adapter *adapter)
861 : : {
862 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
863 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
864 : : struct iavf_cmd_info args;
865 : : int ret;
866 : :
867 : 0 : args.ops = VIRTCHNL_OP_GET_SUPPORTED_RXDIDS;
868 : 0 : args.in_args = NULL;
869 : 0 : args.in_args_size = 0;
870 : 0 : args.out_buffer = msg_buf;
871 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
872 : :
873 : 0 : ret = iavf_execute_vf_cmd_safe(adapter, &args);
874 [ # # ]: 0 : if (ret) {
875 : 0 : PMD_DRV_LOG(ERR,
876 : : "Failed to execute command of OP_GET_SUPPORTED_RXDIDS");
877 : 0 : return ret;
878 : : }
879 : :
880 : 0 : vf->supported_rxdid =
881 : 0 : ((struct virtchnl_supported_rxdids *)args.out_buffer)->supported_rxdids;
882 : :
883 : 0 : return 0;
884 : : }
885 : :
886 : : int
887 : 0 : iavf_config_outer_vlan_strip_v2(struct iavf_adapter *adapter, bool enable)
888 : : {
889 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
890 : : struct virtchnl_vlan_supported_caps *stripping_caps;
891 : : struct virtchnl_vlan_setting vlan_strip;
892 [ # # ]: 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
893 : : struct iavf_cmd_info args;
894 : : uint32_t *ethertype;
895 : : int ret;
896 : :
897 : : memset(&vlan_strip, 0, sizeof(vlan_strip));
898 : : stripping_caps = &vf->vlan_v2_caps.offloads.stripping_support;
899 [ # # # # ]: 0 : if ((stripping_caps->outer & VIRTCHNL_VLAN_ETHERTYPE_88A8) &&
900 : 0 : (stripping_caps->outer & VIRTCHNL_VLAN_TOGGLE) &&
901 [ # # ]: 0 : adapter->tpid == RTE_ETHER_TYPE_QINQ) {
902 : : ethertype = &vlan_strip.outer_ethertype_setting;
903 : 0 : *ethertype = VIRTCHNL_VLAN_ETHERTYPE_88A8;
904 [ # # # # ]: 0 : } else if ((stripping_caps->outer & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
905 : 0 : (stripping_caps->outer & VIRTCHNL_VLAN_TOGGLE) &&
906 [ # # ]: 0 : adapter->tpid == RTE_ETHER_TYPE_VLAN) {
907 : : ethertype = &vlan_strip.outer_ethertype_setting;
908 : 0 : *ethertype = VIRTCHNL_VLAN_ETHERTYPE_8100;
909 : : } else {
910 : : return -ENOTSUP;
911 : : }
912 : :
913 : 0 : vlan_strip.vport_id = vf->vsi_res->vsi_id;
914 : :
915 [ # # ]: 0 : args.ops = enable ? VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 :
916 : : VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2;
917 : 0 : args.in_args = (uint8_t *)&vlan_strip;
918 : 0 : args.in_args_size = sizeof(vlan_strip);
919 : 0 : args.out_buffer = msg_buf;
920 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
921 : 0 : ret = iavf_execute_vf_cmd_safe(adapter, &args);
922 [ # # ]: 0 : if (ret)
923 [ # # ]: 0 : PMD_DRV_LOG(ERR, "fail to execute command %s",
924 : : enable ? "VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2" :
925 : : "VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2");
926 : :
927 : : return ret;
928 : : }
929 : :
930 : : int
931 : 0 : iavf_config_vlan_strip_v2(struct iavf_adapter *adapter, bool enable)
932 : : {
933 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
934 : : struct virtchnl_vlan_supported_caps *stripping_caps;
935 : : struct virtchnl_vlan_setting vlan_strip;
936 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
937 : : struct iavf_cmd_info args;
938 : : uint32_t *ethertype;
939 : 0 : bool qinq = adapter->dev_data->dev_conf.rxmode.offloads &
940 : : RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
941 : 0 : bool strip_qinq = adapter->dev_data->dev_conf.rxmode.offloads &
942 : : RTE_ETH_RX_OFFLOAD_QINQ_STRIP;
943 : : int ret;
944 : :
945 [ # # # # ]: 0 : if (qinq && strip_qinq && adapter->tpid == RTE_ETHER_TYPE_VLAN)
946 : 0 : iavf_config_outer_vlan_strip_v2(adapter, enable);
947 : :
948 : : stripping_caps = &vf->vlan_v2_caps.offloads.stripping_support;
949 : :
950 : : /* When VLAN extend is disabled, Single VLAN mode which is Outer VLAN
951 : : * When VLAN extend is enabled i.e. DVM mode or when hardware reports
952 : : * Single VLAN capability through inner stripping_caps, this API
953 : : * works only on Inner VLAN strip which is always 0x8100.
954 : : */
955 [ # # # # : 0 : if (!qinq && (stripping_caps->outer & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
# # ]
956 : : (stripping_caps->outer & VIRTCHNL_VLAN_TOGGLE))
957 : : ethertype = &vlan_strip.outer_ethertype_setting;
958 [ # # # # ]: 0 : else if ((stripping_caps->inner & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
959 : : (stripping_caps->inner & VIRTCHNL_VLAN_TOGGLE))
960 : : ethertype = &vlan_strip.inner_ethertype_setting;
961 : : else
962 : : /* Return success for non-inner VLAN supported hardware */
963 [ # # # # ]: 0 : return (qinq && adapter->tpid == RTE_ETHER_TYPE_VLAN) ? 0 : -ENOTSUP;
964 : :
965 : : memset(&vlan_strip, 0, sizeof(vlan_strip));
966 : 0 : vlan_strip.vport_id = vf->vsi_res->vsi_id;
967 : 0 : *ethertype = VIRTCHNL_VLAN_ETHERTYPE_8100;
968 : :
969 [ # # ]: 0 : args.ops = enable ? VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 :
970 : : VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2;
971 : 0 : args.in_args = (uint8_t *)&vlan_strip;
972 : 0 : args.in_args_size = sizeof(vlan_strip);
973 : 0 : args.out_buffer = msg_buf;
974 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
975 : 0 : ret = iavf_execute_vf_cmd_safe(adapter, &args);
976 [ # # ]: 0 : if (ret)
977 [ # # ]: 0 : PMD_DRV_LOG(ERR, "fail to execute command %s",
978 : : enable ? "VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2" :
979 : : "VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2");
980 : :
981 : : return ret;
982 : : }
983 : :
984 : : int
985 : 0 : iavf_config_outer_vlan_insert_v2(struct iavf_adapter *adapter, bool enable)
986 : : {
987 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
988 : : struct virtchnl_vlan_supported_caps *insertion_caps;
989 : : struct virtchnl_vlan_setting vlan_insert;
990 [ # # ]: 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
991 : : struct iavf_cmd_info args;
992 : : uint32_t *ethertype;
993 : : int ret;
994 : :
995 : : memset(&vlan_insert, 0, sizeof(vlan_insert));
996 : : insertion_caps = &vf->vlan_v2_caps.offloads.insertion_support;
997 : :
998 [ # # # # ]: 0 : if ((insertion_caps->outer & VIRTCHNL_VLAN_ETHERTYPE_88A8) &&
999 : 0 : (insertion_caps->outer & VIRTCHNL_VLAN_TOGGLE) &&
1000 [ # # ]: 0 : adapter->tpid == RTE_ETHER_TYPE_QINQ) {
1001 : : ethertype = &vlan_insert.outer_ethertype_setting;
1002 : 0 : *ethertype = VIRTCHNL_VLAN_ETHERTYPE_88A8;
1003 [ # # # # ]: 0 : } else if ((insertion_caps->outer & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
1004 : 0 : (insertion_caps->outer & VIRTCHNL_VLAN_TOGGLE) &&
1005 [ # # ]: 0 : adapter->tpid == RTE_ETHER_TYPE_VLAN) {
1006 : : ethertype = &vlan_insert.outer_ethertype_setting;
1007 : 0 : *ethertype = VIRTCHNL_VLAN_ETHERTYPE_8100;
1008 : : } else {
1009 : : return -ENOTSUP;
1010 : : }
1011 : :
1012 : 0 : vlan_insert.vport_id = vf->vsi_res->vsi_id;
1013 : :
1014 [ # # ]: 0 : args.ops = enable ? VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 :
1015 : : VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2;
1016 : 0 : args.in_args = (uint8_t *)&vlan_insert;
1017 : 0 : args.in_args_size = sizeof(vlan_insert);
1018 : 0 : args.out_buffer = msg_buf;
1019 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
1020 : 0 : ret = iavf_execute_vf_cmd_safe(adapter, &args);
1021 [ # # ]: 0 : if (ret)
1022 [ # # ]: 0 : PMD_DRV_LOG(ERR, "fail to execute command %s",
1023 : : enable ? "VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2" :
1024 : : "VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2");
1025 : :
1026 : : return ret;
1027 : : }
1028 : :
1029 : : int
1030 : 0 : iavf_config_vlan_insert_v2(struct iavf_adapter *adapter, bool enable)
1031 : : {
1032 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1033 : : struct virtchnl_vlan_supported_caps *insertion_caps;
1034 : : struct virtchnl_vlan_setting vlan_insert;
1035 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
1036 : : struct iavf_cmd_info args;
1037 : : uint32_t *ethertype;
1038 : 0 : bool qinq = adapter->dev_data->dev_conf.rxmode.offloads &
1039 : : RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
1040 : 0 : bool insert_qinq = adapter->dev_data->dev_conf.txmode.offloads &
1041 : : RTE_ETH_TX_OFFLOAD_QINQ_INSERT;
1042 : : int ret;
1043 : :
1044 [ # # ]: 0 : if (qinq && insert_qinq)
1045 : 0 : iavf_config_outer_vlan_insert_v2(adapter, enable);
1046 : :
1047 : : insertion_caps = &vf->vlan_v2_caps.offloads.insertion_support;
1048 : :
1049 [ # # # # : 0 : if (!qinq && (insertion_caps->outer & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
# # ]
1050 : : (insertion_caps->outer & VIRTCHNL_VLAN_TOGGLE))
1051 : : ethertype = &vlan_insert.outer_ethertype_setting;
1052 [ # # # # ]: 0 : else if ((insertion_caps->inner & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
1053 : : (insertion_caps->inner & VIRTCHNL_VLAN_TOGGLE))
1054 : : ethertype = &vlan_insert.inner_ethertype_setting;
1055 : : else
1056 : : /* Return success for non-inner VLAN supported hardware */
1057 [ # # # # ]: 0 : return (qinq && adapter->tpid == RTE_ETHER_TYPE_VLAN) ? 0 : -ENOTSUP;
1058 : :
1059 : : memset(&vlan_insert, 0, sizeof(vlan_insert));
1060 : 0 : vlan_insert.vport_id = vf->vsi_res->vsi_id;
1061 : 0 : *ethertype = VIRTCHNL_VLAN_ETHERTYPE_8100;
1062 : :
1063 [ # # ]: 0 : args.ops = enable ? VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 :
1064 : : VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2;
1065 : 0 : args.in_args = (uint8_t *)&vlan_insert;
1066 : 0 : args.in_args_size = sizeof(vlan_insert);
1067 : 0 : args.out_buffer = msg_buf;
1068 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
1069 : 0 : ret = iavf_execute_vf_cmd_safe(adapter, &args);
1070 [ # # ]: 0 : if (ret)
1071 [ # # ]: 0 : PMD_DRV_LOG(ERR, "fail to execute command %s",
1072 : : enable ? "VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2" :
1073 : : "VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2");
1074 : :
1075 : : return ret;
1076 : : }
1077 : :
1078 : : int
1079 : 0 : iavf_add_del_vlan_v2(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
1080 : : {
1081 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1082 : : struct virtchnl_vlan_supported_caps *supported_caps;
1083 : : struct virtchnl_vlan_filter_list_v2 vlan_filter;
1084 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
1085 : : struct virtchnl_vlan *vlan_setting;
1086 : : struct iavf_cmd_info args;
1087 : : uint32_t filtering_caps;
1088 : 0 : bool qinq = adapter->dev_data->dev_conf.rxmode.offloads &
1089 : : RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
1090 : : int err;
1091 : :
1092 : : supported_caps = &vf->vlan_v2_caps.filtering.filtering_support;
1093 [ # # ]: 0 : if (supported_caps->outer) {
1094 : : filtering_caps = supported_caps->outer;
1095 : : vlan_setting = &vlan_filter.filters[0].outer;
1096 : : } else {
1097 : 0 : filtering_caps = supported_caps->inner;
1098 : : vlan_setting = &vlan_filter.filters[0].inner;
1099 : : }
1100 : :
1101 [ # # ]: 0 : if (!(filtering_caps & VIRTCHNL_VLAN_ETHERTYPE_8100))
1102 : : return -ENOTSUP;
1103 : :
1104 : : memset(&vlan_filter, 0, sizeof(vlan_filter));
1105 : 0 : vlan_filter.vport_id = vf->vsi_res->vsi_id;
1106 : 0 : vlan_filter.num_elements = 1;
1107 [ # # # # ]: 0 : if (qinq && adapter->tpid == RTE_ETHER_TYPE_QINQ)
1108 : 0 : vlan_setting->tpid = RTE_ETHER_TYPE_QINQ;
1109 : : else
1110 : 0 : vlan_setting->tpid = RTE_ETHER_TYPE_VLAN;
1111 : 0 : vlan_setting->tci = vlanid;
1112 : :
1113 [ # # ]: 0 : args.ops = add ? VIRTCHNL_OP_ADD_VLAN_V2 : VIRTCHNL_OP_DEL_VLAN_V2;
1114 : 0 : args.in_args = (uint8_t *)&vlan_filter;
1115 : 0 : args.in_args_size = sizeof(vlan_filter);
1116 : 0 : args.out_buffer = msg_buf;
1117 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
1118 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
1119 [ # # ]: 0 : if (err)
1120 [ # # ]: 0 : PMD_DRV_LOG(ERR, "fail to execute command %s",
1121 : : add ? "OP_ADD_VLAN_V2" : "OP_DEL_VLAN_V2");
1122 : :
1123 : : return err;
1124 : : }
1125 : :
1126 : : int
1127 : 0 : iavf_get_vlan_offload_caps_v2(struct iavf_adapter *adapter)
1128 : : {
1129 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1130 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
1131 : : struct iavf_cmd_info args;
1132 : : int ret;
1133 : :
1134 : 0 : args.ops = VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS;
1135 : 0 : args.in_args = NULL;
1136 : 0 : args.in_args_size = 0;
1137 : 0 : args.out_buffer = msg_buf;
1138 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
1139 : :
1140 : 0 : ret = iavf_execute_vf_cmd_safe(adapter, &args);
1141 [ # # ]: 0 : if (ret) {
1142 : 0 : PMD_DRV_LOG(ERR,
1143 : : "Failed to execute command of VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS");
1144 : 0 : return ret;
1145 : : }
1146 : :
1147 : 0 : memcpy(&vf->vlan_v2_caps, args.out_buffer, sizeof(vf->vlan_v2_caps));
1148 : :
1149 : 0 : return 0;
1150 : : }
1151 : :
1152 : : int
1153 : 0 : iavf_enable_queues(struct iavf_adapter *adapter)
1154 : : {
1155 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1156 : : struct virtchnl_queue_select queue_select;
1157 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
1158 : : struct iavf_cmd_info args;
1159 : : int err;
1160 : :
1161 : : memset(&queue_select, 0, sizeof(queue_select));
1162 : 0 : queue_select.vsi_id = vf->vsi_res->vsi_id;
1163 : :
1164 : 0 : queue_select.rx_queues = BIT(adapter->dev_data->nb_rx_queues) - 1;
1165 : 0 : queue_select.tx_queues = BIT(adapter->dev_data->nb_tx_queues) - 1;
1166 : :
1167 : 0 : args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
1168 : 0 : args.in_args = (u8 *)&queue_select;
1169 : 0 : args.in_args_size = sizeof(queue_select);
1170 : 0 : args.out_buffer = msg_buf;
1171 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
1172 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
1173 [ # # ]: 0 : if (err) {
1174 : 0 : PMD_DRV_LOG(ERR,
1175 : : "Failed to execute command of OP_ENABLE_QUEUES");
1176 : 0 : return err;
1177 : : }
1178 : : return 0;
1179 : : }
1180 : :
1181 : : int
1182 : 0 : iavf_disable_queues(struct iavf_adapter *adapter)
1183 : : {
1184 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1185 : : struct virtchnl_queue_select queue_select;
1186 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
1187 : : struct iavf_cmd_info args;
1188 : : int err;
1189 : :
1190 : : memset(&queue_select, 0, sizeof(queue_select));
1191 : 0 : queue_select.vsi_id = vf->vsi_res->vsi_id;
1192 : :
1193 : 0 : queue_select.rx_queues = BIT(adapter->dev_data->nb_rx_queues) - 1;
1194 : 0 : queue_select.tx_queues = BIT(adapter->dev_data->nb_tx_queues) - 1;
1195 : :
1196 : 0 : args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
1197 : 0 : args.in_args = (u8 *)&queue_select;
1198 : 0 : args.in_args_size = sizeof(queue_select);
1199 : 0 : args.out_buffer = msg_buf;
1200 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
1201 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
1202 [ # # ]: 0 : if (err) {
1203 : 0 : PMD_DRV_LOG(ERR,
1204 : : "Failed to execute command of OP_DISABLE_QUEUES");
1205 : 0 : return err;
1206 : : }
1207 : : return 0;
1208 : : }
1209 : :
1210 : : int
1211 : 0 : iavf_switch_queue(struct iavf_adapter *adapter, uint16_t qid,
1212 : : bool rx, bool on)
1213 : : {
1214 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1215 : : struct virtchnl_queue_select queue_select;
1216 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
1217 : : struct iavf_cmd_info args;
1218 : : int err;
1219 : :
1220 [ # # ]: 0 : if (adapter->closed)
1221 : : return -EIO;
1222 : :
1223 : : memset(&queue_select, 0, sizeof(queue_select));
1224 : 0 : queue_select.vsi_id = vf->vsi_res->vsi_id;
1225 [ # # ]: 0 : if (rx)
1226 : 0 : queue_select.rx_queues |= 1 << qid;
1227 : : else
1228 : 0 : queue_select.tx_queues |= 1 << qid;
1229 : :
1230 [ # # ]: 0 : if (on)
1231 : 0 : args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
1232 : : else
1233 : 0 : args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
1234 : 0 : args.in_args = (u8 *)&queue_select;
1235 : 0 : args.in_args_size = sizeof(queue_select);
1236 : 0 : args.out_buffer = msg_buf;
1237 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
1238 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
1239 [ # # ]: 0 : if (err)
1240 [ # # ]: 0 : PMD_DRV_LOG(ERR, "Failed to execute command of %s",
1241 : : on ? "OP_ENABLE_QUEUES" : "OP_DISABLE_QUEUES");
1242 : : return err;
1243 : : }
1244 : :
1245 : : int
1246 : 0 : iavf_enable_queues_lv(struct iavf_adapter *adapter)
1247 : : {
1248 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1249 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
1250 : : struct {
1251 : : struct virtchnl_del_ena_dis_queues msg;
1252 : : struct virtchnl_queue_chunk chunks[IAVF_RXTX_QUEUE_CHUNKS_NUM - 1];
1253 : 0 : } queue_req = {0};
1254 : : struct virtchnl_del_ena_dis_queues *queue_select = &queue_req.msg;
1255 : : struct virtchnl_queue_chunk *queue_chunk = queue_select->chunks.chunks;
1256 : : struct iavf_cmd_info args;
1257 : : int err;
1258 : :
1259 : 0 : queue_select->chunks.num_chunks = IAVF_RXTX_QUEUE_CHUNKS_NUM;
1260 : 0 : queue_select->vport_id = vf->vsi_res->vsi_id;
1261 : :
1262 : : queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].type = VIRTCHNL_QUEUE_TYPE_TX;
1263 : : queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].start_queue_id = 0;
1264 : 0 : queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].num_queues =
1265 : 0 : adapter->dev_data->nb_tx_queues;
1266 : :
1267 : 0 : queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].type = VIRTCHNL_QUEUE_TYPE_RX;
1268 : : queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].start_queue_id = 0;
1269 : 0 : queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].num_queues =
1270 : 0 : adapter->dev_data->nb_rx_queues;
1271 : :
1272 : 0 : args.ops = VIRTCHNL_OP_ENABLE_QUEUES_V2;
1273 : 0 : args.in_args = (u8 *)queue_select;
1274 : 0 : args.in_args_size = sizeof(queue_req);
1275 : 0 : args.out_buffer = msg_buf;
1276 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
1277 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
1278 [ # # ]: 0 : if (err)
1279 : 0 : PMD_DRV_LOG(ERR,
1280 : : "Failed to execute command of OP_ENABLE_QUEUES_V2");
1281 : :
1282 : 0 : return err;
1283 : : }
1284 : :
1285 : : int
1286 : 0 : iavf_disable_queues_lv(struct iavf_adapter *adapter)
1287 : : {
1288 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1289 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
1290 : : struct {
1291 : : struct virtchnl_del_ena_dis_queues msg;
1292 : : struct virtchnl_queue_chunk chunks[IAVF_RXTX_QUEUE_CHUNKS_NUM - 1];
1293 : 0 : } queue_req = {0};
1294 : : struct virtchnl_del_ena_dis_queues *queue_select = &queue_req.msg;
1295 : : struct virtchnl_queue_chunk *queue_chunk = queue_select->chunks.chunks;
1296 : : struct iavf_cmd_info args;
1297 : : int err;
1298 : :
1299 : 0 : queue_select->chunks.num_chunks = IAVF_RXTX_QUEUE_CHUNKS_NUM;
1300 : 0 : queue_select->vport_id = vf->vsi_res->vsi_id;
1301 : :
1302 : : queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].type = VIRTCHNL_QUEUE_TYPE_TX;
1303 : : queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].start_queue_id = 0;
1304 : 0 : queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].num_queues =
1305 : 0 : adapter->dev_data->nb_tx_queues;
1306 : :
1307 : 0 : queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].type = VIRTCHNL_QUEUE_TYPE_RX;
1308 : : queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].start_queue_id = 0;
1309 : 0 : queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].num_queues =
1310 : 0 : adapter->dev_data->nb_rx_queues;
1311 : :
1312 : 0 : args.ops = VIRTCHNL_OP_DISABLE_QUEUES_V2;
1313 : 0 : args.in_args = (u8 *)queue_select;
1314 : 0 : args.in_args_size = sizeof(queue_req);
1315 : 0 : args.out_buffer = msg_buf;
1316 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
1317 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
1318 [ # # ]: 0 : if (err)
1319 : 0 : PMD_DRV_LOG(ERR,
1320 : : "Failed to execute command of OP_DISABLE_QUEUES_V2");
1321 : :
1322 : 0 : return err;
1323 : : }
1324 : :
1325 : : int
1326 : 0 : iavf_switch_queue_lv(struct iavf_adapter *adapter, uint16_t qid,
1327 : : bool rx, bool on)
1328 : : {
1329 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1330 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
1331 : : struct {
1332 : : struct virtchnl_del_ena_dis_queues msg;
1333 : 0 : } queue_req = {0};
1334 : : struct virtchnl_del_ena_dis_queues *queue_select = &queue_req.msg;
1335 : : struct virtchnl_queue_chunk *queue_chunk = queue_select->chunks.chunks;
1336 : : struct iavf_cmd_info args;
1337 : : int err;
1338 : :
1339 : 0 : queue_select->chunks.num_chunks = 1;
1340 : 0 : queue_select->vport_id = vf->vsi_res->vsi_id;
1341 : :
1342 [ # # ]: 0 : if (rx) {
1343 : 0 : queue_chunk->type = VIRTCHNL_QUEUE_TYPE_RX;
1344 : 0 : queue_chunk->start_queue_id = qid;
1345 : 0 : queue_chunk->num_queues = 1;
1346 : : } else {
1347 : : queue_chunk->type = VIRTCHNL_QUEUE_TYPE_TX;
1348 : 0 : queue_chunk->start_queue_id = qid;
1349 : 0 : queue_chunk->num_queues = 1;
1350 : : }
1351 : :
1352 [ # # ]: 0 : if (on)
1353 : 0 : args.ops = VIRTCHNL_OP_ENABLE_QUEUES_V2;
1354 : : else
1355 : 0 : args.ops = VIRTCHNL_OP_DISABLE_QUEUES_V2;
1356 : 0 : args.in_args = (u8 *)queue_select;
1357 : 0 : args.in_args_size = sizeof(queue_req);
1358 : 0 : args.out_buffer = msg_buf;
1359 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
1360 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
1361 [ # # ]: 0 : if (err)
1362 [ # # ]: 0 : PMD_DRV_LOG(ERR, "Failed to execute command of %s",
1363 : : on ? "OP_ENABLE_QUEUES_V2" : "OP_DISABLE_QUEUES_V2");
1364 : :
1365 : 0 : return err;
1366 : : }
1367 : :
1368 : : int
1369 : 0 : iavf_configure_rss_lut(struct iavf_adapter *adapter)
1370 : : {
1371 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1372 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
1373 : : struct virtchnl_rss_lut *rss_lut;
1374 : : struct iavf_cmd_info args;
1375 : : int len, err = 0;
1376 : :
1377 : 0 : len = sizeof(*rss_lut) + vf->vf_res->rss_lut_size - 1;
1378 : 0 : rss_lut = calloc(1, len);
1379 [ # # ]: 0 : if (!rss_lut)
1380 : : return -ENOMEM;
1381 : :
1382 : 0 : rss_lut->vsi_id = vf->vsi_res->vsi_id;
1383 : 0 : rss_lut->lut_entries = vf->vf_res->rss_lut_size;
1384 : 0 : memcpy(rss_lut->lut, vf->rss_lut, vf->vf_res->rss_lut_size);
1385 : :
1386 : 0 : args.ops = VIRTCHNL_OP_CONFIG_RSS_LUT;
1387 : 0 : args.in_args = (u8 *)rss_lut;
1388 : 0 : args.in_args_size = len;
1389 : 0 : args.out_buffer = msg_buf;
1390 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
1391 : :
1392 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
1393 [ # # ]: 0 : if (err)
1394 : 0 : PMD_DRV_LOG(ERR,
1395 : : "Failed to execute command of OP_CONFIG_RSS_LUT");
1396 : :
1397 : 0 : free(rss_lut);
1398 : 0 : return err;
1399 : : }
1400 : :
1401 : : int
1402 : 0 : iavf_configure_rss_key(struct iavf_adapter *adapter)
1403 : : {
1404 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1405 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
1406 : : struct virtchnl_rss_key *rss_key;
1407 : : struct iavf_cmd_info args;
1408 : : int len, err = 0;
1409 : :
1410 : 0 : len = sizeof(*rss_key) + vf->vf_res->rss_key_size - 1;
1411 : 0 : rss_key = calloc(1, len);
1412 [ # # ]: 0 : if (!rss_key)
1413 : : return -ENOMEM;
1414 : :
1415 : 0 : rss_key->vsi_id = vf->vsi_res->vsi_id;
1416 : 0 : rss_key->key_len = vf->vf_res->rss_key_size;
1417 : 0 : memcpy(rss_key->key, vf->rss_key, vf->vf_res->rss_key_size);
1418 : :
1419 : 0 : args.ops = VIRTCHNL_OP_CONFIG_RSS_KEY;
1420 : 0 : args.in_args = (u8 *)rss_key;
1421 : 0 : args.in_args_size = len;
1422 : 0 : args.out_buffer = msg_buf;
1423 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
1424 : :
1425 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
1426 [ # # ]: 0 : if (err)
1427 : 0 : PMD_DRV_LOG(ERR,
1428 : : "Failed to execute command of OP_CONFIG_RSS_KEY");
1429 : :
1430 : 0 : free(rss_key);
1431 : 0 : return err;
1432 : : }
1433 : :
1434 : : static void
1435 : 0 : iavf_configure_queue_pair(struct iavf_adapter *adapter,
1436 : : struct virtchnl_queue_pair_info *vc_qp,
1437 : : uint16_t q_idx)
1438 : : {
1439 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1440 : 0 : struct ci_rx_queue **rxq = (struct ci_rx_queue **)adapter->dev_data->rx_queues;
1441 : 0 : struct ci_tx_queue **txq = (struct ci_tx_queue **)adapter->dev_data->tx_queues;
1442 : :
1443 : : /* common parts */
1444 : 0 : vc_qp->txq.vsi_id = vf->vsi_res->vsi_id;
1445 : 0 : vc_qp->txq.queue_id = q_idx;
1446 : :
1447 : 0 : vc_qp->rxq.vsi_id = vf->vsi_res->vsi_id;
1448 : 0 : vc_qp->rxq.queue_id = q_idx;
1449 : 0 : vc_qp->rxq.max_pkt_size = vf->max_pkt_len;
1450 : :
1451 : : /* is this txq active? */
1452 [ # # ]: 0 : if (q_idx < adapter->dev_data->nb_tx_queues) {
1453 : 0 : vc_qp->txq.ring_len = txq[q_idx]->nb_tx_desc;
1454 : 0 : vc_qp->txq.dma_ring_addr = txq[q_idx]->tx_ring_dma;
1455 : : }
1456 : :
1457 : : /* is this rxq active? */
1458 [ # # ]: 0 : if (q_idx >= adapter->dev_data->nb_rx_queues)
1459 : : return;
1460 : :
1461 : 0 : vc_qp->rxq.ring_len = rxq[q_idx]->nb_rx_desc;
1462 : 0 : vc_qp->rxq.dma_ring_addr = rxq[q_idx]->rx_ring_phys_addr;
1463 : 0 : vc_qp->rxq.databuffer_size = rxq[q_idx]->rx_buf_len;
1464 : 0 : vc_qp->rxq.crc_disable = rxq[q_idx]->crc_len != 0 ? 1 : 0;
1465 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC) {
1466 [ # # ]: 0 : if (vf->supported_rxdid & RTE_BIT64(rxq[q_idx]->rxdid)) {
1467 : 0 : vc_qp->rxq.rxdid = rxq[q_idx]->rxdid;
1468 : 0 : PMD_DRV_LOG(NOTICE, "request RXDID[%d] in Queue[%d]",
1469 : : vc_qp->rxq.rxdid, q_idx);
1470 : : } else {
1471 : 0 : PMD_DRV_LOG(NOTICE, "RXDID[%d] is not supported, "
1472 : : "request default RXDID[%d] in Queue[%d]",
1473 : : rxq[q_idx]->rxdid, IAVF_RXDID_LEGACY_1, q_idx);
1474 : 0 : vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_1;
1475 : : }
1476 : :
1477 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_PTP &&
1478 [ # # ]: 0 : vf->ptp_caps & VIRTCHNL_1588_PTP_CAP_RX_TSTAMP &&
1479 [ # # ]: 0 : rxq[q_idx]->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP)
1480 : 0 : vc_qp->rxq.flags |= VIRTCHNL_PTP_RX_TSTAMP;
1481 : : }
1482 : : }
1483 : :
1484 : : static int
1485 : 0 : iavf_configure_queue_chunk(struct iavf_adapter *adapter,
1486 : : uint16_t chunk_sz,
1487 : : uint16_t chunk_start)
1488 : : {
1489 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1490 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
1491 : : struct {
1492 : : struct virtchnl_vsi_queue_config_info config;
1493 : : struct virtchnl_queue_pair_info qp[IAVF_CFG_Q_NUM_PER_BUF];
1494 : 0 : } queue_req = {0};
1495 : 0 : struct iavf_cmd_info args = {0};
1496 : : struct virtchnl_vsi_queue_config_info *vc_config = &queue_req.config;
1497 : : struct virtchnl_queue_pair_info *vc_qp = vc_config->qpair;
1498 : 0 : uint16_t chunk_end = chunk_start + chunk_sz;
1499 : : uint16_t i;
1500 : : size_t buf_len;
1501 : : int err;
1502 : :
1503 [ # # ]: 0 : if (chunk_sz > IAVF_CFG_Q_NUM_PER_BUF)
1504 : : return -EINVAL;
1505 : :
1506 : 0 : vc_config->vsi_id = vf->vsi_res->vsi_id;
1507 : 0 : vc_config->num_queue_pairs = chunk_sz;
1508 : :
1509 [ # # ]: 0 : for (i = chunk_start; i < chunk_end; i++, vc_qp++)
1510 : 0 : iavf_configure_queue_pair(adapter, vc_qp, i);
1511 : :
1512 : : /* for some reason PF side checks for buffer being too big, so adjust it down */
1513 : 0 : buf_len = sizeof(struct virtchnl_vsi_queue_config_info) +
1514 : 0 : sizeof(struct virtchnl_queue_pair_info) * chunk_sz;
1515 : :
1516 : 0 : args.ops = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
1517 : 0 : args.in_args = (uint8_t *)vc_config;
1518 : 0 : args.in_args_size = buf_len;
1519 : 0 : args.out_buffer = msg_buf;
1520 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
1521 : :
1522 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
1523 [ # # ]: 0 : if (err)
1524 : 0 : PMD_DRV_LOG(ERR, "Failed to execute command VIRTCHNL_OP_CONFIG_VSI_QUEUES");
1525 : : return err;
1526 : : }
1527 : :
1528 : : int
1529 : 0 : iavf_configure_queues(struct iavf_adapter *adapter, uint16_t num_queue_pairs)
1530 : : {
1531 : : uint16_t c;
1532 : : int err;
1533 : :
1534 : : /*
1535 : : * we cannot configure all queues in one go because they won't fit into
1536 : : * adminq buffer, so we're going to chunk them instead
1537 : : */
1538 [ # # ]: 0 : for (c = 0; c < num_queue_pairs; c += IAVF_CFG_Q_NUM_PER_BUF) {
1539 : 0 : uint16_t chunk_sz = RTE_MIN(num_queue_pairs - c, IAVF_CFG_Q_NUM_PER_BUF);
1540 : 0 : err = iavf_configure_queue_chunk(adapter, chunk_sz, c);
1541 [ # # ]: 0 : if (err) {
1542 : 0 : PMD_DRV_LOG(ERR, "Failed to configure queues chunk [%u, %u)",
1543 : : c, c + chunk_sz);
1544 : 0 : return err;
1545 : : }
1546 : : }
1547 : : return 0;
1548 : : }
1549 : :
1550 : : int
1551 : 0 : iavf_config_irq_map(struct iavf_adapter *adapter)
1552 : : {
1553 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1554 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
1555 : : struct {
1556 : : struct virtchnl_irq_map_info map_info;
1557 : : struct virtchnl_vector_map vecmap[IAVF_MAX_NUM_QUEUES_DFLT];
1558 : 0 : } map_req = {0};
1559 : : struct virtchnl_irq_map_info *map_info = &map_req.map_info;
1560 : 0 : struct iavf_cmd_info args = {0};
1561 : : int i, err, max_vmi = -1;
1562 : : size_t buf_len;
1563 : :
1564 [ # # ]: 0 : if (adapter->dev_data->nb_rx_queues > IAVF_MAX_NUM_QUEUES_DFLT) {
1565 : 0 : PMD_DRV_LOG(ERR, "number of queues (%u) exceeds the max supported (%u)",
1566 : : adapter->dev_data->nb_rx_queues, IAVF_MAX_NUM_QUEUES_DFLT);
1567 : 0 : return -EINVAL;
1568 : : }
1569 : :
1570 [ # # ]: 0 : for (i = 0; i < adapter->dev_data->nb_rx_queues; i++) {
1571 : : struct virtchnl_vector_map *vecmap;
1572 : : /* always 0 for 1 MSIX, never bigger than rxq for multi MSIX */
1573 : 0 : uint16_t vmi = vf->qv_map[i].vector_id - vf->msix_base;
1574 : :
1575 : : /* can't happen but avoid static analysis warnings */
1576 [ # # ]: 0 : if (vmi >= IAVF_MAX_NUM_QUEUES_DFLT) {
1577 : 0 : PMD_DRV_LOG(ERR, "vector id (%u) exceeds the max supported (%u)",
1578 : : vf->qv_map[i].vector_id,
1579 : : vf->msix_base + IAVF_MAX_NUM_QUEUES_DFLT - 1);
1580 : 0 : return -EINVAL;
1581 : : }
1582 : :
1583 : 0 : vecmap = &map_info->vecmap[vmi];
1584 : 0 : vecmap->vsi_id = vf->vsi_res->vsi_id;
1585 : 0 : vecmap->rxitr_idx = IAVF_ITR_INDEX_DEFAULT;
1586 : 0 : vecmap->vector_id = vf->qv_map[i].vector_id;
1587 : 0 : vecmap->txq_map = 0;
1588 : 0 : vecmap->rxq_map |= 1 << vf->qv_map[i].queue_id;
1589 : :
1590 : : /* MSIX vectors round robin so look for max */
1591 [ # # ]: 0 : if (vmi > max_vmi) {
1592 : 0 : map_info->num_vectors++;
1593 : : max_vmi = vmi;
1594 : : }
1595 : : }
1596 : :
1597 : : /* for some reason PF side checks for buffer being too big, so adjust it down */
1598 : 0 : buf_len = sizeof(struct virtchnl_irq_map_info) +
1599 : 0 : sizeof(struct virtchnl_vector_map) * map_info->num_vectors;
1600 : :
1601 : 0 : args.ops = VIRTCHNL_OP_CONFIG_IRQ_MAP;
1602 : 0 : args.in_args = (u8 *)map_info;
1603 : 0 : args.in_args_size = buf_len;
1604 : 0 : args.out_buffer = msg_buf;
1605 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
1606 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
1607 [ # # ]: 0 : if (err)
1608 : 0 : PMD_DRV_LOG(ERR, "fail to execute command OP_CONFIG_IRQ_MAP");
1609 : :
1610 : : return err;
1611 : : }
1612 : :
1613 : : static int
1614 : 0 : iavf_config_irq_map_lv_chunk(struct iavf_adapter *adapter,
1615 : : uint16_t chunk_sz,
1616 : : uint16_t chunk_start)
1617 : : {
1618 : : struct {
1619 : : struct virtchnl_queue_vector_maps map_info;
1620 : : struct virtchnl_queue_vector qv_maps[IAVF_CFG_Q_NUM_PER_BUF];
1621 : 0 : } chunk_req = {0};
1622 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1623 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
1624 : 0 : struct iavf_cmd_info args = {0};
1625 : : struct virtchnl_queue_vector_maps *map_info = &chunk_req.map_info;
1626 : : struct virtchnl_queue_vector *qv_maps = chunk_req.qv_maps;
1627 : : size_t buf_len;
1628 : : uint16_t i;
1629 : :
1630 [ # # ]: 0 : if (chunk_sz > IAVF_CFG_Q_NUM_PER_BUF)
1631 : : return -EINVAL;
1632 : :
1633 : 0 : map_info->vport_id = vf->vsi_res->vsi_id;
1634 : 0 : map_info->num_qv_maps = chunk_sz;
1635 [ # # ]: 0 : for (i = 0; i < chunk_sz; i++) {
1636 : 0 : qv_maps = &map_info->qv_maps[i];
1637 : 0 : qv_maps->itr_idx = VIRTCHNL_ITR_IDX_0;
1638 : 0 : qv_maps->queue_type = VIRTCHNL_QUEUE_TYPE_RX;
1639 : 0 : qv_maps->queue_id = vf->qv_map[chunk_start + i].queue_id;
1640 : 0 : qv_maps->vector_id = vf->qv_map[chunk_start + i].vector_id;
1641 : : }
1642 : :
1643 : : /* for some reason PF side checks for buffer being too big, so adjust it down */
1644 : 0 : buf_len = sizeof(struct virtchnl_queue_vector_maps) +
1645 : 0 : sizeof(struct virtchnl_queue_vector) * (chunk_sz - 1);
1646 : :
1647 : 0 : args.ops = VIRTCHNL_OP_MAP_QUEUE_VECTOR;
1648 : 0 : args.in_args = (u8 *)map_info;
1649 : 0 : args.in_args_size = buf_len;
1650 : 0 : args.out_buffer = msg_buf;
1651 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
1652 : :
1653 : 0 : return iavf_execute_vf_cmd_safe(adapter, &args);
1654 : : }
1655 : :
1656 : : int
1657 : 0 : iavf_config_irq_map_lv(struct iavf_adapter *adapter, uint16_t num)
1658 : : {
1659 : : uint16_t c;
1660 : : int err;
1661 : :
1662 [ # # ]: 0 : for (c = 0; c < num; c += IAVF_CFG_Q_NUM_PER_BUF) {
1663 : 0 : uint16_t chunk_sz = RTE_MIN(num - c, IAVF_CFG_Q_NUM_PER_BUF);
1664 : 0 : err = iavf_config_irq_map_lv_chunk(adapter, chunk_sz, c);
1665 [ # # ]: 0 : if (err) {
1666 : 0 : PMD_DRV_LOG(ERR, "Failed to configure irq map chunk [%u, %u)",
1667 : : c, c + chunk_sz);
1668 : 0 : return err;
1669 : : }
1670 : : }
1671 : : return 0;
1672 : : }
1673 : :
1674 : : void
1675 : 0 : iavf_add_del_all_mac_addr(struct iavf_adapter *adapter, bool add)
1676 : : {
1677 : : struct {
1678 : : struct virtchnl_ether_addr_list list;
1679 : : struct virtchnl_ether_addr addr[IAVF_NUM_MACADDR_MAX];
1680 : 0 : } list_req = {0};
1681 : : struct virtchnl_ether_addr_list *list = &list_req.list;
1682 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1683 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
1684 : 0 : struct iavf_cmd_info args = {0};
1685 : : int err, i;
1686 : : size_t buf_len;
1687 : :
1688 [ # # ]: 0 : for (i = 0; i < IAVF_NUM_MACADDR_MAX; i++) {
1689 : 0 : struct rte_ether_addr *addr = &adapter->dev_data->mac_addrs[i];
1690 [ # # ]: 0 : struct virtchnl_ether_addr *vc_addr = &list->list[list->num_elements];
1691 : :
1692 : : /* ignore empty addresses */
1693 [ # # ]: 0 : if (rte_is_zero_ether_addr(addr))
1694 : 0 : continue;
1695 : 0 : list->num_elements++;
1696 : :
1697 [ # # ]: 0 : memcpy(vc_addr->addr, addr->addr_bytes, sizeof(addr->addr_bytes));
1698 [ # # ]: 0 : vc_addr->type = (list->num_elements == 1) ?
1699 : : VIRTCHNL_ETHER_ADDR_PRIMARY :
1700 : : VIRTCHNL_ETHER_ADDR_EXTRA;
1701 : : }
1702 : :
1703 : : /* for some reason PF side checks for buffer being too big, so adjust it down */
1704 : 0 : buf_len = sizeof(struct virtchnl_ether_addr_list) +
1705 : 0 : sizeof(struct virtchnl_ether_addr) * list->num_elements;
1706 : :
1707 : 0 : list->vsi_id = vf->vsi_res->vsi_id;
1708 [ # # ]: 0 : args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
1709 : 0 : args.in_args = (uint8_t *)list;
1710 : 0 : args.in_args_size = buf_len;
1711 : 0 : args.out_buffer = msg_buf;
1712 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
1713 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
1714 [ # # ]: 0 : if (err)
1715 [ # # ]: 0 : PMD_DRV_LOG(ERR, "fail to execute command %s",
1716 : : add ? "OP_ADD_ETHER_ADDRESS" : "OP_DEL_ETHER_ADDRESS");
1717 : 0 : }
1718 : :
1719 : : int
1720 : 0 : iavf_query_stats(struct iavf_adapter *adapter,
1721 : : struct virtchnl_eth_stats *pstats)
1722 : : {
1723 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1724 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
1725 : : struct virtchnl_queue_select q_stats;
1726 : : struct iavf_cmd_info args;
1727 : : int err;
1728 : :
1729 [ # # ]: 0 : if (adapter->closed)
1730 : : return -EIO;
1731 : :
1732 : : memset(&q_stats, 0, sizeof(q_stats));
1733 : 0 : q_stats.vsi_id = vf->vsi_res->vsi_id;
1734 : 0 : args.ops = VIRTCHNL_OP_GET_STATS;
1735 : 0 : args.in_args = (uint8_t *)&q_stats;
1736 : 0 : args.in_args_size = sizeof(q_stats);
1737 : 0 : args.out_buffer = msg_buf;
1738 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
1739 : :
1740 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
1741 [ # # ]: 0 : if (err) {
1742 : 0 : PMD_DRV_LOG(ERR, "fail to execute command OP_GET_STATS");
1743 : 0 : return err;
1744 : : }
1745 : 0 : *pstats = *(struct virtchnl_eth_stats *)args.out_buffer;
1746 : 0 : return 0;
1747 : : }
1748 : :
1749 : : int
1750 : 0 : iavf_config_promisc(struct iavf_adapter *adapter,
1751 : : bool enable_unicast,
1752 : : bool enable_multicast)
1753 : : {
1754 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1755 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
1756 : : struct virtchnl_promisc_info promisc;
1757 : : struct iavf_cmd_info args;
1758 : : int err;
1759 : :
1760 [ # # ]: 0 : if (adapter->closed)
1761 : : return -EIO;
1762 : :
1763 : 0 : promisc.flags = 0;
1764 : 0 : promisc.vsi_id = vf->vsi_res->vsi_id;
1765 : :
1766 [ # # ]: 0 : if (enable_unicast)
1767 : 0 : promisc.flags |= FLAG_VF_UNICAST_PROMISC;
1768 : :
1769 [ # # ]: 0 : if (enable_multicast)
1770 : 0 : promisc.flags |= FLAG_VF_MULTICAST_PROMISC;
1771 : :
1772 : 0 : args.ops = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
1773 : 0 : args.in_args = (uint8_t *)&promisc;
1774 : 0 : args.in_args_size = sizeof(promisc);
1775 : 0 : args.out_buffer = msg_buf;
1776 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
1777 : :
1778 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
1779 : :
1780 [ # # ]: 0 : if (err) {
1781 : 0 : PMD_DRV_LOG(ERR,
1782 : : "fail to execute command CONFIG_PROMISCUOUS_MODE");
1783 : :
1784 [ # # ]: 0 : if (err == -ENOTSUP)
1785 : : return err;
1786 : :
1787 : 0 : return -EAGAIN;
1788 : : }
1789 : :
1790 : 0 : vf->promisc_unicast_enabled = enable_unicast;
1791 : 0 : vf->promisc_multicast_enabled = enable_multicast;
1792 : 0 : return 0;
1793 : : }
1794 : :
1795 : : int
1796 : 0 : iavf_add_del_eth_addr(struct iavf_adapter *adapter, struct rte_ether_addr *addr,
1797 : : bool add, uint8_t type)
1798 : : {
1799 : : struct virtchnl_ether_addr_list *list;
1800 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1801 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
1802 : : uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
1803 : : sizeof(struct virtchnl_ether_addr)];
1804 : : struct iavf_cmd_info args;
1805 : : int err;
1806 : :
1807 [ # # ]: 0 : if (adapter->closed)
1808 : : return -EIO;
1809 : :
1810 : : list = (struct virtchnl_ether_addr_list *)cmd_buffer;
1811 : 0 : list->vsi_id = vf->vsi_res->vsi_id;
1812 : 0 : list->num_elements = 1;
1813 : 0 : list->list[0].type = type;
1814 : : memcpy(list->list[0].addr, addr->addr_bytes,
1815 : : sizeof(addr->addr_bytes));
1816 : :
1817 [ # # ]: 0 : args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
1818 : 0 : args.in_args = cmd_buffer;
1819 : 0 : args.in_args_size = sizeof(cmd_buffer);
1820 : 0 : args.out_buffer = msg_buf;
1821 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
1822 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
1823 [ # # ]: 0 : if (err)
1824 [ # # ]: 0 : PMD_DRV_LOG(ERR, "fail to execute command %s",
1825 : : add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");
1826 : : return err;
1827 : : }
1828 : :
1829 : : int
1830 : 0 : iavf_add_del_vlan(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
1831 : : {
1832 : : struct virtchnl_vlan_filter_list *vlan_list;
1833 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1834 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
1835 : : uint8_t cmd_buffer[sizeof(struct virtchnl_vlan_filter_list) +
1836 : : sizeof(uint16_t)];
1837 : : struct iavf_cmd_info args;
1838 : : int err;
1839 : :
1840 : : vlan_list = (struct virtchnl_vlan_filter_list *)cmd_buffer;
1841 : 0 : vlan_list->vsi_id = vf->vsi_res->vsi_id;
1842 : 0 : vlan_list->num_elements = 1;
1843 : 0 : vlan_list->vlan_id[0] = vlanid;
1844 : :
1845 [ # # ]: 0 : args.ops = add ? VIRTCHNL_OP_ADD_VLAN : VIRTCHNL_OP_DEL_VLAN;
1846 : 0 : args.in_args = cmd_buffer;
1847 : 0 : args.in_args_size = sizeof(cmd_buffer);
1848 : 0 : args.out_buffer = msg_buf;
1849 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
1850 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
1851 [ # # ]: 0 : if (err)
1852 [ # # ]: 0 : PMD_DRV_LOG(ERR, "fail to execute command %s",
1853 : : add ? "OP_ADD_VLAN" : "OP_DEL_VLAN");
1854 : :
1855 : 0 : return err;
1856 : : }
1857 : :
1858 : : int
1859 : 0 : iavf_fdir_add(struct iavf_adapter *adapter,
1860 : : struct iavf_fdir_conf *filter)
1861 : : {
1862 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1863 : : struct virtchnl_fdir_add *fdir_ret;
1864 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
1865 : : struct iavf_cmd_info args;
1866 : : int err;
1867 : :
1868 : 0 : filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
1869 : 0 : filter->add_fltr.validate_only = 0;
1870 : :
1871 : 0 : args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
1872 : 0 : args.in_args = (uint8_t *)(&filter->add_fltr);
1873 : 0 : args.in_args_size = sizeof(*(&filter->add_fltr));
1874 : 0 : args.out_buffer = msg_buf;
1875 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
1876 : :
1877 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
1878 [ # # ]: 0 : if (err) {
1879 : 0 : PMD_DRV_LOG(ERR, "fail to execute command OP_ADD_FDIR_FILTER");
1880 : 0 : return err;
1881 : : }
1882 : :
1883 : 0 : fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
1884 : 0 : filter->flow_id = fdir_ret->flow_id;
1885 : :
1886 [ # # ]: 0 : if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1887 : 0 : PMD_DRV_LOG(INFO,
1888 : : "Succeed in adding rule request by PF");
1889 : : } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE) {
1890 : 0 : PMD_DRV_LOG(ERR,
1891 : : "Failed to add rule request due to no hw resource");
1892 : 0 : return -1;
1893 : : } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_EXIST) {
1894 : 0 : PMD_DRV_LOG(ERR,
1895 : : "Failed to add rule request due to the rule is already existed");
1896 : 0 : return -1;
1897 : : } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT) {
1898 : 0 : PMD_DRV_LOG(ERR,
1899 : : "Failed to add rule request due to the rule is conflict with existing rule");
1900 : 0 : return -1;
1901 : : } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
1902 : 0 : PMD_DRV_LOG(ERR,
1903 : : "Failed to add rule request due to the hw doesn't support");
1904 : 0 : return -1;
1905 : : } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
1906 : 0 : PMD_DRV_LOG(ERR,
1907 : : "Failed to add rule request due to time out for programming");
1908 : 0 : return -1;
1909 : : } else {
1910 : 0 : PMD_DRV_LOG(ERR,
1911 : : "Failed to add rule request due to other reasons");
1912 : 0 : return -1;
1913 : : }
1914 : :
1915 : 0 : return 0;
1916 : : };
1917 : :
1918 : : int
1919 : 0 : iavf_fdir_del(struct iavf_adapter *adapter,
1920 : : struct iavf_fdir_conf *filter)
1921 : : {
1922 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1923 : : struct virtchnl_fdir_del *fdir_ret;
1924 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
1925 : : struct iavf_cmd_info args;
1926 : : int err;
1927 : :
1928 : 0 : filter->del_fltr.vsi_id = vf->vsi_res->vsi_id;
1929 : 0 : filter->del_fltr.flow_id = filter->flow_id;
1930 : :
1931 : 0 : args.ops = VIRTCHNL_OP_DEL_FDIR_FILTER;
1932 : 0 : args.in_args = (uint8_t *)(&filter->del_fltr);
1933 : 0 : args.in_args_size = sizeof(filter->del_fltr);
1934 : 0 : args.out_buffer = msg_buf;
1935 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
1936 : :
1937 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
1938 [ # # ]: 0 : if (err) {
1939 : 0 : PMD_DRV_LOG(ERR, "fail to execute command OP_DEL_FDIR_FILTER");
1940 : 0 : return err;
1941 : : }
1942 : :
1943 : 0 : fdir_ret = (struct virtchnl_fdir_del *)args.out_buffer;
1944 : :
1945 [ # # ]: 0 : if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1946 : 0 : PMD_DRV_LOG(INFO,
1947 : : "Succeed in deleting rule request by PF");
1948 [ # # ]: 0 : } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST) {
1949 : 0 : PMD_DRV_LOG(ERR,
1950 : : "Failed to delete rule request due to this rule doesn't exist");
1951 : 0 : return -1;
1952 [ # # ]: 0 : } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
1953 : 0 : PMD_DRV_LOG(ERR,
1954 : : "Failed to delete rule request due to time out for programming");
1955 : 0 : return -1;
1956 : : } else {
1957 : 0 : PMD_DRV_LOG(ERR,
1958 : : "Failed to delete rule request due to other reasons");
1959 : 0 : return -1;
1960 : : }
1961 : :
1962 : 0 : return 0;
1963 : : };
1964 : :
1965 : : int
1966 : 0 : iavf_fdir_check(struct iavf_adapter *adapter,
1967 : : struct iavf_fdir_conf *filter)
1968 : : {
1969 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1970 : : struct virtchnl_fdir_add *fdir_ret;
1971 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
1972 : : struct iavf_cmd_info args;
1973 : : int err;
1974 : :
1975 : 0 : filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
1976 : 0 : filter->add_fltr.validate_only = 1;
1977 : :
1978 : 0 : args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
1979 : 0 : args.in_args = (uint8_t *)(&filter->add_fltr);
1980 : 0 : args.in_args_size = sizeof(*(&filter->add_fltr));
1981 : 0 : args.out_buffer = msg_buf;
1982 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
1983 : :
1984 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
1985 [ # # ]: 0 : if (err) {
1986 : 0 : PMD_DRV_LOG(ERR, "fail to check flow director rule");
1987 : 0 : return err;
1988 : : }
1989 : :
1990 : 0 : fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
1991 : :
1992 [ # # ]: 0 : if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1993 : 0 : PMD_DRV_LOG(INFO,
1994 : : "Succeed in checking rule request by PF");
1995 [ # # ]: 0 : } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
1996 : 0 : PMD_DRV_LOG(ERR,
1997 : : "Failed to check rule request due to parameters validation"
1998 : : " or HW doesn't support");
1999 : : err = -1;
2000 : : } else {
2001 : 0 : PMD_DRV_LOG(ERR,
2002 : : "Failed to check rule request due to other reasons");
2003 : : err = -1;
2004 : : }
2005 : :
2006 : : return err;
2007 : : }
2008 : :
2009 : : int
2010 : 0 : iavf_flow_sub(struct iavf_adapter *adapter, struct iavf_fsub_conf *filter)
2011 : : {
2012 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
2013 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
2014 : : struct virtchnl_flow_sub *fsub_cfg;
2015 : : struct iavf_cmd_info args;
2016 : : int err;
2017 : :
2018 : 0 : filter->sub_fltr.vsi_id = vf->vsi_res->vsi_id;
2019 : 0 : filter->sub_fltr.validate_only = 0;
2020 : :
2021 : : memset(&args, 0, sizeof(args));
2022 : 0 : args.ops = VIRTCHNL_OP_FLOW_SUBSCRIBE;
2023 : 0 : args.in_args = (uint8_t *)(&filter->sub_fltr);
2024 : 0 : args.in_args_size = sizeof(*(&filter->sub_fltr));
2025 : 0 : args.out_buffer = msg_buf;
2026 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
2027 : :
2028 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
2029 [ # # ]: 0 : if (err) {
2030 : 0 : PMD_DRV_LOG(ERR, "Failed to execute command of "
2031 : : "OP_FLOW_SUBSCRIBE");
2032 : 0 : return err;
2033 : : }
2034 : :
2035 : 0 : fsub_cfg = (struct virtchnl_flow_sub *)args.out_buffer;
2036 : 0 : filter->flow_id = fsub_cfg->flow_id;
2037 : :
2038 [ # # ]: 0 : if (fsub_cfg->status == VIRTCHNL_FSUB_SUCCESS) {
2039 : 0 : PMD_DRV_LOG(INFO, "Succeed in adding rule request by PF");
2040 [ # # ]: 0 : } else if (fsub_cfg->status == VIRTCHNL_FSUB_FAILURE_RULE_NORESOURCE) {
2041 : 0 : PMD_DRV_LOG(ERR, "Failed to add rule request due to no hw "
2042 : : "resource");
2043 : : err = -1;
2044 [ # # ]: 0 : } else if (fsub_cfg->status == VIRTCHNL_FSUB_FAILURE_RULE_EXIST) {
2045 : 0 : PMD_DRV_LOG(ERR, "Failed to add rule request due to the rule "
2046 : : "is already existed");
2047 : : err = -1;
2048 [ # # ]: 0 : } else if (fsub_cfg->status == VIRTCHNL_FSUB_FAILURE_RULE_INVALID) {
2049 : 0 : PMD_DRV_LOG(ERR, "Failed to add rule request due to the hw "
2050 : : "doesn't support");
2051 : : err = -1;
2052 : : } else {
2053 : 0 : PMD_DRV_LOG(ERR, "Failed to add rule request due to other "
2054 : : "reasons");
2055 : : err = -1;
2056 : : }
2057 : :
2058 : : return err;
2059 : : }
2060 : :
2061 : : int
2062 : 0 : iavf_flow_unsub(struct iavf_adapter *adapter, struct iavf_fsub_conf *filter)
2063 : : {
2064 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
2065 : : struct virtchnl_flow_unsub *unsub_cfg;
2066 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
2067 : : struct iavf_cmd_info args;
2068 : : int err;
2069 : :
2070 : 0 : filter->unsub_fltr.vsi_id = vf->vsi_res->vsi_id;
2071 : 0 : filter->unsub_fltr.flow_id = filter->flow_id;
2072 : :
2073 : : memset(&args, 0, sizeof(args));
2074 : 0 : args.ops = VIRTCHNL_OP_FLOW_UNSUBSCRIBE;
2075 : 0 : args.in_args = (uint8_t *)(&filter->unsub_fltr);
2076 : 0 : args.in_args_size = sizeof(filter->unsub_fltr);
2077 : 0 : args.out_buffer = msg_buf;
2078 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
2079 : :
2080 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
2081 [ # # ]: 0 : if (err) {
2082 : 0 : PMD_DRV_LOG(ERR, "Failed to execute command of "
2083 : : "OP_FLOW_UNSUBSCRIBE");
2084 : 0 : return err;
2085 : : }
2086 : :
2087 : 0 : unsub_cfg = (struct virtchnl_flow_unsub *)args.out_buffer;
2088 : :
2089 [ # # ]: 0 : if (unsub_cfg->status == VIRTCHNL_FSUB_SUCCESS) {
2090 : 0 : PMD_DRV_LOG(INFO, "Succeed in deleting rule request by PF");
2091 [ # # ]: 0 : } else if (unsub_cfg->status == VIRTCHNL_FSUB_FAILURE_RULE_NONEXIST) {
2092 : 0 : PMD_DRV_LOG(ERR, "Failed to delete rule request due to this "
2093 : : "rule doesn't exist");
2094 : : err = -1;
2095 : : } else {
2096 : 0 : PMD_DRV_LOG(ERR, "Failed to delete rule request due to other "
2097 : : "reasons");
2098 : : err = -1;
2099 : : }
2100 : :
2101 : : return err;
2102 : : }
2103 : :
2104 : : int
2105 : 0 : iavf_flow_sub_check(struct iavf_adapter *adapter,
2106 : : struct iavf_fsub_conf *filter)
2107 : : {
2108 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
2109 : : struct virtchnl_flow_sub *fsub_cfg;
2110 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
2111 : : struct iavf_cmd_info args;
2112 : : int err;
2113 : :
2114 : 0 : filter->sub_fltr.vsi_id = vf->vsi_res->vsi_id;
2115 : 0 : filter->sub_fltr.validate_only = 1;
2116 : :
2117 : 0 : args.ops = VIRTCHNL_OP_FLOW_SUBSCRIBE;
2118 : 0 : args.in_args = (uint8_t *)(&filter->sub_fltr);
2119 : 0 : args.in_args_size = sizeof(*(&filter->sub_fltr));
2120 : 0 : args.out_buffer = msg_buf;
2121 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
2122 : :
2123 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
2124 [ # # ]: 0 : if (err) {
2125 : 0 : PMD_DRV_LOG(ERR, "Failed to check flow subscription rule");
2126 : 0 : return err;
2127 : : }
2128 : :
2129 : 0 : fsub_cfg = (struct virtchnl_flow_sub *)args.out_buffer;
2130 : :
2131 [ # # ]: 0 : if (fsub_cfg->status == VIRTCHNL_FSUB_SUCCESS) {
2132 : 0 : PMD_DRV_LOG(INFO, "Succeed in checking rule request by PF");
2133 [ # # ]: 0 : } else if (fsub_cfg->status == VIRTCHNL_FSUB_FAILURE_RULE_INVALID) {
2134 : 0 : PMD_DRV_LOG(ERR, "Failed to check rule request due to "
2135 : : "parameters validation or HW doesn't "
2136 : : "support");
2137 : : err = -1;
2138 : : } else {
2139 : 0 : PMD_DRV_LOG(ERR, "Failed to check rule request due to other "
2140 : : "reasons");
2141 : : err = -1;
2142 : : }
2143 : :
2144 : : return err;
2145 : : }
2146 : :
2147 : : int
2148 : 0 : iavf_add_del_rss_cfg(struct iavf_adapter *adapter,
2149 : : struct virtchnl_rss_cfg *rss_cfg, bool add)
2150 : : {
2151 [ # # ]: 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
2152 : : struct iavf_cmd_info args;
2153 : : int err;
2154 : :
2155 : : memset(&args, 0, sizeof(args));
2156 [ # # ]: 0 : args.ops = add ? VIRTCHNL_OP_ADD_RSS_CFG :
2157 : : VIRTCHNL_OP_DEL_RSS_CFG;
2158 : 0 : args.in_args = (u8 *)rss_cfg;
2159 : 0 : args.in_args_size = sizeof(*rss_cfg);
2160 : 0 : args.out_buffer = msg_buf;
2161 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
2162 : :
2163 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
2164 [ # # ]: 0 : if (err)
2165 [ # # ]: 0 : PMD_DRV_LOG(ERR,
2166 : : "Failed to execute command of %s",
2167 : : add ? "OP_ADD_RSS_CFG" :
2168 : : "OP_DEL_RSS_INPUT_CFG");
2169 : :
2170 : 0 : return err;
2171 : : }
2172 : :
2173 : : int
2174 : 0 : iavf_get_hena_caps(struct iavf_adapter *adapter, uint64_t *caps)
2175 : : {
2176 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
2177 : : struct virtchnl_rss_hena *hena;
2178 : : struct iavf_cmd_info args;
2179 : : int err;
2180 : :
2181 : 0 : args.ops = VIRTCHNL_OP_GET_RSS_HENA_CAPS;
2182 : 0 : args.in_args = NULL;
2183 : 0 : args.in_args_size = 0;
2184 : 0 : args.out_buffer = msg_buf;
2185 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
2186 : :
2187 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
2188 [ # # ]: 0 : if (err) {
2189 : 0 : PMD_DRV_LOG(ERR,
2190 : : "Failed to execute command of OP_GET_RSS_HENA_CAPS");
2191 : 0 : return err;
2192 : : }
2193 : :
2194 : 0 : hena = (struct virtchnl_rss_hena *)args.out_buffer;
2195 : 0 : *caps = hena->hena;
2196 : 0 : return 0;
2197 : : }
2198 : :
2199 : : int
2200 : 0 : iavf_set_hena(struct iavf_adapter *adapter, uint64_t hena)
2201 : : {
2202 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
2203 : : struct virtchnl_rss_hena vrh;
2204 : : struct iavf_cmd_info args;
2205 : : int err;
2206 : :
2207 : 0 : vrh.hena = hena;
2208 : 0 : args.ops = VIRTCHNL_OP_SET_RSS_HENA;
2209 : 0 : args.in_args = (u8 *)&vrh;
2210 : 0 : args.in_args_size = sizeof(vrh);
2211 : 0 : args.out_buffer = msg_buf;
2212 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
2213 : :
2214 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
2215 [ # # ]: 0 : if (err)
2216 : 0 : PMD_DRV_LOG(ERR,
2217 : : "Failed to execute command of OP_SET_RSS_HENA");
2218 : :
2219 : 0 : return err;
2220 : : }
2221 : :
2222 : : int
2223 : 0 : iavf_get_qos_cap(struct iavf_adapter *adapter)
2224 : : {
2225 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
2226 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
2227 : : struct iavf_cmd_info args;
2228 : : uint32_t len;
2229 : : int err;
2230 : :
2231 : 0 : args.ops = VIRTCHNL_OP_GET_QOS_CAPS;
2232 : 0 : args.in_args = NULL;
2233 : 0 : args.in_args_size = 0;
2234 : 0 : args.out_buffer = msg_buf;
2235 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
2236 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
2237 : :
2238 [ # # ]: 0 : if (err) {
2239 : 0 : PMD_DRV_LOG(ERR,
2240 : : "Failed to execute command of OP_GET_VF_RESOURCE");
2241 : 0 : return -1;
2242 : : }
2243 : :
2244 : : len = sizeof(struct virtchnl_qos_cap_list) +
2245 : : IAVF_MAX_TRAFFIC_CLASS * sizeof(struct virtchnl_qos_cap_elem);
2246 : :
2247 : 0 : memcpy(vf->qos_cap, args.out_buffer,
2248 : 0 : RTE_MIN(args.out_size, len));
2249 : :
2250 : 0 : return 0;
2251 : : }
2252 : :
2253 : 0 : int iavf_set_q_tc_map(struct rte_eth_dev *dev,
2254 : : struct virtchnl_queue_tc_mapping *q_tc_mapping, uint16_t size)
2255 : : {
2256 : 0 : struct iavf_adapter *adapter =
2257 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2258 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
2259 : : struct iavf_cmd_info args;
2260 : : int err;
2261 : :
2262 : : memset(&args, 0, sizeof(args));
2263 : 0 : args.ops = VIRTCHNL_OP_CONFIG_QUEUE_TC_MAP;
2264 : 0 : args.in_args = (uint8_t *)q_tc_mapping;
2265 : 0 : args.in_args_size = size;
2266 : 0 : args.out_buffer = msg_buf;
2267 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
2268 : :
2269 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
2270 [ # # ]: 0 : if (err)
2271 : 0 : PMD_DRV_LOG(ERR, "Failed to execute command of"
2272 : : " VIRTCHNL_OP_CONFIG_TC_MAP");
2273 : 0 : return err;
2274 : : }
2275 : :
2276 : 0 : int iavf_set_q_bw(struct rte_eth_dev *dev,
2277 : : struct virtchnl_queues_bw_cfg *q_bw, uint16_t size)
2278 : : {
2279 : 0 : struct iavf_adapter *adapter =
2280 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2281 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
2282 : : struct iavf_cmd_info args;
2283 : : int err;
2284 : :
2285 : : memset(&args, 0, sizeof(args));
2286 : 0 : args.ops = VIRTCHNL_OP_CONFIG_QUEUE_BW;
2287 : 0 : args.in_args = (uint8_t *)q_bw;
2288 : 0 : args.in_args_size = size;
2289 : 0 : args.out_buffer = msg_buf;
2290 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
2291 : :
2292 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
2293 [ # # ]: 0 : if (err)
2294 : 0 : PMD_DRV_LOG(ERR, "Failed to execute command of"
2295 : : " VIRTCHNL_OP_CONFIG_QUEUE_BW");
2296 : 0 : return err;
2297 : : }
2298 : :
2299 : : int
2300 : 0 : iavf_add_del_mc_addr_list(struct iavf_adapter *adapter,
2301 : : struct rte_ether_addr *mc_addrs,
2302 : : uint32_t mc_addrs_num, bool add)
2303 : : {
2304 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
2305 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
2306 : : uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
2307 : : (IAVF_NUM_MACADDR_MAX * sizeof(struct virtchnl_ether_addr))];
2308 : : struct virtchnl_ether_addr_list *list;
2309 : : struct iavf_cmd_info args;
2310 : : uint32_t i;
2311 : : int err;
2312 : :
2313 [ # # ]: 0 : if (mc_addrs == NULL || mc_addrs_num == 0)
2314 : : return 0;
2315 : :
2316 : : list = (struct virtchnl_ether_addr_list *)cmd_buffer;
2317 : 0 : list->vsi_id = vf->vsi_res->vsi_id;
2318 : 0 : list->num_elements = mc_addrs_num;
2319 : :
2320 [ # # ]: 0 : for (i = 0; i < mc_addrs_num; i++) {
2321 [ # # ]: 0 : if (!IAVF_IS_MULTICAST(mc_addrs[i].addr_bytes)) {
2322 : 0 : PMD_DRV_LOG(ERR, "Invalid mac:" RTE_ETHER_ADDR_PRT_FMT,
2323 : : RTE_ETHER_ADDR_BYTES(&mc_addrs[i]));
2324 : 0 : return -EINVAL;
2325 : : }
2326 : :
2327 : 0 : memcpy(list->list[i].addr, mc_addrs[i].addr_bytes,
2328 : : sizeof(list->list[i].addr));
2329 : 0 : list->list[i].type = VIRTCHNL_ETHER_ADDR_EXTRA;
2330 : : }
2331 : :
2332 [ # # ]: 0 : args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
2333 : 0 : args.in_args = cmd_buffer;
2334 : 0 : args.in_args_size = sizeof(struct virtchnl_ether_addr_list) +
2335 : 0 : i * sizeof(struct virtchnl_ether_addr);
2336 : 0 : args.out_buffer = msg_buf;
2337 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
2338 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
2339 : :
2340 [ # # ]: 0 : if (err) {
2341 [ # # ]: 0 : PMD_DRV_LOG(ERR, "fail to execute command %s",
2342 : : add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");
2343 : 0 : return err;
2344 : : }
2345 : :
2346 : : return 0;
2347 : : }
2348 : :
2349 : : int
2350 : 0 : iavf_request_queues(struct rte_eth_dev *dev, uint16_t num)
2351 : : {
2352 : 0 : struct iavf_adapter *adapter =
2353 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2354 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
2355 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
2356 : : struct virtchnl_vf_res_request vfres;
2357 : : struct iavf_cmd_info args;
2358 : : uint16_t num_queue_pairs;
2359 : : int err;
2360 : : int i = 0;
2361 : :
2362 [ # # ]: 0 : if (!(vf->vf_res->vf_cap_flags &
2363 : : VIRTCHNL_VF_OFFLOAD_REQ_QUEUES)) {
2364 : 0 : PMD_DRV_LOG(ERR, "request queues not supported");
2365 : 0 : return -1;
2366 : : }
2367 : :
2368 [ # # ]: 0 : if (num == 0) {
2369 : 0 : PMD_DRV_LOG(ERR, "queue number cannot be zero");
2370 : 0 : return -1;
2371 : : }
2372 : 0 : vfres.num_queue_pairs = num;
2373 : :
2374 : 0 : args.ops = VIRTCHNL_OP_REQUEST_QUEUES;
2375 : 0 : args.in_args = (u8 *)&vfres;
2376 : 0 : args.in_args_size = sizeof(vfres);
2377 : 0 : args.out_buffer = msg_buf;
2378 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
2379 : :
2380 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) {
2381 : 0 : iavf_phc_sync_alarm_stop(dev);
2382 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
2383 : 0 : iavf_phc_sync_alarm_start(dev);
2384 : : } else {
2385 : 0 : iavf_phc_sync_alarm_stop(dev);
2386 : 0 : rte_eal_alarm_cancel(iavf_dev_alarm_handler, dev);
2387 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
2388 : 0 : rte_eal_alarm_set(IAVF_ALARM_INTERVAL,
2389 : : iavf_dev_alarm_handler, dev);
2390 : 0 : iavf_phc_sync_alarm_start(dev);
2391 : : }
2392 : :
2393 [ # # ]: 0 : if (err) {
2394 : 0 : PMD_DRV_LOG(ERR, "fail to execute command OP_REQUEST_QUEUES");
2395 : 0 : return err;
2396 : : }
2397 : :
2398 : : /* wait for interrupt notification vf is resetting */
2399 [ # # ]: 0 : while (i++ < MAX_TRY_TIMES) {
2400 [ # # ]: 0 : if (vf->vf_reset)
2401 : : break;
2402 : 0 : iavf_msec_delay(ASQ_DELAY_MS);
2403 : : }
2404 : :
2405 : : /* request queues succeeded, vf is resetting */
2406 [ # # ]: 0 : if (vf->vf_reset) {
2407 : 0 : PMD_DRV_LOG(INFO, "vf is resetting");
2408 : 0 : return 0;
2409 : : }
2410 : :
2411 : : /* request additional queues failed, return available number */
2412 : 0 : num_queue_pairs =
2413 : 0 : ((struct virtchnl_vf_res_request *)args.out_buffer)->num_queue_pairs;
2414 : 0 : PMD_DRV_LOG(ERR, "request queues failed, only %u queues "
2415 : : "available", num_queue_pairs);
2416 : :
2417 : 0 : return -1;
2418 : : }
2419 : :
2420 : : int
2421 : 0 : iavf_get_max_rss_queue_region(struct iavf_adapter *adapter)
2422 : : {
2423 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
2424 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
2425 : : struct iavf_cmd_info args;
2426 : : uint16_t qregion_width;
2427 : : int err;
2428 : :
2429 : 0 : args.ops = VIRTCHNL_OP_GET_MAX_RSS_QREGION;
2430 : 0 : args.in_args = NULL;
2431 : 0 : args.in_args_size = 0;
2432 : 0 : args.out_buffer = msg_buf;
2433 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
2434 : :
2435 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
2436 [ # # ]: 0 : if (err) {
2437 : 0 : PMD_DRV_LOG(ERR, "Failed to execute command of VIRTCHNL_OP_GET_MAX_RSS_QREGION");
2438 : 0 : return err;
2439 : : }
2440 : :
2441 : 0 : qregion_width =
2442 : 0 : ((struct virtchnl_max_rss_qregion *)args.out_buffer)->qregion_width;
2443 : :
2444 : 0 : vf->max_rss_qregion = (uint16_t)(1 << qregion_width);
2445 : :
2446 : 0 : return 0;
2447 : : }
2448 : :
2449 : :
2450 : :
2451 : : int
2452 : 0 : iavf_ipsec_crypto_request(struct iavf_adapter *adapter,
2453 : : uint8_t *msg, size_t msg_len,
2454 : : uint8_t *resp_msg, size_t resp_msg_len)
2455 : : {
2456 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
2457 : : struct iavf_cmd_info args;
2458 : : int err;
2459 : :
2460 : 0 : args.ops = VIRTCHNL_OP_INLINE_IPSEC_CRYPTO;
2461 : 0 : args.in_args = msg;
2462 : 0 : args.in_args_size = msg_len;
2463 : 0 : args.out_buffer = msg_buf;
2464 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
2465 : :
2466 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
2467 [ # # ]: 0 : if (err) {
2468 : 0 : PMD_DRV_LOG(ERR, "fail to execute command %s",
2469 : : "OP_INLINE_IPSEC_CRYPTO");
2470 : 0 : return err;
2471 : : }
2472 : :
2473 : 0 : memcpy(resp_msg, args.out_buffer, resp_msg_len);
2474 : :
2475 : 0 : return 0;
2476 : : }
2477 : :
2478 : : int
2479 : 0 : iavf_set_vf_quanta_size(struct iavf_adapter *adapter, u16 start_queue_id, u16 num_queues)
2480 : : {
2481 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
2482 : : struct iavf_cmd_info args;
2483 : : struct virtchnl_quanta_cfg q_quanta;
2484 : : int err;
2485 : :
2486 [ # # ]: 0 : if (adapter->devargs.quanta_size == 0)
2487 : : return 0;
2488 : :
2489 : 0 : q_quanta.quanta_size = adapter->devargs.quanta_size;
2490 : 0 : q_quanta.queue_select.type = VIRTCHNL_QUEUE_TYPE_TX;
2491 : 0 : q_quanta.queue_select.start_queue_id = start_queue_id;
2492 : 0 : q_quanta.queue_select.num_queues = num_queues;
2493 : :
2494 : 0 : args.ops = VIRTCHNL_OP_CONFIG_QUANTA;
2495 : 0 : args.in_args = (uint8_t *)&q_quanta;
2496 : 0 : args.in_args_size = sizeof(q_quanta);
2497 : 0 : args.out_buffer = msg_buf;
2498 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
2499 : :
2500 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
2501 [ # # ]: 0 : if (err) {
2502 : 0 : PMD_DRV_LOG(ERR, "Failed to execute command VIRTCHNL_OP_CONFIG_QUANTA");
2503 : 0 : return err;
2504 : : }
2505 : :
2506 : : return 0;
2507 : : }
2508 : :
2509 : : int
2510 : 0 : iavf_get_ptp_cap(struct iavf_adapter *adapter)
2511 : : {
2512 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
2513 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
2514 : : struct virtchnl_ptp_caps ptp_caps;
2515 : : struct iavf_cmd_info args;
2516 : : int err;
2517 : :
2518 : 0 : ptp_caps.caps = VIRTCHNL_1588_PTP_CAP_RX_TSTAMP |
2519 : : VIRTCHNL_1588_PTP_CAP_READ_PHC;
2520 : :
2521 : 0 : args.ops = VIRTCHNL_OP_1588_PTP_GET_CAPS;
2522 : 0 : args.in_args = (uint8_t *)&ptp_caps;
2523 : 0 : args.in_args_size = sizeof(ptp_caps);
2524 : 0 : args.out_buffer = msg_buf;
2525 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
2526 : :
2527 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
2528 [ # # ]: 0 : if (err) {
2529 : 0 : PMD_DRV_LOG(ERR,
2530 : : "Failed to execute command of OP_1588_PTP_GET_CAPS");
2531 : 0 : return err;
2532 : : }
2533 : :
2534 : 0 : vf->ptp_caps = ((struct virtchnl_ptp_caps *)args.out_buffer)->caps;
2535 : :
2536 : 0 : return 0;
2537 : : }
2538 : :
2539 : : int
2540 : 0 : iavf_phc_get_time(struct iavf_adapter *adapter, uint64_t *time)
2541 : : {
2542 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
2543 : 0 : uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
2544 : : struct virtchnl_phc_time phc_time;
2545 : : struct iavf_cmd_info args;
2546 : : int err = 0;
2547 : :
2548 : 0 : args.ops = VIRTCHNL_OP_1588_PTP_GET_TIME;
2549 : 0 : args.in_args = (uint8_t *)&phc_time;
2550 : 0 : args.in_args_size = sizeof(phc_time);
2551 : 0 : args.out_buffer = msg_buf;
2552 : 0 : args.out_size = IAVF_AQ_BUF_SZ;
2553 : :
2554 : 0 : rte_spinlock_lock(&vf->phc_time_aq_lock);
2555 : 0 : err = iavf_execute_vf_cmd_safe(adapter, &args);
2556 [ # # ]: 0 : if (err) {
2557 : 0 : PMD_DRV_LOG(ERR,
2558 : : "Failed to execute command of VIRTCHNL_OP_1588_PTP_GET_TIME");
2559 : 0 : goto out;
2560 : : }
2561 : 0 : *time = ((struct virtchnl_phc_time *)args.out_buffer)->time;
2562 : :
2563 : 0 : out:
2564 : : rte_spinlock_unlock(&vf->phc_time_aq_lock);
2565 : 0 : return err;
2566 : : }
2567 : :
2568 : : int
2569 : 0 : iavf_get_phc_time(struct ci_rx_queue *rxq)
2570 : : {
2571 : 0 : struct iavf_adapter *adapter = rxq->iavf_vsi->adapter;
2572 : :
2573 : 0 : return iavf_phc_get_time(adapter, &rxq->phc_time);
2574 : : }
|