55a425a7fe9ceb12595baf83bef1762f333c90a1
[dpdk.git] / drivers / net / avf / avf_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.h>
20 #include <rte_dev.h>
21
22 #include "avf_log.h"
23 #include "base/avf_prototype.h"
24 #include "base/avf_adminq_cmd.h"
25 #include "base/avf_type.h"
26
27 #include "avf.h"
28 #include "avf_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 avf_status_code
35 avf_read_msg_from_pf(struct avf_adapter *adapter, uint16_t buf_len,
36                      uint8_t *buf)
37 {
38         struct avf_hw *hw = AVF_DEV_PRIVATE_TO_HW(adapter);
39         struct avf_info *vf = AVF_DEV_PRIVATE_TO_VF(adapter);
40         struct avf_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 = avf_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 AVF_SUCCESS;
65 }
66
67 static int
68 avf_execute_vf_cmd(struct avf_adapter *adapter, struct avf_cmd_info *args)
69 {
70         struct avf_hw *hw = AVF_DEV_PRIVATE_TO_HW(adapter);
71         struct avf_info *vf = AVF_DEV_PRIVATE_TO_VF(adapter);
72         struct avf_arq_event_info event_info;
73         enum avf_status_code ret;
74         int err = 0;
75         int i = 0;
76
77         if (_atomic_set_cmd(vf, args->ops))
78                 return -1;
79
80         ret = avf_aq_send_msg_to_pf(hw, args->ops, AVF_SUCCESS,
81                                     args->in_args, args->in_args_size, NULL);
82         if (ret) {
83                 PMD_DRV_LOG(ERR, "fail to send cmd %d", args->ops);
84                 _clear_cmd(vf);
85                 return err;
86         }
87
88         switch (args->ops) {
89         case VIRTCHNL_OP_RESET_VF:
90                 /*no need to wait for response */
91                 _clear_cmd(vf);
92                 break;
93         case VIRTCHNL_OP_VERSION:
94         case VIRTCHNL_OP_GET_VF_RESOURCES:
95                 /* for init virtchnl ops, need to poll the response */
96                 do {
97                         ret = avf_read_msg_from_pf(adapter, args->out_size,
98                                                    args->out_buffer);
99                         if (ret == AVF_SUCCESS)
100                                 break;
101                         rte_delay_ms(ASQ_DELAY_MS);
102                 } while (i++ < MAX_TRY_TIMES);
103                 if (i >= MAX_TRY_TIMES ||
104                     vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
105                         err = -1;
106                         PMD_DRV_LOG(ERR, "No response or return failure (%d)"
107                                     " for cmd %d", vf->cmd_retval, args->ops);
108                 }
109                 _clear_cmd(vf);
110                 break;
111
112         default:
113                 /* For other virtchnl ops in running time,
114                  * wait for the cmd done flag.
115                  */
116                 do {
117                         if (vf->pend_cmd == VIRTCHNL_OP_UNKNOWN)
118                                 break;
119                         rte_delay_ms(ASQ_DELAY_MS);
120                         /* If don't read msg or read sys event, continue */
121                 } while (i++ < MAX_TRY_TIMES);
122                 /* If there's no response is received, clear command */
123                 if (i >= MAX_TRY_TIMES  ||
124                     vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
125                         err = -1;
126                         PMD_DRV_LOG(ERR, "No response or return failure (%d)"
127                                     " for cmd %d", vf->cmd_retval, args->ops);
128                         _clear_cmd(vf);
129                 }
130                 break;
131         }
132
133         return err;
134 }
135
136 void
137 avf_handle_virtchnl_msg(struct rte_eth_dev *dev)
138 {
139         struct avf_hw *hw = AVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
140         struct avf_info *vf = AVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
141         struct avf_arq_event_info info;
142         uint16_t pending, aq_opc;
143         enum virtchnl_ops msg_opc;
144         enum avf_status_code msg_ret;
145         int ret;
146
147         info.buf_len = AVF_AQ_BUF_SZ;
148         if (!vf->aq_resp) {
149                 PMD_DRV_LOG(ERR, "Buffer for adminq resp should not be NULL");
150                 return;
151         }
152         info.msg_buf = vf->aq_resp;
153
154         pending = 1;
155         while (pending) {
156                 ret = avf_clean_arq_element(hw, &info, &pending);
157
158                 if (ret != AVF_SUCCESS) {
159                         PMD_DRV_LOG(INFO, "Failed to read msg from AdminQ,"
160                                     "ret: %d", ret);
161                         break;
162                 }
163                 aq_opc = rte_le_to_cpu_16(info.desc.opcode);
164                 /* For the message sent from pf to vf, opcode is stored in
165                  * cookie_high of struct avf_aq_desc, while return error code
166                  * are stored in cookie_low, Which is done by PF driver.
167                  */
168                 msg_opc = (enum virtchnl_ops)rte_le_to_cpu_32(
169                                                   info.desc.cookie_high);
170                 msg_ret = (enum avf_status_code)rte_le_to_cpu_32(
171                                                   info.desc.cookie_low);
172                 switch (aq_opc) {
173                 case avf_aqc_opc_send_msg_to_vf:
174                         if (msg_opc == VIRTCHNL_OP_EVENT) {
175                                 /* TODO */
176                         } else {
177                                 /* read message and it's expected one */
178                                 if (msg_opc == vf->pend_cmd) {
179                                         vf->cmd_retval = msg_ret;
180                                         /* prevent compiler reordering */
181                                         rte_compiler_barrier();
182                                         _clear_cmd(vf);
183                                 } else
184                                         PMD_DRV_LOG(ERR, "command mismatch,"
185                                                     "expect %u, get %u",
186                                                     vf->pend_cmd, msg_opc);
187                                 PMD_DRV_LOG(DEBUG,
188                                             "adminq response is received,"
189                                             " opcode = %d", msg_opc);
190                         }
191                         break;
192                 default:
193                         PMD_DRV_LOG(ERR, "Request %u is not supported yet",
194                                     aq_opc);
195                         break;
196                 }
197         }
198 }
199
200 int
201 avf_enable_vlan_strip(struct avf_adapter *adapter)
202 {
203         struct avf_info *vf = AVF_DEV_PRIVATE_TO_VF(adapter);
204         struct avf_cmd_info args;
205         int ret;
206
207         memset(&args, 0, sizeof(args));
208         args.ops = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
209         args.in_args = NULL;
210         args.in_args_size = 0;
211         args.out_buffer = vf->aq_resp;
212         args.out_size = AVF_AQ_BUF_SZ;
213         ret = avf_execute_vf_cmd(adapter, &args);
214         if (ret)
215                 PMD_DRV_LOG(ERR, "Failed to execute command of"
216                             " OP_ENABLE_VLAN_STRIPPING");
217
218         return ret;
219 }
220
221 int
222 avf_disable_vlan_strip(struct avf_adapter *adapter)
223 {
224         struct avf_info *vf = AVF_DEV_PRIVATE_TO_VF(adapter);
225         struct avf_cmd_info args;
226         int ret;
227
228         memset(&args, 0, sizeof(args));
229         args.ops = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
230         args.in_args = NULL;
231         args.in_args_size = 0;
232         args.out_buffer = vf->aq_resp;
233         args.out_size = AVF_AQ_BUF_SZ;
234         ret = avf_execute_vf_cmd(adapter, &args);
235         if (ret)
236                 PMD_DRV_LOG(ERR, "Failed to execute command of"
237                             " OP_DISABLE_VLAN_STRIPPING");
238
239         return ret;
240 }
241
242 #define VIRTCHNL_VERSION_MAJOR_START 1
243 #define VIRTCHNL_VERSION_MINOR_START 1
244
245 /* Check API version with sync wait until version read from admin queue */
246 int
247 avf_check_api_version(struct avf_adapter *adapter)
248 {
249         struct avf_info *vf = AVF_DEV_PRIVATE_TO_VF(adapter);
250         struct virtchnl_version_info version, *pver;
251         struct avf_cmd_info args;
252         int err;
253
254         version.major = VIRTCHNL_VERSION_MAJOR;
255         version.minor = VIRTCHNL_VERSION_MINOR;
256
257         args.ops = VIRTCHNL_OP_VERSION;
258         args.in_args = (uint8_t *)&version;
259         args.in_args_size = sizeof(version);
260         args.out_buffer = vf->aq_resp;
261         args.out_size = AVF_AQ_BUF_SZ;
262
263         err = avf_execute_vf_cmd(adapter, &args);
264         if (err) {
265                 PMD_INIT_LOG(ERR, "Fail to execute command of OP_VERSION");
266                 return err;
267         }
268
269         pver = (struct virtchnl_version_info *)args.out_buffer;
270         vf->virtchnl_version = *pver;
271
272         if (vf->virtchnl_version.major < VIRTCHNL_VERSION_MAJOR_START ||
273             (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR_START &&
274              vf->virtchnl_version.minor < VIRTCHNL_VERSION_MINOR_START)) {
275                 PMD_INIT_LOG(ERR, "VIRTCHNL API version should not be lower"
276                              " than (%u.%u) to support Adapative VF",
277                              VIRTCHNL_VERSION_MAJOR_START,
278                              VIRTCHNL_VERSION_MAJOR_START);
279                 return -1;
280         } else if (vf->virtchnl_version.major > VIRTCHNL_VERSION_MAJOR ||
281                    (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR &&
282                     vf->virtchnl_version.minor > VIRTCHNL_VERSION_MINOR)) {
283                 PMD_INIT_LOG(ERR, "PF/VF API version mismatch:(%u.%u)-(%u.%u)",
284                              vf->virtchnl_version.major,
285                              vf->virtchnl_version.minor,
286                              VIRTCHNL_VERSION_MAJOR,
287                              VIRTCHNL_VERSION_MINOR);
288                 return -1;
289         }
290
291         PMD_DRV_LOG(DEBUG, "Peer is supported PF host");
292         return 0;
293 }
294
295 int
296 avf_get_vf_resource(struct avf_adapter *adapter)
297 {
298         struct avf_hw *hw = AVF_DEV_PRIVATE_TO_HW(adapter);
299         struct avf_info *vf = AVF_DEV_PRIVATE_TO_VF(adapter);
300         struct avf_cmd_info args;
301         uint32_t caps, len;
302         int err, i;
303
304         args.ops = VIRTCHNL_OP_GET_VF_RESOURCES;
305         args.out_buffer = vf->aq_resp;
306         args.out_size = AVF_AQ_BUF_SZ;
307
308         /* TODO: basic offload capabilities, need to
309          * add advanced/optional offload capabilities
310          */
311
312         caps = AVF_BASIC_OFFLOAD_CAPS;
313
314         args.in_args = (uint8_t *)&caps;
315         args.in_args_size = sizeof(caps);
316
317         err = avf_execute_vf_cmd(adapter, &args);
318
319         if (err) {
320                 PMD_DRV_LOG(ERR,
321                             "Failed to execute command of OP_GET_VF_RESOURCE");
322                 return -1;
323         }
324
325         len =  sizeof(struct virtchnl_vf_resource) +
326                       AVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
327
328         rte_memcpy(vf->vf_res, args.out_buffer,
329                    RTE_MIN(args.out_size, len));
330         /* parse  VF config message back from PF*/
331         avf_parse_hw_config(hw, vf->vf_res);
332         for (i = 0; i < vf->vf_res->num_vsis; i++) {
333                 if (vf->vf_res->vsi_res[i].vsi_type == VIRTCHNL_VSI_SRIOV)
334                         vf->vsi_res = &vf->vf_res->vsi_res[i];
335         }
336
337         if (!vf->vsi_res) {
338                 PMD_INIT_LOG(ERR, "no LAN VSI found");
339                 return -1;
340         }
341
342         vf->vsi.vsi_id = vf->vsi_res->vsi_id;
343         vf->vsi.nb_qps = vf->vsi_res->num_queue_pairs;
344         vf->vsi.adapter = adapter;
345
346         return 0;
347 }
348
349 int
350 avf_enable_queues(struct avf_adapter *adapter)
351 {
352         struct avf_info *vf = AVF_DEV_PRIVATE_TO_VF(adapter);
353         struct virtchnl_queue_select queue_select;
354         struct avf_cmd_info args;
355         int err;
356
357         memset(&queue_select, 0, sizeof(queue_select));
358         queue_select.vsi_id = vf->vsi_res->vsi_id;
359
360         queue_select.rx_queues = BIT(adapter->eth_dev->data->nb_rx_queues) - 1;
361         queue_select.tx_queues = BIT(adapter->eth_dev->data->nb_tx_queues) - 1;
362
363         args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
364         args.in_args = (u8 *)&queue_select;
365         args.in_args_size = sizeof(queue_select);
366         args.out_buffer = vf->aq_resp;
367         args.out_size = AVF_AQ_BUF_SZ;
368         err = avf_execute_vf_cmd(adapter, &args);
369         if (err) {
370                 PMD_DRV_LOG(ERR,
371                             "Failed to execute command of OP_ENABLE_QUEUES");
372                 return err;
373         }
374         return 0;
375 }
376
377 int
378 avf_disable_queues(struct avf_adapter *adapter)
379 {
380         struct avf_info *vf = AVF_DEV_PRIVATE_TO_VF(adapter);
381         struct virtchnl_queue_select queue_select;
382         struct avf_cmd_info args;
383         int err;
384
385         memset(&queue_select, 0, sizeof(queue_select));
386         queue_select.vsi_id = vf->vsi_res->vsi_id;
387
388         queue_select.rx_queues = BIT(adapter->eth_dev->data->nb_rx_queues) - 1;
389         queue_select.tx_queues = BIT(adapter->eth_dev->data->nb_tx_queues) - 1;
390
391         args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
392         args.in_args = (u8 *)&queue_select;
393         args.in_args_size = sizeof(queue_select);
394         args.out_buffer = vf->aq_resp;
395         args.out_size = AVF_AQ_BUF_SZ;
396         err = avf_execute_vf_cmd(adapter, &args);
397         if (err) {
398                 PMD_DRV_LOG(ERR,
399                             "Failed to execute command of OP_DISABLE_QUEUES");
400                 return err;
401         }
402         return 0;
403 }
404
405 int
406 avf_switch_queue(struct avf_adapter *adapter, uint16_t qid,
407                  bool rx, bool on)
408 {
409         struct avf_info *vf = AVF_DEV_PRIVATE_TO_VF(adapter);
410         struct virtchnl_queue_select queue_select;
411         struct avf_cmd_info args;
412         int err;
413
414         memset(&queue_select, 0, sizeof(queue_select));
415         queue_select.vsi_id = vf->vsi_res->vsi_id;
416         if (rx)
417                 queue_select.rx_queues |= 1 << qid;
418         else
419                 queue_select.tx_queues |= 1 << qid;
420
421         if (on)
422                 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
423         else
424                 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
425         args.in_args = (u8 *)&queue_select;
426         args.in_args_size = sizeof(queue_select);
427         args.out_buffer = vf->aq_resp;
428         args.out_size = AVF_AQ_BUF_SZ;
429         err = avf_execute_vf_cmd(adapter, &args);
430         if (err)
431                 PMD_DRV_LOG(ERR, "Failed to execute command of %s",
432                             on ? "OP_ENABLE_QUEUES" : "OP_DISABLE_QUEUES");
433         return err;
434 }
435
436 int
437 avf_configure_rss_lut(struct avf_adapter *adapter)
438 {
439         struct avf_info *vf = AVF_DEV_PRIVATE_TO_VF(adapter);
440         struct virtchnl_rss_lut *rss_lut;
441         struct avf_cmd_info args;
442         int len, err = 0;
443
444         len = sizeof(*rss_lut) + vf->vf_res->rss_lut_size - 1;
445         rss_lut = rte_zmalloc("rss_lut", len, 0);
446         if (!rss_lut)
447                 return -ENOMEM;
448
449         rss_lut->vsi_id = vf->vsi_res->vsi_id;
450         rss_lut->lut_entries = vf->vf_res->rss_lut_size;
451         rte_memcpy(rss_lut->lut, vf->rss_lut, vf->vf_res->rss_lut_size);
452
453         args.ops = VIRTCHNL_OP_CONFIG_RSS_LUT;
454         args.in_args = (u8 *)rss_lut;
455         args.in_args_size = len;
456         args.out_buffer = vf->aq_resp;
457         args.out_size = AVF_AQ_BUF_SZ;
458
459         err = avf_execute_vf_cmd(adapter, &args);
460         if (err)
461                 PMD_DRV_LOG(ERR,
462                             "Failed to execute command of OP_CONFIG_RSS_LUT");
463
464         rte_free(rss_lut);
465         return err;
466 }
467
468 int
469 avf_configure_rss_key(struct avf_adapter *adapter)
470 {
471         struct avf_info *vf = AVF_DEV_PRIVATE_TO_VF(adapter);
472         struct virtchnl_rss_key *rss_key;
473         struct avf_cmd_info args;
474         int len, err = 0;
475
476         len = sizeof(*rss_key) + vf->vf_res->rss_key_size - 1;
477         rss_key = rte_zmalloc("rss_key", len, 0);
478         if (!rss_key)
479                 return -ENOMEM;
480
481         rss_key->vsi_id = vf->vsi_res->vsi_id;
482         rss_key->key_len = vf->vf_res->rss_key_size;
483         rte_memcpy(rss_key->key, vf->rss_key, vf->vf_res->rss_key_size);
484
485         args.ops = VIRTCHNL_OP_CONFIG_RSS_KEY;
486         args.in_args = (u8 *)rss_key;
487         args.in_args_size = len;
488         args.out_buffer = vf->aq_resp;
489         args.out_size = AVF_AQ_BUF_SZ;
490
491         err = avf_execute_vf_cmd(adapter, &args);
492         if (err)
493                 PMD_DRV_LOG(ERR,
494                             "Failed to execute command of OP_CONFIG_RSS_KEY");
495
496         rte_free(rss_key);
497         return err;
498 }
499
500 int
501 avf_configure_queues(struct avf_adapter *adapter)
502 {
503         struct avf_rx_queue **rxq =
504                 (struct avf_rx_queue **)adapter->eth_dev->data->rx_queues;
505         struct avf_tx_queue **txq =
506                 (struct avf_tx_queue **)adapter->eth_dev->data->tx_queues;
507         struct avf_info *vf = AVF_DEV_PRIVATE_TO_VF(adapter);
508         struct virtchnl_vsi_queue_config_info *vc_config;
509         struct virtchnl_queue_pair_info *vc_qp;
510         struct avf_cmd_info args;
511         uint16_t i, size;
512         int err;
513
514         size = sizeof(*vc_config) +
515                sizeof(vc_config->qpair[0]) * vf->num_queue_pairs;
516         vc_config = rte_zmalloc("cfg_queue", size, 0);
517         if (!vc_config)
518                 return -ENOMEM;
519
520         vc_config->vsi_id = vf->vsi_res->vsi_id;
521         vc_config->num_queue_pairs = vf->num_queue_pairs;
522
523         for (i = 0, vc_qp = vc_config->qpair;
524              i < vf->num_queue_pairs;
525              i++, vc_qp++) {
526                 vc_qp->txq.vsi_id = vf->vsi_res->vsi_id;
527                 vc_qp->txq.queue_id = i;
528                 /* Virtchnnl configure queues by pairs */
529                 if (i < adapter->eth_dev->data->nb_tx_queues) {
530                         vc_qp->txq.ring_len = txq[i]->nb_tx_desc;
531                         vc_qp->txq.dma_ring_addr = txq[i]->tx_ring_phys_addr;
532                 }
533                 vc_qp->rxq.vsi_id = vf->vsi_res->vsi_id;
534                 vc_qp->rxq.queue_id = i;
535                 vc_qp->rxq.max_pkt_size = vf->max_pkt_len;
536                 /* Virtchnnl configure queues by pairs */
537                 if (i < adapter->eth_dev->data->nb_rx_queues) {
538                         vc_qp->rxq.ring_len = rxq[i]->nb_rx_desc;
539                         vc_qp->rxq.dma_ring_addr = rxq[i]->rx_ring_phys_addr;
540                         vc_qp->rxq.databuffer_size = rxq[i]->rx_buf_len;
541                 }
542         }
543
544         memset(&args, 0, sizeof(args));
545         args.ops = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
546         args.in_args = (uint8_t *)vc_config;
547         args.in_args_size = size;
548         args.out_buffer = vf->aq_resp;
549         args.out_size = AVF_AQ_BUF_SZ;
550
551         err = avf_execute_vf_cmd(adapter, &args);
552         if (err)
553                 PMD_DRV_LOG(ERR, "Failed to execute command of"
554                             " VIRTCHNL_OP_CONFIG_VSI_QUEUES");
555
556         rte_free(vc_config);
557         return err;
558 }
559
560 int
561 avf_config_irq_map(struct avf_adapter *adapter)
562 {
563         struct avf_info *vf = AVF_DEV_PRIVATE_TO_VF(adapter);
564         struct virtchnl_irq_map_info *map_info;
565         struct virtchnl_vector_map *vecmap;
566         struct avf_cmd_info args;
567         uint32_t vector_id;
568         int len, i, err;
569
570         len = sizeof(struct virtchnl_irq_map_info) +
571               sizeof(struct virtchnl_vector_map) * vf->nb_msix;
572
573         map_info = rte_zmalloc("map_info", len, 0);
574         if (!map_info)
575                 return -ENOMEM;
576
577         map_info->num_vectors = vf->nb_msix;
578         for (i = 0; i < vf->nb_msix; i++) {
579                 vecmap = &map_info->vecmap[i];
580                 vecmap->vsi_id = vf->vsi_res->vsi_id;
581                 vecmap->rxitr_idx = AVF_ITR_INDEX_DEFAULT;
582                 vecmap->vector_id = vf->msix_base + i;
583                 vecmap->txq_map = 0;
584                 vecmap->rxq_map = vf->rxq_map[vf->msix_base + i];
585         }
586
587         args.ops = VIRTCHNL_OP_CONFIG_IRQ_MAP;
588         args.in_args = (u8 *)map_info;
589         args.in_args_size = len;
590         args.out_buffer = vf->aq_resp;
591         args.out_size = AVF_AQ_BUF_SZ;
592         err = avf_execute_vf_cmd(adapter, &args);
593         if (err)
594                 PMD_DRV_LOG(ERR, "fail to execute command OP_CONFIG_IRQ_MAP");
595
596         rte_free(map_info);
597         return err;
598 }
599
600 void
601 avf_add_del_all_mac_addr(struct avf_adapter *adapter, bool add)
602 {
603         struct virtchnl_ether_addr_list *list;
604         struct avf_info *vf = AVF_DEV_PRIVATE_TO_VF(adapter);
605         struct ether_addr *addr;
606         struct avf_cmd_info args;
607         int len, err, i, j;
608         int next_begin = 0;
609         int begin = 0;
610
611         do {
612                 j = 0;
613                 len = sizeof(struct virtchnl_ether_addr_list);
614                 for (i = begin; i < AVF_NUM_MACADDR_MAX; i++, next_begin++) {
615                         addr = &adapter->eth_dev->data->mac_addrs[i];
616                         if (is_zero_ether_addr(addr))
617                                 continue;
618                         len += sizeof(struct virtchnl_ether_addr);
619                         if (len >= AVF_AQ_BUF_SZ) {
620                                 next_begin = i + 1;
621                                 break;
622                         }
623                 }
624
625                 list = rte_zmalloc("avf_del_mac_buffer", len, 0);
626                 if (!list) {
627                         PMD_DRV_LOG(ERR, "fail to allocate memory");
628                         return;
629                 }
630
631                 for (i = begin; i < next_begin; i++) {
632                         addr = &adapter->eth_dev->data->mac_addrs[i];
633                         if (is_zero_ether_addr(addr))
634                                 continue;
635                         rte_memcpy(list->list[j].addr, addr->addr_bytes,
636                                    sizeof(addr->addr_bytes));
637                         PMD_DRV_LOG(DEBUG, "add/rm mac:%x:%x:%x:%x:%x:%x",
638                                     addr->addr_bytes[0], addr->addr_bytes[1],
639                                     addr->addr_bytes[2], addr->addr_bytes[3],
640                                     addr->addr_bytes[4], addr->addr_bytes[5]);
641                         j++;
642                 }
643                 list->vsi_id = vf->vsi_res->vsi_id;
644                 list->num_elements = j;
645                 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR :
646                            VIRTCHNL_OP_DEL_ETH_ADDR;
647                 args.in_args = (uint8_t *)list;
648                 args.in_args_size = len;
649                 args.out_buffer = vf->aq_resp;
650                 args.out_size = AVF_AQ_BUF_SZ;
651                 err = avf_execute_vf_cmd(adapter, &args);
652                 if (err)
653                         PMD_DRV_LOG(ERR, "fail to execute command %s",
654                                     add ? "OP_ADD_ETHER_ADDRESS" :
655                                     "OP_DEL_ETHER_ADDRESS");
656                 rte_free(list);
657                 begin = next_begin;
658         } while (begin < AVF_NUM_MACADDR_MAX);
659 }