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