net/iavf: optimize promiscuous device operations
[dpdk.git] / 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.h"
23 #include "iavf_rxtx.h"
24
25 #define MAX_TRY_TIMES 200
26 #define ASQ_DELAY_MS  10
27
28 /* Read data in admin queue to get msg from pf driver */
29 static enum iavf_status
30 iavf_read_msg_from_pf(struct iavf_adapter *adapter, uint16_t buf_len,
31                      uint8_t *buf)
32 {
33         struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
34         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
35         struct iavf_arq_event_info event;
36         enum virtchnl_ops opcode;
37         int ret;
38
39         event.buf_len = buf_len;
40         event.msg_buf = buf;
41         ret = iavf_clean_arq_element(hw, &event, NULL);
42         /* Can't read any msg from adminQ */
43         if (ret) {
44                 PMD_DRV_LOG(DEBUG, "Can't read msg from AQ");
45                 return ret;
46         }
47
48         opcode = (enum virtchnl_ops)rte_le_to_cpu_32(event.desc.cookie_high);
49         vf->cmd_retval = (enum virtchnl_status_code)rte_le_to_cpu_32(
50                         event.desc.cookie_low);
51
52         PMD_DRV_LOG(DEBUG, "AQ from pf carries opcode %u, retval %d",
53                     opcode, vf->cmd_retval);
54
55         if (opcode != vf->pend_cmd) {
56                 if (opcode != VIRTCHNL_OP_EVENT) {
57                         PMD_DRV_LOG(WARNING,
58                                     "command mismatch, expect %u, get %u",
59                                     vf->pend_cmd, opcode);
60                 }
61                 return IAVF_ERR_OPCODE_MISMATCH;
62         }
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 ret;
73         int err = 0;
74         int i = 0;
75
76         if (vf->vf_reset)
77                 return -EIO;
78
79         if (_atomic_set_cmd(vf, args->ops))
80                 return -1;
81
82         ret = iavf_aq_send_msg_to_pf(hw, args->ops, IAVF_SUCCESS,
83                                     args->in_args, args->in_args_size, NULL);
84         if (ret) {
85                 PMD_DRV_LOG(ERR, "fail to send cmd %d", args->ops);
86                 _clear_cmd(vf);
87                 return err;
88         }
89
90         switch (args->ops) {
91         case VIRTCHNL_OP_RESET_VF:
92                 /*no need to wait for response */
93                 _clear_cmd(vf);
94                 break;
95         case VIRTCHNL_OP_VERSION:
96         case VIRTCHNL_OP_GET_VF_RESOURCES:
97         case VIRTCHNL_OP_GET_SUPPORTED_RXDIDS:
98                 /* for init virtchnl ops, need to poll the response */
99                 do {
100                         ret = iavf_read_msg_from_pf(adapter, args->out_size,
101                                                    args->out_buffer);
102                         if (ret == IAVF_SUCCESS)
103                                 break;
104                         rte_delay_ms(ASQ_DELAY_MS);
105                 } while (i++ < MAX_TRY_TIMES);
106                 if (i >= MAX_TRY_TIMES ||
107                     vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
108                         err = -1;
109                         PMD_DRV_LOG(ERR, "No response or return failure (%d)"
110                                     " for cmd %d", vf->cmd_retval, args->ops);
111                 }
112                 _clear_cmd(vf);
113                 break;
114
115         default:
116                 /* For other virtchnl ops in running time,
117                  * wait for the cmd done flag.
118                  */
119                 do {
120                         if (vf->pend_cmd == VIRTCHNL_OP_UNKNOWN)
121                                 break;
122                         rte_delay_ms(ASQ_DELAY_MS);
123                         /* If don't read msg or read sys event, continue */
124                 } while (i++ < MAX_TRY_TIMES);
125                 /* If there's no response is received, clear command */
126                 if (i >= MAX_TRY_TIMES  ||
127                     vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
128                         err = -1;
129                         PMD_DRV_LOG(ERR, "No response or return failure (%d)"
130                                     " for cmd %d", vf->cmd_retval, args->ops);
131                         _clear_cmd(vf);
132                 }
133                 break;
134         }
135
136         return err;
137 }
138
139 static uint32_t
140 iavf_convert_link_speed(enum virtchnl_link_speed virt_link_speed)
141 {
142         uint32_t speed;
143
144         switch (virt_link_speed) {
145         case VIRTCHNL_LINK_SPEED_100MB:
146                 speed = 100;
147                 break;
148         case VIRTCHNL_LINK_SPEED_1GB:
149                 speed = 1000;
150                 break;
151         case VIRTCHNL_LINK_SPEED_10GB:
152                 speed = 10000;
153                 break;
154         case VIRTCHNL_LINK_SPEED_40GB:
155                 speed = 40000;
156                 break;
157         case VIRTCHNL_LINK_SPEED_20GB:
158                 speed = 20000;
159                 break;
160         case VIRTCHNL_LINK_SPEED_25GB:
161                 speed = 25000;
162                 break;
163         case VIRTCHNL_LINK_SPEED_2_5GB:
164                 speed = 2500;
165                 break;
166         case VIRTCHNL_LINK_SPEED_5GB:
167                 speed = 5000;
168                 break;
169         default:
170                 speed = 0;
171                 break;
172         }
173
174         return speed;
175 }
176
177 static void
178 iavf_handle_pf_event_msg(struct rte_eth_dev *dev, uint8_t *msg,
179                         uint16_t msglen)
180 {
181         struct virtchnl_pf_event *pf_msg =
182                         (struct virtchnl_pf_event *)msg;
183         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
184
185         if (msglen < sizeof(struct virtchnl_pf_event)) {
186                 PMD_DRV_LOG(DEBUG, "Error event");
187                 return;
188         }
189         switch (pf_msg->event) {
190         case VIRTCHNL_EVENT_RESET_IMPENDING:
191                 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_RESET_IMPENDING event");
192                 vf->vf_reset = true;
193                 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET,
194                                               NULL);
195                 break;
196         case VIRTCHNL_EVENT_LINK_CHANGE:
197                 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_LINK_CHANGE event");
198                 vf->link_up = pf_msg->event_data.link_event.link_status;
199                 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_ADV_LINK_SPEED) {
200                         vf->link_speed =
201                                 pf_msg->event_data.link_event_adv.link_speed;
202                 } else {
203                         enum virtchnl_link_speed speed;
204                         speed = pf_msg->event_data.link_event.link_speed;
205                         vf->link_speed = iavf_convert_link_speed(speed);
206                 }
207                 iavf_dev_link_update(dev, 0);
208                 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
209                 break;
210         case VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
211                 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_PF_DRIVER_CLOSE event");
212                 break;
213         default:
214                 PMD_DRV_LOG(ERR, " unknown event received %u", pf_msg->event);
215                 break;
216         }
217 }
218
219 void
220 iavf_handle_virtchnl_msg(struct rte_eth_dev *dev)
221 {
222         struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
223         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
224         struct iavf_arq_event_info info;
225         uint16_t pending, aq_opc;
226         enum virtchnl_ops msg_opc;
227         enum iavf_status msg_ret;
228         int ret;
229
230         info.buf_len = IAVF_AQ_BUF_SZ;
231         if (!vf->aq_resp) {
232                 PMD_DRV_LOG(ERR, "Buffer for adminq resp should not be NULL");
233                 return;
234         }
235         info.msg_buf = vf->aq_resp;
236
237         pending = 1;
238         while (pending) {
239                 ret = iavf_clean_arq_element(hw, &info, &pending);
240
241                 if (ret != IAVF_SUCCESS) {
242                         PMD_DRV_LOG(INFO, "Failed to read msg from AdminQ,"
243                                     "ret: %d", ret);
244                         break;
245                 }
246                 aq_opc = rte_le_to_cpu_16(info.desc.opcode);
247                 /* For the message sent from pf to vf, opcode is stored in
248                  * cookie_high of struct iavf_aq_desc, while return error code
249                  * are stored in cookie_low, Which is done by PF driver.
250                  */
251                 msg_opc = (enum virtchnl_ops)rte_le_to_cpu_32(
252                                                   info.desc.cookie_high);
253                 msg_ret = (enum iavf_status)rte_le_to_cpu_32(
254                                                   info.desc.cookie_low);
255                 switch (aq_opc) {
256                 case iavf_aqc_opc_send_msg_to_vf:
257                         if (msg_opc == VIRTCHNL_OP_EVENT) {
258                                 iavf_handle_pf_event_msg(dev, info.msg_buf,
259                                                         info.msg_len);
260                         } else {
261                                 /* read message and it's expected one */
262                                 if (msg_opc == vf->pend_cmd)
263                                         _notify_cmd(vf, msg_ret);
264                                 else
265                                         PMD_DRV_LOG(ERR, "command mismatch,"
266                                                     "expect %u, get %u",
267                                                     vf->pend_cmd, msg_opc);
268                                 PMD_DRV_LOG(DEBUG,
269                                             "adminq response is received,"
270                                             " opcode = %d", msg_opc);
271                         }
272                         break;
273                 default:
274                         PMD_DRV_LOG(DEBUG, "Request %u is not supported yet",
275                                     aq_opc);
276                         break;
277                 }
278         }
279 }
280
281 int
282 iavf_enable_vlan_strip(struct iavf_adapter *adapter)
283 {
284         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
285         struct iavf_cmd_info args;
286         int ret;
287
288         memset(&args, 0, sizeof(args));
289         args.ops = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
290         args.in_args = NULL;
291         args.in_args_size = 0;
292         args.out_buffer = vf->aq_resp;
293         args.out_size = IAVF_AQ_BUF_SZ;
294         ret = iavf_execute_vf_cmd(adapter, &args);
295         if (ret)
296                 PMD_DRV_LOG(ERR, "Failed to execute command of"
297                             " OP_ENABLE_VLAN_STRIPPING");
298
299         return ret;
300 }
301
302 int
303 iavf_disable_vlan_strip(struct iavf_adapter *adapter)
304 {
305         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
306         struct iavf_cmd_info args;
307         int ret;
308
309         memset(&args, 0, sizeof(args));
310         args.ops = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
311         args.in_args = NULL;
312         args.in_args_size = 0;
313         args.out_buffer = vf->aq_resp;
314         args.out_size = IAVF_AQ_BUF_SZ;
315         ret = iavf_execute_vf_cmd(adapter, &args);
316         if (ret)
317                 PMD_DRV_LOG(ERR, "Failed to execute command of"
318                             " OP_DISABLE_VLAN_STRIPPING");
319
320         return ret;
321 }
322
323 #define VIRTCHNL_VERSION_MAJOR_START 1
324 #define VIRTCHNL_VERSION_MINOR_START 1
325
326 /* Check API version with sync wait until version read from admin queue */
327 int
328 iavf_check_api_version(struct iavf_adapter *adapter)
329 {
330         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
331         struct virtchnl_version_info version, *pver;
332         struct iavf_cmd_info args;
333         int err;
334
335         version.major = VIRTCHNL_VERSION_MAJOR;
336         version.minor = VIRTCHNL_VERSION_MINOR;
337
338         args.ops = VIRTCHNL_OP_VERSION;
339         args.in_args = (uint8_t *)&version;
340         args.in_args_size = sizeof(version);
341         args.out_buffer = vf->aq_resp;
342         args.out_size = IAVF_AQ_BUF_SZ;
343
344         err = iavf_execute_vf_cmd(adapter, &args);
345         if (err) {
346                 PMD_INIT_LOG(ERR, "Fail to execute command of OP_VERSION");
347                 return err;
348         }
349
350         pver = (struct virtchnl_version_info *)args.out_buffer;
351         vf->virtchnl_version = *pver;
352
353         if (vf->virtchnl_version.major < VIRTCHNL_VERSION_MAJOR_START ||
354             (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR_START &&
355              vf->virtchnl_version.minor < VIRTCHNL_VERSION_MINOR_START)) {
356                 PMD_INIT_LOG(ERR, "VIRTCHNL API version should not be lower"
357                              " than (%u.%u) to support Adapative VF",
358                              VIRTCHNL_VERSION_MAJOR_START,
359                              VIRTCHNL_VERSION_MAJOR_START);
360                 return -1;
361         } else if (vf->virtchnl_version.major > VIRTCHNL_VERSION_MAJOR ||
362                    (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR &&
363                     vf->virtchnl_version.minor > VIRTCHNL_VERSION_MINOR)) {
364                 PMD_INIT_LOG(ERR, "PF/VF API version mismatch:(%u.%u)-(%u.%u)",
365                              vf->virtchnl_version.major,
366                              vf->virtchnl_version.minor,
367                              VIRTCHNL_VERSION_MAJOR,
368                              VIRTCHNL_VERSION_MINOR);
369                 return -1;
370         }
371
372         PMD_DRV_LOG(DEBUG, "Peer is supported PF host");
373         return 0;
374 }
375
376 int
377 iavf_get_vf_resource(struct iavf_adapter *adapter)
378 {
379         struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
380         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
381         struct iavf_cmd_info args;
382         uint32_t caps, len;
383         int err, i;
384
385         args.ops = VIRTCHNL_OP_GET_VF_RESOURCES;
386         args.out_buffer = vf->aq_resp;
387         args.out_size = IAVF_AQ_BUF_SZ;
388
389         caps = IAVF_BASIC_OFFLOAD_CAPS | VIRTCHNL_VF_CAP_ADV_LINK_SPEED |
390                 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC |
391                 VIRTCHNL_VF_OFFLOAD_FDIR_PF |
392                 VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF;
393
394         args.in_args = (uint8_t *)&caps;
395         args.in_args_size = sizeof(caps);
396
397         err = iavf_execute_vf_cmd(adapter, &args);
398
399         if (err) {
400                 PMD_DRV_LOG(ERR,
401                             "Failed to execute command of OP_GET_VF_RESOURCE");
402                 return -1;
403         }
404
405         len =  sizeof(struct virtchnl_vf_resource) +
406                       IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
407
408         rte_memcpy(vf->vf_res, args.out_buffer,
409                    RTE_MIN(args.out_size, len));
410         /* parse  VF config message back from PF*/
411         iavf_vf_parse_hw_config(hw, vf->vf_res);
412         for (i = 0; i < vf->vf_res->num_vsis; i++) {
413                 if (vf->vf_res->vsi_res[i].vsi_type == VIRTCHNL_VSI_SRIOV)
414                         vf->vsi_res = &vf->vf_res->vsi_res[i];
415         }
416
417         if (!vf->vsi_res) {
418                 PMD_INIT_LOG(ERR, "no LAN VSI found");
419                 return -1;
420         }
421
422         vf->vsi.vsi_id = vf->vsi_res->vsi_id;
423         vf->vsi.nb_qps = vf->vsi_res->num_queue_pairs;
424         vf->vsi.adapter = adapter;
425
426         return 0;
427 }
428
429 int
430 iavf_get_supported_rxdid(struct iavf_adapter *adapter)
431 {
432         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
433         struct iavf_cmd_info args;
434         int ret;
435
436         args.ops = VIRTCHNL_OP_GET_SUPPORTED_RXDIDS;
437         args.in_args = NULL;
438         args.in_args_size = 0;
439         args.out_buffer = vf->aq_resp;
440         args.out_size = IAVF_AQ_BUF_SZ;
441
442         ret = iavf_execute_vf_cmd(adapter, &args);
443         if (ret) {
444                 PMD_DRV_LOG(ERR,
445                             "Failed to execute command of OP_GET_SUPPORTED_RXDIDS");
446                 return ret;
447         }
448
449         vf->supported_rxdid =
450                 ((struct virtchnl_supported_rxdids *)args.out_buffer)->supported_rxdids;
451
452         return 0;
453 }
454
455 int
456 iavf_enable_queues(struct iavf_adapter *adapter)
457 {
458         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
459         struct virtchnl_queue_select queue_select;
460         struct iavf_cmd_info args;
461         int err;
462
463         memset(&queue_select, 0, sizeof(queue_select));
464         queue_select.vsi_id = vf->vsi_res->vsi_id;
465
466         queue_select.rx_queues = BIT(adapter->eth_dev->data->nb_rx_queues) - 1;
467         queue_select.tx_queues = BIT(adapter->eth_dev->data->nb_tx_queues) - 1;
468
469         args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
470         args.in_args = (u8 *)&queue_select;
471         args.in_args_size = sizeof(queue_select);
472         args.out_buffer = vf->aq_resp;
473         args.out_size = IAVF_AQ_BUF_SZ;
474         err = iavf_execute_vf_cmd(adapter, &args);
475         if (err) {
476                 PMD_DRV_LOG(ERR,
477                             "Failed to execute command of OP_ENABLE_QUEUES");
478                 return err;
479         }
480         return 0;
481 }
482
483 int
484 iavf_disable_queues(struct iavf_adapter *adapter)
485 {
486         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
487         struct virtchnl_queue_select queue_select;
488         struct iavf_cmd_info args;
489         int err;
490
491         memset(&queue_select, 0, sizeof(queue_select));
492         queue_select.vsi_id = vf->vsi_res->vsi_id;
493
494         queue_select.rx_queues = BIT(adapter->eth_dev->data->nb_rx_queues) - 1;
495         queue_select.tx_queues = BIT(adapter->eth_dev->data->nb_tx_queues) - 1;
496
497         args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
498         args.in_args = (u8 *)&queue_select;
499         args.in_args_size = sizeof(queue_select);
500         args.out_buffer = vf->aq_resp;
501         args.out_size = IAVF_AQ_BUF_SZ;
502         err = iavf_execute_vf_cmd(adapter, &args);
503         if (err) {
504                 PMD_DRV_LOG(ERR,
505                             "Failed to execute command of OP_DISABLE_QUEUES");
506                 return err;
507         }
508         return 0;
509 }
510
511 int
512 iavf_switch_queue(struct iavf_adapter *adapter, uint16_t qid,
513                  bool rx, bool on)
514 {
515         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
516         struct virtchnl_queue_select queue_select;
517         struct iavf_cmd_info args;
518         int err;
519
520         memset(&queue_select, 0, sizeof(queue_select));
521         queue_select.vsi_id = vf->vsi_res->vsi_id;
522         if (rx)
523                 queue_select.rx_queues |= 1 << qid;
524         else
525                 queue_select.tx_queues |= 1 << qid;
526
527         if (on)
528                 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
529         else
530                 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
531         args.in_args = (u8 *)&queue_select;
532         args.in_args_size = sizeof(queue_select);
533         args.out_buffer = vf->aq_resp;
534         args.out_size = IAVF_AQ_BUF_SZ;
535         err = iavf_execute_vf_cmd(adapter, &args);
536         if (err)
537                 PMD_DRV_LOG(ERR, "Failed to execute command of %s",
538                             on ? "OP_ENABLE_QUEUES" : "OP_DISABLE_QUEUES");
539         return err;
540 }
541
542 int
543 iavf_configure_rss_lut(struct iavf_adapter *adapter)
544 {
545         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
546         struct virtchnl_rss_lut *rss_lut;
547         struct iavf_cmd_info args;
548         int len, err = 0;
549
550         len = sizeof(*rss_lut) + vf->vf_res->rss_lut_size - 1;
551         rss_lut = rte_zmalloc("rss_lut", len, 0);
552         if (!rss_lut)
553                 return -ENOMEM;
554
555         rss_lut->vsi_id = vf->vsi_res->vsi_id;
556         rss_lut->lut_entries = vf->vf_res->rss_lut_size;
557         rte_memcpy(rss_lut->lut, vf->rss_lut, vf->vf_res->rss_lut_size);
558
559         args.ops = VIRTCHNL_OP_CONFIG_RSS_LUT;
560         args.in_args = (u8 *)rss_lut;
561         args.in_args_size = len;
562         args.out_buffer = vf->aq_resp;
563         args.out_size = IAVF_AQ_BUF_SZ;
564
565         err = iavf_execute_vf_cmd(adapter, &args);
566         if (err)
567                 PMD_DRV_LOG(ERR,
568                             "Failed to execute command of OP_CONFIG_RSS_LUT");
569
570         rte_free(rss_lut);
571         return err;
572 }
573
574 int
575 iavf_configure_rss_key(struct iavf_adapter *adapter)
576 {
577         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
578         struct virtchnl_rss_key *rss_key;
579         struct iavf_cmd_info args;
580         int len, err = 0;
581
582         len = sizeof(*rss_key) + vf->vf_res->rss_key_size - 1;
583         rss_key = rte_zmalloc("rss_key", len, 0);
584         if (!rss_key)
585                 return -ENOMEM;
586
587         rss_key->vsi_id = vf->vsi_res->vsi_id;
588         rss_key->key_len = vf->vf_res->rss_key_size;
589         rte_memcpy(rss_key->key, vf->rss_key, vf->vf_res->rss_key_size);
590
591         args.ops = VIRTCHNL_OP_CONFIG_RSS_KEY;
592         args.in_args = (u8 *)rss_key;
593         args.in_args_size = len;
594         args.out_buffer = vf->aq_resp;
595         args.out_size = IAVF_AQ_BUF_SZ;
596
597         err = iavf_execute_vf_cmd(adapter, &args);
598         if (err)
599                 PMD_DRV_LOG(ERR,
600                             "Failed to execute command of OP_CONFIG_RSS_KEY");
601
602         rte_free(rss_key);
603         return err;
604 }
605
606 int
607 iavf_configure_queues(struct iavf_adapter *adapter)
608 {
609         struct iavf_rx_queue **rxq =
610                 (struct iavf_rx_queue **)adapter->eth_dev->data->rx_queues;
611         struct iavf_tx_queue **txq =
612                 (struct iavf_tx_queue **)adapter->eth_dev->data->tx_queues;
613         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
614         struct virtchnl_vsi_queue_config_info *vc_config;
615         struct virtchnl_queue_pair_info *vc_qp;
616         struct iavf_cmd_info args;
617         uint16_t i, size;
618         int err;
619
620         size = sizeof(*vc_config) +
621                sizeof(vc_config->qpair[0]) * vf->num_queue_pairs;
622         vc_config = rte_zmalloc("cfg_queue", size, 0);
623         if (!vc_config)
624                 return -ENOMEM;
625
626         vc_config->vsi_id = vf->vsi_res->vsi_id;
627         vc_config->num_queue_pairs = vf->num_queue_pairs;
628
629         for (i = 0, vc_qp = vc_config->qpair;
630              i < vf->num_queue_pairs;
631              i++, vc_qp++) {
632                 vc_qp->txq.vsi_id = vf->vsi_res->vsi_id;
633                 vc_qp->txq.queue_id = i;
634                 /* Virtchnnl configure queues by pairs */
635                 if (i < adapter->eth_dev->data->nb_tx_queues) {
636                         vc_qp->txq.ring_len = txq[i]->nb_tx_desc;
637                         vc_qp->txq.dma_ring_addr = txq[i]->tx_ring_phys_addr;
638                 }
639                 vc_qp->rxq.vsi_id = vf->vsi_res->vsi_id;
640                 vc_qp->rxq.queue_id = i;
641                 vc_qp->rxq.max_pkt_size = vf->max_pkt_len;
642                 /* Virtchnnl configure queues by pairs */
643                 if (i < adapter->eth_dev->data->nb_rx_queues) {
644                         vc_qp->rxq.ring_len = rxq[i]->nb_rx_desc;
645                         vc_qp->rxq.dma_ring_addr = rxq[i]->rx_ring_phys_addr;
646                         vc_qp->rxq.databuffer_size = rxq[i]->rx_buf_len;
647                 }
648
649 #ifndef RTE_LIBRTE_IAVF_16BYTE_RX_DESC
650                 if (vf->vf_res->vf_cap_flags &
651                         VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
652                         vf->supported_rxdid & BIT(IAVF_RXDID_COMMS_OVS_1)) {
653                         vc_qp->rxq.rxdid = IAVF_RXDID_COMMS_OVS_1;
654                         PMD_DRV_LOG(NOTICE, "request RXDID == %d in "
655                                         "Queue[%d]", vc_qp->rxq.rxdid, i);
656                 } else {
657                         vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_1;
658                         PMD_DRV_LOG(NOTICE, "request RXDID == %d in "
659                                         "Queue[%d]", vc_qp->rxq.rxdid, i);
660                 }
661 #else
662                 if (vf->vf_res->vf_cap_flags &
663                         VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
664                         vf->supported_rxdid & BIT(IAVF_RXDID_LEGACY_0)) {
665                         vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_0;
666                         PMD_DRV_LOG(NOTICE, "request RXDID == %d in "
667                                         "Queue[%d]", vc_qp->rxq.rxdid, i);
668                 } else {
669                         PMD_DRV_LOG(ERR, "RXDID == 0 is not supported");
670                         return -1;
671                 }
672 #endif
673         }
674
675         memset(&args, 0, sizeof(args));
676         args.ops = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
677         args.in_args = (uint8_t *)vc_config;
678         args.in_args_size = size;
679         args.out_buffer = vf->aq_resp;
680         args.out_size = IAVF_AQ_BUF_SZ;
681
682         err = iavf_execute_vf_cmd(adapter, &args);
683         if (err)
684                 PMD_DRV_LOG(ERR, "Failed to execute command of"
685                             " VIRTCHNL_OP_CONFIG_VSI_QUEUES");
686
687         rte_free(vc_config);
688         return err;
689 }
690
691 int
692 iavf_config_irq_map(struct iavf_adapter *adapter)
693 {
694         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
695         struct virtchnl_irq_map_info *map_info;
696         struct virtchnl_vector_map *vecmap;
697         struct iavf_cmd_info args;
698         int len, i, err;
699
700         len = sizeof(struct virtchnl_irq_map_info) +
701               sizeof(struct virtchnl_vector_map) * vf->nb_msix;
702
703         map_info = rte_zmalloc("map_info", len, 0);
704         if (!map_info)
705                 return -ENOMEM;
706
707         map_info->num_vectors = vf->nb_msix;
708         for (i = 0; i < vf->nb_msix; i++) {
709                 vecmap = &map_info->vecmap[i];
710                 vecmap->vsi_id = vf->vsi_res->vsi_id;
711                 vecmap->rxitr_idx = IAVF_ITR_INDEX_DEFAULT;
712                 vecmap->vector_id = vf->msix_base + i;
713                 vecmap->txq_map = 0;
714                 vecmap->rxq_map = vf->rxq_map[vf->msix_base + i];
715         }
716
717         args.ops = VIRTCHNL_OP_CONFIG_IRQ_MAP;
718         args.in_args = (u8 *)map_info;
719         args.in_args_size = len;
720         args.out_buffer = vf->aq_resp;
721         args.out_size = IAVF_AQ_BUF_SZ;
722         err = iavf_execute_vf_cmd(adapter, &args);
723         if (err)
724                 PMD_DRV_LOG(ERR, "fail to execute command OP_CONFIG_IRQ_MAP");
725
726         rte_free(map_info);
727         return err;
728 }
729
730 void
731 iavf_add_del_all_mac_addr(struct iavf_adapter *adapter, bool add)
732 {
733         struct virtchnl_ether_addr_list *list;
734         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
735         struct rte_ether_addr *addr;
736         struct iavf_cmd_info args;
737         int len, err, i, j;
738         int next_begin = 0;
739         int begin = 0;
740
741         do {
742                 j = 0;
743                 len = sizeof(struct virtchnl_ether_addr_list);
744                 for (i = begin; i < IAVF_NUM_MACADDR_MAX; i++, next_begin++) {
745                         addr = &adapter->eth_dev->data->mac_addrs[i];
746                         if (rte_is_zero_ether_addr(addr))
747                                 continue;
748                         len += sizeof(struct virtchnl_ether_addr);
749                         if (len >= IAVF_AQ_BUF_SZ) {
750                                 next_begin = i + 1;
751                                 break;
752                         }
753                 }
754
755                 list = rte_zmalloc("iavf_del_mac_buffer", len, 0);
756                 if (!list) {
757                         PMD_DRV_LOG(ERR, "fail to allocate memory");
758                         return;
759                 }
760
761                 for (i = begin; i < next_begin; i++) {
762                         addr = &adapter->eth_dev->data->mac_addrs[i];
763                         if (rte_is_zero_ether_addr(addr))
764                                 continue;
765                         rte_memcpy(list->list[j].addr, addr->addr_bytes,
766                                    sizeof(addr->addr_bytes));
767                         PMD_DRV_LOG(DEBUG, "add/rm mac:%x:%x:%x:%x:%x:%x",
768                                     addr->addr_bytes[0], addr->addr_bytes[1],
769                                     addr->addr_bytes[2], addr->addr_bytes[3],
770                                     addr->addr_bytes[4], addr->addr_bytes[5]);
771                         j++;
772                 }
773                 list->vsi_id = vf->vsi_res->vsi_id;
774                 list->num_elements = j;
775                 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR :
776                            VIRTCHNL_OP_DEL_ETH_ADDR;
777                 args.in_args = (uint8_t *)list;
778                 args.in_args_size = len;
779                 args.out_buffer = vf->aq_resp;
780                 args.out_size = IAVF_AQ_BUF_SZ;
781                 err = iavf_execute_vf_cmd(adapter, &args);
782                 if (err)
783                         PMD_DRV_LOG(ERR, "fail to execute command %s",
784                                     add ? "OP_ADD_ETHER_ADDRESS" :
785                                     "OP_DEL_ETHER_ADDRESS");
786                 rte_free(list);
787                 begin = next_begin;
788         } while (begin < IAVF_NUM_MACADDR_MAX);
789 }
790
791 int
792 iavf_query_stats(struct iavf_adapter *adapter,
793                 struct virtchnl_eth_stats **pstats)
794 {
795         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
796         struct virtchnl_queue_select q_stats;
797         struct iavf_cmd_info args;
798         int err;
799
800         memset(&q_stats, 0, sizeof(q_stats));
801         q_stats.vsi_id = vf->vsi_res->vsi_id;
802         args.ops = VIRTCHNL_OP_GET_STATS;
803         args.in_args = (uint8_t *)&q_stats;
804         args.in_args_size = sizeof(q_stats);
805         args.out_buffer = vf->aq_resp;
806         args.out_size = IAVF_AQ_BUF_SZ;
807
808         err = iavf_execute_vf_cmd(adapter, &args);
809         if (err) {
810                 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_STATS");
811                 *pstats = NULL;
812                 return err;
813         }
814         *pstats = (struct virtchnl_eth_stats *)args.out_buffer;
815         return 0;
816 }
817
818 int
819 iavf_config_promisc(struct iavf_adapter *adapter,
820                    bool enable_unicast,
821                    bool enable_multicast)
822 {
823         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
824         struct virtchnl_promisc_info promisc;
825         struct iavf_cmd_info args;
826         int err;
827
828         promisc.flags = 0;
829         promisc.vsi_id = vf->vsi_res->vsi_id;
830
831         if (enable_unicast)
832                 promisc.flags |= FLAG_VF_UNICAST_PROMISC;
833
834         if (enable_multicast)
835                 promisc.flags |= FLAG_VF_MULTICAST_PROMISC;
836
837         args.ops = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
838         args.in_args = (uint8_t *)&promisc;
839         args.in_args_size = sizeof(promisc);
840         args.out_buffer = vf->aq_resp;
841         args.out_size = IAVF_AQ_BUF_SZ;
842
843         err = iavf_execute_vf_cmd(adapter, &args);
844
845         if (err) {
846                 PMD_DRV_LOG(ERR,
847                             "fail to execute command CONFIG_PROMISCUOUS_MODE");
848
849                 if (err == IAVF_NOT_SUPPORTED)
850                         return -ENOTSUP;
851
852                 return -EAGAIN;
853         }
854
855         vf->promisc_unicast_enabled = enable_unicast;
856         vf->promisc_multicast_enabled = enable_multicast;
857         return 0;
858 }
859
860 int
861 iavf_add_del_eth_addr(struct iavf_adapter *adapter, struct rte_ether_addr *addr,
862                      bool add)
863 {
864         struct virtchnl_ether_addr_list *list;
865         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
866         uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
867                            sizeof(struct virtchnl_ether_addr)];
868         struct iavf_cmd_info args;
869         int err;
870
871         list = (struct virtchnl_ether_addr_list *)cmd_buffer;
872         list->vsi_id = vf->vsi_res->vsi_id;
873         list->num_elements = 1;
874         rte_memcpy(list->list[0].addr, addr->addr_bytes,
875                    sizeof(addr->addr_bytes));
876
877         args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
878         args.in_args = cmd_buffer;
879         args.in_args_size = sizeof(cmd_buffer);
880         args.out_buffer = vf->aq_resp;
881         args.out_size = IAVF_AQ_BUF_SZ;
882         err = iavf_execute_vf_cmd(adapter, &args);
883         if (err)
884                 PMD_DRV_LOG(ERR, "fail to execute command %s",
885                             add ? "OP_ADD_ETH_ADDR" :  "OP_DEL_ETH_ADDR");
886         return err;
887 }
888
889 int
890 iavf_add_del_vlan(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
891 {
892         struct virtchnl_vlan_filter_list *vlan_list;
893         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
894         uint8_t cmd_buffer[sizeof(struct virtchnl_vlan_filter_list) +
895                                                         sizeof(uint16_t)];
896         struct iavf_cmd_info args;
897         int err;
898
899         vlan_list = (struct virtchnl_vlan_filter_list *)cmd_buffer;
900         vlan_list->vsi_id = vf->vsi_res->vsi_id;
901         vlan_list->num_elements = 1;
902         vlan_list->vlan_id[0] = vlanid;
903
904         args.ops = add ? VIRTCHNL_OP_ADD_VLAN : VIRTCHNL_OP_DEL_VLAN;
905         args.in_args = cmd_buffer;
906         args.in_args_size = sizeof(cmd_buffer);
907         args.out_buffer = vf->aq_resp;
908         args.out_size = IAVF_AQ_BUF_SZ;
909         err = iavf_execute_vf_cmd(adapter, &args);
910         if (err)
911                 PMD_DRV_LOG(ERR, "fail to execute command %s",
912                             add ? "OP_ADD_VLAN" :  "OP_DEL_VLAN");
913
914         return err;
915 }
916
917 int
918 iavf_fdir_add(struct iavf_adapter *adapter,
919         struct iavf_fdir_conf *filter)
920 {
921         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
922         struct virtchnl_fdir_add *fdir_ret;
923
924         struct iavf_cmd_info args;
925         int err;
926
927         filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
928         filter->add_fltr.validate_only = 0;
929
930         args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
931         args.in_args = (uint8_t *)(&filter->add_fltr);
932         args.in_args_size = sizeof(*(&filter->add_fltr));
933         args.out_buffer = vf->aq_resp;
934         args.out_size = IAVF_AQ_BUF_SZ;
935
936         err = iavf_execute_vf_cmd(adapter, &args);
937         if (err) {
938                 PMD_DRV_LOG(ERR, "fail to execute command OP_ADD_FDIR_FILTER");
939                 return err;
940         }
941
942         fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
943         filter->flow_id = fdir_ret->flow_id;
944
945         if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
946                 PMD_DRV_LOG(INFO,
947                         "Succeed in adding rule request by PF");
948         } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE) {
949                 PMD_DRV_LOG(ERR,
950                         "Failed to add rule request due to no hw resource");
951                 return -1;
952         } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_EXIST) {
953                 PMD_DRV_LOG(ERR,
954                         "Failed to add rule request due to the rule is already existed");
955                 return -1;
956         } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT) {
957                 PMD_DRV_LOG(ERR,
958                         "Failed to add rule request due to the rule is conflict with existing rule");
959                 return -1;
960         } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
961                 PMD_DRV_LOG(ERR,
962                         "Failed to add rule request due to the hw doesn't support");
963                 return -1;
964         } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
965                 PMD_DRV_LOG(ERR,
966                         "Failed to add rule request due to time out for programming");
967                 return -1;
968         } else {
969                 PMD_DRV_LOG(ERR,
970                         "Failed to add rule request due to other reasons");
971                 return -1;
972         }
973
974         return 0;
975 };
976
977 int
978 iavf_fdir_del(struct iavf_adapter *adapter,
979         struct iavf_fdir_conf *filter)
980 {
981         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
982         struct virtchnl_fdir_del *fdir_ret;
983
984         struct iavf_cmd_info args;
985         int err;
986
987         filter->del_fltr.vsi_id = vf->vsi_res->vsi_id;
988         filter->del_fltr.flow_id = filter->flow_id;
989
990         args.ops = VIRTCHNL_OP_DEL_FDIR_FILTER;
991         args.in_args = (uint8_t *)(&filter->del_fltr);
992         args.in_args_size = sizeof(filter->del_fltr);
993         args.out_buffer = vf->aq_resp;
994         args.out_size = IAVF_AQ_BUF_SZ;
995
996         err = iavf_execute_vf_cmd(adapter, &args);
997         if (err) {
998                 PMD_DRV_LOG(ERR, "fail to execute command OP_DEL_FDIR_FILTER");
999                 return err;
1000         }
1001
1002         fdir_ret = (struct virtchnl_fdir_del *)args.out_buffer;
1003
1004         if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1005                 PMD_DRV_LOG(INFO,
1006                         "Succeed in deleting rule request by PF");
1007         } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST) {
1008                 PMD_DRV_LOG(ERR,
1009                         "Failed to delete rule request due to this rule doesn't exist");
1010                 return -1;
1011         } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
1012                 PMD_DRV_LOG(ERR,
1013                         "Failed to delete rule request due to time out for programming");
1014                 return -1;
1015         } else {
1016                 PMD_DRV_LOG(ERR,
1017                         "Failed to delete rule request due to other reasons");
1018                 return -1;
1019         }
1020
1021         return 0;
1022 };
1023
1024 int
1025 iavf_fdir_check(struct iavf_adapter *adapter,
1026                 struct iavf_fdir_conf *filter)
1027 {
1028         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1029         struct virtchnl_fdir_add *fdir_ret;
1030
1031         struct iavf_cmd_info args;
1032         int err;
1033
1034         filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
1035         filter->add_fltr.validate_only = 1;
1036
1037         args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
1038         args.in_args = (uint8_t *)(&filter->add_fltr);
1039         args.in_args_size = sizeof(*(&filter->add_fltr));
1040         args.out_buffer = vf->aq_resp;
1041         args.out_size = IAVF_AQ_BUF_SZ;
1042
1043         err = iavf_execute_vf_cmd(adapter, &args);
1044         if (err) {
1045                 PMD_DRV_LOG(ERR, "fail to check flow direcotor rule");
1046                 return err;
1047         }
1048
1049         fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
1050
1051         if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1052                 PMD_DRV_LOG(INFO,
1053                         "Succeed in checking rule request by PF");
1054         } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
1055                 PMD_DRV_LOG(ERR,
1056                         "Failed to check rule request due to parameters validation"
1057                         " or HW doesn't support");
1058                 return -1;
1059         } else {
1060                 PMD_DRV_LOG(ERR,
1061                         "Failed to check rule request due to other reasons");
1062                 return -1;
1063         }
1064
1065         return 0;
1066 }
1067
1068 int
1069 iavf_add_del_rss_cfg(struct iavf_adapter *adapter,
1070                      struct virtchnl_rss_cfg *rss_cfg, bool add)
1071 {
1072         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1073         struct iavf_cmd_info args;
1074         int err;
1075
1076         memset(&args, 0, sizeof(args));
1077         args.ops = add ? VIRTCHNL_OP_ADD_RSS_CFG :
1078                 VIRTCHNL_OP_DEL_RSS_CFG;
1079         args.in_args = (u8 *)rss_cfg;
1080         args.in_args_size = sizeof(*rss_cfg);
1081         args.out_buffer = vf->aq_resp;
1082         args.out_size = IAVF_AQ_BUF_SZ;
1083
1084         err = iavf_execute_vf_cmd(adapter, &args);
1085         if (err)
1086                 PMD_DRV_LOG(ERR,
1087                             "Failed to execute command of %s",
1088                             add ? "OP_ADD_RSS_CFG" :
1089                             "OP_DEL_RSS_INPUT_CFG");
1090
1091         return err;
1092 }
1093
1094 int
1095 iavf_add_del_mc_addr_list(struct iavf_adapter *adapter,
1096                         struct rte_ether_addr *mc_addrs,
1097                         uint32_t mc_addrs_num, bool add)
1098 {
1099         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1100         uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
1101                 (IAVF_NUM_MACADDR_MAX * sizeof(struct virtchnl_ether_addr))];
1102         struct virtchnl_ether_addr_list *list;
1103         struct iavf_cmd_info args;
1104         uint32_t i;
1105         int err;
1106
1107         if (mc_addrs == NULL || mc_addrs_num == 0)
1108                 return 0;
1109
1110         if (mc_addrs_num > IAVF_NUM_MACADDR_MAX)
1111                 return -EINVAL;
1112
1113         list = (struct virtchnl_ether_addr_list *)cmd_buffer;
1114         list->vsi_id = vf->vsi_res->vsi_id;
1115         list->num_elements = mc_addrs_num;
1116
1117         for (i = 0; i < mc_addrs_num; i++) {
1118                 if (!IAVF_IS_MULTICAST(mc_addrs[i].addr_bytes)) {
1119                         PMD_DRV_LOG(ERR, "Invalid mac:%x:%x:%x:%x:%x:%x",
1120                                     mc_addrs[i].addr_bytes[0],
1121                                     mc_addrs[i].addr_bytes[1],
1122                                     mc_addrs[i].addr_bytes[2],
1123                                     mc_addrs[i].addr_bytes[3],
1124                                     mc_addrs[i].addr_bytes[4],
1125                                     mc_addrs[i].addr_bytes[5]);
1126                         return -EINVAL;
1127                 }
1128
1129                 memcpy(list->list[i].addr, mc_addrs[i].addr_bytes,
1130                         sizeof(list->list[i].addr));
1131         }
1132
1133         args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
1134         args.in_args = cmd_buffer;
1135         args.in_args_size = sizeof(struct virtchnl_ether_addr_list) +
1136                 i * sizeof(struct virtchnl_ether_addr);
1137         args.out_buffer = vf->aq_resp;
1138         args.out_size = IAVF_AQ_BUF_SZ;
1139         err = iavf_execute_vf_cmd(adapter, &args);
1140
1141         if (err) {
1142                 PMD_DRV_LOG(ERR, "fail to execute command %s",
1143                         add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");
1144                 return err;
1145         }
1146
1147         return 0;
1148 }