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