]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/dpdk/drivers/net/iavf/iavf_vchnl.c
import 15.2.0 Octopus source
[ceph.git] / ceph / src / spdk / dpdk / drivers / net / iavf / iavf_vchnl.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
3 */
4
5 #include <stdio.h>
6 #include <errno.h>
7 #include <stdint.h>
8 #include <string.h>
9 #include <unistd.h>
10 #include <stdarg.h>
11 #include <inttypes.h>
12 #include <rte_byteorder.h>
13 #include <rte_common.h>
14
15 #include <rte_debug.h>
16 #include <rte_atomic.h>
17 #include <rte_eal.h>
18 #include <rte_ether.h>
19 #include <rte_ethdev_driver.h>
20 #include <rte_dev.h>
21
22 #include "iavf_log.h"
23 #include "base/iavf_prototype.h"
24 #include "base/iavf_adminq_cmd.h"
25 #include "base/iavf_type.h"
26
27 #include "iavf.h"
28 #include "iavf_rxtx.h"
29
30 #define MAX_TRY_TIMES 200
31 #define ASQ_DELAY_MS 10
32
33 /* Read data in admin queue to get msg from pf driver */
34 static enum iavf_status_code
35 iavf_read_msg_from_pf(struct iavf_adapter *adapter, uint16_t buf_len,
36 uint8_t *buf)
37 {
38 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
39 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
40 struct iavf_arq_event_info event;
41 enum virtchnl_ops opcode;
42 int ret;
43
44 event.buf_len = buf_len;
45 event.msg_buf = buf;
46 ret = iavf_clean_arq_element(hw, &event, NULL);
47 /* Can't read any msg from adminQ */
48 if (ret) {
49 PMD_DRV_LOG(DEBUG, "Can't read msg from AQ");
50 return ret;
51 }
52
53 opcode = (enum virtchnl_ops)rte_le_to_cpu_32(event.desc.cookie_high);
54 vf->cmd_retval = (enum virtchnl_status_code)rte_le_to_cpu_32(
55 event.desc.cookie_low);
56
57 PMD_DRV_LOG(DEBUG, "AQ from pf carries opcode %u, retval %d",
58 opcode, vf->cmd_retval);
59
60 if (opcode != vf->pend_cmd)
61 PMD_DRV_LOG(WARNING, "command mismatch, expect %u, get %u",
62 vf->pend_cmd, opcode);
63
64 return IAVF_SUCCESS;
65 }
66
67 static int
68 iavf_execute_vf_cmd(struct iavf_adapter *adapter, struct iavf_cmd_info *args)
69 {
70 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
71 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
72 enum iavf_status_code ret;
73 int err = 0;
74 int i = 0;
75
76 if (_atomic_set_cmd(vf, args->ops))
77 return -1;
78
79 ret = iavf_aq_send_msg_to_pf(hw, args->ops, IAVF_SUCCESS,
80 args->in_args, args->in_args_size, NULL);
81 if (ret) {
82 PMD_DRV_LOG(ERR, "fail to send cmd %d", args->ops);
83 _clear_cmd(vf);
84 return err;
85 }
86
87 switch (args->ops) {
88 case VIRTCHNL_OP_RESET_VF:
89 /*no need to wait for response */
90 _clear_cmd(vf);
91 break;
92 case VIRTCHNL_OP_VERSION:
93 case VIRTCHNL_OP_GET_VF_RESOURCES:
94 /* for init virtchnl ops, need to poll the response */
95 do {
96 ret = iavf_read_msg_from_pf(adapter, args->out_size,
97 args->out_buffer);
98 if (ret == IAVF_SUCCESS)
99 break;
100 rte_delay_ms(ASQ_DELAY_MS);
101 } while (i++ < MAX_TRY_TIMES);
102 if (i >= MAX_TRY_TIMES ||
103 vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
104 err = -1;
105 PMD_DRV_LOG(ERR, "No response or return failure (%d)"
106 " for cmd %d", vf->cmd_retval, args->ops);
107 }
108 _clear_cmd(vf);
109 break;
110
111 default:
112 /* For other virtchnl ops in running time,
113 * wait for the cmd done flag.
114 */
115 do {
116 if (vf->pend_cmd == VIRTCHNL_OP_UNKNOWN)
117 break;
118 rte_delay_ms(ASQ_DELAY_MS);
119 /* If don't read msg or read sys event, continue */
120 } while (i++ < MAX_TRY_TIMES);
121 /* If there's no response is received, clear command */
122 if (i >= MAX_TRY_TIMES ||
123 vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
124 err = -1;
125 PMD_DRV_LOG(ERR, "No response or return failure (%d)"
126 " for cmd %d", vf->cmd_retval, args->ops);
127 _clear_cmd(vf);
128 }
129 break;
130 }
131
132 return err;
133 }
134
135 static void
136 iavf_handle_pf_event_msg(struct rte_eth_dev *dev, uint8_t *msg,
137 uint16_t msglen)
138 {
139 struct virtchnl_pf_event *pf_msg =
140 (struct virtchnl_pf_event *)msg;
141 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
142
143 if (msglen < sizeof(struct virtchnl_pf_event)) {
144 PMD_DRV_LOG(DEBUG, "Error event");
145 return;
146 }
147 switch (pf_msg->event) {
148 case VIRTCHNL_EVENT_RESET_IMPENDING:
149 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_RESET_IMPENDING event");
150 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET,
151 NULL);
152 break;
153 case VIRTCHNL_EVENT_LINK_CHANGE:
154 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_LINK_CHANGE event");
155 vf->link_up = pf_msg->event_data.link_event.link_status;
156 vf->link_speed = pf_msg->event_data.link_event_adv.link_speed;
157 iavf_dev_link_update(dev, 0);
158 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC,
159 NULL);
160 break;
161 case VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
162 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_PF_DRIVER_CLOSE event");
163 break;
164 default:
165 PMD_DRV_LOG(ERR, " unknown event received %u", pf_msg->event);
166 break;
167 }
168 }
169
170 void
171 iavf_handle_virtchnl_msg(struct rte_eth_dev *dev)
172 {
173 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
174 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
175 struct iavf_arq_event_info info;
176 uint16_t pending, aq_opc;
177 enum virtchnl_ops msg_opc;
178 enum iavf_status_code msg_ret;
179 int ret;
180
181 info.buf_len = IAVF_AQ_BUF_SZ;
182 if (!vf->aq_resp) {
183 PMD_DRV_LOG(ERR, "Buffer for adminq resp should not be NULL");
184 return;
185 }
186 info.msg_buf = vf->aq_resp;
187
188 pending = 1;
189 while (pending) {
190 ret = iavf_clean_arq_element(hw, &info, &pending);
191
192 if (ret != IAVF_SUCCESS) {
193 PMD_DRV_LOG(INFO, "Failed to read msg from AdminQ,"
194 "ret: %d", ret);
195 break;
196 }
197 aq_opc = rte_le_to_cpu_16(info.desc.opcode);
198 /* For the message sent from pf to vf, opcode is stored in
199 * cookie_high of struct iavf_aq_desc, while return error code
200 * are stored in cookie_low, Which is done by PF driver.
201 */
202 msg_opc = (enum virtchnl_ops)rte_le_to_cpu_32(
203 info.desc.cookie_high);
204 msg_ret = (enum iavf_status_code)rte_le_to_cpu_32(
205 info.desc.cookie_low);
206 switch (aq_opc) {
207 case iavf_aqc_opc_send_msg_to_vf:
208 if (msg_opc == VIRTCHNL_OP_EVENT) {
209 iavf_handle_pf_event_msg(dev, info.msg_buf,
210 info.msg_len);
211 } else {
212 /* read message and it's expected one */
213 if (msg_opc == vf->pend_cmd) {
214 vf->cmd_retval = msg_ret;
215 /* prevent compiler reordering */
216 rte_compiler_barrier();
217 _clear_cmd(vf);
218 } else
219 PMD_DRV_LOG(ERR, "command mismatch,"
220 "expect %u, get %u",
221 vf->pend_cmd, msg_opc);
222 PMD_DRV_LOG(DEBUG,
223 "adminq response is received,"
224 " opcode = %d", msg_opc);
225 }
226 break;
227 default:
228 PMD_DRV_LOG(ERR, "Request %u is not supported yet",
229 aq_opc);
230 break;
231 }
232 }
233 }
234
235 int
236 iavf_enable_vlan_strip(struct iavf_adapter *adapter)
237 {
238 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
239 struct iavf_cmd_info args;
240 int ret;
241
242 memset(&args, 0, sizeof(args));
243 args.ops = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
244 args.in_args = NULL;
245 args.in_args_size = 0;
246 args.out_buffer = vf->aq_resp;
247 args.out_size = IAVF_AQ_BUF_SZ;
248 ret = iavf_execute_vf_cmd(adapter, &args);
249 if (ret)
250 PMD_DRV_LOG(ERR, "Failed to execute command of"
251 " OP_ENABLE_VLAN_STRIPPING");
252
253 return ret;
254 }
255
256 int
257 iavf_disable_vlan_strip(struct iavf_adapter *adapter)
258 {
259 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
260 struct iavf_cmd_info args;
261 int ret;
262
263 memset(&args, 0, sizeof(args));
264 args.ops = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
265 args.in_args = NULL;
266 args.in_args_size = 0;
267 args.out_buffer = vf->aq_resp;
268 args.out_size = IAVF_AQ_BUF_SZ;
269 ret = iavf_execute_vf_cmd(adapter, &args);
270 if (ret)
271 PMD_DRV_LOG(ERR, "Failed to execute command of"
272 " OP_DISABLE_VLAN_STRIPPING");
273
274 return ret;
275 }
276
277 #define VIRTCHNL_VERSION_MAJOR_START 1
278 #define VIRTCHNL_VERSION_MINOR_START 1
279
280 /* Check API version with sync wait until version read from admin queue */
281 int
282 iavf_check_api_version(struct iavf_adapter *adapter)
283 {
284 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
285 struct virtchnl_version_info version, *pver;
286 struct iavf_cmd_info args;
287 int err;
288
289 version.major = VIRTCHNL_VERSION_MAJOR;
290 version.minor = VIRTCHNL_VERSION_MINOR;
291
292 args.ops = VIRTCHNL_OP_VERSION;
293 args.in_args = (uint8_t *)&version;
294 args.in_args_size = sizeof(version);
295 args.out_buffer = vf->aq_resp;
296 args.out_size = IAVF_AQ_BUF_SZ;
297
298 err = iavf_execute_vf_cmd(adapter, &args);
299 if (err) {
300 PMD_INIT_LOG(ERR, "Fail to execute command of OP_VERSION");
301 return err;
302 }
303
304 pver = (struct virtchnl_version_info *)args.out_buffer;
305 vf->virtchnl_version = *pver;
306
307 if (vf->virtchnl_version.major < VIRTCHNL_VERSION_MAJOR_START ||
308 (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR_START &&
309 vf->virtchnl_version.minor < VIRTCHNL_VERSION_MINOR_START)) {
310 PMD_INIT_LOG(ERR, "VIRTCHNL API version should not be lower"
311 " than (%u.%u) to support Adapative VF",
312 VIRTCHNL_VERSION_MAJOR_START,
313 VIRTCHNL_VERSION_MAJOR_START);
314 return -1;
315 } else if (vf->virtchnl_version.major > VIRTCHNL_VERSION_MAJOR ||
316 (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR &&
317 vf->virtchnl_version.minor > VIRTCHNL_VERSION_MINOR)) {
318 PMD_INIT_LOG(ERR, "PF/VF API version mismatch:(%u.%u)-(%u.%u)",
319 vf->virtchnl_version.major,
320 vf->virtchnl_version.minor,
321 VIRTCHNL_VERSION_MAJOR,
322 VIRTCHNL_VERSION_MINOR);
323 return -1;
324 }
325
326 PMD_DRV_LOG(DEBUG, "Peer is supported PF host");
327 return 0;
328 }
329
330 int
331 iavf_get_vf_resource(struct iavf_adapter *adapter)
332 {
333 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
334 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
335 struct iavf_cmd_info args;
336 uint32_t caps, len;
337 int err, i;
338
339 args.ops = VIRTCHNL_OP_GET_VF_RESOURCES;
340 args.out_buffer = vf->aq_resp;
341 args.out_size = IAVF_AQ_BUF_SZ;
342
343 /* TODO: basic offload capabilities, need to
344 * add advanced/optional offload capabilities
345 */
346
347 caps = IAVF_BASIC_OFFLOAD_CAPS | VIRTCHNL_VF_CAP_ADV_LINK_SPEED;
348
349 args.in_args = (uint8_t *)&caps;
350 args.in_args_size = sizeof(caps);
351
352 err = iavf_execute_vf_cmd(adapter, &args);
353
354 if (err) {
355 PMD_DRV_LOG(ERR,
356 "Failed to execute command of OP_GET_VF_RESOURCE");
357 return -1;
358 }
359
360 len = sizeof(struct virtchnl_vf_resource) +
361 IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
362
363 rte_memcpy(vf->vf_res, args.out_buffer,
364 RTE_MIN(args.out_size, len));
365 /* parse VF config message back from PF*/
366 iavf_parse_hw_config(hw, vf->vf_res);
367 for (i = 0; i < vf->vf_res->num_vsis; i++) {
368 if (vf->vf_res->vsi_res[i].vsi_type == VIRTCHNL_VSI_SRIOV)
369 vf->vsi_res = &vf->vf_res->vsi_res[i];
370 }
371
372 if (!vf->vsi_res) {
373 PMD_INIT_LOG(ERR, "no LAN VSI found");
374 return -1;
375 }
376
377 vf->vsi.vsi_id = vf->vsi_res->vsi_id;
378 vf->vsi.nb_qps = vf->vsi_res->num_queue_pairs;
379 vf->vsi.adapter = adapter;
380
381 return 0;
382 }
383
384 int
385 iavf_enable_queues(struct iavf_adapter *adapter)
386 {
387 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
388 struct virtchnl_queue_select queue_select;
389 struct iavf_cmd_info args;
390 int err;
391
392 memset(&queue_select, 0, sizeof(queue_select));
393 queue_select.vsi_id = vf->vsi_res->vsi_id;
394
395 queue_select.rx_queues = BIT(adapter->eth_dev->data->nb_rx_queues) - 1;
396 queue_select.tx_queues = BIT(adapter->eth_dev->data->nb_tx_queues) - 1;
397
398 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
399 args.in_args = (u8 *)&queue_select;
400 args.in_args_size = sizeof(queue_select);
401 args.out_buffer = vf->aq_resp;
402 args.out_size = IAVF_AQ_BUF_SZ;
403 err = iavf_execute_vf_cmd(adapter, &args);
404 if (err) {
405 PMD_DRV_LOG(ERR,
406 "Failed to execute command of OP_ENABLE_QUEUES");
407 return err;
408 }
409 return 0;
410 }
411
412 int
413 iavf_disable_queues(struct iavf_adapter *adapter)
414 {
415 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
416 struct virtchnl_queue_select queue_select;
417 struct iavf_cmd_info args;
418 int err;
419
420 memset(&queue_select, 0, sizeof(queue_select));
421 queue_select.vsi_id = vf->vsi_res->vsi_id;
422
423 queue_select.rx_queues = BIT(adapter->eth_dev->data->nb_rx_queues) - 1;
424 queue_select.tx_queues = BIT(adapter->eth_dev->data->nb_tx_queues) - 1;
425
426 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
427 args.in_args = (u8 *)&queue_select;
428 args.in_args_size = sizeof(queue_select);
429 args.out_buffer = vf->aq_resp;
430 args.out_size = IAVF_AQ_BUF_SZ;
431 err = iavf_execute_vf_cmd(adapter, &args);
432 if (err) {
433 PMD_DRV_LOG(ERR,
434 "Failed to execute command of OP_DISABLE_QUEUES");
435 return err;
436 }
437 return 0;
438 }
439
440 int
441 iavf_switch_queue(struct iavf_adapter *adapter, uint16_t qid,
442 bool rx, bool on)
443 {
444 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
445 struct virtchnl_queue_select queue_select;
446 struct iavf_cmd_info args;
447 int err;
448
449 memset(&queue_select, 0, sizeof(queue_select));
450 queue_select.vsi_id = vf->vsi_res->vsi_id;
451 if (rx)
452 queue_select.rx_queues |= 1 << qid;
453 else
454 queue_select.tx_queues |= 1 << qid;
455
456 if (on)
457 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
458 else
459 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
460 args.in_args = (u8 *)&queue_select;
461 args.in_args_size = sizeof(queue_select);
462 args.out_buffer = vf->aq_resp;
463 args.out_size = IAVF_AQ_BUF_SZ;
464 err = iavf_execute_vf_cmd(adapter, &args);
465 if (err)
466 PMD_DRV_LOG(ERR, "Failed to execute command of %s",
467 on ? "OP_ENABLE_QUEUES" : "OP_DISABLE_QUEUES");
468 return err;
469 }
470
471 int
472 iavf_configure_rss_lut(struct iavf_adapter *adapter)
473 {
474 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
475 struct virtchnl_rss_lut *rss_lut;
476 struct iavf_cmd_info args;
477 int len, err = 0;
478
479 len = sizeof(*rss_lut) + vf->vf_res->rss_lut_size - 1;
480 rss_lut = rte_zmalloc("rss_lut", len, 0);
481 if (!rss_lut)
482 return -ENOMEM;
483
484 rss_lut->vsi_id = vf->vsi_res->vsi_id;
485 rss_lut->lut_entries = vf->vf_res->rss_lut_size;
486 rte_memcpy(rss_lut->lut, vf->rss_lut, vf->vf_res->rss_lut_size);
487
488 args.ops = VIRTCHNL_OP_CONFIG_RSS_LUT;
489 args.in_args = (u8 *)rss_lut;
490 args.in_args_size = len;
491 args.out_buffer = vf->aq_resp;
492 args.out_size = IAVF_AQ_BUF_SZ;
493
494 err = iavf_execute_vf_cmd(adapter, &args);
495 if (err)
496 PMD_DRV_LOG(ERR,
497 "Failed to execute command of OP_CONFIG_RSS_LUT");
498
499 rte_free(rss_lut);
500 return err;
501 }
502
503 int
504 iavf_configure_rss_key(struct iavf_adapter *adapter)
505 {
506 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
507 struct virtchnl_rss_key *rss_key;
508 struct iavf_cmd_info args;
509 int len, err = 0;
510
511 len = sizeof(*rss_key) + vf->vf_res->rss_key_size - 1;
512 rss_key = rte_zmalloc("rss_key", len, 0);
513 if (!rss_key)
514 return -ENOMEM;
515
516 rss_key->vsi_id = vf->vsi_res->vsi_id;
517 rss_key->key_len = vf->vf_res->rss_key_size;
518 rte_memcpy(rss_key->key, vf->rss_key, vf->vf_res->rss_key_size);
519
520 args.ops = VIRTCHNL_OP_CONFIG_RSS_KEY;
521 args.in_args = (u8 *)rss_key;
522 args.in_args_size = len;
523 args.out_buffer = vf->aq_resp;
524 args.out_size = IAVF_AQ_BUF_SZ;
525
526 err = iavf_execute_vf_cmd(adapter, &args);
527 if (err)
528 PMD_DRV_LOG(ERR,
529 "Failed to execute command of OP_CONFIG_RSS_KEY");
530
531 rte_free(rss_key);
532 return err;
533 }
534
535 int
536 iavf_configure_queues(struct iavf_adapter *adapter)
537 {
538 struct iavf_rx_queue **rxq =
539 (struct iavf_rx_queue **)adapter->eth_dev->data->rx_queues;
540 struct iavf_tx_queue **txq =
541 (struct iavf_tx_queue **)adapter->eth_dev->data->tx_queues;
542 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
543 struct virtchnl_vsi_queue_config_info *vc_config;
544 struct virtchnl_queue_pair_info *vc_qp;
545 struct iavf_cmd_info args;
546 uint16_t i, size;
547 int err;
548
549 size = sizeof(*vc_config) +
550 sizeof(vc_config->qpair[0]) * vf->num_queue_pairs;
551 vc_config = rte_zmalloc("cfg_queue", size, 0);
552 if (!vc_config)
553 return -ENOMEM;
554
555 vc_config->vsi_id = vf->vsi_res->vsi_id;
556 vc_config->num_queue_pairs = vf->num_queue_pairs;
557
558 for (i = 0, vc_qp = vc_config->qpair;
559 i < vf->num_queue_pairs;
560 i++, vc_qp++) {
561 vc_qp->txq.vsi_id = vf->vsi_res->vsi_id;
562 vc_qp->txq.queue_id = i;
563 /* Virtchnnl configure queues by pairs */
564 if (i < adapter->eth_dev->data->nb_tx_queues) {
565 vc_qp->txq.ring_len = txq[i]->nb_tx_desc;
566 vc_qp->txq.dma_ring_addr = txq[i]->tx_ring_phys_addr;
567 }
568 vc_qp->rxq.vsi_id = vf->vsi_res->vsi_id;
569 vc_qp->rxq.queue_id = i;
570 vc_qp->rxq.max_pkt_size = vf->max_pkt_len;
571 /* Virtchnnl configure queues by pairs */
572 if (i < adapter->eth_dev->data->nb_rx_queues) {
573 vc_qp->rxq.ring_len = rxq[i]->nb_rx_desc;
574 vc_qp->rxq.dma_ring_addr = rxq[i]->rx_ring_phys_addr;
575 vc_qp->rxq.databuffer_size = rxq[i]->rx_buf_len;
576 }
577 }
578
579 memset(&args, 0, sizeof(args));
580 args.ops = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
581 args.in_args = (uint8_t *)vc_config;
582 args.in_args_size = size;
583 args.out_buffer = vf->aq_resp;
584 args.out_size = IAVF_AQ_BUF_SZ;
585
586 err = iavf_execute_vf_cmd(adapter, &args);
587 if (err)
588 PMD_DRV_LOG(ERR, "Failed to execute command of"
589 " VIRTCHNL_OP_CONFIG_VSI_QUEUES");
590
591 rte_free(vc_config);
592 return err;
593 }
594
595 int
596 iavf_config_irq_map(struct iavf_adapter *adapter)
597 {
598 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
599 struct virtchnl_irq_map_info *map_info;
600 struct virtchnl_vector_map *vecmap;
601 struct iavf_cmd_info args;
602 int len, i, err;
603
604 len = sizeof(struct virtchnl_irq_map_info) +
605 sizeof(struct virtchnl_vector_map) * vf->nb_msix;
606
607 map_info = rte_zmalloc("map_info", len, 0);
608 if (!map_info)
609 return -ENOMEM;
610
611 map_info->num_vectors = vf->nb_msix;
612 for (i = 0; i < vf->nb_msix; i++) {
613 vecmap = &map_info->vecmap[i];
614 vecmap->vsi_id = vf->vsi_res->vsi_id;
615 vecmap->rxitr_idx = IAVF_ITR_INDEX_DEFAULT;
616 vecmap->vector_id = vf->msix_base + i;
617 vecmap->txq_map = 0;
618 vecmap->rxq_map = vf->rxq_map[vf->msix_base + i];
619 }
620
621 args.ops = VIRTCHNL_OP_CONFIG_IRQ_MAP;
622 args.in_args = (u8 *)map_info;
623 args.in_args_size = len;
624 args.out_buffer = vf->aq_resp;
625 args.out_size = IAVF_AQ_BUF_SZ;
626 err = iavf_execute_vf_cmd(adapter, &args);
627 if (err)
628 PMD_DRV_LOG(ERR, "fail to execute command OP_CONFIG_IRQ_MAP");
629
630 rte_free(map_info);
631 return err;
632 }
633
634 void
635 iavf_add_del_all_mac_addr(struct iavf_adapter *adapter, bool add)
636 {
637 struct virtchnl_ether_addr_list *list;
638 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
639 struct ether_addr *addr;
640 struct iavf_cmd_info args;
641 int len, err, i, j;
642 int next_begin = 0;
643 int begin = 0;
644
645 do {
646 j = 0;
647 len = sizeof(struct virtchnl_ether_addr_list);
648 for (i = begin; i < IAVF_NUM_MACADDR_MAX; i++, next_begin++) {
649 addr = &adapter->eth_dev->data->mac_addrs[i];
650 if (is_zero_ether_addr(addr))
651 continue;
652 len += sizeof(struct virtchnl_ether_addr);
653 if (len >= IAVF_AQ_BUF_SZ) {
654 next_begin = i + 1;
655 break;
656 }
657 }
658
659 list = rte_zmalloc("iavf_del_mac_buffer", len, 0);
660 if (!list) {
661 PMD_DRV_LOG(ERR, "fail to allocate memory");
662 return;
663 }
664
665 for (i = begin; i < next_begin; i++) {
666 addr = &adapter->eth_dev->data->mac_addrs[i];
667 if (is_zero_ether_addr(addr))
668 continue;
669 rte_memcpy(list->list[j].addr, addr->addr_bytes,
670 sizeof(addr->addr_bytes));
671 PMD_DRV_LOG(DEBUG, "add/rm mac:%x:%x:%x:%x:%x:%x",
672 addr->addr_bytes[0], addr->addr_bytes[1],
673 addr->addr_bytes[2], addr->addr_bytes[3],
674 addr->addr_bytes[4], addr->addr_bytes[5]);
675 j++;
676 }
677 list->vsi_id = vf->vsi_res->vsi_id;
678 list->num_elements = j;
679 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR :
680 VIRTCHNL_OP_DEL_ETH_ADDR;
681 args.in_args = (uint8_t *)list;
682 args.in_args_size = len;
683 args.out_buffer = vf->aq_resp;
684 args.out_size = IAVF_AQ_BUF_SZ;
685 err = iavf_execute_vf_cmd(adapter, &args);
686 if (err)
687 PMD_DRV_LOG(ERR, "fail to execute command %s",
688 add ? "OP_ADD_ETHER_ADDRESS" :
689 "OP_DEL_ETHER_ADDRESS");
690 rte_free(list);
691 begin = next_begin;
692 } while (begin < IAVF_NUM_MACADDR_MAX);
693 }
694
695 int
696 iavf_query_stats(struct iavf_adapter *adapter,
697 struct virtchnl_eth_stats **pstats)
698 {
699 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
700 struct virtchnl_queue_select q_stats;
701 struct iavf_cmd_info args;
702 int err;
703
704 memset(&q_stats, 0, sizeof(q_stats));
705 q_stats.vsi_id = vf->vsi_res->vsi_id;
706 args.ops = VIRTCHNL_OP_GET_STATS;
707 args.in_args = (uint8_t *)&q_stats;
708 args.in_args_size = sizeof(q_stats);
709 args.out_buffer = vf->aq_resp;
710 args.out_size = IAVF_AQ_BUF_SZ;
711
712 err = iavf_execute_vf_cmd(adapter, &args);
713 if (err) {
714 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_STATS");
715 *pstats = NULL;
716 return err;
717 }
718 *pstats = (struct virtchnl_eth_stats *)args.out_buffer;
719 return 0;
720 }
721
722 int
723 iavf_config_promisc(struct iavf_adapter *adapter,
724 bool enable_unicast,
725 bool enable_multicast)
726 {
727 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
728 struct virtchnl_promisc_info promisc;
729 struct iavf_cmd_info args;
730 int err;
731
732 promisc.flags = 0;
733 promisc.vsi_id = vf->vsi_res->vsi_id;
734
735 if (enable_unicast)
736 promisc.flags |= FLAG_VF_UNICAST_PROMISC;
737
738 if (enable_multicast)
739 promisc.flags |= FLAG_VF_MULTICAST_PROMISC;
740
741 args.ops = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
742 args.in_args = (uint8_t *)&promisc;
743 args.in_args_size = sizeof(promisc);
744 args.out_buffer = vf->aq_resp;
745 args.out_size = IAVF_AQ_BUF_SZ;
746
747 err = iavf_execute_vf_cmd(adapter, &args);
748
749 if (err)
750 PMD_DRV_LOG(ERR,
751 "fail to execute command CONFIG_PROMISCUOUS_MODE");
752 return err;
753 }
754
755 int
756 iavf_add_del_eth_addr(struct iavf_adapter *adapter, struct ether_addr *addr,
757 bool add)
758 {
759 struct virtchnl_ether_addr_list *list;
760 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
761 uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
762 sizeof(struct virtchnl_ether_addr)];
763 struct iavf_cmd_info args;
764 int err;
765
766 list = (struct virtchnl_ether_addr_list *)cmd_buffer;
767 list->vsi_id = vf->vsi_res->vsi_id;
768 list->num_elements = 1;
769 rte_memcpy(list->list[0].addr, addr->addr_bytes,
770 sizeof(addr->addr_bytes));
771
772 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
773 args.in_args = cmd_buffer;
774 args.in_args_size = sizeof(cmd_buffer);
775 args.out_buffer = vf->aq_resp;
776 args.out_size = IAVF_AQ_BUF_SZ;
777 err = iavf_execute_vf_cmd(adapter, &args);
778 if (err)
779 PMD_DRV_LOG(ERR, "fail to execute command %s",
780 add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");
781 return err;
782 }
783
784 int
785 iavf_add_del_vlan(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
786 {
787 struct virtchnl_vlan_filter_list *vlan_list;
788 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
789 uint8_t cmd_buffer[sizeof(struct virtchnl_vlan_filter_list) +
790 sizeof(uint16_t)];
791 struct iavf_cmd_info args;
792 int err;
793
794 vlan_list = (struct virtchnl_vlan_filter_list *)cmd_buffer;
795 vlan_list->vsi_id = vf->vsi_res->vsi_id;
796 vlan_list->num_elements = 1;
797 vlan_list->vlan_id[0] = vlanid;
798
799 args.ops = add ? VIRTCHNL_OP_ADD_VLAN : VIRTCHNL_OP_DEL_VLAN;
800 args.in_args = cmd_buffer;
801 args.in_args_size = sizeof(cmd_buffer);
802 args.out_buffer = vf->aq_resp;
803 args.out_size = IAVF_AQ_BUF_SZ;
804 err = iavf_execute_vf_cmd(adapter, &args);
805 if (err)
806 PMD_DRV_LOG(ERR, "fail to execute command %s",
807 add ? "OP_ADD_VLAN" : "OP_DEL_VLAN");
808
809 return err;
810 }