1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation.
3 */
4
5 #include <rte_eth_bond.h>
6 #include <rte_eth_bond_8023ad.h>
7
8 #include <cmdline_parse.h>
9 #include <cmdline_parse_etheraddr.h>
10 #include <cmdline_parse_num.h>
11 #include <cmdline_parse_string.h>
12
13 #include "testpmd.h"
14
15 /* *** SET BONDING MODE *** */
16 struct cmd_set_bonding_mode_result {
17 cmdline_fixed_string_t set;
18 cmdline_fixed_string_t bonding;
19 cmdline_fixed_string_t mode;
20 uint8_t value;
21 portid_t port_id;
22 };
23
cmd_set_bonding_mode_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)24 static void cmd_set_bonding_mode_parsed(void *parsed_result,
25 __rte_unused struct cmdline *cl, __rte_unused void *data)
26 {
27 struct cmd_set_bonding_mode_result *res = parsed_result;
28 portid_t port_id = res->port_id;
29 struct rte_port *port = &ports[port_id];
30
31 /*
32 * Bonding mode changed means resources of device changed, like whether
33 * started rte timer or not. Device should be restarted when resources
34 * of device changed.
35 */
36 if (port->port_status != RTE_PORT_STOPPED) {
37 fprintf(stderr,
38 "\t Error: Can't set bonding mode when port %d is not stopped\n",
39 port_id);
40 return;
41 }
42
43 /* Set the bonding mode for the relevant port. */
44 if (rte_eth_bond_mode_set(port_id, res->value) != 0)
45 fprintf(stderr, "\t Failed to set bonding mode for port = %d.\n",
46 port_id);
47 }
48
49 static cmdline_parse_token_string_t cmd_setbonding_mode_set =
50 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
51 set, "set");
52 static cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
53 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
54 bonding, "bonding");
55 static cmdline_parse_token_string_t cmd_setbonding_mode_mode =
56 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
57 mode, "mode");
58 static cmdline_parse_token_num_t cmd_setbonding_mode_value =
59 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
60 value, RTE_UINT8);
61 static cmdline_parse_token_num_t cmd_setbonding_mode_port =
62 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
63 port_id, RTE_UINT16);
64
65 static cmdline_parse_inst_t cmd_set_bonding_mode = {
66 .f = cmd_set_bonding_mode_parsed,
67 .help_str = "set bonding mode <mode_value> <port_id>: "
68 "Set the bonding mode for port_id",
69 .data = NULL,
70 .tokens = {
71 (void *)&cmd_setbonding_mode_set,
72 (void *)&cmd_setbonding_mode_bonding,
73 (void *)&cmd_setbonding_mode_mode,
74 (void *)&cmd_setbonding_mode_value,
75 (void *)&cmd_setbonding_mode_port,
76 NULL
77 }
78 };
79
80 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
81 struct cmd_set_bonding_lacp_dedicated_queues_result {
82 cmdline_fixed_string_t set;
83 cmdline_fixed_string_t bonding;
84 cmdline_fixed_string_t lacp;
85 cmdline_fixed_string_t dedicated_queues;
86 portid_t port_id;
87 cmdline_fixed_string_t mode;
88 };
89
cmd_set_bonding_lacp_dedicated_queues_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)90 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
91 __rte_unused struct cmdline *cl, __rte_unused void *data)
92 {
93 struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
94 portid_t port_id = res->port_id;
95 struct rte_port *port;
96
97 port = &ports[port_id];
98
99 /** Check if the port is not started **/
100 if (port->port_status != RTE_PORT_STOPPED) {
101 fprintf(stderr, "Please stop port %d first\n", port_id);
102 return;
103 }
104
105 if (!strcmp(res->mode, "enable")) {
106 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
107 printf("Dedicate queues for LACP control packets"
108 " enabled\n");
109 else
110 printf("Enabling dedicate queues for LACP control "
111 "packets on port %d failed\n", port_id);
112 } else if (!strcmp(res->mode, "disable")) {
113 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
114 printf("Dedicated queues for LACP control packets "
115 "disabled\n");
116 else
117 printf("Disabling dedicated queues for LACP control "
118 "traffic on port %d failed\n", port_id);
119 }
120 }
121
122 static cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
123 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
124 set, "set");
125 static cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
126 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
127 bonding, "bonding");
128 static cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
129 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
130 lacp, "lacp");
131 static cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
132 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
133 dedicated_queues, "dedicated_queues");
134 static cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
135 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
136 port_id, RTE_UINT16);
137 static cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
138 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
139 mode, "enable#disable");
140
141 static cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
142 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
143 .help_str = "set bonding lacp dedicated_queues <port_id> "
144 "enable|disable: "
145 "Enable/disable dedicated queues for LACP control traffic for port_id",
146 .data = NULL,
147 .tokens = {
148 (void *)&cmd_setbonding_lacp_dedicated_queues_set,
149 (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
150 (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
151 (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
152 (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
153 (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
154 NULL
155 }
156 };
157
158 /* *** SET BALANCE XMIT POLICY *** */
159 struct cmd_set_bonding_balance_xmit_policy_result {
160 cmdline_fixed_string_t set;
161 cmdline_fixed_string_t bonding;
162 cmdline_fixed_string_t balance_xmit_policy;
163 portid_t port_id;
164 cmdline_fixed_string_t policy;
165 };
166
cmd_set_bonding_balance_xmit_policy_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)167 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
168 __rte_unused struct cmdline *cl, __rte_unused void *data)
169 {
170 struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
171 portid_t port_id = res->port_id;
172 uint8_t policy;
173
174 if (!strcmp(res->policy, "l2")) {
175 policy = BALANCE_XMIT_POLICY_LAYER2;
176 } else if (!strcmp(res->policy, "l23")) {
177 policy = BALANCE_XMIT_POLICY_LAYER23;
178 } else if (!strcmp(res->policy, "l34")) {
179 policy = BALANCE_XMIT_POLICY_LAYER34;
180 } else {
181 fprintf(stderr, "\t Invalid xmit policy selection");
182 return;
183 }
184
185 /* Set the bonding mode for the relevant port. */
186 if (rte_eth_bond_xmit_policy_set(port_id, policy) != 0) {
187 fprintf(stderr,
188 "\t Failed to set bonding balance xmit policy for port = %d.\n",
189 port_id);
190 }
191 }
192
193 static cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
194 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
195 set, "set");
196 static cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
197 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
198 bonding, "bonding");
199 static cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
200 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
201 balance_xmit_policy, "balance_xmit_policy");
202 static cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
203 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
204 port_id, RTE_UINT16);
205 static cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
206 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
207 policy, "l2#l23#l34");
208
209 static cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
210 .f = cmd_set_bonding_balance_xmit_policy_parsed,
211 .help_str = "set bonding balance_xmit_policy <port_id> "
212 "l2|l23|l34: "
213 "Set the bonding balance_xmit_policy for port_id",
214 .data = NULL,
215 .tokens = {
216 (void *)&cmd_setbonding_balance_xmit_policy_set,
217 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
218 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
219 (void *)&cmd_setbonding_balance_xmit_policy_port,
220 (void *)&cmd_setbonding_balance_xmit_policy_policy,
221 NULL
222 }
223 };
224
225 /* *** SHOW NIC BONDING CONFIGURATION *** */
226 struct cmd_show_bonding_config_result {
227 cmdline_fixed_string_t show;
228 cmdline_fixed_string_t bonding;
229 cmdline_fixed_string_t config;
230 portid_t port_id;
231 };
232
cmd_show_bonding_config_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)233 static void cmd_show_bonding_config_parsed(void *parsed_result,
234 __rte_unused struct cmdline *cl, __rte_unused void *data)
235 {
236 struct cmd_show_bonding_config_result *res = parsed_result;
237 portid_t port_id = res->port_id;
238 int bonding_mode;
239
240 bonding_mode = rte_eth_bond_mode_get(port_id);
241 if (bonding_mode < 0) {
242 fprintf(stderr, "\tFailed to get bonding mode for port = %d\n",
243 port_id);
244 return;
245 }
246
247 (void)rte_eth_dev_priv_dump(port_id, stdout);
248 }
249
250 static cmdline_parse_token_string_t cmd_showbonding_config_show =
251 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
252 show, "show");
253 static cmdline_parse_token_string_t cmd_showbonding_config_bonding =
254 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
255 bonding, "bonding");
256 static cmdline_parse_token_string_t cmd_showbonding_config_config =
257 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
258 config, "config");
259 static cmdline_parse_token_num_t cmd_showbonding_config_port =
260 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
261 port_id, RTE_UINT16);
262
263 static cmdline_parse_inst_t cmd_show_bonding_config = {
264 .f = cmd_show_bonding_config_parsed,
265 .help_str = "show bonding config <port_id>: "
266 "Show the bonding config for port_id",
267 .data = NULL,
268 .tokens = {
269 (void *)&cmd_showbonding_config_show,
270 (void *)&cmd_showbonding_config_bonding,
271 (void *)&cmd_showbonding_config_config,
272 (void *)&cmd_showbonding_config_port,
273 NULL
274 }
275 };
276
277 /* *** SET BONDING PRIMARY *** */
278 struct cmd_set_bonding_primary_result {
279 cmdline_fixed_string_t set;
280 cmdline_fixed_string_t bonding;
281 cmdline_fixed_string_t primary;
282 portid_t member_id;
283 portid_t port_id;
284 };
285
cmd_set_bonding_primary_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)286 static void cmd_set_bonding_primary_parsed(void *parsed_result,
287 __rte_unused struct cmdline *cl, __rte_unused void *data)
288 {
289 struct cmd_set_bonding_primary_result *res = parsed_result;
290 portid_t main_port_id = res->port_id;
291 portid_t member_port_id = res->member_id;
292
293 /* Set the primary member for a bonding device. */
294 if (rte_eth_bond_primary_set(main_port_id, member_port_id) != 0) {
295 fprintf(stderr, "\t Failed to set primary member for port = %d.\n",
296 main_port_id);
297 return;
298 }
299 init_port_config();
300 }
301
302 static cmdline_parse_token_string_t cmd_setbonding_primary_set =
303 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
304 set, "set");
305 static cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
306 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
307 bonding, "bonding");
308 static cmdline_parse_token_string_t cmd_setbonding_primary_primary =
309 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
310 primary, "primary");
311 static cmdline_parse_token_num_t cmd_setbonding_primary_member =
312 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
313 member_id, RTE_UINT16);
314 static cmdline_parse_token_num_t cmd_setbonding_primary_port =
315 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
316 port_id, RTE_UINT16);
317
318 static cmdline_parse_inst_t cmd_set_bonding_primary = {
319 .f = cmd_set_bonding_primary_parsed,
320 .help_str = "set bonding primary <member_id> <port_id>: "
321 "Set the primary member for port_id",
322 .data = NULL,
323 .tokens = {
324 (void *)&cmd_setbonding_primary_set,
325 (void *)&cmd_setbonding_primary_bonding,
326 (void *)&cmd_setbonding_primary_primary,
327 (void *)&cmd_setbonding_primary_member,
328 (void *)&cmd_setbonding_primary_port,
329 NULL
330 }
331 };
332
333 /* *** ADD Member *** */
334 struct cmd_add_bonding_member_result {
335 cmdline_fixed_string_t add;
336 cmdline_fixed_string_t bonding;
337 cmdline_fixed_string_t member;
338 portid_t member_id;
339 portid_t port_id;
340 };
341
cmd_add_bonding_member_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)342 static void cmd_add_bonding_member_parsed(void *parsed_result,
343 __rte_unused struct cmdline *cl, __rte_unused void *data)
344 {
345 struct cmd_add_bonding_member_result *res = parsed_result;
346 portid_t main_port_id = res->port_id;
347 portid_t member_port_id = res->member_id;
348
349 /* add the member for a bonding device. */
350 if (rte_eth_bond_member_add(main_port_id, member_port_id) != 0) {
351 fprintf(stderr,
352 "\t Failed to add member %d to main port = %d.\n",
353 member_port_id, main_port_id);
354 return;
355 }
356 ports[main_port_id].update_conf = 1;
357 init_port_config();
358 set_port_member_flag(member_port_id);
359 }
360
361 static cmdline_parse_token_string_t cmd_addbonding_member_add =
362 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_member_result,
363 add, "add");
364 static cmdline_parse_token_string_t cmd_addbonding_member_bonding =
365 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_member_result,
366 bonding, "bonding");
367 static cmdline_parse_token_string_t cmd_addbonding_member_member =
368 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_member_result,
369 member, "member");
370 static cmdline_parse_token_num_t cmd_addbonding_member_memberid =
371 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_member_result,
372 member_id, RTE_UINT16);
373 static cmdline_parse_token_num_t cmd_addbonding_member_port =
374 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_member_result,
375 port_id, RTE_UINT16);
376
377 static cmdline_parse_inst_t cmd_add_bonding_member = {
378 .f = cmd_add_bonding_member_parsed,
379 .help_str = "add bonding member <member_id> <port_id>: "
380 "Add a member device to a bonding device",
381 .data = NULL,
382 .tokens = {
383 (void *)&cmd_addbonding_member_add,
384 (void *)&cmd_addbonding_member_bonding,
385 (void *)&cmd_addbonding_member_member,
386 (void *)&cmd_addbonding_member_memberid,
387 (void *)&cmd_addbonding_member_port,
388 NULL
389 }
390 };
391
392 /* *** REMOVE Member *** */
393 struct cmd_remove_bonding_member_result {
394 cmdline_fixed_string_t remove;
395 cmdline_fixed_string_t bonding;
396 cmdline_fixed_string_t member;
397 portid_t member_id;
398 portid_t port_id;
399 };
400
cmd_remove_bonding_member_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)401 static void cmd_remove_bonding_member_parsed(void *parsed_result,
402 __rte_unused struct cmdline *cl, __rte_unused void *data)
403 {
404 struct cmd_remove_bonding_member_result *res = parsed_result;
405 portid_t main_port_id = res->port_id;
406 portid_t member_port_id = res->member_id;
407
408 /* remove the member from a bonding device. */
409 if (rte_eth_bond_member_remove(main_port_id, member_port_id) != 0) {
410 fprintf(stderr,
411 "\t Failed to remove member %d from main port = %d.\n",
412 member_port_id, main_port_id);
413 return;
414 }
415 init_port_config();
416 clear_port_member_flag(member_port_id);
417 }
418
419 static cmdline_parse_token_string_t cmd_removebonding_member_remove =
420 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_member_result,
421 remove, "remove");
422 static cmdline_parse_token_string_t cmd_removebonding_member_bonding =
423 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_member_result,
424 bonding, "bonding");
425 static cmdline_parse_token_string_t cmd_removebonding_member_member =
426 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_member_result,
427 member, "member");
428 static cmdline_parse_token_num_t cmd_removebonding_member_memberid =
429 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_member_result,
430 member_id, RTE_UINT16);
431 static cmdline_parse_token_num_t cmd_removebonding_member_port =
432 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_member_result,
433 port_id, RTE_UINT16);
434
435 static cmdline_parse_inst_t cmd_remove_bonding_member = {
436 .f = cmd_remove_bonding_member_parsed,
437 .help_str = "remove bonding member <member_id> <port_id>: "
438 "Remove a member device from a bonding device",
439 .data = NULL,
440 .tokens = {
441 (void *)&cmd_removebonding_member_remove,
442 (void *)&cmd_removebonding_member_bonding,
443 (void *)&cmd_removebonding_member_member,
444 (void *)&cmd_removebonding_member_memberid,
445 (void *)&cmd_removebonding_member_port,
446 NULL
447 }
448 };
449
450 /* *** CREATE BONDING DEVICE *** */
451 struct cmd_create_bonding_device_result {
452 cmdline_fixed_string_t create;
453 cmdline_fixed_string_t bonding;
454 cmdline_fixed_string_t device;
455 uint8_t mode;
456 uint8_t socket;
457 };
458
459 static int bond_dev_num;
460
cmd_create_bonding_device_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)461 static void cmd_create_bonding_device_parsed(void *parsed_result,
462 __rte_unused struct cmdline *cl, __rte_unused void *data)
463 {
464 struct cmd_create_bonding_device_result *res = parsed_result;
465 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
466 int port_id;
467 int ret;
468
469 if (test_done == 0) {
470 fprintf(stderr, "Please stop forwarding first\n");
471 return;
472 }
473
474 snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
475 bond_dev_num++);
476
477 /* Create a new bonding device. */
478 port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
479 if (port_id < 0) {
480 fprintf(stderr, "\t Failed to create bonding device.\n");
481 return;
482 }
483 printf("Created new bonding device %s on (port %d).\n", ethdev_name,
484 port_id);
485
486 /* Update number of ports */
487 nb_ports = rte_eth_dev_count_avail();
488 reconfig(port_id, res->socket);
489 ret = rte_eth_promiscuous_enable(port_id);
490 if (ret != 0)
491 fprintf(stderr, "Failed to enable promiscuous mode for port %u: %s - ignore\n",
492 port_id, rte_strerror(-ret));
493
494 ports[port_id].update_conf = 1;
495 ports[port_id].bond_flag = 1;
496 ports[port_id].need_setup = 0;
497 ports[port_id].port_status = RTE_PORT_STOPPED;
498 }
499
500 static cmdline_parse_token_string_t cmd_createbonding_device_create =
501 TOKEN_STRING_INITIALIZER(struct cmd_create_bonding_device_result,
502 create, "create");
503 static cmdline_parse_token_string_t cmd_createbonding_device_bonding =
504 TOKEN_STRING_INITIALIZER(struct cmd_create_bonding_device_result,
505 bonding, "bonding");
506 static cmdline_parse_token_string_t cmd_createbonding_device_device =
507 TOKEN_STRING_INITIALIZER(struct cmd_create_bonding_device_result,
508 device, "device");
509 static cmdline_parse_token_num_t cmd_createbonding_device_mode =
510 TOKEN_NUM_INITIALIZER(struct cmd_create_bonding_device_result,
511 mode, RTE_UINT8);
512 static cmdline_parse_token_num_t cmd_createbonding_device_socket =
513 TOKEN_NUM_INITIALIZER(struct cmd_create_bonding_device_result,
514 socket, RTE_UINT8);
515
516 static cmdline_parse_inst_t cmd_create_bonding_device = {
517 .f = cmd_create_bonding_device_parsed,
518 .help_str = "create bonding device <mode> <socket>: "
519 "Create a new bonding device with specific bonding mode and socket",
520 .data = NULL,
521 .tokens = {
522 (void *)&cmd_createbonding_device_create,
523 (void *)&cmd_createbonding_device_bonding,
524 (void *)&cmd_createbonding_device_device,
525 (void *)&cmd_createbonding_device_mode,
526 (void *)&cmd_createbonding_device_socket,
527 NULL
528 }
529 };
530
531 /* *** SET MAC ADDRESS IN BONDING DEVICE *** */
532 struct cmd_set_bond_mac_addr_result {
533 cmdline_fixed_string_t set;
534 cmdline_fixed_string_t bonding;
535 cmdline_fixed_string_t mac_addr;
536 uint16_t port_num;
537 struct rte_ether_addr address;
538 };
539
cmd_set_bond_mac_addr_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)540 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
541 __rte_unused struct cmdline *cl, __rte_unused void *data)
542 {
543 struct cmd_set_bond_mac_addr_result *res = parsed_result;
544 int ret;
545
546 if (port_id_is_invalid(res->port_num, ENABLED_WARN))
547 return;
548
549 ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
550
551 /* check the return value and print it if is < 0 */
552 if (ret < 0)
553 fprintf(stderr, "set_bond_mac_addr error: (%s)\n",
554 strerror(-ret));
555 }
556
557 static cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
558 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result,
559 set, "set");
560 static cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
561 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result,
562 bonding, "bonding");
563 static cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
564 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result,
565 mac_addr, "mac_addr");
566 static cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
567 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
568 port_num, RTE_UINT16);
569 static cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
570 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result,
571 address);
572
573 static cmdline_parse_inst_t cmd_set_bond_mac_addr = {
574 .f = cmd_set_bond_mac_addr_parsed,
575 .data = NULL,
576 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
577 .tokens = {
578 (void *)&cmd_set_bond_mac_addr_set,
579 (void *)&cmd_set_bond_mac_addr_bonding,
580 (void *)&cmd_set_bond_mac_addr_mac,
581 (void *)&cmd_set_bond_mac_addr_portnum,
582 (void *)&cmd_set_bond_mac_addr_addr,
583 NULL
584 }
585 };
586
587 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDING DEVICE *** */
588 struct cmd_set_bond_mon_period_result {
589 cmdline_fixed_string_t set;
590 cmdline_fixed_string_t bonding;
591 cmdline_fixed_string_t mon_period;
592 uint16_t port_num;
593 uint32_t period_ms;
594 };
595
cmd_set_bond_mon_period_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)596 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
597 __rte_unused struct cmdline *cl, __rte_unused void *data)
598 {
599 struct cmd_set_bond_mon_period_result *res = parsed_result;
600 int ret;
601
602 ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
603
604 /* check the return value and print it if is < 0 */
605 if (ret < 0)
606 fprintf(stderr, "set_bond_mac_addr error: (%s)\n",
607 strerror(-ret));
608 }
609
610 static cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
611 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
612 set, "set");
613 static cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
614 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
615 bonding, "bonding");
616 static cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
617 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
618 mon_period, "mon_period");
619 static cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
620 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
621 port_num, RTE_UINT16);
622 static cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
623 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
624 period_ms, RTE_UINT32);
625
626 static cmdline_parse_inst_t cmd_set_bond_mon_period = {
627 .f = cmd_set_bond_mon_period_parsed,
628 .data = NULL,
629 .help_str = "set bonding mon_period <port_id> <period_ms>",
630 .tokens = {
631 (void *)&cmd_set_bond_mon_period_set,
632 (void *)&cmd_set_bond_mon_period_bonding,
633 (void *)&cmd_set_bond_mon_period_mon_period,
634 (void *)&cmd_set_bond_mon_period_portnum,
635 (void *)&cmd_set_bond_mon_period_period_ms,
636 NULL
637 }
638 };
639
640 struct cmd_set_bonding_agg_mode_policy_result {
641 cmdline_fixed_string_t set;
642 cmdline_fixed_string_t bonding;
643 cmdline_fixed_string_t agg_mode;
644 uint16_t port_num;
645 cmdline_fixed_string_t policy;
646 };
647
648 static void
cmd_set_bonding_agg_mode(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)649 cmd_set_bonding_agg_mode(void *parsed_result,
650 __rte_unused struct cmdline *cl, __rte_unused void *data)
651 {
652 struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
653 uint8_t policy = AGG_BANDWIDTH;
654
655 if (!strcmp(res->policy, "bandwidth"))
656 policy = AGG_BANDWIDTH;
657 else if (!strcmp(res->policy, "stable"))
658 policy = AGG_STABLE;
659 else if (!strcmp(res->policy, "count"))
660 policy = AGG_COUNT;
661
662 rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
663 }
664
665 static cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
666 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
667 set, "set");
668 static cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
669 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
670 bonding, "bonding");
671 static cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
672 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
673 agg_mode, "agg_mode");
674 static cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
675 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
676 port_num, RTE_UINT16);
677 static cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
678 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
679 policy, "stable#bandwidth#count");
680
681 static cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
682 .f = cmd_set_bonding_agg_mode,
683 .data = NULL,
684 .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
685 .tokens = {
686 (void *)&cmd_set_bonding_agg_mode_set,
687 (void *)&cmd_set_bonding_agg_mode_bonding,
688 (void *)&cmd_set_bonding_agg_mode_agg_mode,
689 (void *)&cmd_set_bonding_agg_mode_portnum,
690 (void *)&cmd_set_bonding_agg_mode_policy_string,
691 NULL
692 }
693 };
694
695 static struct testpmd_driver_commands bonding_cmds = {
696 .commands = {
697 {
698 &cmd_set_bonding_mode,
699 "set bonding mode (value) (port_id)\n"
700 " Set the bonding mode on a bonding device.\n",
701 },
702 {
703 &cmd_show_bonding_config,
704 "show bonding config (port_id)\n"
705 " Show the bonding config for port_id.\n",
706 },
707 {
708 &cmd_set_bonding_primary,
709 "set bonding primary (member_id) (port_id)\n"
710 " Set the primary member for a bonding device.\n",
711 },
712 {
713 &cmd_add_bonding_member,
714 "add bonding member (member_id) (port_id)\n"
715 " Add a member device to a bonding device.\n",
716 },
717 {
718 &cmd_remove_bonding_member,
719 "remove bonding member (member_id) (port_id)\n"
720 " Remove a member device from a bonding device.\n",
721 },
722 {
723 &cmd_create_bonding_device,
724 "create bonding device (mode) (socket)\n"
725 " Create a new bonding device with specific bonding mode and socket.\n",
726 },
727 {
728 &cmd_set_bond_mac_addr,
729 "set bonding mac_addr (port_id) (address)\n"
730 " Set the MAC address of a bonding device.\n",
731 },
732 {
733 &cmd_set_balance_xmit_policy,
734 "set bonding balance_xmit_policy (port_id) (l2|l23|l34)\n"
735 " Set the transmit balance policy for bonding device running in balance mode.\n",
736 },
737 {
738 &cmd_set_bond_mon_period,
739 "set bonding mon_period (port_id) (value)\n"
740 " Set the bonding link status monitoring polling period in ms.\n",
741 },
742 {
743 &cmd_set_lacp_dedicated_queues,
744 "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
745 " Enable/disable dedicated queues for LACP control traffic.\n",
746 },
747 {
748 &cmd_set_bonding_agg_mode_policy,
749 "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)\n"
750 " Set Aggregation mode for IEEE802.3AD (mode 4)\n",
751 },
752 { NULL, NULL },
753 },
754 };
755 TESTPMD_ADD_DRIVER_COMMANDS(bonding_cmds)
756