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 if (strcasecmp("all", params->opt) == 0) {
345 } else if (strcasecmp("tx", params->opt) == 0) {
348 } else if (strcasecmp("rx", params->opt) == 0) {
355 stat = rte_ethtool_set_pauseparam(params->port, &info);
358 if (info.rx_pause && info.tx_pause)
359 printf("Port %i: Tx & Rx Paused\n", params->port);
360 else if (info.rx_pause)
361 printf("Port %i: Rx Paused\n", params->port);
362 else if (info.tx_pause)
363 printf("Port %i: Tx Paused\n", params->port);
365 printf("Port %i: Tx & Rx not paused\n", params->port);
366 } else if (stat == -ENOTSUP)
367 printf("Port %i: Operation not supported\n", params->port);
369 printf("Port %i: Error %i\n", params->port, stat);
374 pcmd_open_callback(__rte_unused void *ptr_params,
375 __rte_unused struct cmdline *ctx,
376 __rte_unused void *ptr_data)
378 struct pcmd_int_params *params = ptr_params;
381 if (!rte_eth_dev_is_valid_port(params->port)) {
382 printf("Error: Invalid port number %i\n", params->port);
385 lock_port(params->port);
386 stat = rte_ethtool_net_open(params->port);
387 mark_port_active(params->port);
388 unlock_port(params->port);
391 else if (stat == -ENOTSUP)
392 printf("Port %i: Operation not supported\n", params->port);
394 printf("Port %i: Error opening device\n", params->port);
398 pcmd_stop_callback(__rte_unused void *ptr_params,
399 __rte_unused struct cmdline *ctx,
400 __rte_unused void *ptr_data)
402 struct pcmd_int_params *params = ptr_params;
405 if (!rte_eth_dev_is_valid_port(params->port)) {
406 printf("Error: Invalid port number %i\n", params->port);
409 lock_port(params->port);
410 stat = rte_ethtool_net_stop(params->port);
411 mark_port_inactive(params->port);
412 unlock_port(params->port);
415 else if (stat == -ENOTSUP)
416 printf("Port %i: Operation not supported\n", params->port);
418 printf("Port %i: Error stopping device\n", params->port);
423 pcmd_rxmode_callback(void *ptr_params,
424 __rte_unused struct cmdline *ctx,
425 __rte_unused void *ptr_data)
427 struct pcmd_intstr_params *params = ptr_params;
430 if (!rte_eth_dev_is_valid_port(params->port)) {
431 printf("Error: Invalid port number %i\n", params->port);
434 stat = rte_ethtool_net_set_rx_mode(params->port);
437 else if (stat == -ENOTSUP)
438 printf("Port %i: Operation not supported\n", params->port);
440 printf("Port %i: Error setting rx mode\n", params->port);
445 pcmd_macaddr_callback(void *ptr_params,
446 __rte_unused struct cmdline *ctx,
449 struct pcmd_intmac_params *params = ptr_params;
450 struct ether_addr mac_addr;
454 if (!rte_eth_dev_is_valid_port(params->port)) {
455 printf("Error: Invalid port number %i\n", params->port);
458 if (ptr_data != NULL) {
459 lock_port(params->port);
460 stat = rte_ethtool_net_set_mac_addr(params->port,
462 mark_port_newmac(params->port);
463 unlock_port(params->port);
465 printf("MAC address changed\n");
469 stat = rte_ethtool_net_get_mac_addr(params->port, &mac_addr);
472 "Port %i MAC Address: %02x:%02x:%02x:%02x:%02x:%02x\n",
474 mac_addr.addr_bytes[0],
475 mac_addr.addr_bytes[1],
476 mac_addr.addr_bytes[2],
477 mac_addr.addr_bytes[3],
478 mac_addr.addr_bytes[4],
479 mac_addr.addr_bytes[5]);
484 printf("Port %i: Error %s\n", params->port,
489 pcmd_mtu_callback(void *ptr_params,
490 __rte_unused struct cmdline *ctx,
491 __rte_unused void *ptr_data)
493 struct pcmd_intstr_params *params = ptr_params;
498 if (!rte_eth_dev_is_valid_port(params->port)) {
499 printf("Error: Invalid port number %i\n", params->port);
502 new_mtu = atoi(params->opt);
503 new_mtu = strtoul(params->opt, &ptr_parse_end, 10);
504 if (*ptr_parse_end != '\0' ||
505 new_mtu < ETHER_MIN_MTU ||
506 new_mtu > ETHER_MAX_JUMBO_FRAME_LEN) {
507 printf("Port %i: Invalid MTU value\n", params->port);
510 stat = rte_ethtool_net_change_mtu(params->port, new_mtu);
512 printf("Port %i: MTU set to %i\n", params->port, new_mtu);
513 else if (stat == -ENOTSUP)
514 printf("Port %i: Operation not supported\n", params->port);
516 printf("Port %i: Error setting MTU\n", params->port);
521 static void pcmd_portstats_callback(__rte_unused void *ptr_params,
522 __rte_unused struct cmdline *ctx,
523 __rte_unused void *ptr_data)
525 struct pcmd_int_params *params = ptr_params;
526 struct rte_eth_stats stat_info;
529 if (!rte_eth_dev_is_valid_port(params->port)) {
530 printf("Error: Invalid port number %i\n", params->port);
533 stat = rte_ethtool_net_get_stats64(params->port, &stat_info);
535 /* Most of rte_eth_stats is deprecated.. */
536 printf("Port %i stats\n", params->port);
537 printf(" In: %" PRIu64 " (%" PRIu64 " bytes)\n"
538 " Out: %"PRIu64" (%"PRIu64 " bytes)\n"
544 stat_info.ierrors+stat_info.oerrors
546 } else if (stat == -ENOTSUP)
547 printf("Port %i: Operation not supported\n", params->port);
549 printf("Port %i: Error fetching statistics\n", params->port);
552 static void pcmd_ringparam_callback(__rte_unused void *ptr_params,
553 __rte_unused struct cmdline *ctx,
556 struct pcmd_intintint_params *params = ptr_params;
557 struct ethtool_ringparam ring_data;
558 struct ethtool_ringparam ring_params;
561 if (!rte_eth_dev_is_valid_port(params->port)) {
562 printf("Error: Invalid port number %i\n", params->port);
565 if (ptr_data == NULL) {
566 stat = rte_ethtool_get_ringparam(params->port, &ring_data);
568 printf("Port %i ring parameters\n"
569 " Rx Pending: %i (%i max)\n"
570 " Tx Pending: %i (%i max)\n",
572 ring_data.rx_pending,
573 ring_data.rx_max_pending,
574 ring_data.tx_pending,
575 ring_data.tx_max_pending);
578 if (params->tx < 1 || params->rx < 1) {
579 printf("Error: Invalid parameters\n");
582 memset(&ring_params, 0, sizeof(struct ethtool_ringparam));
583 ring_params.tx_pending = params->tx;
584 ring_params.rx_pending = params->rx;
585 lock_port(params->port);
586 stat = rte_ethtool_set_ringparam(params->port, &ring_params);
587 unlock_port(params->port);
591 else if (stat == -ENOTSUP)
592 printf("Port %i: Operation not supported\n", params->port);
594 printf("Port %i: Error fetching statistics\n", params->port);
597 static void pcmd_validate_callback(void *ptr_params,
598 __rte_unused struct cmdline *ctx,
599 __rte_unused void *ptr_data)
601 struct pcmd_intmac_params *params = ptr_params;
603 if (rte_ethtool_net_validate_addr(0, ¶ms->mac))
604 printf("Address is unicast\n");
606 printf("Address is not unicast\n");
610 static void pcmd_vlan_callback(__rte_unused void *ptr_params,
611 __rte_unused struct cmdline *ctx,
612 __rte_unused void *ptr_data)
614 struct pcmd_vlan_params *params = ptr_params;
617 if (!rte_eth_dev_is_valid_port(params->port)) {
618 printf("Error: Invalid port number %i\n", params->port);
623 if (strcasecmp("add", params->mode) == 0) {
624 stat = rte_ethtool_net_vlan_rx_add_vid(
625 params->port, params->vid
628 printf("VLAN vid %i added\n", params->vid);
630 } else if (strcasecmp("del", params->mode) == 0) {
631 stat = rte_ethtool_net_vlan_rx_kill_vid(
632 params->port, params->vid
635 printf("VLAN vid %i removed\n", params->vid);
637 /* Should not happen! */
638 printf("Error: Bad mode %s\n", params->mode);
640 if (stat == -ENOTSUP)
641 printf("Port %i: Operation not supported\n", params->port);
642 else if (stat == -ENOSYS)
643 printf("Port %i: VLAN filtering disabled\n", params->port);
645 printf("Port %i: Error changing VLAN setup (code %i)\n",
646 params->port, -stat);
650 cmdline_parse_inst_t pcmd_quit = {
651 .f = pcmd_quit_callback,
653 .help_str = "quit\n Exit program",
654 .tokens = {(void *)&pcmd_quit_token_cmd, NULL},
656 cmdline_parse_inst_t pcmd_drvinfo = {
657 .f = pcmd_drvinfo_callback,
659 .help_str = "drvinfo\n Print driver info",
660 .tokens = {(void *)&pcmd_drvinfo_token_cmd, NULL},
662 cmdline_parse_inst_t pcmd_link = {
663 .f = pcmd_link_callback,
665 .help_str = "link\n Print port link states",
666 .tokens = {(void *)&pcmd_link_token_cmd, NULL},
668 cmdline_parse_inst_t pcmd_regs = {
669 .f = pcmd_regs_callback,
671 .help_str = "regs <port_id> <filename>\n"
672 " Dump port register(s) to file",
674 (void *)&pcmd_regs_token_cmd,
675 (void *)&pcmd_intstr_token_port,
676 (void *)&pcmd_intstr_token_opt,
680 cmdline_parse_inst_t pcmd_eeprom = {
681 .f = pcmd_eeprom_callback,
683 .help_str = "eeprom <port_id> <filename>\n Dump EEPROM to file",
685 (void *)&pcmd_eeprom_token_cmd,
686 (void *)&pcmd_intstr_token_port,
687 (void *)&pcmd_intstr_token_opt,
691 cmdline_parse_inst_t pcmd_pause_noopt = {
692 .f = pcmd_pause_callback,
693 .data = (void *)0x01,
694 .help_str = "pause <port_id>\n Print port pause state",
696 (void *)&pcmd_pause_token_cmd,
697 (void *)&pcmd_pause_token_port,
701 cmdline_parse_inst_t pcmd_pause = {
702 .f = pcmd_pause_callback,
705 "pause <port_id> <all|tx|rx|none>\n Pause/unpause port",
707 (void *)&pcmd_pause_token_cmd,
708 (void *)&pcmd_pause_token_port,
709 (void *)&pcmd_pause_token_opt,
713 cmdline_parse_inst_t pcmd_open = {
714 .f = pcmd_open_callback,
716 .help_str = "open <port_id>\n Open port",
718 (void *)&pcmd_open_token_cmd,
719 (void *)&pcmd_int_token_port,
723 cmdline_parse_inst_t pcmd_stop = {
724 .f = pcmd_stop_callback,
726 .help_str = "stop <port_id>\n Stop port",
728 (void *)&pcmd_stop_token_cmd,
729 (void *)&pcmd_int_token_port,
733 cmdline_parse_inst_t pcmd_rxmode = {
734 .f = pcmd_rxmode_callback,
736 .help_str = "rxmode <port_id>\n Toggle port Rx mode",
738 (void *)&pcmd_rxmode_token_cmd,
739 (void *)&pcmd_int_token_port,
743 cmdline_parse_inst_t pcmd_macaddr_get = {
744 .f = pcmd_macaddr_callback,
746 .help_str = "macaddr <port_id>\n"
749 (void *)&pcmd_macaddr_token_cmd,
750 (void *)&pcmd_intstr_token_port,
754 cmdline_parse_inst_t pcmd_macaddr = {
755 .f = pcmd_macaddr_callback,
756 .data = (void *)0x01,
758 "macaddr <port_id> <mac_addr>\n"
761 (void *)&pcmd_macaddr_token_cmd,
762 (void *)&pcmd_intmac_token_port,
763 (void *)&pcmd_intmac_token_mac,
767 cmdline_parse_inst_t pcmd_mtu = {
768 .f = pcmd_mtu_callback,
770 .help_str = "mtu <port_id> <mtu_value>\n"
773 (void *)&pcmd_mtu_token_cmd,
774 (void *)&pcmd_intstr_token_port,
775 (void *)&pcmd_intstr_token_opt,
779 cmdline_parse_inst_t pcmd_portstats = {
780 .f = pcmd_portstats_callback,
782 .help_str = "portstats <port_id>\n"
783 " Print port eth statistics",
785 (void *)&pcmd_portstats_token_cmd,
786 (void *)&pcmd_int_token_port,
790 cmdline_parse_inst_t pcmd_ringparam = {
791 .f = pcmd_ringparam_callback,
793 .help_str = "ringparam <port_id>\n"
794 " Print ring parameters",
796 (void *)&pcmd_ringparam_token_cmd,
797 (void *)&pcmd_intintint_token_port,
801 cmdline_parse_inst_t pcmd_ringparam_set = {
802 .f = pcmd_ringparam_callback,
804 .help_str = "ringparam <port_id> <tx_param> <rx_param>\n"
805 " Set ring parameters",
807 (void *)&pcmd_ringparam_token_cmd,
808 (void *)&pcmd_intintint_token_port,
809 (void *)&pcmd_intintint_token_tx,
810 (void *)&pcmd_intintint_token_rx,
814 cmdline_parse_inst_t pcmd_validate = {
815 .f = pcmd_validate_callback,
817 .help_str = "validate <mac_addr>\n"
818 " Check that MAC address is valid unicast address",
820 (void *)&pcmd_validate_token_cmd,
821 (void *)&pcmd_intmac_token_mac,
825 cmdline_parse_inst_t pcmd_vlan = {
826 .f = pcmd_vlan_callback,
828 .help_str = "vlan <port_id> <add|del> <vlan_id>\n"
829 " Add/remove VLAN id",
831 (void *)&pcmd_vlan_token_cmd,
832 (void *)&pcmd_vlan_token_port,
833 (void *)&pcmd_vlan_token_mode,
834 (void *)&pcmd_vlan_token_vid,
840 cmdline_parse_ctx_t list_prompt_commands[] = {
841 (cmdline_parse_inst_t *)&pcmd_drvinfo,
842 (cmdline_parse_inst_t *)&pcmd_eeprom,
843 (cmdline_parse_inst_t *)&pcmd_link,
844 (cmdline_parse_inst_t *)&pcmd_macaddr_get,
845 (cmdline_parse_inst_t *)&pcmd_macaddr,
846 (cmdline_parse_inst_t *)&pcmd_mtu,
847 (cmdline_parse_inst_t *)&pcmd_open,
848 (cmdline_parse_inst_t *)&pcmd_pause_noopt,
849 (cmdline_parse_inst_t *)&pcmd_pause,
850 (cmdline_parse_inst_t *)&pcmd_portstats,
851 (cmdline_parse_inst_t *)&pcmd_regs,
852 (cmdline_parse_inst_t *)&pcmd_ringparam,
853 (cmdline_parse_inst_t *)&pcmd_ringparam_set,
854 (cmdline_parse_inst_t *)&pcmd_rxmode,
855 (cmdline_parse_inst_t *)&pcmd_stop,
856 (cmdline_parse_inst_t *)&pcmd_validate,
857 (cmdline_parse_inst_t *)&pcmd_vlan,
858 (cmdline_parse_inst_t *)&pcmd_quit,
863 void ethapp_main(void)
865 struct cmdline *ctx_cmdline;
867 ctx_cmdline = cmdline_stdin_new(list_prompt_commands, "EthApp> ");
868 cmdline_interact(ctx_cmdline);
869 cmdline_stdin_exit(ctx_cmdline);