2 * Copyright (c) 2011 Chelsio Communications, Inc.
4 * Written by: Navdeep Parhar <np@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
40 #include <sys/ioctl.h>
43 #include <sys/types.h>
44 #include <sys/socket.h>
46 #include <net/ethernet.h>
47 #include <netinet/in.h>
48 #include <arpa/inet.h>
52 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
54 #define max(x, y) ((x) > (y) ? (x) : (y))
56 static const char *progname, *nexus;
57 static int chip_id; /* 4 for T4, 5 for T5 */
67 const struct reg_info *ri;
71 const char *name; /* Field name */
72 unsigned short start; /* Start bit position */
73 unsigned short end; /* End bit position */
74 unsigned char shift; /* # of low order bits omitted and implicitly 0 */
75 unsigned char hex; /* Print field in hex instead of decimal */
76 unsigned char islog2; /* Field contains the base-2 log of the value */
79 #include "reg_defs_t4.c"
80 #include "reg_defs_t4vf.c"
81 #include "reg_defs_t5.c"
86 fprintf(fp, "Usage: %s <nexus> [operation]\n", progname);
88 "\tclearstats <port> clear port statistics\n"
89 "\tcontext <type> <id> show an SGE context\n"
90 "\tfilter <idx> [<param> <val>] ... set a filter\n"
91 "\tfilter <idx> delete|clear delete a filter\n"
92 "\tfilter list list all filters\n"
93 "\tfilter mode [<match>] ... get/set global filter mode\n"
94 "\ti2c <port> <devaddr> <addr> [<len>] read from i2c device\n"
95 "\tloadfw <fw-image.bin> install firmware\n"
96 "\tmemdump <addr> <len> dump a memory range\n"
97 "\treg <address>[=<val>] read/write register\n"
98 "\treg64 <address>[=<val>] read/write 64 bit register\n"
99 "\tregdump [<module>] ... dump registers\n"
100 "\tstdio interactive mode\n"
101 "\ttcb <tid> read TCB\n"
102 "\ttracer <idx> tx<n>|rx<n> set and enable a tracer)\n"
103 "\ttracer <idx> disable|enable disable or enable a tracer\n"
104 "\ttracer list list all tracers\n"
108 static inline unsigned int
109 get_card_vers(unsigned int version)
111 return (version & 0x3ff);
115 real_doit(unsigned long cmd, void *data, const char *cmdstr)
123 snprintf(buf, sizeof(buf), "/dev/%s", nexus);
124 if ((fd = open(buf, O_RDWR)) < 0) {
125 warn("open(%s)", nexus);
129 chip_id = nexus[1] - '0';
132 rc = ioctl(fd, cmd, data);
140 #define doit(x, y) real_doit(x, y, #x)
143 str_to_number(const char *s, long *val, long long *vall)
148 *vall = strtoll(s, &p, 0);
150 *val = strtol(s, &p, 0);
158 read_reg(long addr, int size, long long *val)
163 reg.addr = (uint32_t) addr;
164 reg.size = (uint32_t) size;
167 rc = doit(CHELSIO_T4_GETREG, ®);
175 write_reg(long addr, int size, long long val)
179 reg.addr = (uint32_t) addr;
180 reg.size = (uint32_t) size;
181 reg.val = (uint64_t) val;
183 return doit(CHELSIO_T4_SETREG, ®);
187 register_io(int argc, const char *argv[], int size)
195 /* <reg> OR <reg>=<value> */
197 p = str_to_number(argv[0], &addr, NULL);
200 warnx("invalid register \"%s\"", argv[0]);
206 p = str_to_number(v, NULL, &val);
209 warnx("invalid value \"%s\"", v);
214 } else if (argc == 2) {
219 p = str_to_number(argv[0], &addr, NULL);
221 warnx("invalid register \"%s\"", argv[0]);
225 p = str_to_number(argv[1], NULL, &val);
227 warnx("invalid value \"%s\"", argv[1]);
231 warnx("reg: invalid number of arguments (%d)", argc);
236 rc = write_reg(addr, size, val);
238 rc = read_reg(addr, size, &val);
240 printf("0x%llx [%llu]\n", val, val);
246 static inline uint32_t
247 xtract(uint32_t val, int shift, int len)
249 return (val >> shift) & ((1 << len) - 1);
253 dump_block_regs(const struct reg_info *reg_array, const uint32_t *regs)
255 uint32_t reg_val = 0;
257 for ( ; reg_array->name; ++reg_array)
258 if (!reg_array->len) {
259 reg_val = regs[reg_array->addr / 4];
260 printf("[%#7x] %-47s %#-10x %u\n", reg_array->addr,
261 reg_array->name, reg_val, reg_val);
263 uint32_t v = xtract(reg_val, reg_array->addr,
266 printf(" %*u:%u %-47s %#-10x %u\n",
267 reg_array->addr < 10 ? 3 : 2,
268 reg_array->addr + reg_array->len - 1,
269 reg_array->addr, reg_array->name, v, v);
276 dump_regs_table(int argc, const char *argv[], const uint32_t *regs,
277 const struct mod_regs *modtab, int nmodules)
281 for (i = 0; i < argc; i++) {
282 for (j = 0; j < nmodules; j++) {
283 if (!strcmp(argv[i], modtab[j].name))
288 warnx("invalid register block \"%s\"", argv[i]);
289 fprintf(stderr, "\nAvailable blocks:");
290 for ( ; nmodules; nmodules--, modtab++)
291 fprintf(stderr, " %s", modtab->name);
292 fprintf(stderr, "\n");
297 for ( ; nmodules; nmodules--, modtab++) {
299 match = argc == 0 ? 1 : 0;
300 for (i = 0; !match && i < argc; i++) {
301 if (!strcmp(argv[i], modtab->name))
306 dump_block_regs(modtab->ri, regs);
312 #define T4_MODREGS(name) { #name, t4_##name##_regs }
314 dump_regs_t4(int argc, const char *argv[], const uint32_t *regs)
316 static struct mod_regs t4_mod[] = {
318 { "pci", t4_pcie_regs },
322 { "edc0", t4_edc_0_regs },
323 { "edc1", t4_edc_1_regs },
328 { "pmrx", t4_pm_rx_regs },
329 { "pmtx", t4_pm_tx_regs },
331 { "cplsw", t4_cpl_switch_regs },
333 { "i2c", t4_i2cm_regs },
344 return dump_regs_table(argc, argv, regs, t4_mod, ARRAY_SIZE(t4_mod));
349 dump_regs_t4vf(int argc, const char *argv[], const uint32_t *regs)
351 static struct mod_regs t4vf_mod[] = {
352 { "sge", t4vf_sge_regs },
353 { "mps", t4vf_mps_regs },
354 { "pl", t4vf_pl_regs },
355 { "mbdata", t4vf_mbdata_regs },
356 { "cim", t4vf_cim_regs },
359 return dump_regs_table(argc, argv, regs, t4vf_mod,
360 ARRAY_SIZE(t4vf_mod));
363 #define T5_MODREGS(name) { #name, t5_##name##_regs }
365 dump_regs_t5(int argc, const char *argv[], const uint32_t *regs)
367 static struct mod_regs t5_mod[] = {
369 { "pci", t5_pcie_regs },
371 { "mc0", t5_mc_0_regs },
372 { "mc1", t5_mc_1_regs },
374 { "edc0", t5_edc_t50_regs },
375 { "edc1", t5_edc_t51_regs },
378 { "ulprx", t5_ulp_rx_regs },
379 { "ulptx", t5_ulp_tx_regs },
380 { "pmrx", t5_pm_rx_regs },
381 { "pmtx", t5_pm_tx_regs },
383 { "cplsw", t5_cpl_switch_regs },
385 { "i2c", t5_i2cm_regs },
394 { "hma", t5_hma_t5_regs }
397 return dump_regs_table(argc, argv, regs, t5_mod, ARRAY_SIZE(t5_mod));
402 dump_regs(int argc, const char *argv[])
404 int vers, revision, rc;
405 struct t4_regdump regs;
408 len = max(T4_REGDUMP_SIZE, T5_REGDUMP_SIZE);
409 regs.data = calloc(1, len);
410 if (regs.data == NULL) {
411 warnc(ENOMEM, "regdump");
416 rc = doit(CHELSIO_T4_REGDUMP, ®s);
420 vers = get_card_vers(regs.version);
421 revision = (regs.version >> 10) & 0x3f;
424 if (revision == 0x3f)
425 rc = dump_regs_t4vf(argc, argv, regs.data);
427 rc = dump_regs_t4(argc, argv, regs.data);
428 } else if (vers == 5)
429 rc = dump_regs_t5(argc, argv, regs.data);
431 warnx("%s (type %d, rev %d) is not a known card.",
432 nexus, vers, revision);
441 do_show_info_header(uint32_t mode)
445 printf ("%4s %8s", "Idx", "Hits");
446 for (i = T4_FILTER_FCoE; i <= T4_FILTER_IP_FRAGMENT; i <<= 1) {
457 printf (" vld:VNIC");
461 printf (" vld:VLAN");
464 case T4_FILTER_IP_TOS:
468 case T4_FILTER_IP_PROTO:
472 case T4_FILTER_ETH_TYPE:
476 case T4_FILTER_MAC_IDX:
480 case T4_FILTER_MPS_HIT_TYPE:
484 case T4_FILTER_IP_FRAGMENT:
489 /* compressed filter field not enabled */
493 printf(" %20s %20s %9s %9s %s\n",
494 "DIP", "SIP", "DPORT", "SPORT", "Action");
498 * Parse an argument sub-vector as a { <parameter name> <value>[:<mask>] }
499 * ordered tuple. If the parameter name in the argument sub-vector does not
500 * match the passed in parameter name, then a zero is returned for the
501 * function and no parsing is performed. If there is a match, then the value
502 * and optional mask are parsed and returned in the provided return value
503 * pointers. If no optional mask is specified, then a default mask of all 1s
506 * An error in parsing the value[:mask] will result in an error message and
507 * program termination.
510 parse_val_mask(const char *param, const char *args[], uint32_t *val,
515 if (strcmp(param, args[0]) != 0)
518 *val = strtoul(args[1], &p, 0);
525 if (p[0] == ':' && p[1] != 0) {
526 *mask = strtoul(p+1, &p, 0);
532 warnx("parameter \"%s\" has bad \"value[:mask]\" %s",
539 * Parse an argument sub-vector as a { <parameter name> <addr>[/<mask>] }
540 * ordered tuple. If the parameter name in the argument sub-vector does not
541 * match the passed in parameter name, then a zero is returned for the
542 * function and no parsing is performed. If there is a match, then the value
543 * and optional mask are parsed and returned in the provided return value
544 * pointers. If no optional mask is specified, then a default mask of all 1s
547 * The value return parameter "afp" is used to specify the expected address
548 * family -- IPv4 or IPv6 -- of the address[/mask] and return its actual
549 * format. A passed in value of AF_UNSPEC indicates that either IPv4 or IPv6
550 * is acceptable; AF_INET means that only IPv4 addresses are acceptable; and
551 * AF_INET6 means that only IPv6 are acceptable. AF_INET is returned for IPv4
552 * and AF_INET6 for IPv6 addresses, respectively. IPv4 address/mask pairs are
553 * returned in the first four bytes of the address and mask return values with
554 * the address A.B.C.D returned with { A, B, C, D } returned in addresses { 0,
555 * 1, 2, 3}, respectively.
557 * An error in parsing the value[:mask] will result in an error message and
558 * program termination.
561 parse_ipaddr(const char *param, const char *args[], int *afp, uint8_t addr[],
564 const char *colon, *afn;
568 unsigned int masksize;
571 * Is this our parameter?
573 if (strcmp(param, args[0]) != 0)
577 * Fundamental IPv4 versus IPv6 selection.
579 colon = strchr(args[1], ':');
589 if (*afp == AF_UNSPEC)
591 else if (*afp != af) {
592 warnx("address %s is not of expected family %s",
593 args[1], *afp == AF_INET ? "IP" : "IPv6");
598 * Parse address (temporarily stripping off any "/mask"
601 slash = strchr(args[1], '/');
604 ret = inet_pton(af, args[1], addr);
608 warnx("Cannot parse %s %s address %s", param, afn, args[1]);
613 * Parse optional mask specification.
617 unsigned int prefix = strtoul(slash + 1, &p, 10);
619 if (p == slash + 1) {
620 warnx("missing address prefix for %s", param);
624 warnx("%s is not a valid address prefix", slash + 1);
627 if (prefix > masksize) {
628 warnx("prefix %u is too long for an %s address",
632 memset(mask, 0, masksize / 8);
639 for (m = mask; masksize >= 8; m++, masksize -= 8)
642 *m = ~0 << (8 - masksize);
648 * Parse an argument sub-vector as a { <parameter name> <value> } ordered
649 * tuple. If the parameter name in the argument sub-vector does not match the
650 * passed in parameter name, then a zero is returned for the function and no
651 * parsing is performed. If there is a match, then the value is parsed and
652 * returned in the provided return value pointer.
655 parse_val(const char *param, const char *args[], uint32_t *val)
659 if (strcmp(param, args[0]) != 0)
662 *val = strtoul(args[1], &p, 0);
663 if (p > args[1] && p[0] == 0)
666 warnx("parameter \"%s\" has bad \"value\" %s", args[0], args[1]);
671 filters_show_ipaddr(int type, uint8_t *addr, uint8_t *addrm)
682 for (octet = 0; octet < noctets; octet++)
683 printf("%02x", addr[octet]);
685 for (octet = 0; octet < noctets; octet++)
686 printf("%02x", addrm[octet]);
690 do_show_one_filter_info(struct t4_filter *t, uint32_t mode)
694 printf("%4d", t->idx);
695 if (t->hits == UINT64_MAX)
698 printf(" %8ju", t->hits);
701 * Compressed header portion of filter.
703 for (i = T4_FILTER_FCoE; i <= T4_FILTER_IP_FRAGMENT; i <<= 1) {
706 printf(" %1d/%1d", t->fs.val.fcoe, t->fs.mask.fcoe);
710 printf(" %1d/%1d", t->fs.val.iport, t->fs.mask.iport);
714 printf(" %1d:%1x:%02x/%1d:%1x:%02x",
715 t->fs.val.vnic_vld, (t->fs.val.vnic >> 7) & 0x7,
716 t->fs.val.vnic & 0x7f, t->fs.mask.vnic_vld,
717 (t->fs.mask.vnic >> 7) & 0x7,
718 t->fs.mask.vnic & 0x7f);
722 printf(" %1d:%04x/%1d:%04x",
723 t->fs.val.vlan_vld, t->fs.val.vlan,
724 t->fs.mask.vlan_vld, t->fs.mask.vlan);
727 case T4_FILTER_IP_TOS:
728 printf(" %02x/%02x", t->fs.val.tos, t->fs.mask.tos);
731 case T4_FILTER_IP_PROTO:
732 printf(" %02x/%02x", t->fs.val.proto, t->fs.mask.proto);
735 case T4_FILTER_ETH_TYPE:
736 printf(" %04x/%04x", t->fs.val.ethtype,
740 case T4_FILTER_MAC_IDX:
741 printf(" %03x/%03x", t->fs.val.macidx,
745 case T4_FILTER_MPS_HIT_TYPE:
746 printf(" %1x/%1x", t->fs.val.matchtype,
747 t->fs.mask.matchtype);
750 case T4_FILTER_IP_FRAGMENT:
751 printf(" %1d/%1d", t->fs.val.frag, t->fs.mask.frag);
755 /* compressed filter field not enabled */
761 * Fixed portion of filter.
763 filters_show_ipaddr(t->fs.type, t->fs.val.dip, t->fs.mask.dip);
764 filters_show_ipaddr(t->fs.type, t->fs.val.sip, t->fs.mask.sip);
765 printf(" %04x/%04x %04x/%04x",
766 t->fs.val.dport, t->fs.mask.dport,
767 t->fs.val.sport, t->fs.mask.sport);
770 * Variable length filter action.
772 if (t->fs.action == FILTER_DROP)
774 else if (t->fs.action == FILTER_SWITCH) {
775 printf(" Switch: port=%d", t->fs.eport);
778 ", dmac=%02x:%02x:%02x:%02x:%02x:%02x "
780 t->fs.dmac[0], t->fs.dmac[1],
781 t->fs.dmac[2], t->fs.dmac[3],
782 t->fs.dmac[4], t->fs.dmac[5],
786 ", smac=%02x:%02x:%02x:%02x:%02x:%02x "
788 t->fs.smac[0], t->fs.smac[1],
789 t->fs.smac[2], t->fs.smac[3],
790 t->fs.smac[4], t->fs.smac[5],
792 if (t->fs.newvlan == VLAN_REMOVE)
793 printf(", vlan=none");
794 else if (t->fs.newvlan == VLAN_INSERT)
795 printf(", vlan=insert(%x)", t->fs.vlan);
796 else if (t->fs.newvlan == VLAN_REWRITE)
797 printf(", vlan=rewrite(%x)", t->fs.vlan);
800 if (t->fs.dirsteer == 0) {
803 printf("(TCB=hash)");
805 printf("%d", t->fs.iq);
806 if (t->fs.dirsteerhash == 0)
822 uint32_t mode = 0, header = 0;
826 /* Get the global filter mode first */
827 rc = doit(CHELSIO_T4_GET_FILTER_MODE, &mode);
832 for (t.idx = 0; ; t.idx++) {
833 rc = doit(CHELSIO_T4_GET_FILTER, &t);
834 if (rc != 0 || t.idx == 0xffffffff)
838 do_show_info_header(mode);
841 do_show_one_filter_info(&t, mode);
848 get_filter_mode(void)
853 rc = doit(CHELSIO_T4_GET_FILTER_MODE, &mode);
857 if (mode & T4_FILTER_IPv4)
860 if (mode & T4_FILTER_IPv6)
863 if (mode & T4_FILTER_IP_SADDR)
866 if (mode & T4_FILTER_IP_DADDR)
869 if (mode & T4_FILTER_IP_SPORT)
872 if (mode & T4_FILTER_IP_DPORT)
875 if (mode & T4_FILTER_IP_FRAGMENT)
878 if (mode & T4_FILTER_MPS_HIT_TYPE)
879 printf("matchtype ");
881 if (mode & T4_FILTER_MAC_IDX)
884 if (mode & T4_FILTER_ETH_TYPE)
887 if (mode & T4_FILTER_IP_PROTO)
890 if (mode & T4_FILTER_IP_TOS)
893 if (mode & T4_FILTER_VLAN)
896 if (mode & T4_FILTER_VNIC)
897 printf("vnic/ovlan ");
899 if (mode & T4_FILTER_PORT)
902 if (mode & T4_FILTER_FCoE)
911 set_filter_mode(int argc, const char *argv[])
915 for (; argc; argc--, argv++) {
916 if (!strcmp(argv[0], "frag"))
917 mode |= T4_FILTER_IP_FRAGMENT;
919 if (!strcmp(argv[0], "matchtype"))
920 mode |= T4_FILTER_MPS_HIT_TYPE;
922 if (!strcmp(argv[0], "macidx"))
923 mode |= T4_FILTER_MAC_IDX;
925 if (!strcmp(argv[0], "ethtype"))
926 mode |= T4_FILTER_ETH_TYPE;
928 if (!strcmp(argv[0], "proto"))
929 mode |= T4_FILTER_IP_PROTO;
931 if (!strcmp(argv[0], "tos"))
932 mode |= T4_FILTER_IP_TOS;
934 if (!strcmp(argv[0], "vlan"))
935 mode |= T4_FILTER_VLAN;
937 if (!strcmp(argv[0], "ovlan") ||
938 !strcmp(argv[0], "vnic"))
939 mode |= T4_FILTER_VNIC;
941 if (!strcmp(argv[0], "iport"))
942 mode |= T4_FILTER_PORT;
944 if (!strcmp(argv[0], "fcoe"))
945 mode |= T4_FILTER_FCoE;
948 return doit(CHELSIO_T4_SET_FILTER_MODE, &mode);
952 del_filter(uint32_t idx)
958 return doit(CHELSIO_T4_DEL_FILTER, &t);
962 set_filter(uint32_t idx, int argc, const char *argv[])
964 int af = AF_UNSPEC, start_arg = 0;
968 warnc(EINVAL, "%s", __func__);
971 bzero(&t, sizeof (t));
975 for (start_arg = 0; start_arg + 2 <= argc; start_arg += 2) {
976 const char **args = &argv[start_arg];
979 if (!strcmp(argv[start_arg], "type")) {
981 if (!strcasecmp(argv[start_arg + 1], "ipv4"))
983 else if (!strcasecmp(argv[start_arg + 1], "ipv6"))
986 warnx("invalid type \"%s\"; "
987 "must be one of \"ipv4\" or \"ipv6\"",
988 argv[start_arg + 1]);
992 if (af != AF_UNSPEC && af != newaf) {
993 warnx("conflicting IPv4/IPv6 specifications.");
997 } else if (!parse_val_mask("fcoe", args, &val, &mask)) {
999 t.fs.mask.fcoe = mask;
1000 } else if (!parse_val_mask("iport", args, &val, &mask)) {
1001 t.fs.val.iport = val;
1002 t.fs.mask.iport = mask;
1003 } else if (!parse_val_mask("ovlan", args, &val, &mask)) {
1004 t.fs.val.vnic = val;
1005 t.fs.mask.vnic = mask;
1006 t.fs.val.vnic_vld = 1;
1007 t.fs.mask.vnic_vld = 1;
1008 } else if (!parse_val_mask("vnic", args, &val, &mask)) {
1009 t.fs.val.vnic = val;
1010 t.fs.mask.vnic = mask;
1011 t.fs.val.vnic_vld = 1;
1012 t.fs.mask.vnic_vld = 1;
1013 } else if (!parse_val_mask("ivlan", args, &val, &mask)) {
1014 t.fs.val.vlan = val;
1015 t.fs.mask.vlan = mask;
1016 t.fs.val.vlan_vld = 1;
1017 t.fs.mask.vlan_vld = 1;
1018 } else if (!parse_val_mask("tos", args, &val, &mask)) {
1020 t.fs.mask.tos = mask;
1021 } else if (!parse_val_mask("proto", args, &val, &mask)) {
1022 t.fs.val.proto = val;
1023 t.fs.mask.proto = mask;
1024 } else if (!parse_val_mask("ethtype", args, &val, &mask)) {
1025 t.fs.val.ethtype = val;
1026 t.fs.mask.ethtype = mask;
1027 } else if (!parse_val_mask("macidx", args, &val, &mask)) {
1028 t.fs.val.macidx = val;
1029 t.fs.mask.macidx = mask;
1030 } else if (!parse_val_mask("matchtype", args, &val, &mask)) {
1031 t.fs.val.matchtype = val;
1032 t.fs.mask.matchtype = mask;
1033 } else if (!parse_val_mask("frag", args, &val, &mask)) {
1034 t.fs.val.frag = val;
1035 t.fs.mask.frag = mask;
1036 } else if (!parse_val_mask("dport", args, &val, &mask)) {
1037 t.fs.val.dport = val;
1038 t.fs.mask.dport = mask;
1039 } else if (!parse_val_mask("sport", args, &val, &mask)) {
1040 t.fs.val.sport = val;
1041 t.fs.mask.sport = mask;
1042 } else if (!parse_ipaddr("dip", args, &af, t.fs.val.dip,
1045 } else if (!parse_ipaddr("sip", args, &af, t.fs.val.sip,
1048 } else if (!strcmp(argv[start_arg], "action")) {
1049 if (!strcmp(argv[start_arg + 1], "pass"))
1050 t.fs.action = FILTER_PASS;
1051 else if (!strcmp(argv[start_arg + 1], "drop"))
1052 t.fs.action = FILTER_DROP;
1053 else if (!strcmp(argv[start_arg + 1], "switch"))
1054 t.fs.action = FILTER_SWITCH;
1056 warnx("invalid action \"%s\"; must be one of"
1057 " \"pass\", \"drop\" or \"switch\"",
1058 argv[start_arg + 1]);
1061 } else if (!parse_val("hitcnts", args, &val)) {
1063 } else if (!parse_val("prio", args, &val)) {
1065 } else if (!parse_val("rpttid", args, &val)) {
1067 } else if (!parse_val("queue", args, &val)) {
1070 } else if (!parse_val("tcbhash", args, &val)) {
1072 t.fs.dirsteerhash = 1;
1073 } else if (!parse_val("eport", args, &val)) {
1075 } else if (!strcmp(argv[start_arg], "dmac")) {
1076 struct ether_addr *daddr;
1078 daddr = ether_aton(argv[start_arg + 1]);
1079 if (daddr == NULL) {
1080 warnx("invalid dmac address \"%s\"",
1081 argv[start_arg + 1]);
1084 memcpy(t.fs.dmac, daddr, ETHER_ADDR_LEN);
1086 } else if (!strcmp(argv[start_arg], "smac")) {
1087 struct ether_addr *saddr;
1089 saddr = ether_aton(argv[start_arg + 1]);
1090 if (saddr == NULL) {
1091 warnx("invalid smac address \"%s\"",
1092 argv[start_arg + 1]);
1095 memcpy(t.fs.smac, saddr, ETHER_ADDR_LEN);
1097 } else if (!strcmp(argv[start_arg], "vlan")) {
1099 if (!strcmp(argv[start_arg + 1], "none")) {
1100 t.fs.newvlan = VLAN_REMOVE;
1101 } else if (argv[start_arg + 1][0] == '=') {
1102 t.fs.newvlan = VLAN_REWRITE;
1103 } else if (argv[start_arg + 1][0] == '+') {
1104 t.fs.newvlan = VLAN_INSERT;
1105 } else if (isdigit(argv[start_arg + 1][0]) &&
1106 !parse_val_mask("vlan", args, &val, &mask)) {
1107 t.fs.val.vlan = val;
1108 t.fs.mask.vlan = mask;
1109 t.fs.val.vlan_vld = 1;
1110 t.fs.mask.vlan_vld = 1;
1112 warnx("unknown vlan parameter \"%s\"; must"
1113 " be one of \"none\", \"=<vlan>\", "
1114 " \"+<vlan>\", or \"<vlan>\"",
1115 argv[start_arg + 1]);
1118 if (t.fs.newvlan == VLAN_REWRITE ||
1119 t.fs.newvlan == VLAN_INSERT) {
1120 t.fs.vlan = strtoul(argv[start_arg + 1] + 1,
1122 if (p == argv[start_arg + 1] + 1 || p[0] != 0) {
1123 warnx("invalid vlan \"%s\"",
1124 argv[start_arg + 1]);
1129 warnx("invalid parameter \"%s\"", argv[start_arg]);
1133 if (start_arg != argc) {
1134 warnx("no value for \"%s\"", argv[start_arg]);
1139 * Check basic sanity of option combinations.
1141 if (t.fs.action != FILTER_SWITCH &&
1142 (t.fs.eport || t.fs.newdmac || t.fs.newsmac || t.fs.newvlan)) {
1143 warnx("prio, port dmac, smac and vlan only make sense with"
1144 " \"action switch\"");
1147 if (t.fs.action != FILTER_PASS &&
1148 (t.fs.rpttid || t.fs.dirsteer || t.fs.maskhash)) {
1149 warnx("rpttid, queue and tcbhash don't make sense with"
1150 " action \"drop\" or \"switch\"");
1154 t.fs.type = (af == AF_INET6 ? 1 : 0); /* default IPv4 */
1155 return doit(CHELSIO_T4_SET_FILTER, &t);
1159 filter_cmd(int argc, const char *argv[])
1166 warnx("filter: no arguments.");
1171 if (strcmp(argv[0], "list") == 0) {
1173 warnx("trailing arguments after \"list\" ignored.");
1175 return show_filters();
1179 if (argc == 1 && strcmp(argv[0], "mode") == 0)
1180 return get_filter_mode();
1183 if (strcmp(argv[0], "mode") == 0)
1184 return set_filter_mode(argc - 1, argv + 1);
1187 s = str_to_number(argv[0], NULL, &val);
1188 if (*s || val > 0xffffffffU) {
1189 warnx("\"%s\" is neither an index nor a filter subcommand.",
1193 idx = (uint32_t) val;
1195 /* <idx> delete|clear */
1197 (strcmp(argv[1], "delete") == 0 || strcmp(argv[1], "clear") == 0)) {
1198 return del_filter(idx);
1201 /* <idx> [<param> <val>] ... */
1202 return set_filter(idx, argc - 1, argv + 1);
1206 * Shows the fields of a multi-word structure. The structure is considered to
1207 * consist of @nwords 32-bit words (i.e, it's an (@nwords * 32)-bit structure)
1208 * whose fields are described by @fd. The 32-bit words are given in @words
1209 * starting with the least significant 32-bit word.
1212 show_struct(const uint32_t *words, int nwords, const struct field_desc *fd)
1215 const struct field_desc *p;
1217 for (p = fd; p->name; p++)
1218 w = max(w, strlen(p->name));
1221 unsigned long long data;
1222 int first_word = fd->start / 32;
1223 int shift = fd->start % 32;
1224 int width = fd->end - fd->start + 1;
1225 unsigned long long mask = (1ULL << width) - 1;
1227 data = (words[first_word] >> shift) |
1228 ((uint64_t)words[first_word + 1] << (32 - shift));
1230 data |= ((uint64_t)words[first_word + 2] << (64 - shift));
1234 printf("%-*s ", w, fd->name);
1235 printf(fd->hex ? "%#llx\n" : "%llu\n", data << fd->shift);
1240 #define FIELD(name, start, end) { name, start, end, 0, 0, 0 }
1241 #define FIELD1(name, start) FIELD(name, start, start)
1244 show_sge_context(const struct t4_sge_context *p)
1246 static struct field_desc egress[] = {
1247 FIELD1("StatusPgNS:", 180),
1248 FIELD1("StatusPgRO:", 179),
1249 FIELD1("FetchNS:", 178),
1250 FIELD1("FetchRO:", 177),
1251 FIELD1("Valid:", 176),
1252 FIELD("PCIeDataChannel:", 174, 175),
1253 FIELD1("DCAEgrQEn:", 173),
1254 FIELD("DCACPUID:", 168, 172),
1255 FIELD1("FCThreshOverride:", 167),
1256 FIELD("WRLength:", 162, 166),
1257 FIELD1("WRLengthKnown:", 161),
1258 FIELD1("ReschedulePending:", 160),
1259 FIELD1("OnChipQueue:", 159),
1260 FIELD1("FetchSizeMode", 158),
1261 { "FetchBurstMin:", 156, 157, 4, 0, 1 },
1262 { "FetchBurstMax:", 153, 154, 6, 0, 1 },
1263 FIELD("uPToken:", 133, 152),
1264 FIELD1("uPTokenEn:", 132),
1265 FIELD1("UserModeIO:", 131),
1266 FIELD("uPFLCredits:", 123, 130),
1267 FIELD1("uPFLCreditEn:", 122),
1268 FIELD("FID:", 111, 121),
1269 FIELD("HostFCMode:", 109, 110),
1270 FIELD1("HostFCOwner:", 108),
1271 { "CIDXFlushThresh:", 105, 107, 0, 0, 1 },
1272 FIELD("CIDX:", 89, 104),
1273 FIELD("PIDX:", 73, 88),
1274 { "BaseAddress:", 18, 72, 9, 1 },
1275 FIELD("QueueSize:", 2, 17),
1276 FIELD1("QueueType:", 1),
1277 FIELD1("CachePriority:", 0),
1280 static struct field_desc fl[] = {
1281 FIELD1("StatusPgNS:", 180),
1282 FIELD1("StatusPgRO:", 179),
1283 FIELD1("FetchNS:", 178),
1284 FIELD1("FetchRO:", 177),
1285 FIELD1("Valid:", 176),
1286 FIELD("PCIeDataChannel:", 174, 175),
1287 FIELD1("DCAEgrQEn:", 173),
1288 FIELD("DCACPUID:", 168, 172),
1289 FIELD1("FCThreshOverride:", 167),
1290 FIELD("WRLength:", 162, 166),
1291 FIELD1("WRLengthKnown:", 161),
1292 FIELD1("ReschedulePending:", 160),
1293 FIELD1("OnChipQueue:", 159),
1294 FIELD1("FetchSizeMode", 158),
1295 { "FetchBurstMin:", 156, 157, 4, 0, 1 },
1296 { "FetchBurstMax:", 153, 154, 6, 0, 1 },
1297 FIELD1("FLMcongMode:", 152),
1298 FIELD("MaxuPFLCredits:", 144, 151),
1299 FIELD("FLMcontextID:", 133, 143),
1300 FIELD1("uPTokenEn:", 132),
1301 FIELD1("UserModeIO:", 131),
1302 FIELD("uPFLCredits:", 123, 130),
1303 FIELD1("uPFLCreditEn:", 122),
1304 FIELD("FID:", 111, 121),
1305 FIELD("HostFCMode:", 109, 110),
1306 FIELD1("HostFCOwner:", 108),
1307 { "CIDXFlushThresh:", 105, 107, 0, 0, 1 },
1308 FIELD("CIDX:", 89, 104),
1309 FIELD("PIDX:", 73, 88),
1310 { "BaseAddress:", 18, 72, 9, 1 },
1311 FIELD("QueueSize:", 2, 17),
1312 FIELD1("QueueType:", 1),
1313 FIELD1("CachePriority:", 0),
1316 static struct field_desc ingress[] = {
1317 FIELD1("NoSnoop:", 145),
1318 FIELD1("RelaxedOrdering:", 144),
1319 FIELD1("GTSmode:", 143),
1320 FIELD1("ISCSICoalescing:", 142),
1321 FIELD1("Valid:", 141),
1322 FIELD1("TimerPending:", 140),
1323 FIELD1("DropRSS:", 139),
1324 FIELD("PCIeChannel:", 137, 138),
1325 FIELD1("SEInterruptArmed:", 136),
1326 FIELD1("CongestionMgtEnable:", 135),
1327 FIELD1("DCAIngQEnable:", 134),
1328 FIELD("DCACPUID:", 129, 133),
1329 FIELD1("UpdateScheduling:", 128),
1330 FIELD("UpdateDelivery:", 126, 127),
1331 FIELD1("InterruptSent:", 125),
1332 FIELD("InterruptIDX:", 114, 124),
1333 FIELD1("InterruptDestination:", 113),
1334 FIELD1("InterruptArmed:", 112),
1335 FIELD("RxIntCounter:", 106, 111),
1336 FIELD("RxIntCounterThreshold:", 104, 105),
1337 FIELD1("Generation:", 103),
1338 { "BaseAddress:", 48, 102, 9, 1 },
1339 FIELD("PIDX:", 32, 47),
1340 FIELD("CIDX:", 16, 31),
1341 { "QueueSize:", 4, 15, 4, 0 },
1342 { "QueueEntrySize:", 2, 3, 4, 0, 1 },
1343 FIELD1("QueueEntryOverride:", 1),
1344 FIELD1("CachePriority:", 0),
1347 static struct field_desc flm[] = {
1348 FIELD1("NoSnoop:", 79),
1349 FIELD1("RelaxedOrdering:", 78),
1350 FIELD1("Valid:", 77),
1351 FIELD("DCACPUID:", 72, 76),
1352 FIELD1("DCAFLEn:", 71),
1353 FIELD("EQid:", 54, 70),
1354 FIELD("SplitEn:", 52, 53),
1355 FIELD1("PadEn:", 51),
1356 FIELD1("PackEn:", 50),
1357 FIELD1("DBpriority:", 48),
1358 FIELD("PackOffset:", 16, 47),
1359 FIELD("CIDX:", 8, 15),
1360 FIELD("PIDX:", 0, 7),
1363 static struct field_desc conm[] = {
1364 FIELD1("CngDBPHdr:", 6),
1365 FIELD1("CngDBPData:", 5),
1366 FIELD1("CngIMSG:", 4),
1367 FIELD("CngChMap:", 0, 3),
1370 static struct field_desc t5_conm[] = {
1371 FIELD1("CngMPSEnable:", 21),
1372 FIELD("CngTPMode:", 19, 20),
1373 FIELD1("CngDBPHdr:", 18),
1374 FIELD1("CngDBPData:", 17),
1375 FIELD1("CngIMSG:", 16),
1376 FIELD("CngChMap:", 0, 15),
1380 if (p->mem_id == SGE_CONTEXT_EGRESS)
1381 show_struct(p->data, 6, (p->data[0] & 2) ? fl : egress);
1382 else if (p->mem_id == SGE_CONTEXT_FLM)
1383 show_struct(p->data, 3, flm);
1384 else if (p->mem_id == SGE_CONTEXT_INGRESS)
1385 show_struct(p->data, 5, ingress);
1386 else if (p->mem_id == SGE_CONTEXT_CNM)
1387 show_struct(p->data, 1, chip_id == 5 ? t5_conm : conm);
1394 get_sge_context(int argc, const char *argv[])
1399 struct t4_sge_context cntxt = {0};
1402 warnx("sge_context: incorrect number of arguments.");
1406 if (!strcmp(argv[0], "egress"))
1407 cntxt.mem_id = SGE_CONTEXT_EGRESS;
1408 else if (!strcmp(argv[0], "ingress"))
1409 cntxt.mem_id = SGE_CONTEXT_INGRESS;
1410 else if (!strcmp(argv[0], "fl"))
1411 cntxt.mem_id = SGE_CONTEXT_FLM;
1412 else if (!strcmp(argv[0], "cong"))
1413 cntxt.mem_id = SGE_CONTEXT_CNM;
1415 warnx("unknown context type \"%s\"; known types are egress, "
1416 "ingress, fl, and cong.", argv[0]);
1420 p = str_to_number(argv[1], &cid, NULL);
1422 warnx("invalid context id \"%s\"", argv[1]);
1427 rc = doit(CHELSIO_T4_GET_SGE_CONTEXT, &cntxt);
1431 show_sge_context(&cntxt);
1436 loadfw(int argc, const char *argv[])
1439 struct t4_data data = {0};
1440 const char *fname = argv[0];
1441 struct stat st = {0};
1444 warnx("loadfw: incorrect number of arguments.");
1448 fd = open(fname, O_RDONLY);
1450 warn("open(%s)", fname);
1454 if (fstat(fd, &st) < 0) {
1460 data.len = st.st_size;
1461 data.data = mmap(0, data.len, PROT_READ, 0, fd, 0);
1462 if (data.data == MAP_FAILED) {
1468 rc = doit(CHELSIO_T4_LOAD_FW, &data);
1469 munmap(data.data, data.len);
1475 read_mem(uint32_t addr, uint32_t len, void (*output)(uint32_t *, uint32_t))
1478 struct t4_mem_range mr;
1482 mr.data = malloc(mr.len);
1485 warn("read_mem: malloc");
1489 rc = doit(CHELSIO_T4_GET_MEM, &mr);
1494 (*output)(mr.data, mr.len);
1501 * Display memory as list of 'n' 4-byte values per line.
1504 show_mem(uint32_t *buf, uint32_t len)
1510 for (i = 0; len && i < n; i++, buf++, len -= 4) {
1512 printf("%s%08x", s, htonl(*buf));
1519 memdump(int argc, const char *argv[])
1526 warnx("incorrect number of arguments.");
1530 p = str_to_number(argv[0], &l, NULL);
1532 warnx("invalid address \"%s\"", argv[0]);
1537 p = str_to_number(argv[1], &l, NULL);
1539 warnx("memdump: invalid length \"%s\"", argv[1]);
1544 return (read_mem(addr, len, show_mem));
1548 * Display TCB as list of 'n' 4-byte values per line.
1551 show_tcb(uint32_t *buf, uint32_t len)
1557 for (i = 0; len && i < n; i++, buf++, len -= 4) {
1559 printf("%s%08x", s, htonl(*buf));
1565 #define A_TP_CMM_TCB_BASE 0x7d10
1566 #define TCB_SIZE 128
1568 read_tcb(int argc, const char *argv[])
1578 warnx("incorrect number of arguments.");
1582 p = str_to_number(argv[0], &l, NULL);
1584 warnx("invalid tid \"%s\"", argv[0]);
1589 rc = read_reg(A_TP_CMM_TCB_BASE, 4, &val);
1593 addr = val + tid * TCB_SIZE;
1595 return (read_mem(addr, TCB_SIZE, show_tcb));
1599 read_i2c(int argc, const char *argv[])
1603 struct t4_i2c_data i2cd;
1606 if (argc < 3 || argc > 4) {
1607 warnx("incorrect number of arguments.");
1611 p = str_to_number(argv[0], &l, NULL);
1612 if (*p || l > UCHAR_MAX) {
1613 warnx("invalid port id \"%s\"", argv[0]);
1618 p = str_to_number(argv[1], &l, NULL);
1619 if (*p || l > UCHAR_MAX) {
1620 warnx("invalid i2c device address \"%s\"", argv[1]);
1625 p = str_to_number(argv[2], &l, NULL);
1626 if (*p || l > UCHAR_MAX) {
1627 warnx("invalid byte offset \"%s\"", argv[2]);
1633 p = str_to_number(argv[3], &l, NULL);
1634 if (*p || l > sizeof(i2cd.data)) {
1635 warnx("invalid number of bytes \"%s\"", argv[3]);
1642 rc = doit(CHELSIO_T4_GET_I2C, &i2cd);
1646 for (i = 0; i < i2cd.len; i++)
1647 printf("0x%x [%u]\n", i2cd.data[i], i2cd.data[i]);
1653 clearstats(int argc, const char *argv[])
1660 warnx("incorrect number of arguments.");
1664 p = str_to_number(argv[0], &l, NULL);
1666 warnx("invalid port id \"%s\"", argv[0]);
1671 return doit(CHELSIO_T4_CLEAR_STATS, &port);
1679 int rc, port_idx, i;
1682 /* Magic values: MPS_TRC_CFG = 0x9800. MPS_TRC_CFG[1:1] = TrcEn */
1683 rc = read_reg(0x9800, 4, &val);
1686 printf("tracing is %s\n", val & 2 ? "ENABLED" : "DISABLED");
1689 for (t.idx = 0; ; t.idx++) {
1690 rc = doit(CHELSIO_T4_GET_TRACER, &t);
1691 if (rc != 0 || t.idx == 0xff)
1694 if (t.tp.port < 4) {
1696 port_idx = t.tp.port;
1697 } else if (t.tp.port < 8) {
1699 port_idx = t.tp.port - 4;
1700 } else if (t.tp.port < 12) {
1702 port_idx = t.tp.port - 8;
1703 } else if (t.tp.port < 16) {
1705 port_idx = t.tp.port - 12;
1706 } else if (t.tp.port < 20) {
1708 port_idx = t.tp.port - 16;
1711 port_idx = t.tp.port;
1714 printf("\ntracer %u (currently %s) captures ", t.idx,
1715 t.enabled ? "ENABLED" : "DISABLED");
1717 printf("port %u %s, ", port_idx, s);
1719 printf("%s %u, ", s, port_idx);
1720 printf("snap length: %u, min length: %u\n", t.tp.snap_len,
1722 printf("packets captured %smatch filter\n",
1723 t.tp.invert ? "do not " : "");
1724 if (t.tp.skip_ofst) {
1725 printf("filter pattern: ");
1726 for (i = 0; i < t.tp.skip_ofst * 2; i += 2)
1727 printf("%08x%08x", t.tp.data[i],
1730 for (i = 0; i < t.tp.skip_ofst * 2; i += 2)
1731 printf("%08x%08x", t.tp.mask[i],
1735 printf("filter pattern: ");
1736 for (i = t.tp.skip_ofst * 2; i < T4_TRACE_LEN / 4; i += 2)
1737 printf("%08x%08x", t.tp.data[i], t.tp.data[i + 1]);
1739 for (i = t.tp.skip_ofst * 2; i < T4_TRACE_LEN / 4; i += 2)
1740 printf("%08x%08x", t.tp.mask[i], t.tp.mask[i + 1]);
1741 printf("@%u\n", (t.tp.skip_ofst + t.tp.skip_len) * 8);
1748 tracer_onoff(uint8_t idx, int enabled)
1753 t.enabled = enabled;
1756 return doit(CHELSIO_T4_SET_TRACER, &t);
1760 create_tracing_ifnet()
1763 "/sbin/ifconfig", __DECONST(char *, nexus), "create", NULL
1765 char *env[] = {NULL};
1768 close(STDERR_FILENO);
1769 execve(cmd[0], cmd, env);
1775 * XXX: Allow user to specify snaplen, minlen, and pattern (including inverted
1776 * matching). Right now this is a quick-n-dirty implementation that traces the
1777 * first 128B of all tx or rx on a port
1780 set_tracer(uint8_t idx, int argc, const char *argv[])
1785 bzero(&t, sizeof (t));
1791 warnx("must specify tx<n> or rx<n>.");
1795 len = strlen(argv[0]);
1797 warnx("argument must be 3 characters (tx<n> or rx<n>)");
1801 if (strncmp(argv[0], "tx", 2) == 0) {
1802 port = argv[0][2] - '0';
1803 if (port < 0 || port > 3) {
1804 warnx("'%c' in %s is invalid", argv[0][2], argv[0]);
1808 } else if (strncmp(argv[0], "rx", 2) == 0) {
1809 port = argv[0][2] - '0';
1810 if (port < 0 || port > 3) {
1811 warnx("'%c' in %s is invalid", argv[0][2], argv[0]);
1815 warnx("argument '%s' isn't tx<n> or rx<n>", argv[0]);
1819 t.tp.snap_len = 128;
1826 create_tracing_ifnet();
1827 return doit(CHELSIO_T4_SET_TRACER, &t);
1831 tracer_cmd(int argc, const char *argv[])
1838 warnx("tracer: no arguments.");
1843 if (strcmp(argv[0], "list") == 0) {
1845 warnx("trailing arguments after \"list\" ignored.");
1847 return show_tracers();
1851 s = str_to_number(argv[0], NULL, &val);
1852 if (*s || val > 0xff) {
1853 warnx("\"%s\" is neither an index nor a tracer subcommand.",
1860 if (argc == 2 && strcmp(argv[1], "disable") == 0)
1861 return tracer_onoff(idx, 0);
1864 if (argc == 2 && strcmp(argv[1], "enable") == 0)
1865 return tracer_onoff(idx, 1);
1868 return set_tracer(idx, argc - 1, argv + 1);
1872 run_cmd(int argc, const char *argv[])
1875 const char *cmd = argv[0];
1881 if (!strcmp(cmd, "reg") || !strcmp(cmd, "reg32"))
1882 rc = register_io(argc, argv, 4);
1883 else if (!strcmp(cmd, "reg64"))
1884 rc = register_io(argc, argv, 8);
1885 else if (!strcmp(cmd, "regdump"))
1886 rc = dump_regs(argc, argv);
1887 else if (!strcmp(cmd, "filter"))
1888 rc = filter_cmd(argc, argv);
1889 else if (!strcmp(cmd, "context"))
1890 rc = get_sge_context(argc, argv);
1891 else if (!strcmp(cmd, "loadfw"))
1892 rc = loadfw(argc, argv);
1893 else if (!strcmp(cmd, "memdump"))
1894 rc = memdump(argc, argv);
1895 else if (!strcmp(cmd, "tcb"))
1896 rc = read_tcb(argc, argv);
1897 else if (!strcmp(cmd, "i2c"))
1898 rc = read_i2c(argc, argv);
1899 else if (!strcmp(cmd, "clearstats"))
1900 rc = clearstats(argc, argv);
1901 else if (!strcmp(cmd, "tracer"))
1902 rc = tracer_cmd(argc, argv);
1905 warnx("invalid command \"%s\"", cmd);
1916 char buffer[128], *buf;
1917 const char *args[MAX_ARGS + 1];
1920 * Simple loop: displays a "> " prompt and processes any input as a
1921 * cxgbetool command. You're supposed to enter only the part after
1922 * "cxgbetool t4nexX". Use "quit" or "exit" to exit.
1925 fprintf(stdout, "> ");
1927 buf = fgets(buffer, sizeof(buffer), stdin);
1929 if (ferror(stdin)) {
1930 warn("stdin error");
1931 rc = errno; /* errno from fgets */
1937 while ((args[i] = strsep(&buf, " \t\n")) != NULL) {
1938 if (args[i][0] != 0 && ++i == MAX_ARGS)
1944 continue; /* skip empty line */
1946 if (!strcmp(args[0], "quit") || !strcmp(args[0], "exit"))
1949 rc = run_cmd(i, args);
1952 /* rc normally comes from the last command (not including quit/exit) */
1957 main(int argc, const char *argv[])
1964 if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
1977 /* progname and nexus */
1981 if (argc == 1 && !strcmp(argv[0], "stdio"))
1982 rc = run_cmd_loop();
1984 rc = run_cmd(argc, argv);