4 * Copyright(c) 2015 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <cmdline_parse.h>
35 #include <cmdline_parse_num.h>
36 #include <cmdline_parse_string.h>
37 #include <cmdline_parse_etheraddr.h>
38 #include <cmdline_socket.h>
41 #include "rte_ethtool.h"
44 #define EEPROM_DUMP_CHUNKSIZE 1024
47 struct pcmd_get_params {
48 cmdline_fixed_string_t cmd;
50 struct pcmd_int_params {
51 cmdline_fixed_string_t cmd;
54 struct pcmd_intstr_params {
55 cmdline_fixed_string_t cmd;
57 cmdline_fixed_string_t opt;
59 struct pcmd_intmac_params {
60 cmdline_fixed_string_t cmd;
62 struct ether_addr mac;
64 struct pcmd_str_params {
65 cmdline_fixed_string_t cmd;
66 cmdline_fixed_string_t opt;
68 struct pcmd_vlan_params {
69 cmdline_fixed_string_t cmd;
71 cmdline_fixed_string_t mode;
74 struct pcmd_intintint_params {
75 cmdline_fixed_string_t cmd;
82 /* Parameter-less commands */
83 cmdline_parse_token_string_t pcmd_quit_token_cmd =
84 TOKEN_STRING_INITIALIZER(struct pcmd_get_params, cmd, "quit");
85 cmdline_parse_token_string_t pcmd_stats_token_cmd =
86 TOKEN_STRING_INITIALIZER(struct pcmd_get_params, cmd, "stats");
87 cmdline_parse_token_string_t pcmd_drvinfo_token_cmd =
88 TOKEN_STRING_INITIALIZER(struct pcmd_get_params, cmd, "drvinfo");
89 cmdline_parse_token_string_t pcmd_link_token_cmd =
90 TOKEN_STRING_INITIALIZER(struct pcmd_get_params, cmd, "link");
92 /* Commands taking just port id */
93 cmdline_parse_token_string_t pcmd_open_token_cmd =
94 TOKEN_STRING_INITIALIZER(struct pcmd_int_params, cmd, "open");
95 cmdline_parse_token_string_t pcmd_stop_token_cmd =
96 TOKEN_STRING_INITIALIZER(struct pcmd_int_params, cmd, "stop");
97 cmdline_parse_token_string_t pcmd_rxmode_token_cmd =
98 TOKEN_STRING_INITIALIZER(struct pcmd_int_params, cmd, "rxmode");
99 cmdline_parse_token_string_t pcmd_portstats_token_cmd =
100 TOKEN_STRING_INITIALIZER(struct pcmd_int_params, cmd, "portstats");
101 cmdline_parse_token_num_t pcmd_int_token_port =
102 TOKEN_NUM_INITIALIZER(struct pcmd_int_params, port, UINT16);
104 /* Commands taking port id and string */
105 cmdline_parse_token_string_t pcmd_eeprom_token_cmd =
106 TOKEN_STRING_INITIALIZER(struct pcmd_intstr_params, cmd, "eeprom");
107 cmdline_parse_token_string_t pcmd_mtu_token_cmd =
108 TOKEN_STRING_INITIALIZER(struct pcmd_intstr_params, cmd, "mtu");
109 cmdline_parse_token_string_t pcmd_regs_token_cmd =
110 TOKEN_STRING_INITIALIZER(struct pcmd_intstr_params, cmd, "regs");
112 cmdline_parse_token_num_t pcmd_intstr_token_port =
113 TOKEN_NUM_INITIALIZER(struct pcmd_intstr_params, port, UINT16);
114 cmdline_parse_token_string_t pcmd_intstr_token_opt =
115 TOKEN_STRING_INITIALIZER(struct pcmd_intstr_params, opt, NULL);
117 /* Commands taking port id and a MAC address string */
118 cmdline_parse_token_string_t pcmd_macaddr_token_cmd =
119 TOKEN_STRING_INITIALIZER(struct pcmd_intmac_params, cmd, "macaddr");
120 cmdline_parse_token_num_t pcmd_intmac_token_port =
121 TOKEN_NUM_INITIALIZER(struct pcmd_intmac_params, port, UINT16);
122 cmdline_parse_token_etheraddr_t pcmd_intmac_token_mac =
123 TOKEN_ETHERADDR_INITIALIZER(struct pcmd_intmac_params, mac);
125 /* Command taking just a MAC address */
126 cmdline_parse_token_string_t pcmd_validate_token_cmd =
127 TOKEN_STRING_INITIALIZER(struct pcmd_intmac_params, cmd, "validate");
130 /* Commands taking port id and two integers */
131 cmdline_parse_token_string_t pcmd_ringparam_token_cmd =
132 TOKEN_STRING_INITIALIZER(struct pcmd_intintint_params, cmd,
134 cmdline_parse_token_num_t pcmd_intintint_token_port =
135 TOKEN_NUM_INITIALIZER(struct pcmd_intintint_params, port, UINT16);
136 cmdline_parse_token_num_t pcmd_intintint_token_tx =
137 TOKEN_NUM_INITIALIZER(struct pcmd_intintint_params, tx, UINT16);
138 cmdline_parse_token_num_t pcmd_intintint_token_rx =
139 TOKEN_NUM_INITIALIZER(struct pcmd_intintint_params, rx, UINT16);
143 cmdline_parse_token_string_t pcmd_pause_token_cmd =
144 TOKEN_STRING_INITIALIZER(struct pcmd_intstr_params, cmd, "pause");
145 cmdline_parse_token_num_t pcmd_pause_token_port =
146 TOKEN_NUM_INITIALIZER(struct pcmd_intstr_params, port, UINT16);
147 cmdline_parse_token_string_t pcmd_pause_token_opt =
148 TOKEN_STRING_INITIALIZER(struct pcmd_intstr_params,
149 opt, "all#tx#rx#none");
152 cmdline_parse_token_string_t pcmd_vlan_token_cmd =
153 TOKEN_STRING_INITIALIZER(struct pcmd_vlan_params, cmd, "vlan");
154 cmdline_parse_token_num_t pcmd_vlan_token_port =
155 TOKEN_NUM_INITIALIZER(struct pcmd_vlan_params, port, UINT16);
156 cmdline_parse_token_string_t pcmd_vlan_token_mode =
157 TOKEN_STRING_INITIALIZER(struct pcmd_vlan_params, mode, "add#del");
158 cmdline_parse_token_num_t pcmd_vlan_token_vid =
159 TOKEN_NUM_INITIALIZER(struct pcmd_vlan_params, vid, UINT16);
163 pcmd_quit_callback(__rte_unused void *ptr_params,
165 __rte_unused void *ptr_data)
172 pcmd_drvinfo_callback(__rte_unused void *ptr_params,
173 __rte_unused struct cmdline *ctx,
174 __rte_unused void *ptr_data)
176 struct ethtool_drvinfo info;
179 for (id_port = 0; id_port < rte_eth_dev_count(); id_port++) {
180 if (rte_ethtool_get_drvinfo(id_port, &info)) {
181 printf("Error getting info for port %i\n", id_port);
184 printf("Port %i driver: %s (ver: %s)\n",
185 id_port, info.driver, info.version
192 pcmd_link_callback(__rte_unused void *ptr_params,
193 __rte_unused struct cmdline *ctx,
194 __rte_unused void *ptr_data)
196 int num_ports = rte_eth_dev_count();
197 int id_port, stat_port;
199 for (id_port = 0; id_port < num_ports; id_port++) {
200 if (!rte_eth_dev_is_valid_port(id_port))
202 stat_port = rte_ethtool_get_link(id_port);
205 printf("Port %i: Down\n", id_port);
208 printf("Port %i: Up\n", id_port);
211 printf("Port %i: Error getting link status\n",
222 pcmd_regs_callback(void *ptr_params,
223 __rte_unused struct cmdline *ctx,
224 __rte_unused void *ptr_data)
226 struct pcmd_intstr_params *params = ptr_params;
228 struct ethtool_regs regs;
229 unsigned char *buf_data;
232 if (!rte_eth_dev_is_valid_port(params->port)) {
233 printf("Error: Invalid port number %i\n", params->port);
236 len_regs = rte_ethtool_get_regs_len(params->port);
238 printf("Port %i: %i bytes\n", params->port, len_regs);
239 buf_data = malloc(len_regs);
240 if (buf_data == NULL) {
241 printf("Error allocating %i bytes for buffer\n",
245 if (!rte_ethtool_get_regs(params->port, ®s, buf_data)) {
246 fp_regs = fopen(params->opt, "wb");
247 if (fp_regs == NULL) {
248 printf("Error opening '%s' for writing\n",
251 if ((int)fwrite(buf_data,
253 fp_regs) != len_regs)
254 printf("Error writing '%s'\n",
260 } else if (len_regs == -ENOTSUP)
261 printf("Port %i: Operation not supported\n", params->port);
263 printf("Port %i: Error getting registers\n", params->port);
268 pcmd_eeprom_callback(void *ptr_params,
269 __rte_unused struct cmdline *ctx,
270 __rte_unused void *ptr_data)
272 struct pcmd_intstr_params *params = ptr_params;
273 struct ethtool_eeprom info_eeprom;
277 unsigned char bytes_eeprom[EEPROM_DUMP_CHUNKSIZE];
280 if (!rte_eth_dev_is_valid_port(params->port)) {
281 printf("Error: Invalid port number %i\n", params->port);
284 len_eeprom = rte_ethtool_get_eeprom_len(params->port);
285 if (len_eeprom > 0) {
286 fp_eeprom = fopen(params->opt, "wb");
287 if (fp_eeprom == NULL) {
288 printf("Error opening '%s' for writing\n",
292 printf("Total EEPROM length: %i bytes\n", len_eeprom);
293 info_eeprom.len = EEPROM_DUMP_CHUNKSIZE;
295 pos_eeprom < len_eeprom;
296 pos_eeprom += EEPROM_DUMP_CHUNKSIZE) {
297 info_eeprom.offset = pos_eeprom;
298 if (pos_eeprom + EEPROM_DUMP_CHUNKSIZE > len_eeprom)
299 info_eeprom.len = len_eeprom - pos_eeprom;
301 info_eeprom.len = EEPROM_DUMP_CHUNKSIZE;
302 stat = rte_ethtool_get_eeprom(
303 params->port, &info_eeprom, bytes_eeprom
306 printf("EEPROM read error %i\n", stat);
309 if (fwrite(bytes_eeprom,
311 fp_eeprom) != info_eeprom.len) {
312 printf("Error writing '%s'\n", params->opt);
317 } else if (len_eeprom == 0)
318 printf("Port %i: Device does not have EEPROM\n", params->port);
319 else if (len_eeprom == -ENOTSUP)
320 printf("Port %i: Operation not supported\n", params->port);
322 printf("Port %i: Error getting EEPROM\n", params->port);
327 pcmd_pause_callback(void *ptr_params,
328 __rte_unused struct cmdline *ctx,
331 struct pcmd_intstr_params *params = ptr_params;
332 struct ethtool_pauseparam info;
335 if (!rte_eth_dev_is_valid_port(params->port)) {
336 printf("Error: Invalid port number %i\n", params->port);
339 if (ptr_data != NULL) {
340 stat = rte_ethtool_get_pauseparam(params->port, &info);
342 memset(&info, 0, sizeof(info));
343 if (strcasecmp("all", params->opt) == 0) {
346 } else if (strcasecmp("tx", params->opt) == 0) {
349 } else if (strcasecmp("rx", params->opt) == 0) {
356 /* Assume auto-negotiation wanted */
358 stat = rte_ethtool_set_pauseparam(params->port, &info);
361 if (info.rx_pause && info.tx_pause)
362 printf("Port %i: Tx & Rx Paused\n", params->port);
363 else if (info.rx_pause)
364 printf("Port %i: Rx Paused\n", params->port);
365 else if (info.tx_pause)
366 printf("Port %i: Tx Paused\n", params->port);
368 printf("Port %i: Tx & Rx not paused\n", params->port);
369 } else if (stat == -ENOTSUP)
370 printf("Port %i: Operation not supported\n", params->port);
372 printf("Port %i: Error %i\n", params->port, stat);
377 pcmd_open_callback(__rte_unused void *ptr_params,
378 __rte_unused struct cmdline *ctx,
379 __rte_unused void *ptr_data)
381 struct pcmd_int_params *params = ptr_params;
384 if (!rte_eth_dev_is_valid_port(params->port)) {
385 printf("Error: Invalid port number %i\n", params->port);
388 lock_port(params->port);
389 stat = rte_ethtool_net_open(params->port);
390 mark_port_active(params->port);
391 unlock_port(params->port);
394 else if (stat == -ENOTSUP)
395 printf("Port %i: Operation not supported\n", params->port);
397 printf("Port %i: Error opening device\n", params->port);
401 pcmd_stop_callback(__rte_unused void *ptr_params,
402 __rte_unused struct cmdline *ctx,
403 __rte_unused void *ptr_data)
405 struct pcmd_int_params *params = ptr_params;
408 if (!rte_eth_dev_is_valid_port(params->port)) {
409 printf("Error: Invalid port number %i\n", params->port);
412 lock_port(params->port);
413 stat = rte_ethtool_net_stop(params->port);
414 mark_port_inactive(params->port);
415 unlock_port(params->port);
418 else if (stat == -ENOTSUP)
419 printf("Port %i: Operation not supported\n", params->port);
421 printf("Port %i: Error stopping device\n", params->port);
426 pcmd_rxmode_callback(void *ptr_params,
427 __rte_unused struct cmdline *ctx,
428 __rte_unused void *ptr_data)
430 struct pcmd_intstr_params *params = ptr_params;
433 if (!rte_eth_dev_is_valid_port(params->port)) {
434 printf("Error: Invalid port number %i\n", params->port);
437 stat = rte_ethtool_net_set_rx_mode(params->port);
440 else if (stat == -ENOTSUP)
441 printf("Port %i: Operation not supported\n", params->port);
443 printf("Port %i: Error setting rx mode\n", params->port);
448 pcmd_macaddr_callback(void *ptr_params,
449 __rte_unused struct cmdline *ctx,
452 struct pcmd_intmac_params *params = ptr_params;
453 struct ether_addr mac_addr;
457 if (!rte_eth_dev_is_valid_port(params->port)) {
458 printf("Error: Invalid port number %i\n", params->port);
461 if (ptr_data != NULL) {
462 lock_port(params->port);
463 stat = rte_ethtool_net_set_mac_addr(params->port,
465 mark_port_newmac(params->port);
466 unlock_port(params->port);
468 printf("MAC address changed\n");
472 stat = rte_ethtool_net_get_mac_addr(params->port, &mac_addr);
475 "Port %i MAC Address: %02x:%02x:%02x:%02x:%02x:%02x\n",
477 mac_addr.addr_bytes[0],
478 mac_addr.addr_bytes[1],
479 mac_addr.addr_bytes[2],
480 mac_addr.addr_bytes[3],
481 mac_addr.addr_bytes[4],
482 mac_addr.addr_bytes[5]);
487 printf("Port %i: Error %s\n", params->port,
492 pcmd_mtu_callback(void *ptr_params,
493 __rte_unused struct cmdline *ctx,
494 __rte_unused void *ptr_data)
496 struct pcmd_intstr_params *params = ptr_params;
501 if (!rte_eth_dev_is_valid_port(params->port)) {
502 printf("Error: Invalid port number %i\n", params->port);
505 new_mtu = atoi(params->opt);
506 new_mtu = strtoul(params->opt, &ptr_parse_end, 10);
507 if (*ptr_parse_end != '\0' ||
508 new_mtu < ETHER_MIN_MTU ||
509 new_mtu > ETHER_MAX_JUMBO_FRAME_LEN) {
510 printf("Port %i: Invalid MTU value\n", params->port);
513 stat = rte_ethtool_net_change_mtu(params->port, new_mtu);
515 printf("Port %i: MTU set to %i\n", params->port, new_mtu);
516 else if (stat == -ENOTSUP)
517 printf("Port %i: Operation not supported\n", params->port);
519 printf("Port %i: Error setting MTU\n", params->port);
524 static void pcmd_portstats_callback(__rte_unused void *ptr_params,
525 __rte_unused struct cmdline *ctx,
526 __rte_unused void *ptr_data)
528 struct pcmd_int_params *params = ptr_params;
529 struct rte_eth_stats stat_info;
532 if (!rte_eth_dev_is_valid_port(params->port)) {
533 printf("Error: Invalid port number %i\n", params->port);
536 stat = rte_ethtool_net_get_stats64(params->port, &stat_info);
538 /* Most of rte_eth_stats is deprecated.. */
539 printf("Port %i stats\n", params->port);
540 printf(" In: %" PRIu64 " (%" PRIu64 " bytes)\n"
541 " Out: %"PRIu64" (%"PRIu64 " bytes)\n"
547 stat_info.ierrors+stat_info.oerrors
549 } else if (stat == -ENOTSUP)
550 printf("Port %i: Operation not supported\n", params->port);
552 printf("Port %i: Error fetching statistics\n", params->port);
555 static void pcmd_ringparam_callback(__rte_unused void *ptr_params,
556 __rte_unused struct cmdline *ctx,
559 struct pcmd_intintint_params *params = ptr_params;
560 struct ethtool_ringparam ring_data;
561 struct ethtool_ringparam ring_params;
564 if (!rte_eth_dev_is_valid_port(params->port)) {
565 printf("Error: Invalid port number %i\n", params->port);
568 if (ptr_data == NULL) {
569 stat = rte_ethtool_get_ringparam(params->port, &ring_data);
571 printf("Port %i ring parameters\n"
572 " Rx Pending: %i (%i max)\n"
573 " Tx Pending: %i (%i max)\n",
575 ring_data.rx_pending,
576 ring_data.rx_max_pending,
577 ring_data.tx_pending,
578 ring_data.tx_max_pending);
581 if (params->tx < 1 || params->rx < 1) {
582 printf("Error: Invalid parameters\n");
585 memset(&ring_params, 0, sizeof(struct ethtool_ringparam));
586 ring_params.tx_pending = params->tx;
587 ring_params.rx_pending = params->rx;
588 lock_port(params->port);
589 stat = rte_ethtool_set_ringparam(params->port, &ring_params);
590 unlock_port(params->port);
594 else if (stat == -ENOTSUP)
595 printf("Port %i: Operation not supported\n", params->port);
597 printf("Port %i: Error fetching statistics\n", params->port);
600 static void pcmd_validate_callback(void *ptr_params,
601 __rte_unused struct cmdline *ctx,
602 __rte_unused void *ptr_data)
604 struct pcmd_intmac_params *params = ptr_params;
606 if (rte_ethtool_net_validate_addr(0, ¶ms->mac))
607 printf("Address is unicast\n");
609 printf("Address is not unicast\n");
613 static void pcmd_vlan_callback(__rte_unused void *ptr_params,
614 __rte_unused struct cmdline *ctx,
615 __rte_unused void *ptr_data)
617 struct pcmd_vlan_params *params = ptr_params;
620 if (!rte_eth_dev_is_valid_port(params->port)) {
621 printf("Error: Invalid port number %i\n", params->port);
626 if (strcasecmp("add", params->mode) == 0) {
627 stat = rte_ethtool_net_vlan_rx_add_vid(
628 params->port, params->vid
631 printf("VLAN vid %i added\n", params->vid);
633 } else if (strcasecmp("del", params->mode) == 0) {
634 stat = rte_ethtool_net_vlan_rx_kill_vid(
635 params->port, params->vid
638 printf("VLAN vid %i removed\n", params->vid);
640 /* Should not happen! */
641 printf("Error: Bad mode %s\n", params->mode);
643 if (stat == -ENOTSUP)
644 printf("Port %i: Operation not supported\n", params->port);
645 else if (stat == -ENOSYS)
646 printf("Port %i: VLAN filtering disabled\n", params->port);
648 printf("Port %i: Error changing VLAN setup (code %i)\n",
649 params->port, -stat);
653 cmdline_parse_inst_t pcmd_quit = {
654 .f = pcmd_quit_callback,
656 .help_str = "quit\n Exit program",
657 .tokens = {(void *)&pcmd_quit_token_cmd, NULL},
659 cmdline_parse_inst_t pcmd_drvinfo = {
660 .f = pcmd_drvinfo_callback,
662 .help_str = "drvinfo\n Print driver info",
663 .tokens = {(void *)&pcmd_drvinfo_token_cmd, NULL},
665 cmdline_parse_inst_t pcmd_link = {
666 .f = pcmd_link_callback,
668 .help_str = "link\n Print port link states",
669 .tokens = {(void *)&pcmd_link_token_cmd, NULL},
671 cmdline_parse_inst_t pcmd_regs = {
672 .f = pcmd_regs_callback,
674 .help_str = "regs <port_id> <filename>\n"
675 " Dump port register(s) to file",
677 (void *)&pcmd_regs_token_cmd,
678 (void *)&pcmd_intstr_token_port,
679 (void *)&pcmd_intstr_token_opt,
683 cmdline_parse_inst_t pcmd_eeprom = {
684 .f = pcmd_eeprom_callback,
686 .help_str = "eeprom <port_id> <filename>\n Dump EEPROM to file",
688 (void *)&pcmd_eeprom_token_cmd,
689 (void *)&pcmd_intstr_token_port,
690 (void *)&pcmd_intstr_token_opt,
694 cmdline_parse_inst_t pcmd_pause_noopt = {
695 .f = pcmd_pause_callback,
696 .data = (void *)0x01,
697 .help_str = "pause <port_id>\n Print port pause state",
699 (void *)&pcmd_pause_token_cmd,
700 (void *)&pcmd_pause_token_port,
704 cmdline_parse_inst_t pcmd_pause = {
705 .f = pcmd_pause_callback,
708 "pause <port_id> <all|tx|rx|none>\n Pause/unpause port",
710 (void *)&pcmd_pause_token_cmd,
711 (void *)&pcmd_pause_token_port,
712 (void *)&pcmd_pause_token_opt,
716 cmdline_parse_inst_t pcmd_open = {
717 .f = pcmd_open_callback,
719 .help_str = "open <port_id>\n Open port",
721 (void *)&pcmd_open_token_cmd,
722 (void *)&pcmd_int_token_port,
726 cmdline_parse_inst_t pcmd_stop = {
727 .f = pcmd_stop_callback,
729 .help_str = "stop <port_id>\n Stop port",
731 (void *)&pcmd_stop_token_cmd,
732 (void *)&pcmd_int_token_port,
736 cmdline_parse_inst_t pcmd_rxmode = {
737 .f = pcmd_rxmode_callback,
739 .help_str = "rxmode <port_id>\n Toggle port Rx mode",
741 (void *)&pcmd_rxmode_token_cmd,
742 (void *)&pcmd_int_token_port,
746 cmdline_parse_inst_t pcmd_macaddr_get = {
747 .f = pcmd_macaddr_callback,
749 .help_str = "macaddr <port_id>\n"
752 (void *)&pcmd_macaddr_token_cmd,
753 (void *)&pcmd_intstr_token_port,
757 cmdline_parse_inst_t pcmd_macaddr = {
758 .f = pcmd_macaddr_callback,
759 .data = (void *)0x01,
761 "macaddr <port_id> <mac_addr>\n"
764 (void *)&pcmd_macaddr_token_cmd,
765 (void *)&pcmd_intmac_token_port,
766 (void *)&pcmd_intmac_token_mac,
770 cmdline_parse_inst_t pcmd_mtu = {
771 .f = pcmd_mtu_callback,
773 .help_str = "mtu <port_id> <mtu_value>\n"
776 (void *)&pcmd_mtu_token_cmd,
777 (void *)&pcmd_intstr_token_port,
778 (void *)&pcmd_intstr_token_opt,
782 cmdline_parse_inst_t pcmd_portstats = {
783 .f = pcmd_portstats_callback,
785 .help_str = "portstats <port_id>\n"
786 " Print port eth statistics",
788 (void *)&pcmd_portstats_token_cmd,
789 (void *)&pcmd_int_token_port,
793 cmdline_parse_inst_t pcmd_ringparam = {
794 .f = pcmd_ringparam_callback,
796 .help_str = "ringparam <port_id>\n"
797 " Print ring parameters",
799 (void *)&pcmd_ringparam_token_cmd,
800 (void *)&pcmd_intintint_token_port,
804 cmdline_parse_inst_t pcmd_ringparam_set = {
805 .f = pcmd_ringparam_callback,
807 .help_str = "ringparam <port_id> <tx_param> <rx_param>\n"
808 " Set ring parameters",
810 (void *)&pcmd_ringparam_token_cmd,
811 (void *)&pcmd_intintint_token_port,
812 (void *)&pcmd_intintint_token_tx,
813 (void *)&pcmd_intintint_token_rx,
817 cmdline_parse_inst_t pcmd_validate = {
818 .f = pcmd_validate_callback,
820 .help_str = "validate <mac_addr>\n"
821 " Check that MAC address is valid unicast address",
823 (void *)&pcmd_validate_token_cmd,
824 (void *)&pcmd_intmac_token_mac,
828 cmdline_parse_inst_t pcmd_vlan = {
829 .f = pcmd_vlan_callback,
831 .help_str = "vlan <port_id> <add|del> <vlan_id>\n"
832 " Add/remove VLAN id",
834 (void *)&pcmd_vlan_token_cmd,
835 (void *)&pcmd_vlan_token_port,
836 (void *)&pcmd_vlan_token_mode,
837 (void *)&pcmd_vlan_token_vid,
843 cmdline_parse_ctx_t list_prompt_commands[] = {
844 (cmdline_parse_inst_t *)&pcmd_drvinfo,
845 (cmdline_parse_inst_t *)&pcmd_eeprom,
846 (cmdline_parse_inst_t *)&pcmd_link,
847 (cmdline_parse_inst_t *)&pcmd_macaddr_get,
848 (cmdline_parse_inst_t *)&pcmd_macaddr,
849 (cmdline_parse_inst_t *)&pcmd_mtu,
850 (cmdline_parse_inst_t *)&pcmd_open,
851 (cmdline_parse_inst_t *)&pcmd_pause_noopt,
852 (cmdline_parse_inst_t *)&pcmd_pause,
853 (cmdline_parse_inst_t *)&pcmd_portstats,
854 (cmdline_parse_inst_t *)&pcmd_regs,
855 (cmdline_parse_inst_t *)&pcmd_ringparam,
856 (cmdline_parse_inst_t *)&pcmd_ringparam_set,
857 (cmdline_parse_inst_t *)&pcmd_rxmode,
858 (cmdline_parse_inst_t *)&pcmd_stop,
859 (cmdline_parse_inst_t *)&pcmd_validate,
860 (cmdline_parse_inst_t *)&pcmd_vlan,
861 (cmdline_parse_inst_t *)&pcmd_quit,
866 void ethapp_main(void)
868 struct cmdline *ctx_cmdline;
870 ctx_cmdline = cmdline_stdin_new(list_prompt_commands, "EthApp> ");
871 cmdline_interact(ctx_cmdline);
872 cmdline_stdin_exit(ctx_cmdline);