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