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 memset(&info, 0, sizeof(info));
181 if (rte_ethtool_get_drvinfo(id_port, &info)) {
182 printf("Error getting info for port %i\n", id_port);
185 printf("Port %i driver: %s (ver: %s)\n",
186 id_port, info.driver, info.version
188 printf("firmware-version: %s\n", info.fw_version);
194 pcmd_link_callback(__rte_unused void *ptr_params,
195 __rte_unused struct cmdline *ctx,
196 __rte_unused void *ptr_data)
198 int num_ports = rte_eth_dev_count();
199 int id_port, stat_port;
201 for (id_port = 0; id_port < num_ports; id_port++) {
202 if (!rte_eth_dev_is_valid_port(id_port))
204 stat_port = rte_ethtool_get_link(id_port);
207 printf("Port %i: Down\n", id_port);
210 printf("Port %i: Up\n", id_port);
213 printf("Port %i: Error getting link status\n",
224 pcmd_regs_callback(void *ptr_params,
225 __rte_unused struct cmdline *ctx,
226 __rte_unused void *ptr_data)
228 struct pcmd_intstr_params *params = ptr_params;
230 struct ethtool_regs regs;
231 unsigned char *buf_data;
234 if (!rte_eth_dev_is_valid_port(params->port)) {
235 printf("Error: Invalid port number %i\n", params->port);
238 len_regs = rte_ethtool_get_regs_len(params->port);
240 printf("Port %i: %i bytes\n", params->port, len_regs);
241 buf_data = malloc(len_regs);
242 if (buf_data == NULL) {
243 printf("Error allocating %i bytes for buffer\n",
247 if (!rte_ethtool_get_regs(params->port, ®s, buf_data)) {
248 fp_regs = fopen(params->opt, "wb");
249 if (fp_regs == NULL) {
250 printf("Error opening '%s' for writing\n",
253 if ((int)fwrite(buf_data,
255 fp_regs) != len_regs)
256 printf("Error writing '%s'\n",
262 } else if (len_regs == -ENOTSUP)
263 printf("Port %i: Operation not supported\n", params->port);
265 printf("Port %i: Error getting registers\n", params->port);
270 pcmd_eeprom_callback(void *ptr_params,
271 __rte_unused struct cmdline *ctx,
272 __rte_unused void *ptr_data)
274 struct pcmd_intstr_params *params = ptr_params;
275 struct ethtool_eeprom info_eeprom;
279 unsigned char bytes_eeprom[EEPROM_DUMP_CHUNKSIZE];
282 if (!rte_eth_dev_is_valid_port(params->port)) {
283 printf("Error: Invalid port number %i\n", params->port);
286 len_eeprom = rte_ethtool_get_eeprom_len(params->port);
287 if (len_eeprom > 0) {
288 fp_eeprom = fopen(params->opt, "wb");
289 if (fp_eeprom == NULL) {
290 printf("Error opening '%s' for writing\n",
294 printf("Total EEPROM length: %i bytes\n", len_eeprom);
295 info_eeprom.len = EEPROM_DUMP_CHUNKSIZE;
297 pos_eeprom < len_eeprom;
298 pos_eeprom += EEPROM_DUMP_CHUNKSIZE) {
299 info_eeprom.offset = pos_eeprom;
300 if (pos_eeprom + EEPROM_DUMP_CHUNKSIZE > len_eeprom)
301 info_eeprom.len = len_eeprom - pos_eeprom;
303 info_eeprom.len = EEPROM_DUMP_CHUNKSIZE;
304 stat = rte_ethtool_get_eeprom(
305 params->port, &info_eeprom, bytes_eeprom
308 printf("EEPROM read error %i\n", stat);
311 if (fwrite(bytes_eeprom,
313 fp_eeprom) != info_eeprom.len) {
314 printf("Error writing '%s'\n", params->opt);
319 } else if (len_eeprom == 0)
320 printf("Port %i: Device does not have EEPROM\n", params->port);
321 else if (len_eeprom == -ENOTSUP)
322 printf("Port %i: Operation not supported\n", params->port);
324 printf("Port %i: Error getting EEPROM\n", params->port);
329 pcmd_pause_callback(void *ptr_params,
330 __rte_unused struct cmdline *ctx,
333 struct pcmd_intstr_params *params = ptr_params;
334 struct ethtool_pauseparam info;
337 if (!rte_eth_dev_is_valid_port(params->port)) {
338 printf("Error: Invalid port number %i\n", params->port);
341 if (ptr_data != NULL) {
342 stat = rte_ethtool_get_pauseparam(params->port, &info);
344 memset(&info, 0, sizeof(info));
345 if (strcasecmp("all", params->opt) == 0) {
348 } else if (strcasecmp("tx", params->opt) == 0) {
351 } else if (strcasecmp("rx", params->opt) == 0) {
358 /* Assume auto-negotiation wanted */
360 stat = rte_ethtool_set_pauseparam(params->port, &info);
363 if (info.rx_pause && info.tx_pause)
364 printf("Port %i: Tx & Rx Paused\n", params->port);
365 else if (info.rx_pause)
366 printf("Port %i: Rx Paused\n", params->port);
367 else if (info.tx_pause)
368 printf("Port %i: Tx Paused\n", params->port);
370 printf("Port %i: Tx & Rx not paused\n", params->port);
371 } else if (stat == -ENOTSUP)
372 printf("Port %i: Operation not supported\n", params->port);
374 printf("Port %i: Error %i\n", params->port, stat);
379 pcmd_open_callback(__rte_unused void *ptr_params,
380 __rte_unused struct cmdline *ctx,
381 __rte_unused void *ptr_data)
383 struct pcmd_int_params *params = ptr_params;
386 if (!rte_eth_dev_is_valid_port(params->port)) {
387 printf("Error: Invalid port number %i\n", params->port);
390 lock_port(params->port);
391 stat = rte_ethtool_net_open(params->port);
392 mark_port_active(params->port);
393 unlock_port(params->port);
396 else if (stat == -ENOTSUP)
397 printf("Port %i: Operation not supported\n", params->port);
399 printf("Port %i: Error opening device\n", params->port);
403 pcmd_stop_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_stop(params->port);
416 mark_port_inactive(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 stopping device\n", params->port);
428 pcmd_rxmode_callback(void *ptr_params,
429 __rte_unused struct cmdline *ctx,
430 __rte_unused void *ptr_data)
432 struct pcmd_intstr_params *params = ptr_params;
435 if (!rte_eth_dev_is_valid_port(params->port)) {
436 printf("Error: Invalid port number %i\n", params->port);
439 stat = rte_ethtool_net_set_rx_mode(params->port);
442 else if (stat == -ENOTSUP)
443 printf("Port %i: Operation not supported\n", params->port);
445 printf("Port %i: Error setting rx mode\n", params->port);
450 pcmd_macaddr_callback(void *ptr_params,
451 __rte_unused struct cmdline *ctx,
454 struct pcmd_intmac_params *params = ptr_params;
455 struct ether_addr mac_addr;
459 if (!rte_eth_dev_is_valid_port(params->port)) {
460 printf("Error: Invalid port number %i\n", params->port);
463 if (ptr_data != NULL) {
464 lock_port(params->port);
465 stat = rte_ethtool_net_set_mac_addr(params->port,
467 mark_port_newmac(params->port);
468 unlock_port(params->port);
470 printf("MAC address changed\n");
474 stat = rte_ethtool_net_get_mac_addr(params->port, &mac_addr);
477 "Port %i MAC Address: %02x:%02x:%02x:%02x:%02x:%02x\n",
479 mac_addr.addr_bytes[0],
480 mac_addr.addr_bytes[1],
481 mac_addr.addr_bytes[2],
482 mac_addr.addr_bytes[3],
483 mac_addr.addr_bytes[4],
484 mac_addr.addr_bytes[5]);
489 printf("Port %i: Error %s\n", params->port,
494 pcmd_mtu_callback(void *ptr_params,
495 __rte_unused struct cmdline *ctx,
496 __rte_unused void *ptr_data)
498 struct pcmd_intstr_params *params = ptr_params;
503 if (!rte_eth_dev_is_valid_port(params->port)) {
504 printf("Error: Invalid port number %i\n", params->port);
507 new_mtu = atoi(params->opt);
508 new_mtu = strtoul(params->opt, &ptr_parse_end, 10);
509 if (*ptr_parse_end != '\0' ||
510 new_mtu < ETHER_MIN_MTU ||
511 new_mtu > ETHER_MAX_JUMBO_FRAME_LEN) {
512 printf("Port %i: Invalid MTU value\n", params->port);
515 stat = rte_ethtool_net_change_mtu(params->port, new_mtu);
517 printf("Port %i: MTU set to %i\n", params->port, new_mtu);
518 else if (stat == -ENOTSUP)
519 printf("Port %i: Operation not supported\n", params->port);
521 printf("Port %i: Error setting MTU\n", params->port);
526 static void pcmd_portstats_callback(__rte_unused void *ptr_params,
527 __rte_unused struct cmdline *ctx,
528 __rte_unused void *ptr_data)
530 struct pcmd_int_params *params = ptr_params;
531 struct rte_eth_stats stat_info;
534 if (!rte_eth_dev_is_valid_port(params->port)) {
535 printf("Error: Invalid port number %i\n", params->port);
538 stat = rte_ethtool_net_get_stats64(params->port, &stat_info);
540 printf("Port %i stats\n", params->port);
541 printf(" In: %" PRIu64 " (%" PRIu64 " bytes)\n"
542 " Out: %"PRIu64" (%"PRIu64 " bytes)\n"
548 stat_info.ierrors+stat_info.oerrors
550 } else if (stat == -ENOTSUP)
551 printf("Port %i: Operation not supported\n", params->port);
553 printf("Port %i: Error fetching statistics\n", params->port);
556 static void pcmd_ringparam_callback(__rte_unused void *ptr_params,
557 __rte_unused struct cmdline *ctx,
560 struct pcmd_intintint_params *params = ptr_params;
561 struct ethtool_ringparam ring_data;
562 struct ethtool_ringparam ring_params;
565 if (!rte_eth_dev_is_valid_port(params->port)) {
566 printf("Error: Invalid port number %i\n", params->port);
569 if (ptr_data == NULL) {
570 stat = rte_ethtool_get_ringparam(params->port, &ring_data);
572 printf("Port %i ring parameters\n"
573 " Rx Pending: %i (%i max)\n"
574 " Tx Pending: %i (%i max)\n",
576 ring_data.rx_pending,
577 ring_data.rx_max_pending,
578 ring_data.tx_pending,
579 ring_data.tx_max_pending);
582 if (params->tx < 1 || params->rx < 1) {
583 printf("Error: Invalid parameters\n");
586 memset(&ring_params, 0, sizeof(struct ethtool_ringparam));
587 ring_params.tx_pending = params->tx;
588 ring_params.rx_pending = params->rx;
589 lock_port(params->port);
590 stat = rte_ethtool_set_ringparam(params->port, &ring_params);
591 unlock_port(params->port);
595 else if (stat == -ENOTSUP)
596 printf("Port %i: Operation not supported\n", params->port);
598 printf("Port %i: Error fetching statistics\n", params->port);
601 static void pcmd_validate_callback(void *ptr_params,
602 __rte_unused struct cmdline *ctx,
603 __rte_unused void *ptr_data)
605 struct pcmd_intmac_params *params = ptr_params;
607 if (rte_ethtool_net_validate_addr(0, ¶ms->mac))
608 printf("Address is unicast\n");
610 printf("Address is not unicast\n");
614 static void pcmd_vlan_callback(__rte_unused void *ptr_params,
615 __rte_unused struct cmdline *ctx,
616 __rte_unused void *ptr_data)
618 struct pcmd_vlan_params *params = ptr_params;
621 if (!rte_eth_dev_is_valid_port(params->port)) {
622 printf("Error: Invalid port number %i\n", params->port);
627 if (strcasecmp("add", params->mode) == 0) {
628 stat = rte_ethtool_net_vlan_rx_add_vid(
629 params->port, params->vid
632 printf("VLAN vid %i added\n", params->vid);
634 } else if (strcasecmp("del", params->mode) == 0) {
635 stat = rte_ethtool_net_vlan_rx_kill_vid(
636 params->port, params->vid
639 printf("VLAN vid %i removed\n", params->vid);
641 /* Should not happen! */
642 printf("Error: Bad mode %s\n", params->mode);
644 if (stat == -ENOTSUP)
645 printf("Port %i: Operation not supported\n", params->port);
646 else if (stat == -ENOSYS)
647 printf("Port %i: VLAN filtering disabled\n", params->port);
649 printf("Port %i: Error changing VLAN setup (code %i)\n",
650 params->port, -stat);
654 cmdline_parse_inst_t pcmd_quit = {
655 .f = pcmd_quit_callback,
657 .help_str = "quit\n Exit program",
658 .tokens = {(void *)&pcmd_quit_token_cmd, NULL},
660 cmdline_parse_inst_t pcmd_drvinfo = {
661 .f = pcmd_drvinfo_callback,
663 .help_str = "drvinfo\n Print driver info",
664 .tokens = {(void *)&pcmd_drvinfo_token_cmd, NULL},
666 cmdline_parse_inst_t pcmd_link = {
667 .f = pcmd_link_callback,
669 .help_str = "link\n Print port link states",
670 .tokens = {(void *)&pcmd_link_token_cmd, NULL},
672 cmdline_parse_inst_t pcmd_regs = {
673 .f = pcmd_regs_callback,
675 .help_str = "regs <port_id> <filename>\n"
676 " Dump port register(s) to file",
678 (void *)&pcmd_regs_token_cmd,
679 (void *)&pcmd_intstr_token_port,
680 (void *)&pcmd_intstr_token_opt,
684 cmdline_parse_inst_t pcmd_eeprom = {
685 .f = pcmd_eeprom_callback,
687 .help_str = "eeprom <port_id> <filename>\n Dump EEPROM to file",
689 (void *)&pcmd_eeprom_token_cmd,
690 (void *)&pcmd_intstr_token_port,
691 (void *)&pcmd_intstr_token_opt,
695 cmdline_parse_inst_t pcmd_pause_noopt = {
696 .f = pcmd_pause_callback,
697 .data = (void *)0x01,
698 .help_str = "pause <port_id>\n Print port pause state",
700 (void *)&pcmd_pause_token_cmd,
701 (void *)&pcmd_pause_token_port,
705 cmdline_parse_inst_t pcmd_pause = {
706 .f = pcmd_pause_callback,
709 "pause <port_id> <all|tx|rx|none>\n Pause/unpause port",
711 (void *)&pcmd_pause_token_cmd,
712 (void *)&pcmd_pause_token_port,
713 (void *)&pcmd_pause_token_opt,
717 cmdline_parse_inst_t pcmd_open = {
718 .f = pcmd_open_callback,
720 .help_str = "open <port_id>\n Open port",
722 (void *)&pcmd_open_token_cmd,
723 (void *)&pcmd_int_token_port,
727 cmdline_parse_inst_t pcmd_stop = {
728 .f = pcmd_stop_callback,
730 .help_str = "stop <port_id>\n Stop port",
732 (void *)&pcmd_stop_token_cmd,
733 (void *)&pcmd_int_token_port,
737 cmdline_parse_inst_t pcmd_rxmode = {
738 .f = pcmd_rxmode_callback,
740 .help_str = "rxmode <port_id>\n Toggle port Rx mode",
742 (void *)&pcmd_rxmode_token_cmd,
743 (void *)&pcmd_int_token_port,
747 cmdline_parse_inst_t pcmd_macaddr_get = {
748 .f = pcmd_macaddr_callback,
750 .help_str = "macaddr <port_id>\n"
753 (void *)&pcmd_macaddr_token_cmd,
754 (void *)&pcmd_intstr_token_port,
758 cmdline_parse_inst_t pcmd_macaddr = {
759 .f = pcmd_macaddr_callback,
760 .data = (void *)0x01,
762 "macaddr <port_id> <mac_addr>\n"
765 (void *)&pcmd_macaddr_token_cmd,
766 (void *)&pcmd_intmac_token_port,
767 (void *)&pcmd_intmac_token_mac,
771 cmdline_parse_inst_t pcmd_mtu = {
772 .f = pcmd_mtu_callback,
774 .help_str = "mtu <port_id> <mtu_value>\n"
777 (void *)&pcmd_mtu_token_cmd,
778 (void *)&pcmd_intstr_token_port,
779 (void *)&pcmd_intstr_token_opt,
783 cmdline_parse_inst_t pcmd_portstats = {
784 .f = pcmd_portstats_callback,
786 .help_str = "portstats <port_id>\n"
787 " Print port eth statistics",
789 (void *)&pcmd_portstats_token_cmd,
790 (void *)&pcmd_int_token_port,
794 cmdline_parse_inst_t pcmd_ringparam = {
795 .f = pcmd_ringparam_callback,
797 .help_str = "ringparam <port_id>\n"
798 " Print ring parameters",
800 (void *)&pcmd_ringparam_token_cmd,
801 (void *)&pcmd_intintint_token_port,
805 cmdline_parse_inst_t pcmd_ringparam_set = {
806 .f = pcmd_ringparam_callback,
808 .help_str = "ringparam <port_id> <tx_param> <rx_param>\n"
809 " Set ring parameters",
811 (void *)&pcmd_ringparam_token_cmd,
812 (void *)&pcmd_intintint_token_port,
813 (void *)&pcmd_intintint_token_tx,
814 (void *)&pcmd_intintint_token_rx,
818 cmdline_parse_inst_t pcmd_validate = {
819 .f = pcmd_validate_callback,
821 .help_str = "validate <mac_addr>\n"
822 " Check that MAC address is valid unicast address",
824 (void *)&pcmd_validate_token_cmd,
825 (void *)&pcmd_intmac_token_mac,
829 cmdline_parse_inst_t pcmd_vlan = {
830 .f = pcmd_vlan_callback,
832 .help_str = "vlan <port_id> <add|del> <vlan_id>\n"
833 " Add/remove VLAN id",
835 (void *)&pcmd_vlan_token_cmd,
836 (void *)&pcmd_vlan_token_port,
837 (void *)&pcmd_vlan_token_mode,
838 (void *)&pcmd_vlan_token_vid,
844 cmdline_parse_ctx_t list_prompt_commands[] = {
845 (cmdline_parse_inst_t *)&pcmd_drvinfo,
846 (cmdline_parse_inst_t *)&pcmd_eeprom,
847 (cmdline_parse_inst_t *)&pcmd_link,
848 (cmdline_parse_inst_t *)&pcmd_macaddr_get,
849 (cmdline_parse_inst_t *)&pcmd_macaddr,
850 (cmdline_parse_inst_t *)&pcmd_mtu,
851 (cmdline_parse_inst_t *)&pcmd_open,
852 (cmdline_parse_inst_t *)&pcmd_pause_noopt,
853 (cmdline_parse_inst_t *)&pcmd_pause,
854 (cmdline_parse_inst_t *)&pcmd_portstats,
855 (cmdline_parse_inst_t *)&pcmd_regs,
856 (cmdline_parse_inst_t *)&pcmd_ringparam,
857 (cmdline_parse_inst_t *)&pcmd_ringparam_set,
858 (cmdline_parse_inst_t *)&pcmd_rxmode,
859 (cmdline_parse_inst_t *)&pcmd_stop,
860 (cmdline_parse_inst_t *)&pcmd_validate,
861 (cmdline_parse_inst_t *)&pcmd_vlan,
862 (cmdline_parse_inst_t *)&pcmd_quit,
867 void ethapp_main(void)
869 struct cmdline *ctx_cmdline;
871 ctx_cmdline = cmdline_stdin_new(list_prompt_commands, "EthApp> ");
872 cmdline_interact(ctx_cmdline);
873 cmdline_stdin_exit(ctx_cmdline);