1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015 Intel Corporation
5 #include <cmdline_parse.h>
6 #include <cmdline_parse_num.h>
7 #include <cmdline_parse_string.h>
8 #include <cmdline_parse_etheraddr.h>
9 #include <cmdline_socket.h>
12 #include "rte_ethtool.h"
15 #define EEPROM_DUMP_CHUNKSIZE 1024
18 struct pcmd_get_params {
19 cmdline_fixed_string_t cmd;
21 struct pcmd_int_params {
22 cmdline_fixed_string_t cmd;
25 struct pcmd_intstr_params {
26 cmdline_fixed_string_t cmd;
28 cmdline_fixed_string_t opt;
30 struct pcmd_intmac_params {
31 cmdline_fixed_string_t cmd;
33 struct rte_ether_addr mac;
35 struct pcmd_str_params {
36 cmdline_fixed_string_t cmd;
37 cmdline_fixed_string_t opt;
39 struct pcmd_vlan_params {
40 cmdline_fixed_string_t cmd;
42 cmdline_fixed_string_t mode;
45 struct pcmd_intintint_params {
46 cmdline_fixed_string_t cmd;
53 /* Parameter-less commands */
54 cmdline_parse_token_string_t pcmd_quit_token_cmd =
55 TOKEN_STRING_INITIALIZER(struct pcmd_get_params, cmd, "quit");
56 cmdline_parse_token_string_t pcmd_stats_token_cmd =
57 TOKEN_STRING_INITIALIZER(struct pcmd_get_params, cmd, "stats");
58 cmdline_parse_token_string_t pcmd_drvinfo_token_cmd =
59 TOKEN_STRING_INITIALIZER(struct pcmd_get_params, cmd, "drvinfo");
60 cmdline_parse_token_string_t pcmd_link_token_cmd =
61 TOKEN_STRING_INITIALIZER(struct pcmd_get_params, cmd, "link");
63 /* Commands taking just port id */
64 cmdline_parse_token_string_t pcmd_open_token_cmd =
65 TOKEN_STRING_INITIALIZER(struct pcmd_int_params, cmd, "open");
66 cmdline_parse_token_string_t pcmd_stop_token_cmd =
67 TOKEN_STRING_INITIALIZER(struct pcmd_int_params, cmd, "stop");
68 cmdline_parse_token_string_t pcmd_rxmode_token_cmd =
69 TOKEN_STRING_INITIALIZER(struct pcmd_int_params, cmd, "rxmode");
70 cmdline_parse_token_string_t pcmd_portstats_token_cmd =
71 TOKEN_STRING_INITIALIZER(struct pcmd_int_params, cmd, "portstats");
72 cmdline_parse_token_num_t pcmd_int_token_port =
73 TOKEN_NUM_INITIALIZER(struct pcmd_int_params, port, RTE_UINT16);
75 /* Commands taking port id and string */
76 cmdline_parse_token_string_t pcmd_eeprom_token_cmd =
77 TOKEN_STRING_INITIALIZER(struct pcmd_intstr_params, cmd, "eeprom");
78 cmdline_parse_token_string_t pcmd_module_eeprom_token_cmd =
79 TOKEN_STRING_INITIALIZER(struct pcmd_intstr_params, cmd,
81 cmdline_parse_token_string_t pcmd_mtu_token_cmd =
82 TOKEN_STRING_INITIALIZER(struct pcmd_intstr_params, cmd, "mtu");
83 cmdline_parse_token_string_t pcmd_regs_token_cmd =
84 TOKEN_STRING_INITIALIZER(struct pcmd_intstr_params, cmd, "regs");
86 cmdline_parse_token_num_t pcmd_intstr_token_port =
87 TOKEN_NUM_INITIALIZER(struct pcmd_intstr_params, port, RTE_UINT16);
88 cmdline_parse_token_string_t pcmd_intstr_token_opt =
89 TOKEN_STRING_INITIALIZER(struct pcmd_intstr_params, opt, NULL);
91 /* Commands taking port id and a MAC address string */
92 cmdline_parse_token_string_t pcmd_macaddr_token_cmd =
93 TOKEN_STRING_INITIALIZER(struct pcmd_intmac_params, cmd, "macaddr");
94 cmdline_parse_token_num_t pcmd_intmac_token_port =
95 TOKEN_NUM_INITIALIZER(struct pcmd_intmac_params, port, RTE_UINT16);
96 cmdline_parse_token_etheraddr_t pcmd_intmac_token_mac =
97 TOKEN_ETHERADDR_INITIALIZER(struct pcmd_intmac_params, mac);
99 /* Command taking just a MAC address */
100 cmdline_parse_token_string_t pcmd_validate_token_cmd =
101 TOKEN_STRING_INITIALIZER(struct pcmd_intmac_params, cmd, "validate");
104 /* Commands taking port id and two integers */
105 cmdline_parse_token_string_t pcmd_ringparam_token_cmd =
106 TOKEN_STRING_INITIALIZER(struct pcmd_intintint_params, cmd,
108 cmdline_parse_token_num_t pcmd_intintint_token_port =
109 TOKEN_NUM_INITIALIZER(struct pcmd_intintint_params, port,
111 cmdline_parse_token_num_t pcmd_intintint_token_tx =
112 TOKEN_NUM_INITIALIZER(struct pcmd_intintint_params, tx, RTE_UINT16);
113 cmdline_parse_token_num_t pcmd_intintint_token_rx =
114 TOKEN_NUM_INITIALIZER(struct pcmd_intintint_params, rx, RTE_UINT16);
118 cmdline_parse_token_string_t pcmd_pause_token_cmd =
119 TOKEN_STRING_INITIALIZER(struct pcmd_intstr_params, cmd, "pause");
120 cmdline_parse_token_num_t pcmd_pause_token_port =
121 TOKEN_NUM_INITIALIZER(struct pcmd_intstr_params, port, RTE_UINT16);
122 cmdline_parse_token_string_t pcmd_pause_token_opt =
123 TOKEN_STRING_INITIALIZER(struct pcmd_intstr_params,
124 opt, "all#tx#rx#none");
127 cmdline_parse_token_string_t pcmd_vlan_token_cmd =
128 TOKEN_STRING_INITIALIZER(struct pcmd_vlan_params, cmd, "vlan");
129 cmdline_parse_token_num_t pcmd_vlan_token_port =
130 TOKEN_NUM_INITIALIZER(struct pcmd_vlan_params, port, RTE_UINT16);
131 cmdline_parse_token_string_t pcmd_vlan_token_mode =
132 TOKEN_STRING_INITIALIZER(struct pcmd_vlan_params, mode, "add#del");
133 cmdline_parse_token_num_t pcmd_vlan_token_vid =
134 TOKEN_NUM_INITIALIZER(struct pcmd_vlan_params, vid, RTE_UINT16);
138 pcmd_quit_callback(__rte_unused void *ptr_params,
140 __rte_unused void *ptr_data)
147 pcmd_drvinfo_callback(__rte_unused void *ptr_params,
148 __rte_unused struct cmdline *ctx,
149 __rte_unused void *ptr_data)
151 struct ethtool_drvinfo info;
154 RTE_ETH_FOREACH_DEV(id_port) {
155 memset(&info, 0, sizeof(info));
156 if (rte_ethtool_get_drvinfo(id_port, &info)) {
157 printf("Error getting info for port %i\n", id_port);
160 printf("Port %i driver: %s (ver: %s)\n",
161 id_port, info.driver, info.version
163 printf("firmware-version: %s\n", info.fw_version);
164 printf("bus-info: %s\n", info.bus_info);
170 pcmd_link_callback(__rte_unused void *ptr_params,
171 __rte_unused struct cmdline *ctx,
172 __rte_unused void *ptr_data)
177 RTE_ETH_FOREACH_DEV(id_port) {
178 if (!rte_eth_dev_is_valid_port(id_port))
180 stat_port = rte_ethtool_get_link(id_port);
183 printf("Port %i: Down\n", id_port);
186 printf("Port %i: Up\n", id_port);
189 printf("Port %i: Error getting link status\n",
200 pcmd_regs_callback(void *ptr_params,
201 __rte_unused struct cmdline *ctx,
202 __rte_unused void *ptr_data)
204 struct pcmd_intstr_params *params = ptr_params;
206 struct ethtool_regs regs;
207 unsigned char *buf_data;
210 if (!rte_eth_dev_is_valid_port(params->port)) {
211 printf("Error: Invalid port number %i\n", params->port);
214 len_regs = rte_ethtool_get_regs_len(params->port);
216 printf("Port %i: %i bytes\n", params->port, len_regs);
217 buf_data = malloc(len_regs);
218 if (buf_data == NULL) {
219 printf("Error allocating %i bytes for buffer\n",
223 if (!rte_ethtool_get_regs(params->port, ®s, buf_data)) {
224 fp_regs = fopen(params->opt, "wb");
225 if (fp_regs == NULL) {
226 printf("Error opening '%s' for writing\n",
229 if ((int)fwrite(buf_data,
231 fp_regs) != len_regs)
232 printf("Error writing '%s'\n",
238 } else if (len_regs == -ENOTSUP)
239 printf("Port %i: Operation not supported\n", params->port);
241 printf("Port %i: Error getting registers\n", params->port);
246 pcmd_eeprom_callback(void *ptr_params,
247 __rte_unused struct cmdline *ctx,
248 __rte_unused void *ptr_data)
250 struct pcmd_intstr_params *params = ptr_params;
251 struct ethtool_eeprom info_eeprom;
255 unsigned char bytes_eeprom[EEPROM_DUMP_CHUNKSIZE];
258 if (!rte_eth_dev_is_valid_port(params->port)) {
259 printf("Error: Invalid port number %i\n", params->port);
262 len_eeprom = rte_ethtool_get_eeprom_len(params->port);
263 if (len_eeprom > 0) {
264 fp_eeprom = fopen(params->opt, "wb");
265 if (fp_eeprom == NULL) {
266 printf("Error opening '%s' for writing\n",
270 printf("Total EEPROM length: %i bytes\n", len_eeprom);
271 info_eeprom.len = EEPROM_DUMP_CHUNKSIZE;
273 pos_eeprom < len_eeprom;
274 pos_eeprom += EEPROM_DUMP_CHUNKSIZE) {
275 info_eeprom.offset = pos_eeprom;
276 if (pos_eeprom + EEPROM_DUMP_CHUNKSIZE > len_eeprom)
277 info_eeprom.len = len_eeprom - pos_eeprom;
279 info_eeprom.len = EEPROM_DUMP_CHUNKSIZE;
280 stat = rte_ethtool_get_eeprom(
281 params->port, &info_eeprom, bytes_eeprom
284 printf("EEPROM read error %i\n", stat);
287 if (fwrite(bytes_eeprom,
289 fp_eeprom) != info_eeprom.len) {
290 printf("Error writing '%s'\n", params->opt);
295 } else if (len_eeprom == 0)
296 printf("Port %i: Device does not have EEPROM\n", params->port);
297 else if (len_eeprom == -ENOTSUP)
298 printf("Port %i: Operation not supported\n", params->port);
300 printf("Port %i: Error getting EEPROM\n", params->port);
305 pcmd_module_eeprom_callback(void *ptr_params,
306 __rte_unused struct cmdline *ctx,
307 __rte_unused void *ptr_data)
309 struct pcmd_intstr_params *params = ptr_params;
310 struct ethtool_eeprom info_eeprom;
311 uint32_t module_info[2];
313 unsigned char bytes_eeprom[EEPROM_DUMP_CHUNKSIZE];
316 if (!rte_eth_dev_is_valid_port(params->port)) {
317 printf("Error: Invalid port number %i\n", params->port);
321 stat = rte_ethtool_get_module_info(params->port, module_info);
323 printf("Module EEPROM information read error %i\n", stat);
327 info_eeprom.len = module_info[1];
328 info_eeprom.offset = 0;
330 stat = rte_ethtool_get_module_eeprom(params->port,
331 &info_eeprom, bytes_eeprom);
333 printf("Module EEPROM read error %i\n", stat);
337 fp_eeprom = fopen(params->opt, "wb");
338 if (fp_eeprom == NULL) {
339 printf("Error opening '%s' for writing\n", params->opt);
342 printf("Total plugin module EEPROM length: %i bytes\n",
344 if (fwrite(bytes_eeprom, 1, info_eeprom.len,
345 fp_eeprom) != info_eeprom.len) {
346 printf("Error writing '%s'\n", params->opt);
353 pcmd_pause_callback(void *ptr_params,
354 __rte_unused struct cmdline *ctx,
357 struct pcmd_intstr_params *params = ptr_params;
358 struct ethtool_pauseparam info;
361 if (!rte_eth_dev_is_valid_port(params->port)) {
362 printf("Error: Invalid port number %i\n", params->port);
365 if (ptr_data != NULL) {
366 stat = rte_ethtool_get_pauseparam(params->port, &info);
368 memset(&info, 0, sizeof(info));
369 if (strcasecmp("all", params->opt) == 0) {
372 } else if (strcasecmp("tx", params->opt) == 0) {
375 } else if (strcasecmp("rx", params->opt) == 0) {
382 /* Assume auto-negotiation wanted */
384 stat = rte_ethtool_set_pauseparam(params->port, &info);
387 if (info.rx_pause && info.tx_pause)
388 printf("Port %i: Tx & Rx Paused\n", params->port);
389 else if (info.rx_pause)
390 printf("Port %i: Rx Paused\n", params->port);
391 else if (info.tx_pause)
392 printf("Port %i: Tx Paused\n", params->port);
394 printf("Port %i: Tx & Rx not paused\n", params->port);
395 } else if (stat == -ENOTSUP)
396 printf("Port %i: Operation not supported\n", params->port);
398 printf("Port %i: Error %i\n", params->port, stat);
403 pcmd_open_callback(__rte_unused void *ptr_params,
404 __rte_unused struct cmdline *ctx,
405 __rte_unused void *ptr_data)
407 struct pcmd_int_params *params = ptr_params;
410 if (!rte_eth_dev_is_valid_port(params->port)) {
411 printf("Error: Invalid port number %i\n", params->port);
414 lock_port(params->port);
415 stat = rte_ethtool_net_open(params->port);
416 mark_port_active(params->port);
417 unlock_port(params->port);
420 else if (stat == -ENOTSUP)
421 printf("Port %i: Operation not supported\n", params->port);
423 printf("Port %i: Error opening device\n", params->port);
427 pcmd_stop_callback(__rte_unused void *ptr_params,
428 __rte_unused struct cmdline *ctx,
429 __rte_unused void *ptr_data)
431 struct pcmd_int_params *params = ptr_params;
434 if (!rte_eth_dev_is_valid_port(params->port)) {
435 printf("Error: Invalid port number %i\n", params->port);
438 lock_port(params->port);
439 stat = rte_ethtool_net_stop(params->port);
440 mark_port_inactive(params->port);
441 unlock_port(params->port);
444 else if (stat == -ENOTSUP)
445 printf("Port %i: Operation not supported\n", params->port);
447 printf("Port %i: Error stopping device\n", params->port);
452 pcmd_rxmode_callback(void *ptr_params,
453 __rte_unused struct cmdline *ctx,
454 __rte_unused void *ptr_data)
456 struct pcmd_intstr_params *params = ptr_params;
459 if (!rte_eth_dev_is_valid_port(params->port)) {
460 printf("Error: Invalid port number %i\n", params->port);
463 stat = rte_ethtool_net_set_rx_mode(params->port);
466 else if (stat == -ENOTSUP)
467 printf("Port %i: Operation not supported\n", params->port);
469 printf("Port %i: Error setting rx mode\n", params->port);
474 pcmd_macaddr_callback(void *ptr_params,
475 __rte_unused struct cmdline *ctx,
478 struct pcmd_intmac_params *params = ptr_params;
479 struct rte_ether_addr mac_addr;
483 if (!rte_eth_dev_is_valid_port(params->port)) {
484 printf("Error: Invalid port number %i\n", params->port);
487 if (ptr_data != NULL) {
488 lock_port(params->port);
489 stat = rte_ethtool_net_set_mac_addr(params->port,
491 mark_port_newmac(params->port);
492 unlock_port(params->port);
494 printf("MAC address changed\n");
498 stat = rte_ethtool_net_get_mac_addr(params->port, &mac_addr);
501 "Port %i MAC Address: " RTE_ETHER_ADDR_PRT_FMT "\n",
502 params->port, RTE_ETHER_ADDR_BYTES(&mac_addr));
507 printf("Port %i: Error %s\n", params->port,
512 pcmd_mtu_callback(void *ptr_params,
513 __rte_unused struct cmdline *ctx,
514 __rte_unused void *ptr_data)
516 struct pcmd_intstr_params *params = ptr_params;
521 if (!rte_eth_dev_is_valid_port(params->port)) {
522 printf("Error: Invalid port number %i\n", params->port);
525 new_mtu = strtoul(params->opt, &ptr_parse_end, 10);
526 if (*ptr_parse_end != '\0' ||
527 new_mtu < RTE_ETHER_MIN_MTU ||
528 new_mtu > RTE_ETHER_MAX_JUMBO_FRAME_LEN) {
529 printf("Port %i: Invalid MTU value\n", params->port);
532 stat = rte_ethtool_net_change_mtu(params->port, new_mtu);
534 printf("Port %i: MTU set to %i\n", params->port, new_mtu);
535 else if (stat == -ENOTSUP)
536 printf("Port %i: Operation not supported\n", params->port);
538 printf("Port %i: Error setting MTU\n", params->port);
543 static void pcmd_portstats_callback(__rte_unused void *ptr_params,
544 __rte_unused struct cmdline *ctx,
545 __rte_unused void *ptr_data)
547 struct pcmd_int_params *params = ptr_params;
548 struct rte_eth_stats stat_info;
551 if (!rte_eth_dev_is_valid_port(params->port)) {
552 printf("Error: Invalid port number %i\n", params->port);
555 stat = rte_ethtool_net_get_stats64(params->port, &stat_info);
557 printf("Port %i stats\n", params->port);
558 printf(" In: %" PRIu64 " (%" PRIu64 " bytes)\n"
559 " Out: %"PRIu64" (%"PRIu64 " bytes)\n"
565 stat_info.ierrors+stat_info.oerrors
567 } else if (stat == -ENOTSUP)
568 printf("Port %i: Operation not supported\n", params->port);
570 printf("Port %i: Error fetching statistics\n", params->port);
573 static void pcmd_ringparam_callback(__rte_unused void *ptr_params,
574 __rte_unused struct cmdline *ctx,
577 struct pcmd_intintint_params *params = ptr_params;
578 struct ethtool_ringparam ring_data;
579 struct ethtool_ringparam ring_params;
582 if (!rte_eth_dev_is_valid_port(params->port)) {
583 printf("Error: Invalid port number %i\n", params->port);
586 if (ptr_data == NULL) {
587 stat = rte_ethtool_get_ringparam(params->port, &ring_data);
589 printf("Port %i ring parameters\n"
590 " Rx Pending: %i (%i max)\n"
591 " Tx Pending: %i (%i max)\n",
593 ring_data.rx_pending,
594 ring_data.rx_max_pending,
595 ring_data.tx_pending,
596 ring_data.tx_max_pending);
599 if (params->tx < 1 || params->rx < 1) {
600 printf("Error: Invalid parameters\n");
603 memset(&ring_params, 0, sizeof(struct ethtool_ringparam));
604 ring_params.tx_pending = params->tx;
605 ring_params.rx_pending = params->rx;
606 lock_port(params->port);
607 stat = rte_ethtool_set_ringparam(params->port, &ring_params);
608 unlock_port(params->port);
612 else if (stat == -ENOTSUP)
613 printf("Port %i: Operation not supported\n", params->port);
615 printf("Port %i: Error fetching statistics\n", params->port);
618 static void pcmd_validate_callback(void *ptr_params,
619 __rte_unused struct cmdline *ctx,
620 __rte_unused void *ptr_data)
622 struct pcmd_intmac_params *params = ptr_params;
624 if (rte_ethtool_net_validate_addr(0, ¶ms->mac))
625 printf("Address is unicast\n");
627 printf("Address is not unicast\n");
631 static void pcmd_vlan_callback(__rte_unused void *ptr_params,
632 __rte_unused struct cmdline *ctx,
633 __rte_unused void *ptr_data)
635 struct pcmd_vlan_params *params = ptr_params;
638 if (!rte_eth_dev_is_valid_port(params->port)) {
639 printf("Error: Invalid port number %i\n", params->port);
644 if (strcasecmp("add", params->mode) == 0) {
645 stat = rte_ethtool_net_vlan_rx_add_vid(
646 params->port, params->vid
649 printf("VLAN vid %i added\n", params->vid);
651 } else if (strcasecmp("del", params->mode) == 0) {
652 stat = rte_ethtool_net_vlan_rx_kill_vid(
653 params->port, params->vid
656 printf("VLAN vid %i removed\n", params->vid);
658 /* Should not happen! */
659 printf("Error: Bad mode %s\n", params->mode);
661 if (stat == -ENOTSUP)
662 printf("Port %i: Operation not supported\n", params->port);
663 else if (stat == -ENOSYS)
664 printf("Port %i: VLAN filtering disabled\n", params->port);
666 printf("Port %i: Error changing VLAN setup (code %i)\n",
667 params->port, -stat);
671 cmdline_parse_inst_t pcmd_quit = {
672 .f = pcmd_quit_callback,
674 .help_str = "quit\n Exit program",
675 .tokens = {(void *)&pcmd_quit_token_cmd, NULL},
677 cmdline_parse_inst_t pcmd_drvinfo = {
678 .f = pcmd_drvinfo_callback,
680 .help_str = "drvinfo\n Print driver info",
681 .tokens = {(void *)&pcmd_drvinfo_token_cmd, NULL},
683 cmdline_parse_inst_t pcmd_link = {
684 .f = pcmd_link_callback,
686 .help_str = "link\n Print port link states",
687 .tokens = {(void *)&pcmd_link_token_cmd, NULL},
689 cmdline_parse_inst_t pcmd_regs = {
690 .f = pcmd_regs_callback,
692 .help_str = "regs <port_id> <filename>\n"
693 " Dump port register(s) to file",
695 (void *)&pcmd_regs_token_cmd,
696 (void *)&pcmd_intstr_token_port,
697 (void *)&pcmd_intstr_token_opt,
701 cmdline_parse_inst_t pcmd_eeprom = {
702 .f = pcmd_eeprom_callback,
704 .help_str = "eeprom <port_id> <filename>\n Dump EEPROM to file",
706 (void *)&pcmd_eeprom_token_cmd,
707 (void *)&pcmd_intstr_token_port,
708 (void *)&pcmd_intstr_token_opt,
712 cmdline_parse_inst_t pcmd_module_eeprom = {
713 .f = pcmd_module_eeprom_callback,
715 .help_str = "module-eeprom <port_id> <filename>\n"
716 " Dump plugin module EEPROM to file",
718 (void *)&pcmd_module_eeprom_token_cmd,
719 (void *)&pcmd_intstr_token_port,
720 (void *)&pcmd_intstr_token_opt,
724 cmdline_parse_inst_t pcmd_pause_noopt = {
725 .f = pcmd_pause_callback,
726 .data = (void *)0x01,
727 .help_str = "pause <port_id>\n Print port pause state",
729 (void *)&pcmd_pause_token_cmd,
730 (void *)&pcmd_pause_token_port,
734 cmdline_parse_inst_t pcmd_pause = {
735 .f = pcmd_pause_callback,
738 "pause <port_id> <all|tx|rx|none>\n Pause/unpause port",
740 (void *)&pcmd_pause_token_cmd,
741 (void *)&pcmd_pause_token_port,
742 (void *)&pcmd_pause_token_opt,
746 cmdline_parse_inst_t pcmd_open = {
747 .f = pcmd_open_callback,
749 .help_str = "open <port_id>\n Open port",
751 (void *)&pcmd_open_token_cmd,
752 (void *)&pcmd_int_token_port,
756 cmdline_parse_inst_t pcmd_stop = {
757 .f = pcmd_stop_callback,
759 .help_str = "stop <port_id>\n Stop port",
761 (void *)&pcmd_stop_token_cmd,
762 (void *)&pcmd_int_token_port,
766 cmdline_parse_inst_t pcmd_rxmode = {
767 .f = pcmd_rxmode_callback,
769 .help_str = "rxmode <port_id>\n Toggle port Rx mode",
771 (void *)&pcmd_rxmode_token_cmd,
772 (void *)&pcmd_int_token_port,
776 cmdline_parse_inst_t pcmd_macaddr_get = {
777 .f = pcmd_macaddr_callback,
779 .help_str = "macaddr <port_id>\n"
782 (void *)&pcmd_macaddr_token_cmd,
783 (void *)&pcmd_intstr_token_port,
787 cmdline_parse_inst_t pcmd_macaddr = {
788 .f = pcmd_macaddr_callback,
789 .data = (void *)0x01,
791 "macaddr <port_id> <mac_addr>\n"
794 (void *)&pcmd_macaddr_token_cmd,
795 (void *)&pcmd_intmac_token_port,
796 (void *)&pcmd_intmac_token_mac,
800 cmdline_parse_inst_t pcmd_mtu = {
801 .f = pcmd_mtu_callback,
803 .help_str = "mtu <port_id> <mtu_value>\n"
806 (void *)&pcmd_mtu_token_cmd,
807 (void *)&pcmd_intstr_token_port,
808 (void *)&pcmd_intstr_token_opt,
812 cmdline_parse_inst_t pcmd_portstats = {
813 .f = pcmd_portstats_callback,
815 .help_str = "portstats <port_id>\n"
816 " Print port eth statistics",
818 (void *)&pcmd_portstats_token_cmd,
819 (void *)&pcmd_int_token_port,
823 cmdline_parse_inst_t pcmd_ringparam = {
824 .f = pcmd_ringparam_callback,
826 .help_str = "ringparam <port_id>\n"
827 " Print ring parameters",
829 (void *)&pcmd_ringparam_token_cmd,
830 (void *)&pcmd_intintint_token_port,
834 cmdline_parse_inst_t pcmd_ringparam_set = {
835 .f = pcmd_ringparam_callback,
837 .help_str = "ringparam <port_id> <tx_param> <rx_param>\n"
838 " Set ring parameters",
840 (void *)&pcmd_ringparam_token_cmd,
841 (void *)&pcmd_intintint_token_port,
842 (void *)&pcmd_intintint_token_tx,
843 (void *)&pcmd_intintint_token_rx,
847 cmdline_parse_inst_t pcmd_validate = {
848 .f = pcmd_validate_callback,
850 .help_str = "validate <mac_addr>\n"
851 " Check that MAC address is valid unicast address",
853 (void *)&pcmd_validate_token_cmd,
854 (void *)&pcmd_intmac_token_mac,
858 cmdline_parse_inst_t pcmd_vlan = {
859 .f = pcmd_vlan_callback,
861 .help_str = "vlan <port_id> <add|del> <vlan_id>\n"
862 " Add/remove VLAN id",
864 (void *)&pcmd_vlan_token_cmd,
865 (void *)&pcmd_vlan_token_port,
866 (void *)&pcmd_vlan_token_mode,
867 (void *)&pcmd_vlan_token_vid,
873 cmdline_parse_ctx_t list_prompt_commands[] = {
874 (cmdline_parse_inst_t *)&pcmd_drvinfo,
875 (cmdline_parse_inst_t *)&pcmd_eeprom,
876 (cmdline_parse_inst_t *)&pcmd_module_eeprom,
877 (cmdline_parse_inst_t *)&pcmd_link,
878 (cmdline_parse_inst_t *)&pcmd_macaddr_get,
879 (cmdline_parse_inst_t *)&pcmd_macaddr,
880 (cmdline_parse_inst_t *)&pcmd_mtu,
881 (cmdline_parse_inst_t *)&pcmd_open,
882 (cmdline_parse_inst_t *)&pcmd_pause_noopt,
883 (cmdline_parse_inst_t *)&pcmd_pause,
884 (cmdline_parse_inst_t *)&pcmd_portstats,
885 (cmdline_parse_inst_t *)&pcmd_regs,
886 (cmdline_parse_inst_t *)&pcmd_ringparam,
887 (cmdline_parse_inst_t *)&pcmd_ringparam_set,
888 (cmdline_parse_inst_t *)&pcmd_rxmode,
889 (cmdline_parse_inst_t *)&pcmd_stop,
890 (cmdline_parse_inst_t *)&pcmd_validate,
891 (cmdline_parse_inst_t *)&pcmd_vlan,
892 (cmdline_parse_inst_t *)&pcmd_quit,
897 void ethapp_main(void)
899 struct cmdline *ctx_cmdline;
901 ctx_cmdline = cmdline_stdin_new(list_prompt_commands, "EthApp> ");
902 cmdline_interact(ctx_cmdline);
903 cmdline_stdin_exit(ctx_cmdline);