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