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 #include <sys/param.h>
30 #include <sys/ioctl.h>
32 #include <sys/socket.h>
34 #include <sys/sysctl.h>
36 #include <arpa/inet.h>
37 #include <net/ethernet.h>
38 #include <net/sff8472.h>
39 #include <netinet/in.h>
54 #include "tcb_common.h"
56 #define in_range(val, lo, hi) ( val < 0 || (val <= hi && val >= lo))
57 #define max(x, y) ((x) > (y) ? (x) : (y))
59 static const char *progname, *nexus;
60 static int chip_id; /* 4 for T4, 5 for T5, and so on. */
61 static int inst; /* instance of nexus device */
71 const struct reg_info *ri;
75 const char *name; /* Field name */
76 unsigned short start; /* Start bit position */
77 unsigned short end; /* End bit position */
78 unsigned char shift; /* # of low order bits omitted and implicitly 0 */
79 unsigned char hex; /* Print field in hex instead of decimal */
80 unsigned char islog2; /* Field contains the base-2 log of the value */
83 #include "reg_defs_t4.c"
84 #include "reg_defs_t5.c"
85 #include "reg_defs_t6.c"
86 #include "reg_defs_t4vf.c"
91 fprintf(fp, "Usage: %s <nexus> [operation]\n", progname);
93 "\tclearstats <port> clear port statistics\n"
94 "\tclip hold|release <ip6> hold/release an address\n"
95 "\tclip list list the CLIP table\n"
96 "\tcontext <type> <id> show an SGE context\n"
97 "\tdumpstate <dump.bin> dump chip state\n"
98 "\tfilter <idx> [<param> <val>] ... set a filter\n"
99 "\tfilter <idx> delete|clear [prio 1] delete a filter\n"
100 "\tfilter list list all filters\n"
101 "\tfilter mode [<match>] ... get/set global filter mode\n"
102 "\thashfilter [<param> <val>] ... set a hashfilter\n"
103 "\thashfilter <idx> delete|clear delete a hashfilter\n"
104 "\thashfilter list list all hashfilters\n"
105 "\thashfilter mode [<match>] ... get/set global hashfilter mode\n"
106 "\ti2c <port> <devaddr> <addr> [<len>] read from i2c device\n"
107 "\tloadboot <bi.bin> [pf|offset <val>] install boot image\n"
108 "\tloadboot clear [pf|offset <val>] remove boot image\n"
109 "\tloadboot-cfg <bc.bin> install boot config\n"
110 "\tloadboot-cfg clear remove boot config\n"
111 "\tloadcfg <fw-config.txt> install configuration file\n"
112 "\tloadcfg clear remove configuration file\n"
113 "\tloadfw <fw-image.bin> install firmware\n"
114 "\tmemdump <addr> <len> dump a memory range\n"
115 "\tmodinfo <port> [raw] optics/cable information\n"
116 "\tpolicy <policy.txt> install offload policy\n"
117 "\tpolicy clear remove offload policy\n"
118 "\treg <address>[=<val>] read/write register\n"
119 "\treg64 <address>[=<val>] read/write 64 bit register\n"
120 "\tregdump [<module>] ... dump registers\n"
121 "\tsched-class params <param> <val> .. configure TX scheduler class\n"
122 "\tsched-queue <port> <queue> <class> bind NIC queues to TX Scheduling class\n"
123 "\tstdio interactive mode\n"
124 "\ttcb <tid> read TCB\n"
125 "\ttracer <idx> tx<n>|rx<n>|lo<n> set and enable a tracer\n"
126 "\ttracer <idx> disable|enable disable or enable a tracer\n"
127 "\ttracer list list all tracers\n"
131 static inline unsigned int
132 get_card_vers(unsigned int version)
134 return (version & 0x3ff);
138 real_doit(unsigned long cmd, void *data, const char *cmdstr)
146 snprintf(buf, sizeof(buf), "/dev/%s", nexus);
147 if ((fd = open(buf, O_RDWR)) < 0) {
148 warn("open(%s)", nexus);
154 rc = ioctl(fd, cmd, data);
162 #define doit(x, y) real_doit(x, y, #x)
165 str_to_number(const char *s, long *val, long long *vall)
170 *vall = strtoll(s, &p, 0);
172 *val = strtol(s, &p, 0);
180 read_reg(long addr, int size, long long *val)
185 reg.addr = (uint32_t) addr;
186 reg.size = (uint32_t) size;
189 rc = doit(CHELSIO_T4_GETREG, ®);
197 write_reg(long addr, int size, long long val)
201 reg.addr = (uint32_t) addr;
202 reg.size = (uint32_t) size;
203 reg.val = (uint64_t) val;
205 return doit(CHELSIO_T4_SETREG, ®);
209 register_io(int argc, const char *argv[], int size)
217 /* <reg> OR <reg>=<value> */
219 p = str_to_number(argv[0], &addr, NULL);
222 warnx("invalid register \"%s\"", argv[0]);
228 p = str_to_number(v, NULL, &val);
231 warnx("invalid value \"%s\"", v);
236 } else if (argc == 2) {
241 p = str_to_number(argv[0], &addr, NULL);
243 warnx("invalid register \"%s\"", argv[0]);
247 p = str_to_number(argv[1], NULL, &val);
249 warnx("invalid value \"%s\"", argv[1]);
253 warnx("reg: invalid number of arguments (%d)", argc);
258 rc = write_reg(addr, size, val);
260 rc = read_reg(addr, size, &val);
262 printf("0x%llx [%llu]\n", val, val);
268 static inline uint32_t
269 xtract(uint32_t val, int shift, int len)
271 return (val >> shift) & ((1 << len) - 1);
275 dump_block_regs(const struct reg_info *reg_array, const uint32_t *regs)
277 uint32_t reg_val = 0;
279 for ( ; reg_array->name; ++reg_array)
280 if (!reg_array->len) {
281 reg_val = regs[reg_array->addr / 4];
282 printf("[%#7x] %-47s %#-10x %u\n", reg_array->addr,
283 reg_array->name, reg_val, reg_val);
285 uint32_t v = xtract(reg_val, reg_array->addr,
288 printf(" %*u:%u %-47s %#-10x %u\n",
289 reg_array->addr < 10 ? 3 : 2,
290 reg_array->addr + reg_array->len - 1,
291 reg_array->addr, reg_array->name, v, v);
298 dump_regs_table(int argc, const char *argv[], const uint32_t *regs,
299 const struct mod_regs *modtab, int nmodules)
303 for (i = 0; i < argc; i++) {
304 for (j = 0; j < nmodules; j++) {
305 if (!strcmp(argv[i], modtab[j].name))
310 warnx("invalid register block \"%s\"", argv[i]);
311 fprintf(stderr, "\nAvailable blocks:");
312 for ( ; nmodules; nmodules--, modtab++)
313 fprintf(stderr, " %s", modtab->name);
314 fprintf(stderr, "\n");
319 for ( ; nmodules; nmodules--, modtab++) {
321 match = argc == 0 ? 1 : 0;
322 for (i = 0; !match && i < argc; i++) {
323 if (!strcmp(argv[i], modtab->name))
328 dump_block_regs(modtab->ri, regs);
334 #define T4_MODREGS(name) { #name, t4_##name##_regs }
336 dump_regs_t4(int argc, const char *argv[], const uint32_t *regs)
338 static struct mod_regs t4_mod[] = {
340 { "pci", t4_pcie_regs },
344 { "edc0", t4_edc_0_regs },
345 { "edc1", t4_edc_1_regs },
350 { "pmrx", t4_pm_rx_regs },
351 { "pmtx", t4_pm_tx_regs },
353 { "cplsw", t4_cpl_switch_regs },
355 { "i2c", t4_i2cm_regs },
366 return dump_regs_table(argc, argv, regs, t4_mod, nitems(t4_mod));
370 #define T5_MODREGS(name) { #name, t5_##name##_regs }
372 dump_regs_t5(int argc, const char *argv[], const uint32_t *regs)
374 static struct mod_regs t5_mod[] = {
376 { "pci", t5_pcie_regs },
378 { "mc0", t5_mc_0_regs },
379 { "mc1", t5_mc_1_regs },
381 { "edc0", t5_edc_t50_regs },
382 { "edc1", t5_edc_t51_regs },
385 { "ulprx", t5_ulp_rx_regs },
386 { "ulptx", t5_ulp_tx_regs },
387 { "pmrx", t5_pm_rx_regs },
388 { "pmtx", t5_pm_tx_regs },
390 { "cplsw", t5_cpl_switch_regs },
392 { "i2c", t5_i2cm_regs },
401 { "hma", t5_hma_t5_regs }
404 return dump_regs_table(argc, argv, regs, t5_mod, nitems(t5_mod));
408 #define T6_MODREGS(name) { #name, t6_##name##_regs }
410 dump_regs_t6(int argc, const char *argv[], const uint32_t *regs)
412 static struct mod_regs t6_mod[] = {
414 { "pci", t6_pcie_regs },
416 { "mc0", t6_mc_0_regs },
418 { "edc0", t6_edc_t60_regs },
419 { "edc1", t6_edc_t61_regs },
422 { "ulprx", t6_ulp_rx_regs },
423 { "ulptx", t6_ulp_tx_regs },
424 { "pmrx", t6_pm_rx_regs },
425 { "pmtx", t6_pm_tx_regs },
427 { "cplsw", t6_cpl_switch_regs },
429 { "i2c", t6_i2cm_regs },
438 { "hma", t6_hma_t6_regs }
441 return dump_regs_table(argc, argv, regs, t6_mod, nitems(t6_mod));
446 dump_regs_t4vf(int argc, const char *argv[], const uint32_t *regs)
448 static struct mod_regs t4vf_mod[] = {
449 { "sge", t4vf_sge_regs },
450 { "mps", t4vf_mps_regs },
451 { "pl", t4vf_pl_regs },
452 { "mbdata", t4vf_mbdata_regs },
453 { "cim", t4vf_cim_regs },
456 return dump_regs_table(argc, argv, regs, t4vf_mod, nitems(t4vf_mod));
460 dump_regs_t5vf(int argc, const char *argv[], const uint32_t *regs)
462 static struct mod_regs t5vf_mod[] = {
463 { "sge", t5vf_sge_regs },
464 { "mps", t4vf_mps_regs },
465 { "pl", t5vf_pl_regs },
466 { "mbdata", t4vf_mbdata_regs },
467 { "cim", t4vf_cim_regs },
470 return dump_regs_table(argc, argv, regs, t5vf_mod, nitems(t5vf_mod));
474 dump_regs_t6vf(int argc, const char *argv[], const uint32_t *regs)
476 static struct mod_regs t6vf_mod[] = {
477 { "sge", t5vf_sge_regs },
478 { "mps", t4vf_mps_regs },
479 { "pl", t6vf_pl_regs },
480 { "mbdata", t4vf_mbdata_regs },
481 { "cim", t4vf_cim_regs },
484 return dump_regs_table(argc, argv, regs, t6vf_mod, nitems(t6vf_mod));
488 dump_regs(int argc, const char *argv[])
490 int vers, revision, rc;
491 struct t4_regdump regs;
494 len = max(T4_REGDUMP_SIZE, T5_REGDUMP_SIZE);
495 regs.data = calloc(1, len);
496 if (regs.data == NULL) {
497 warnc(ENOMEM, "regdump");
502 rc = doit(CHELSIO_T4_REGDUMP, ®s);
506 vers = get_card_vers(regs.version);
507 revision = (regs.version >> 10) & 0x3f;
510 if (revision == 0x3f)
511 rc = dump_regs_t4vf(argc, argv, regs.data);
513 rc = dump_regs_t4(argc, argv, regs.data);
514 } else if (vers == 5) {
515 if (revision == 0x3f)
516 rc = dump_regs_t5vf(argc, argv, regs.data);
518 rc = dump_regs_t5(argc, argv, regs.data);
519 } else if (vers == 6) {
520 if (revision == 0x3f)
521 rc = dump_regs_t6vf(argc, argv, regs.data);
523 rc = dump_regs_t6(argc, argv, regs.data);
525 warnx("%s (type %d, rev %d) is not a known card.",
526 nexus, vers, revision);
535 do_show_info_header(uint32_t mode)
539 printf("%4s %8s", "Idx", "Hits");
540 for (i = T4_FILTER_FCoE; i <= T4_FILTER_IP_FRAGMENT; i <<= 1) {
549 if (mode & T4_FILTER_IC_VNIC)
550 printf(" VFvld:PF:VF");
552 printf(" vld:oVLAN");
557 case T4_FILTER_IP_TOS:
560 case T4_FILTER_IP_PROTO:
563 case T4_FILTER_ETH_TYPE:
566 case T4_FILTER_MAC_IDX:
569 case T4_FILTER_MPS_HIT_TYPE:
572 case T4_FILTER_IP_FRAGMENT:
576 /* compressed filter field not enabled */
580 printf(" %20s %20s %9s %9s %s\n",
581 "DIP", "SIP", "DPORT", "SPORT", "Action");
585 * Parse an argument sub-vector as a { <parameter name> <value>[:<mask>] }
586 * ordered tuple. If the parameter name in the argument sub-vector does not
587 * match the passed in parameter name, then a zero is returned for the
588 * function and no parsing is performed. If there is a match, then the value
589 * and optional mask are parsed and returned in the provided return value
590 * pointers. If no optional mask is specified, then a default mask of all 1s
593 * An error in parsing the value[:mask] will result in an error message and
594 * program termination.
597 parse_val_mask(const char *param, const char *args[], uint32_t *val,
598 uint32_t *mask, int hashfilter)
603 if (strcmp(param, args[0]) != 0)
606 p = str_to_number(args[1], &l, NULL);
607 if (l >= 0 && l <= UINT32_MAX) {
615 if (p[0] == ':' && p[1] != 0) {
617 warnx("param %s: mask not allowed for "
618 "hashfilter or nat params", param);
621 p = str_to_number(p + 1, &l, NULL);
622 if (l >= 0 && l <= UINT32_MAX && p[0] == 0) {
630 warnx("parameter \"%s\" has bad \"value[:mask]\" %s",
637 * Parse an argument sub-vector as a { <parameter name> <addr>[/<mask>] }
638 * ordered tuple. If the parameter name in the argument sub-vector does not
639 * match the passed in parameter name, then a zero is returned for the
640 * function and no parsing is performed. If there is a match, then the value
641 * and optional mask are parsed and returned in the provided return value
642 * pointers. If no optional mask is specified, then a default mask of all 1s
645 * The value return parameter "afp" is used to specify the expected address
646 * family -- IPv4 or IPv6 -- of the address[/mask] and return its actual
647 * format. A passed in value of AF_UNSPEC indicates that either IPv4 or IPv6
648 * is acceptable; AF_INET means that only IPv4 addresses are acceptable; and
649 * AF_INET6 means that only IPv6 are acceptable. AF_INET is returned for IPv4
650 * and AF_INET6 for IPv6 addresses, respectively. IPv4 address/mask pairs are
651 * returned in the first four bytes of the address and mask return values with
652 * the address A.B.C.D returned with { A, B, C, D } returned in addresses { 0,
653 * 1, 2, 3}, respectively.
655 * An error in parsing the value[:mask] will result in an error message and
656 * program termination.
659 parse_ipaddr(const char *param, const char *args[], int *afp, uint8_t addr[],
660 uint8_t mask[], int maskless)
662 const char *colon, *afn;
666 unsigned int masksize;
669 * Is this our parameter?
671 if (strcmp(param, args[0]) != 0)
675 * Fundamental IPv4 versus IPv6 selection.
677 colon = strchr(args[1], ':');
687 if (*afp == AF_UNSPEC)
689 else if (*afp != af) {
690 warnx("address %s is not of expected family %s",
691 args[1], *afp == AF_INET ? "IP" : "IPv6");
696 * Parse address (temporarily stripping off any "/mask"
699 slash = strchr(args[1], '/');
702 ret = inet_pton(af, args[1], addr);
706 warnx("Cannot parse %s %s address %s", param, afn, args[1]);
711 * Parse optional mask specification.
715 unsigned int prefix = strtoul(slash + 1, &p, 10);
718 warnx("mask cannot be provided for maskless specification");
722 if (p == slash + 1) {
723 warnx("missing address prefix for %s", param);
727 warnx("%s is not a valid address prefix", slash + 1);
730 if (prefix > masksize) {
731 warnx("prefix %u is too long for an %s address",
735 memset(mask, 0, masksize / 8);
743 for (m = mask; masksize >= 8; m++, masksize -= 8)
746 *m = ~0 << (8 - masksize);
753 * Parse an argument sub-vector as a { <parameter name> <value> } ordered
754 * tuple. If the parameter name in the argument sub-vector does not match the
755 * passed in parameter name, then a zero is returned for the function and no
756 * parsing is performed. If there is a match, then the value is parsed and
757 * returned in the provided return value pointer.
760 parse_val(const char *param, const char *args[], uint32_t *val)
765 if (strcmp(param, args[0]) != 0)
768 p = str_to_number(args[1], &l, NULL);
769 if (*p || l < 0 || l > UINT32_MAX) {
770 warnx("parameter \"%s\" has bad \"value\" %s", args[0], args[1]);
779 filters_show_ipaddr(int type, uint8_t *addr, uint8_t *addrm)
790 for (octet = 0; octet < noctets; octet++)
791 printf("%02x", addr[octet]);
793 for (octet = 0; octet < noctets; octet++)
794 printf("%02x", addrm[octet]);
798 do_show_one_filter_info(struct t4_filter *t, uint32_t mode)
802 printf("%4d", t->idx);
803 if (t->hits == UINT64_MAX)
806 printf(" %8ju", t->hits);
809 * Compressed header portion of filter.
811 for (i = T4_FILTER_FCoE; i <= T4_FILTER_IP_FRAGMENT; i <<= 1) {
814 printf(" %1d/%1d", t->fs.val.fcoe, t->fs.mask.fcoe);
817 printf(" %1d/%1d", t->fs.val.iport, t->fs.mask.iport);
820 if (mode & T4_FILTER_IC_VNIC) {
821 printf(" %1d:%1x:%02x/%1d:%1x:%02x",
823 (t->fs.val.vnic >> 13) & 0x7,
824 t->fs.val.vnic & 0x1fff,
826 (t->fs.mask.vnic >> 13) & 0x7,
827 t->fs.mask.vnic & 0x1fff);
829 printf(" %1d:%04x/%1d:%04x",
830 t->fs.val.ovlan_vld, t->fs.val.vnic,
831 t->fs.mask.ovlan_vld, t->fs.mask.vnic);
835 printf(" %1d:%04x/%1d:%04x",
836 t->fs.val.vlan_vld, t->fs.val.vlan,
837 t->fs.mask.vlan_vld, t->fs.mask.vlan);
839 case T4_FILTER_IP_TOS:
840 printf(" %02x/%02x", t->fs.val.tos, t->fs.mask.tos);
842 case T4_FILTER_IP_PROTO:
843 printf(" %02x/%02x", t->fs.val.proto, t->fs.mask.proto);
845 case T4_FILTER_ETH_TYPE:
846 printf(" %04x/%04x", t->fs.val.ethtype,
849 case T4_FILTER_MAC_IDX:
850 printf(" %03x/%03x", t->fs.val.macidx,
853 case T4_FILTER_MPS_HIT_TYPE:
854 printf(" %1x/%1x", t->fs.val.matchtype,
855 t->fs.mask.matchtype);
857 case T4_FILTER_IP_FRAGMENT:
858 printf(" %1d/%1d", t->fs.val.frag, t->fs.mask.frag);
861 /* compressed filter field not enabled */
867 * Fixed portion of filter.
869 filters_show_ipaddr(t->fs.type, t->fs.val.dip, t->fs.mask.dip);
870 filters_show_ipaddr(t->fs.type, t->fs.val.sip, t->fs.mask.sip);
871 printf(" %04x/%04x %04x/%04x",
872 t->fs.val.dport, t->fs.mask.dport,
873 t->fs.val.sport, t->fs.mask.sport);
876 * Variable length filter action.
878 if (t->fs.action == FILTER_DROP)
880 else if (t->fs.action == FILTER_SWITCH) {
881 printf(" Switch: port=%d", t->fs.eport);
884 ", dmac=%02x:%02x:%02x:%02x:%02x:%02x "
886 t->fs.dmac[0], t->fs.dmac[1],
887 t->fs.dmac[2], t->fs.dmac[3],
888 t->fs.dmac[4], t->fs.dmac[5],
892 ", smac=%02x:%02x:%02x:%02x:%02x:%02x "
894 t->fs.smac[0], t->fs.smac[1],
895 t->fs.smac[2], t->fs.smac[3],
896 t->fs.smac[4], t->fs.smac[5],
898 if (t->fs.newvlan == VLAN_REMOVE)
899 printf(", vlan=none");
900 else if (t->fs.newvlan == VLAN_INSERT)
901 printf(", vlan=insert(%x)", t->fs.vlan);
902 else if (t->fs.newvlan == VLAN_REWRITE)
903 printf(", vlan=rewrite(%x)", t->fs.vlan);
906 if (t->fs.dirsteer == 0) {
909 printf("(region %d)", t->fs.iq << 1);
911 printf("%d", t->fs.iq);
912 if (t->fs.dirsteerhash == 0)
918 if (chip_id <= 5 && t->fs.prio)
926 show_filters(int hash)
928 uint32_t mode = 0, header, hpfilter = 0;
932 /* Get the global filter mode first */
933 rc = doit(CHELSIO_T4_GET_FILTER_MODE, &mode);
937 if (!hash && chip_id >= 6) {
939 bzero(&t, sizeof (t));
943 for (t.idx = 0; ; t.idx++) {
944 rc = doit(CHELSIO_T4_GET_FILTER, &t);
945 if (rc != 0 || t.idx == 0xffffffff)
949 printf("High Priority TCAM Region:\n");
950 do_show_info_header(mode);
954 do_show_one_filter_info(&t, mode);
959 bzero(&t, sizeof (t));
962 for (t.idx = 0; ; t.idx++) {
963 rc = doit(CHELSIO_T4_GET_FILTER, &t);
964 if (rc != 0 || t.idx == 0xffffffff)
969 printf("\nNormal Priority TCAM Region:\n");
970 do_show_info_header(mode);
973 do_show_one_filter_info(&t, mode);
980 get_filter_mode(int hashfilter)
982 uint32_t mode = hashfilter;
985 rc = doit(CHELSIO_T4_GET_FILTER_MODE, &mode);
989 if (mode & T4_FILTER_IPv4)
991 if (mode & T4_FILTER_IPv6)
993 if (mode & T4_FILTER_IP_SADDR)
995 if (mode & T4_FILTER_IP_DADDR)
997 if (mode & T4_FILTER_IP_SPORT)
999 if (mode & T4_FILTER_IP_DPORT)
1001 if (mode & T4_FILTER_IP_FRAGMENT)
1003 if (mode & T4_FILTER_MPS_HIT_TYPE)
1004 printf("matchtype ");
1005 if (mode & T4_FILTER_MAC_IDX)
1007 if (mode & T4_FILTER_ETH_TYPE)
1009 if (mode & T4_FILTER_IP_PROTO)
1011 if (mode & T4_FILTER_IP_TOS)
1013 if (mode & T4_FILTER_VLAN)
1015 if (mode & T4_FILTER_VNIC) {
1016 if (mode & T4_FILTER_IC_VNIC)
1018 else if (mode & T4_FILTER_IC_ENCAP)
1023 if (mode & T4_FILTER_PORT)
1025 if (mode & T4_FILTER_FCoE)
1033 set_filter_mode(int argc, const char *argv[], int hashfilter)
1036 int vnic = 0, ovlan = 0, invalid = 0;
1038 for (; argc; argc--, argv++) {
1039 if (!strcmp(argv[0], "ipv4") || !strcmp(argv[0], "ipv6") ||
1040 !strcmp(argv[0], "sip") || !strcmp(argv[0], "dip") ||
1041 !strcmp(argv[0], "sport") || !strcmp(argv[0], "dport")) {
1042 /* These are always available and enabled. */
1044 } else if (!strcmp(argv[0], "frag"))
1045 mode |= T4_FILTER_IP_FRAGMENT;
1046 else if (!strcmp(argv[0], "matchtype"))
1047 mode |= T4_FILTER_MPS_HIT_TYPE;
1048 else if (!strcmp(argv[0], "macidx"))
1049 mode |= T4_FILTER_MAC_IDX;
1050 else if (!strcmp(argv[0], "ethtype"))
1051 mode |= T4_FILTER_ETH_TYPE;
1052 else if (!strcmp(argv[0], "proto"))
1053 mode |= T4_FILTER_IP_PROTO;
1054 else if (!strcmp(argv[0], "tos"))
1055 mode |= T4_FILTER_IP_TOS;
1056 else if (!strcmp(argv[0], "vlan"))
1057 mode |= T4_FILTER_VLAN;
1058 else if (!strcmp(argv[0], "ovlan")) {
1059 mode |= T4_FILTER_VNIC;
1061 } else if (!strcmp(argv[0], "vnic_id")) {
1062 mode |= T4_FILTER_VNIC;
1063 mode |= T4_FILTER_IC_VNIC;
1067 else if (!strcmp(argv[0], "encap")) {
1068 mode |= T4_FILTER_VNIC;
1069 mode |= T4_FILTER_IC_ENCAP;
1073 else if (!strcmp(argv[0], "iport"))
1074 mode |= T4_FILTER_PORT;
1075 else if (!strcmp(argv[0], "fcoe"))
1076 mode |= T4_FILTER_FCoE;
1078 warnx("\"%s\" is not valid while setting filter mode.",
1084 if (vnic + ovlan > 1) {
1085 warnx("\"vnic_id\" and \"ovlan\" are mutually exclusive.");
1093 return doit(CHELSIO_T4_SET_FILTER_MASK, &mode);
1095 return doit(CHELSIO_T4_SET_FILTER_MODE, &mode);
1099 del_filter(uint32_t idx, int prio, int hashfilter)
1104 t.fs.hash = hashfilter;
1107 return doit(CHELSIO_T4_DEL_FILTER, &t);
1110 #define MAX_VLANID (4095)
1113 set_filter(uint32_t idx, int argc, const char *argv[], int hash)
1115 int rc, af = AF_UNSPEC, start_arg = 0;
1119 warnc(EINVAL, "%s", __func__);
1122 bzero(&t, sizeof (t));
1127 for (start_arg = 0; start_arg + 2 <= argc; start_arg += 2) {
1128 const char **args = &argv[start_arg];
1131 if (!strcmp(argv[start_arg], "type")) {
1133 if (!strcasecmp(argv[start_arg + 1], "ipv4"))
1135 else if (!strcasecmp(argv[start_arg + 1], "ipv6"))
1138 warnx("invalid type \"%s\"; "
1139 "must be one of \"ipv4\" or \"ipv6\"",
1140 argv[start_arg + 1]);
1144 if (af != AF_UNSPEC && af != newaf) {
1145 warnx("conflicting IPv4/IPv6 specifications.");
1149 } else if (!parse_val_mask("fcoe", args, &val, &mask, hash)) {
1150 t.fs.val.fcoe = val;
1151 t.fs.mask.fcoe = mask;
1152 } else if (!parse_val_mask("iport", args, &val, &mask, hash)) {
1153 t.fs.val.iport = val;
1154 t.fs.mask.iport = mask;
1155 } else if (!parse_val_mask("ovlan", args, &val, &mask, hash)) {
1156 t.fs.val.vnic = val;
1157 t.fs.mask.vnic = mask;
1158 t.fs.val.ovlan_vld = 1;
1159 t.fs.mask.ovlan_vld = 1;
1160 } else if (!parse_val_mask("ivlan", args, &val, &mask, hash)) {
1161 t.fs.val.vlan = val;
1162 t.fs.mask.vlan = mask;
1163 t.fs.val.vlan_vld = 1;
1164 t.fs.mask.vlan_vld = 1;
1165 } else if (!parse_val_mask("pf", args, &val, &mask, hash)) {
1166 t.fs.val.vnic &= 0x1fff;
1167 t.fs.val.vnic |= (val & 0x7) << 13;
1168 t.fs.mask.vnic &= 0x1fff;
1169 t.fs.mask.vnic |= (mask & 0x7) << 13;
1170 t.fs.val.pfvf_vld = 1;
1171 t.fs.mask.pfvf_vld = 1;
1172 } else if (!parse_val_mask("vf", args, &val, &mask, hash)) {
1173 t.fs.val.vnic &= 0xe000;
1174 t.fs.val.vnic |= val & 0x1fff;
1175 t.fs.mask.vnic &= 0xe000;
1176 t.fs.mask.vnic |= mask & 0x1fff;
1177 t.fs.val.pfvf_vld = 1;
1178 t.fs.mask.pfvf_vld = 1;
1179 } else if (!parse_val_mask("tos", args, &val, &mask, hash)) {
1181 t.fs.mask.tos = mask;
1182 } else if (!parse_val_mask("proto", args, &val, &mask, hash)) {
1183 t.fs.val.proto = val;
1184 t.fs.mask.proto = mask;
1185 } else if (!parse_val_mask("ethtype", args, &val, &mask, hash)) {
1186 t.fs.val.ethtype = val;
1187 t.fs.mask.ethtype = mask;
1188 } else if (!parse_val_mask("macidx", args, &val, &mask, hash)) {
1189 t.fs.val.macidx = val;
1190 t.fs.mask.macidx = mask;
1191 } else if (!parse_val_mask("matchtype", args, &val, &mask, hash)) {
1192 t.fs.val.matchtype = val;
1193 t.fs.mask.matchtype = mask;
1194 } else if (!parse_val_mask("frag", args, &val, &mask, hash)) {
1195 t.fs.val.frag = val;
1196 t.fs.mask.frag = mask;
1197 } else if (!parse_val_mask("dport", args, &val, &mask, hash)) {
1198 t.fs.val.dport = val;
1199 t.fs.mask.dport = mask;
1200 } else if (!parse_val_mask("sport", args, &val, &mask, hash)) {
1201 t.fs.val.sport = val;
1202 t.fs.mask.sport = mask;
1203 } else if (!parse_ipaddr("dip", args, &af, t.fs.val.dip,
1204 t.fs.mask.dip, hash)) {
1206 } else if (!parse_ipaddr("sip", args, &af, t.fs.val.sip,
1207 t.fs.mask.sip, hash)) {
1209 } else if (!parse_ipaddr("nat_dip", args, &af, t.fs.nat_dip, NULL, 1)) {
1211 } else if (!parse_ipaddr("nat_sip", args, &af, t.fs.nat_sip, NULL, 1)) {
1213 } else if (!parse_val_mask("nat_dport", args, &val, &mask, 1)) {
1214 t.fs.nat_dport = val;
1215 } else if (!parse_val_mask("nat_sport", args, &val, &mask, 1)) {
1216 t.fs.nat_sport = val;
1217 } else if (!strcmp(argv[start_arg], "action")) {
1218 if (!strcmp(argv[start_arg + 1], "pass"))
1219 t.fs.action = FILTER_PASS;
1220 else if (!strcmp(argv[start_arg + 1], "drop"))
1221 t.fs.action = FILTER_DROP;
1222 else if (!strcmp(argv[start_arg + 1], "switch"))
1223 t.fs.action = FILTER_SWITCH;
1225 warnx("invalid action \"%s\"; must be one of"
1226 " \"pass\", \"drop\" or \"switch\"",
1227 argv[start_arg + 1]);
1230 } else if (!parse_val("hitcnts", args, &val)) {
1232 } else if (!parse_val("prio", args, &val)) {
1234 warnx("Hashfilters doesn't support \"prio\"\n");
1237 if (val != 0 && val != 1) {
1238 warnx("invalid priority \"%s\"; must be"
1239 " \"0\" or \"1\"", argv[start_arg + 1]);
1243 } else if (!parse_val("rpttid", args, &val)) {
1245 } else if (!parse_val("queue", args, &val)) {
1246 t.fs.dirsteer = 1; /* direct steer */
1247 t.fs.iq = val; /* to the iq with this cntxt_id */
1248 } else if (!parse_val("tcbhash", args, &val)) {
1249 t.fs.dirsteerhash = 1; /* direct steer */
1250 /* XXX: use (val << 1) as the rss_hash? */
1252 } else if (!parse_val("tcbrss", args, &val)) {
1253 t.fs.maskhash = 1; /* steer to RSS region */
1255 * val = start idx of the region but the internal TCB
1256 * field is 10b only and is left shifted by 1 before use.
1259 } else if (!parse_val("eport", args, &val)) {
1261 } else if (!parse_val("swapmac", args, &val)) {
1263 } else if (!strcmp(argv[start_arg], "nat")) {
1264 if (!strcmp(argv[start_arg + 1], "dip"))
1265 t.fs.nat_mode = NAT_MODE_DIP;
1266 else if (!strcmp(argv[start_arg + 1], "dip-dp"))
1267 t.fs.nat_mode = NAT_MODE_DIP_DP;
1268 else if (!strcmp(argv[start_arg + 1], "dip-dp-sip"))
1269 t.fs.nat_mode = NAT_MODE_DIP_DP_SIP;
1270 else if (!strcmp(argv[start_arg + 1], "dip-dp-sp"))
1271 t.fs.nat_mode = NAT_MODE_DIP_DP_SP;
1272 else if (!strcmp(argv[start_arg + 1], "sip-sp"))
1273 t.fs.nat_mode = NAT_MODE_SIP_SP;
1274 else if (!strcmp(argv[start_arg + 1], "dip-sip-sp"))
1275 t.fs.nat_mode = NAT_MODE_DIP_SIP_SP;
1276 else if (!strcmp(argv[start_arg + 1], "all"))
1277 t.fs.nat_mode = NAT_MODE_ALL;
1279 warnx("unknown nat type \"%s\"; known types are dip, "
1280 "dip-dp, dip-dp-sip, dip-dp-sp, sip-sp, "
1281 "dip-sip-sp, and all", argv[start_arg + 1]);
1284 } else if (!parse_val("natseq", args, &val)) {
1285 t.fs.nat_seq_chk = val;
1286 } else if (!parse_val("natflag", args, &val)) {
1287 t.fs.nat_flag_chk = 1;
1288 } else if (!strcmp(argv[start_arg], "dmac")) {
1289 struct ether_addr *daddr;
1291 daddr = ether_aton(argv[start_arg + 1]);
1292 if (daddr == NULL) {
1293 warnx("invalid dmac address \"%s\"",
1294 argv[start_arg + 1]);
1297 memcpy(t.fs.dmac, daddr, ETHER_ADDR_LEN);
1299 } else if (!strcmp(argv[start_arg], "smac")) {
1300 struct ether_addr *saddr;
1302 saddr = ether_aton(argv[start_arg + 1]);
1303 if (saddr == NULL) {
1304 warnx("invalid smac address \"%s\"",
1305 argv[start_arg + 1]);
1308 memcpy(t.fs.smac, saddr, ETHER_ADDR_LEN);
1310 } else if (!strcmp(argv[start_arg], "vlan")) {
1312 if (!strcmp(argv[start_arg + 1], "none")) {
1313 t.fs.newvlan = VLAN_REMOVE;
1314 } else if (argv[start_arg + 1][0] == '=') {
1315 t.fs.newvlan = VLAN_REWRITE;
1316 } else if (argv[start_arg + 1][0] == '+') {
1317 t.fs.newvlan = VLAN_INSERT;
1319 warnx("unknown vlan parameter \"%s\"; must"
1320 " be one of \"none\", \"=<vlan>\", "
1321 " \"+<vlan>\"", argv[start_arg + 1]);
1324 if (t.fs.newvlan == VLAN_REWRITE ||
1325 t.fs.newvlan == VLAN_INSERT) {
1326 t.fs.vlan = strtoul(argv[start_arg + 1] + 1,
1328 if (p == argv[start_arg + 1] + 1 || p[0] != 0 ||
1329 t.fs.vlan > MAX_VLANID) {
1330 warnx("invalid vlan \"%s\"",
1331 argv[start_arg + 1]);
1336 warnx("invalid parameter \"%s\"", argv[start_arg]);
1340 if (start_arg != argc) {
1341 warnx("no value for \"%s\"", argv[start_arg]);
1346 * Check basic sanity of option combinations.
1348 if (t.fs.action != FILTER_SWITCH &&
1349 (t.fs.eport || t.fs.newdmac || t.fs.newsmac || t.fs.newvlan ||
1350 t.fs.swapmac || t.fs.nat_mode)) {
1351 warnx("port, dmac, smac, vlan, and nat only make sense with"
1352 " \"action switch\"");
1355 if (!t.fs.nat_mode && (t.fs.nat_seq_chk || t.fs.nat_flag_chk ||
1356 *t.fs.nat_dip || *t.fs.nat_sip || t.fs.nat_dport || t.fs.nat_sport)) {
1357 warnx("nat params only make sense with valid nat mode");
1360 if (t.fs.action != FILTER_PASS &&
1361 (t.fs.rpttid || t.fs.dirsteer || t.fs.maskhash)) {
1362 warnx("rpttid, queue and tcbhash don't make sense with"
1363 " action \"drop\" or \"switch\"");
1366 if (t.fs.val.ovlan_vld && t.fs.val.pfvf_vld) {
1367 warnx("ovlan and vnic_id (pf/vf) are mutually exclusive");
1371 t.fs.type = (af == AF_INET6 ? 1 : 0); /* default IPv4 */
1372 rc = doit(CHELSIO_T4_SET_FILTER, &t);
1373 if (hash && rc == 0)
1374 printf("%d\n", t.idx);
1379 filter_cmd(int argc, const char *argv[], int hashfilter)
1386 warnx("%sfilter: no arguments.", hashfilter ? "hash" : "");
1391 if (strcmp(argv[0], "list") == 0) {
1393 warnx("trailing arguments after \"list\" ignored.");
1395 return show_filters(hashfilter);
1399 if (argc == 1 && strcmp(argv[0], "mode") == 0)
1400 return get_filter_mode(hashfilter);
1403 if (strcmp(argv[0], "mode") == 0)
1404 return set_filter_mode(argc - 1, argv + 1, hashfilter);
1407 s = str_to_number(argv[0], NULL, &val);
1408 if (*s || val < 0 || val > 0xffffffffU) {
1411 * No numeric index means this must be a request to
1412 * create a new hashfilter and we are already at the
1413 * parameter/value list.
1415 idx = (uint32_t) -1;
1418 warnx("\"%s\" is neither an index nor a filter subcommand.",
1422 idx = (uint32_t) val;
1424 /* <idx> delete|clear [prio 0|1] */
1425 if ((argc == 2 || argc == 4) &&
1426 (strcmp(argv[1], "delete") == 0 || strcmp(argv[1], "clear") == 0)) {
1431 warnx("stray arguments after \"%s\".", argv[1]);
1435 if (strcmp(argv[2], "prio") != 0) {
1436 warnx("\"prio\" is the only valid keyword "
1437 "after \"%s\", found \"%s\" instead.",
1442 s = str_to_number(argv[3], NULL, &val);
1443 if (*s || val < 0 || val > 1) {
1444 warnx("%s \"%s\"; must be \"0\" or \"1\".",
1450 return del_filter(idx, prio, hashfilter);
1458 /* [<param> <val>] ... */
1459 return set_filter(idx, argc, argv, hashfilter);
1463 * Shows the fields of a multi-word structure. The structure is considered to
1464 * consist of @nwords 32-bit words (i.e, it's an (@nwords * 32)-bit structure)
1465 * whose fields are described by @fd. The 32-bit words are given in @words
1466 * starting with the least significant 32-bit word.
1469 show_struct(const uint32_t *words, int nwords, const struct field_desc *fd)
1472 const struct field_desc *p;
1474 for (p = fd; p->name; p++)
1475 w = max(w, strlen(p->name));
1478 unsigned long long data;
1479 int first_word = fd->start / 32;
1480 int shift = fd->start % 32;
1481 int width = fd->end - fd->start + 1;
1482 unsigned long long mask = (1ULL << width) - 1;
1484 data = (words[first_word] >> shift) |
1485 ((uint64_t)words[first_word + 1] << (32 - shift));
1487 data |= ((uint64_t)words[first_word + 2] << (64 - shift));
1491 printf("%-*s ", w, fd->name);
1492 printf(fd->hex ? "%#llx\n" : "%llu\n", data << fd->shift);
1497 #define FIELD(name, start, end) { name, start, end, 0, 0, 0 }
1498 #define FIELD1(name, start) FIELD(name, start, start)
1501 show_t5t6_ctxt(const struct t4_sge_context *p, int vers)
1503 static struct field_desc egress_t5[] = {
1504 FIELD("DCA_ST:", 181, 191),
1505 FIELD1("StatusPgNS:", 180),
1506 FIELD1("StatusPgRO:", 179),
1507 FIELD1("FetchNS:", 178),
1508 FIELD1("FetchRO:", 177),
1509 FIELD1("Valid:", 176),
1510 FIELD("PCIeDataChannel:", 174, 175),
1511 FIELD1("StatusPgTPHintEn:", 173),
1512 FIELD("StatusPgTPHint:", 171, 172),
1513 FIELD1("FetchTPHintEn:", 170),
1514 FIELD("FetchTPHint:", 168, 169),
1515 FIELD1("FCThreshOverride:", 167),
1516 { "WRLength:", 162, 166, 9, 0, 1 },
1517 FIELD1("WRLengthKnown:", 161),
1518 FIELD1("ReschedulePending:", 160),
1519 FIELD1("OnChipQueue:", 159),
1520 FIELD1("FetchSizeMode:", 158),
1521 { "FetchBurstMin:", 156, 157, 4, 0, 1 },
1522 FIELD1("FLMPacking:", 155),
1523 FIELD("FetchBurstMax:", 153, 154),
1524 FIELD("uPToken:", 133, 152),
1525 FIELD1("uPTokenEn:", 132),
1526 FIELD1("UserModeIO:", 131),
1527 FIELD("uPFLCredits:", 123, 130),
1528 FIELD1("uPFLCreditEn:", 122),
1529 FIELD("FID:", 111, 121),
1530 FIELD("HostFCMode:", 109, 110),
1531 FIELD1("HostFCOwner:", 108),
1532 { "CIDXFlushThresh:", 105, 107, 0, 0, 1 },
1533 FIELD("CIDX:", 89, 104),
1534 FIELD("PIDX:", 73, 88),
1535 { "BaseAddress:", 18, 72, 9, 1 },
1536 FIELD("QueueSize:", 2, 17),
1537 FIELD1("QueueType:", 1),
1538 FIELD1("CachePriority:", 0),
1541 static struct field_desc egress_t6[] = {
1542 FIELD("DCA_ST:", 181, 191),
1543 FIELD1("StatusPgNS:", 180),
1544 FIELD1("StatusPgRO:", 179),
1545 FIELD1("FetchNS:", 178),
1546 FIELD1("FetchRO:", 177),
1547 FIELD1("Valid:", 176),
1548 FIELD1("ReschedulePending_1:", 175),
1549 FIELD1("PCIeDataChannel:", 174),
1550 FIELD1("StatusPgTPHintEn:", 173),
1551 FIELD("StatusPgTPHint:", 171, 172),
1552 FIELD1("FetchTPHintEn:", 170),
1553 FIELD("FetchTPHint:", 168, 169),
1554 FIELD1("FCThreshOverride:", 167),
1555 { "WRLength:", 162, 166, 9, 0, 1 },
1556 FIELD1("WRLengthKnown:", 161),
1557 FIELD1("ReschedulePending:", 160),
1558 FIELD("TimerIx:", 157, 159),
1559 FIELD1("FetchBurstMin:", 156),
1560 FIELD1("FLMPacking:", 155),
1561 FIELD("FetchBurstMax:", 153, 154),
1562 FIELD("uPToken:", 133, 152),
1563 FIELD1("uPTokenEn:", 132),
1564 FIELD1("UserModeIO:", 131),
1565 FIELD("uPFLCredits:", 123, 130),
1566 FIELD1("uPFLCreditEn:", 122),
1567 FIELD("FID:", 111, 121),
1568 FIELD("HostFCMode:", 109, 110),
1569 FIELD1("HostFCOwner:", 108),
1570 { "CIDXFlushThresh:", 105, 107, 0, 0, 1 },
1571 FIELD("CIDX:", 89, 104),
1572 FIELD("PIDX:", 73, 88),
1573 { "BaseAddress:", 18, 72, 9, 1 },
1574 FIELD("QueueSize:", 2, 17),
1575 FIELD1("QueueType:", 1),
1576 FIELD1("FetchSizeMode:", 0),
1579 static struct field_desc fl_t5[] = {
1580 FIELD("DCA_ST:", 181, 191),
1581 FIELD1("StatusPgNS:", 180),
1582 FIELD1("StatusPgRO:", 179),
1583 FIELD1("FetchNS:", 178),
1584 FIELD1("FetchRO:", 177),
1585 FIELD1("Valid:", 176),
1586 FIELD("PCIeDataChannel:", 174, 175),
1587 FIELD1("StatusPgTPHintEn:", 173),
1588 FIELD("StatusPgTPHint:", 171, 172),
1589 FIELD1("FetchTPHintEn:", 170),
1590 FIELD("FetchTPHint:", 168, 169),
1591 FIELD1("FCThreshOverride:", 167),
1592 FIELD1("ReschedulePending:", 160),
1593 FIELD1("OnChipQueue:", 159),
1594 FIELD1("FetchSizeMode:", 158),
1595 { "FetchBurstMin:", 156, 157, 4, 0, 1 },
1596 FIELD1("FLMPacking:", 155),
1597 FIELD("FetchBurstMax:", 153, 154),
1598 FIELD1("FLMcongMode:", 152),
1599 FIELD("MaxuPFLCredits:", 144, 151),
1600 FIELD("FLMcontextID:", 133, 143),
1601 FIELD1("uPTokenEn:", 132),
1602 FIELD1("UserModeIO:", 131),
1603 FIELD("uPFLCredits:", 123, 130),
1604 FIELD1("uPFLCreditEn:", 122),
1605 FIELD("FID:", 111, 121),
1606 FIELD("HostFCMode:", 109, 110),
1607 FIELD1("HostFCOwner:", 108),
1608 { "CIDXFlushThresh:", 105, 107, 0, 0, 1 },
1609 FIELD("CIDX:", 89, 104),
1610 FIELD("PIDX:", 73, 88),
1611 { "BaseAddress:", 18, 72, 9, 1 },
1612 FIELD("QueueSize:", 2, 17),
1613 FIELD1("QueueType:", 1),
1614 FIELD1("CachePriority:", 0),
1617 static struct field_desc ingress_t5[] = {
1618 FIELD("DCA_ST:", 143, 153),
1619 FIELD1("ISCSICoalescing:", 142),
1620 FIELD1("Queue_Valid:", 141),
1621 FIELD1("TimerPending:", 140),
1622 FIELD1("DropRSS:", 139),
1623 FIELD("PCIeChannel:", 137, 138),
1624 FIELD1("SEInterruptArmed:", 136),
1625 FIELD1("CongestionMgtEnable:", 135),
1626 FIELD1("NoSnoop:", 134),
1627 FIELD1("RelaxedOrdering:", 133),
1628 FIELD1("GTSmode:", 132),
1629 FIELD1("TPHintEn:", 131),
1630 FIELD("TPHint:", 129, 130),
1631 FIELD1("UpdateScheduling:", 128),
1632 FIELD("UpdateDelivery:", 126, 127),
1633 FIELD1("InterruptSent:", 125),
1634 FIELD("InterruptIDX:", 114, 124),
1635 FIELD1("InterruptDestination:", 113),
1636 FIELD1("InterruptArmed:", 112),
1637 FIELD("RxIntCounter:", 106, 111),
1638 FIELD("RxIntCounterThreshold:", 104, 105),
1639 FIELD1("Generation:", 103),
1640 { "BaseAddress:", 48, 102, 9, 1 },
1641 FIELD("PIDX:", 32, 47),
1642 FIELD("CIDX:", 16, 31),
1643 { "QueueSize:", 4, 15, 4, 0 },
1644 { "QueueEntrySize:", 2, 3, 4, 0, 1 },
1645 FIELD1("QueueEntryOverride:", 1),
1646 FIELD1("CachePriority:", 0),
1649 static struct field_desc ingress_t6[] = {
1650 FIELD1("SP_NS:", 158),
1651 FIELD1("SP_RO:", 157),
1652 FIELD1("SP_TPHintEn:", 156),
1653 FIELD("SP_TPHint:", 154, 155),
1654 FIELD("DCA_ST:", 143, 153),
1655 FIELD1("ISCSICoalescing:", 142),
1656 FIELD1("Queue_Valid:", 141),
1657 FIELD1("TimerPending:", 140),
1658 FIELD1("DropRSS:", 139),
1659 FIELD("PCIeChannel:", 137, 138),
1660 FIELD1("SEInterruptArmed:", 136),
1661 FIELD1("CongestionMgtEnable:", 135),
1662 FIELD1("NoSnoop:", 134),
1663 FIELD1("RelaxedOrdering:", 133),
1664 FIELD1("GTSmode:", 132),
1665 FIELD1("TPHintEn:", 131),
1666 FIELD("TPHint:", 129, 130),
1667 FIELD1("UpdateScheduling:", 128),
1668 FIELD("UpdateDelivery:", 126, 127),
1669 FIELD1("InterruptSent:", 125),
1670 FIELD("InterruptIDX:", 114, 124),
1671 FIELD1("InterruptDestination:", 113),
1672 FIELD1("InterruptArmed:", 112),
1673 FIELD("RxIntCounter:", 106, 111),
1674 FIELD("RxIntCounterThreshold:", 104, 105),
1675 FIELD1("Generation:", 103),
1676 { "BaseAddress:", 48, 102, 9, 1 },
1677 FIELD("PIDX:", 32, 47),
1678 FIELD("CIDX:", 16, 31),
1679 { "QueueSize:", 4, 15, 4, 0 },
1680 { "QueueEntrySize:", 2, 3, 4, 0, 1 },
1681 FIELD1("QueueEntryOverride:", 1),
1682 FIELD1("CachePriority:", 0),
1685 static struct field_desc flm_t5[] = {
1686 FIELD1("Valid:", 89),
1687 FIELD("SplitLenMode:", 87, 88),
1688 FIELD1("TPHintEn:", 86),
1689 FIELD("TPHint:", 84, 85),
1690 FIELD1("NoSnoop:", 83),
1691 FIELD1("RelaxedOrdering:", 82),
1692 FIELD("DCA_ST:", 71, 81),
1693 FIELD("EQid:", 54, 70),
1694 FIELD("SplitEn:", 52, 53),
1695 FIELD1("PadEn:", 51),
1696 FIELD1("PackEn:", 50),
1697 FIELD1("Cache_Lock :", 49),
1698 FIELD1("CongDrop:", 48),
1699 FIELD("PackOffset:", 16, 47),
1700 FIELD("CIDX:", 8, 15),
1701 FIELD("PIDX:", 0, 7),
1704 static struct field_desc flm_t6[] = {
1705 FIELD1("Valid:", 89),
1706 FIELD("SplitLenMode:", 87, 88),
1707 FIELD1("TPHintEn:", 86),
1708 FIELD("TPHint:", 84, 85),
1709 FIELD1("NoSnoop:", 83),
1710 FIELD1("RelaxedOrdering:", 82),
1711 FIELD("DCA_ST:", 71, 81),
1712 FIELD("EQid:", 54, 70),
1713 FIELD("SplitEn:", 52, 53),
1714 FIELD1("PadEn:", 51),
1715 FIELD1("PackEn:", 50),
1716 FIELD1("Cache_Lock :", 49),
1717 FIELD1("CongDrop:", 48),
1718 FIELD1("Inflight:", 47),
1719 FIELD1("CongEn:", 46),
1720 FIELD1("CongMode:", 45),
1721 FIELD("PackOffset:", 20, 39),
1722 FIELD("CIDX:", 8, 15),
1723 FIELD("PIDX:", 0, 7),
1726 static struct field_desc conm_t5[] = {
1727 FIELD1("CngMPSEnable:", 21),
1728 FIELD("CngTPMode:", 19, 20),
1729 FIELD1("CngDBPHdr:", 18),
1730 FIELD1("CngDBPData:", 17),
1731 FIELD1("CngIMSG:", 16),
1732 { "CngChMap:", 0, 15, 0, 1, 0 },
1736 if (p->mem_id == SGE_CONTEXT_EGRESS) {
1738 show_struct(p->data, 6, fl_t5);
1740 show_struct(p->data, 6, egress_t5);
1742 show_struct(p->data, 6, egress_t6);
1743 } else if (p->mem_id == SGE_CONTEXT_FLM)
1744 show_struct(p->data, 3, vers == 5 ? flm_t5 : flm_t6);
1745 else if (p->mem_id == SGE_CONTEXT_INGRESS)
1746 show_struct(p->data, 5, vers == 5 ? ingress_t5 : ingress_t6);
1747 else if (p->mem_id == SGE_CONTEXT_CNM)
1748 show_struct(p->data, 1, conm_t5);
1752 show_t4_ctxt(const struct t4_sge_context *p)
1754 static struct field_desc egress_t4[] = {
1755 FIELD1("StatusPgNS:", 180),
1756 FIELD1("StatusPgRO:", 179),
1757 FIELD1("FetchNS:", 178),
1758 FIELD1("FetchRO:", 177),
1759 FIELD1("Valid:", 176),
1760 FIELD("PCIeDataChannel:", 174, 175),
1761 FIELD1("DCAEgrQEn:", 173),
1762 FIELD("DCACPUID:", 168, 172),
1763 FIELD1("FCThreshOverride:", 167),
1764 FIELD("WRLength:", 162, 166),
1765 FIELD1("WRLengthKnown:", 161),
1766 FIELD1("ReschedulePending:", 160),
1767 FIELD1("OnChipQueue:", 159),
1768 FIELD1("FetchSizeMode", 158),
1769 { "FetchBurstMin:", 156, 157, 4, 0, 1 },
1770 { "FetchBurstMax:", 153, 154, 6, 0, 1 },
1771 FIELD("uPToken:", 133, 152),
1772 FIELD1("uPTokenEn:", 132),
1773 FIELD1("UserModeIO:", 131),
1774 FIELD("uPFLCredits:", 123, 130),
1775 FIELD1("uPFLCreditEn:", 122),
1776 FIELD("FID:", 111, 121),
1777 FIELD("HostFCMode:", 109, 110),
1778 FIELD1("HostFCOwner:", 108),
1779 { "CIDXFlushThresh:", 105, 107, 0, 0, 1 },
1780 FIELD("CIDX:", 89, 104),
1781 FIELD("PIDX:", 73, 88),
1782 { "BaseAddress:", 18, 72, 9, 1 },
1783 FIELD("QueueSize:", 2, 17),
1784 FIELD1("QueueType:", 1),
1785 FIELD1("CachePriority:", 0),
1788 static struct field_desc fl_t4[] = {
1789 FIELD1("StatusPgNS:", 180),
1790 FIELD1("StatusPgRO:", 179),
1791 FIELD1("FetchNS:", 178),
1792 FIELD1("FetchRO:", 177),
1793 FIELD1("Valid:", 176),
1794 FIELD("PCIeDataChannel:", 174, 175),
1795 FIELD1("DCAEgrQEn:", 173),
1796 FIELD("DCACPUID:", 168, 172),
1797 FIELD1("FCThreshOverride:", 167),
1798 FIELD1("ReschedulePending:", 160),
1799 FIELD1("OnChipQueue:", 159),
1800 FIELD1("FetchSizeMode", 158),
1801 { "FetchBurstMin:", 156, 157, 4, 0, 1 },
1802 { "FetchBurstMax:", 153, 154, 6, 0, 1 },
1803 FIELD1("FLMcongMode:", 152),
1804 FIELD("MaxuPFLCredits:", 144, 151),
1805 FIELD("FLMcontextID:", 133, 143),
1806 FIELD1("uPTokenEn:", 132),
1807 FIELD1("UserModeIO:", 131),
1808 FIELD("uPFLCredits:", 123, 130),
1809 FIELD1("uPFLCreditEn:", 122),
1810 FIELD("FID:", 111, 121),
1811 FIELD("HostFCMode:", 109, 110),
1812 FIELD1("HostFCOwner:", 108),
1813 { "CIDXFlushThresh:", 105, 107, 0, 0, 1 },
1814 FIELD("CIDX:", 89, 104),
1815 FIELD("PIDX:", 73, 88),
1816 { "BaseAddress:", 18, 72, 9, 1 },
1817 FIELD("QueueSize:", 2, 17),
1818 FIELD1("QueueType:", 1),
1819 FIELD1("CachePriority:", 0),
1822 static struct field_desc ingress_t4[] = {
1823 FIELD1("NoSnoop:", 145),
1824 FIELD1("RelaxedOrdering:", 144),
1825 FIELD1("GTSmode:", 143),
1826 FIELD1("ISCSICoalescing:", 142),
1827 FIELD1("Valid:", 141),
1828 FIELD1("TimerPending:", 140),
1829 FIELD1("DropRSS:", 139),
1830 FIELD("PCIeChannel:", 137, 138),
1831 FIELD1("SEInterruptArmed:", 136),
1832 FIELD1("CongestionMgtEnable:", 135),
1833 FIELD1("DCAIngQEnable:", 134),
1834 FIELD("DCACPUID:", 129, 133),
1835 FIELD1("UpdateScheduling:", 128),
1836 FIELD("UpdateDelivery:", 126, 127),
1837 FIELD1("InterruptSent:", 125),
1838 FIELD("InterruptIDX:", 114, 124),
1839 FIELD1("InterruptDestination:", 113),
1840 FIELD1("InterruptArmed:", 112),
1841 FIELD("RxIntCounter:", 106, 111),
1842 FIELD("RxIntCounterThreshold:", 104, 105),
1843 FIELD1("Generation:", 103),
1844 { "BaseAddress:", 48, 102, 9, 1 },
1845 FIELD("PIDX:", 32, 47),
1846 FIELD("CIDX:", 16, 31),
1847 { "QueueSize:", 4, 15, 4, 0 },
1848 { "QueueEntrySize:", 2, 3, 4, 0, 1 },
1849 FIELD1("QueueEntryOverride:", 1),
1850 FIELD1("CachePriority:", 0),
1853 static struct field_desc flm_t4[] = {
1854 FIELD1("NoSnoop:", 79),
1855 FIELD1("RelaxedOrdering:", 78),
1856 FIELD1("Valid:", 77),
1857 FIELD("DCACPUID:", 72, 76),
1858 FIELD1("DCAFLEn:", 71),
1859 FIELD("EQid:", 54, 70),
1860 FIELD("SplitEn:", 52, 53),
1861 FIELD1("PadEn:", 51),
1862 FIELD1("PackEn:", 50),
1863 FIELD1("DBpriority:", 48),
1864 FIELD("PackOffset:", 16, 47),
1865 FIELD("CIDX:", 8, 15),
1866 FIELD("PIDX:", 0, 7),
1869 static struct field_desc conm_t4[] = {
1870 FIELD1("CngDBPHdr:", 6),
1871 FIELD1("CngDBPData:", 5),
1872 FIELD1("CngIMSG:", 4),
1873 { "CngChMap:", 0, 3, 0, 1, 0},
1877 if (p->mem_id == SGE_CONTEXT_EGRESS)
1878 show_struct(p->data, 6, (p->data[0] & 2) ? fl_t4 : egress_t4);
1879 else if (p->mem_id == SGE_CONTEXT_FLM)
1880 show_struct(p->data, 3, flm_t4);
1881 else if (p->mem_id == SGE_CONTEXT_INGRESS)
1882 show_struct(p->data, 5, ingress_t4);
1883 else if (p->mem_id == SGE_CONTEXT_CNM)
1884 show_struct(p->data, 1, conm_t4);
1891 get_sge_context(int argc, const char *argv[])
1896 struct t4_sge_context cntxt = {0};
1899 warnx("sge_context: incorrect number of arguments.");
1903 if (!strcmp(argv[0], "egress"))
1904 cntxt.mem_id = SGE_CONTEXT_EGRESS;
1905 else if (!strcmp(argv[0], "ingress"))
1906 cntxt.mem_id = SGE_CONTEXT_INGRESS;
1907 else if (!strcmp(argv[0], "fl"))
1908 cntxt.mem_id = SGE_CONTEXT_FLM;
1909 else if (!strcmp(argv[0], "cong"))
1910 cntxt.mem_id = SGE_CONTEXT_CNM;
1912 warnx("unknown context type \"%s\"; known types are egress, "
1913 "ingress, fl, and cong.", argv[0]);
1917 p = str_to_number(argv[1], &cid, NULL);
1919 warnx("invalid context id \"%s\"", argv[1]);
1924 rc = doit(CHELSIO_T4_GET_SGE_CONTEXT, &cntxt);
1929 show_t4_ctxt(&cntxt);
1931 show_t5t6_ctxt(&cntxt, chip_id);
1937 loadfw(int argc, const char *argv[])
1940 struct t4_data data = {0};
1941 const char *fname = argv[0];
1942 struct stat st = {0};
1945 warnx("loadfw: incorrect number of arguments.");
1949 fd = open(fname, O_RDONLY);
1951 warn("open(%s)", fname);
1955 if (fstat(fd, &st) < 0) {
1961 data.len = st.st_size;
1962 data.data = mmap(0, data.len, PROT_READ, MAP_PRIVATE, fd, 0);
1963 if (data.data == MAP_FAILED) {
1969 rc = doit(CHELSIO_T4_LOAD_FW, &data);
1970 munmap(data.data, data.len);
1976 loadcfg(int argc, const char *argv[])
1979 struct t4_data data = {0};
1980 const char *fname = argv[0];
1981 struct stat st = {0};
1984 warnx("loadcfg: incorrect number of arguments.");
1988 if (strcmp(fname, "clear") == 0)
1989 return (doit(CHELSIO_T4_LOAD_CFG, &data));
1991 fd = open(fname, O_RDONLY);
1993 warn("open(%s)", fname);
1997 if (fstat(fd, &st) < 0) {
2003 data.len = st.st_size;
2004 data.len &= ~3; /* Clip off to make it a multiple of 4 */
2005 data.data = mmap(0, data.len, PROT_READ, MAP_PRIVATE, fd, 0);
2006 if (data.data == MAP_FAILED) {
2012 rc = doit(CHELSIO_T4_LOAD_CFG, &data);
2013 munmap(data.data, data.len);
2019 dumpstate(int argc, const char *argv[])
2022 struct t4_cudbg_dump dump = {0};
2023 const char *fname = argv[0];
2026 warnx("dumpstate: incorrect number of arguments.");
2031 memset(&dump.bitmap, 0xff, sizeof(dump.bitmap));
2032 dump.len = 8 * 1024 * 1024;
2033 dump.data = malloc(dump.len);
2034 if (dump.data == NULL) {
2038 rc = doit(CHELSIO_T4_CUDBG_DUMP, &dump);
2042 fd = open(fname, O_CREAT | O_TRUNC | O_EXCL | O_WRONLY,
2043 S_IRUSR | S_IRGRP | S_IROTH);
2045 warn("open(%s)", fname);
2049 write(fd, dump.data, dump.len);
2057 read_mem(uint32_t addr, uint32_t len, void (*output)(uint32_t *, uint32_t))
2060 struct t4_mem_range mr;
2064 mr.data = malloc(mr.len);
2067 warn("read_mem: malloc");
2071 rc = doit(CHELSIO_T4_GET_MEM, &mr);
2076 (*output)(mr.data, mr.len);
2083 loadboot(int argc, const char *argv[])
2088 struct t4_bootrom br = {0};
2089 const char *fname = argv[0];
2090 struct stat st = {0};
2095 } else if (argc == 3) {
2096 if (!strcmp(argv[1], "pf"))
2098 else if (!strcmp(argv[1], "offset"))
2103 p = str_to_number(argv[2], &l, NULL);
2108 warnx("loadboot: incorrect number of arguments.");
2112 if (strcmp(fname, "clear") == 0)
2113 return (doit(CHELSIO_T4_LOAD_BOOT, &br));
2115 fd = open(fname, O_RDONLY);
2117 warn("open(%s)", fname);
2121 if (fstat(fd, &st) < 0) {
2127 br.len = st.st_size;
2128 br.data = mmap(0, br.len, PROT_READ, MAP_PRIVATE, fd, 0);
2129 if (br.data == MAP_FAILED) {
2135 rc = doit(CHELSIO_T4_LOAD_BOOT, &br);
2136 munmap(br.data, br.len);
2142 loadbootcfg(int argc, const char *argv[])
2145 struct t4_data bc = {0};
2146 const char *fname = argv[0];
2147 struct stat st = {0};
2150 warnx("loadbootcfg: incorrect number of arguments.");
2154 if (strcmp(fname, "clear") == 0)
2155 return (doit(CHELSIO_T4_LOAD_BOOTCFG, &bc));
2157 fd = open(fname, O_RDONLY);
2159 warn("open(%s)", fname);
2163 if (fstat(fd, &st) < 0) {
2169 bc.len = st.st_size;
2170 bc.data = mmap(0, bc.len, PROT_READ, MAP_PRIVATE, fd, 0);
2171 if (bc.data == MAP_FAILED) {
2177 rc = doit(CHELSIO_T4_LOAD_BOOTCFG, &bc);
2178 munmap(bc.data, bc.len);
2184 * Display memory as list of 'n' 4-byte values per line.
2187 show_mem(uint32_t *buf, uint32_t len)
2193 for (i = 0; len && i < n; i++, buf++, len -= 4) {
2195 printf("%s%08x", s, htonl(*buf));
2202 memdump(int argc, const char *argv[])
2209 warnx("incorrect number of arguments.");
2213 p = str_to_number(argv[0], &l, NULL);
2215 warnx("invalid address \"%s\"", argv[0]);
2220 p = str_to_number(argv[1], &l, NULL);
2222 warnx("memdump: invalid length \"%s\"", argv[1]);
2227 return (read_mem(addr, len, show_mem));
2231 * Display TCB as list of 'n' 4-byte values per line.
2234 show_tcb(uint32_t *buf, uint32_t len)
2236 unsigned char *tcb = (unsigned char *)buf;
2241 for (i = 0; len && i < n; i++, buf++, len -= 4) {
2243 printf("%s%08x", s, htonl(*buf));
2247 set_tcb_info(TIDTYPE_TCB, chip_id);
2248 set_print_style(PRNTSTYL_COMP);
2250 parse_n_display_xcb(tcb);
2253 #define A_TP_CMM_TCB_BASE 0x7d10
2254 #define TCB_SIZE 128
2256 read_tcb(int argc, const char *argv[])
2266 warnx("incorrect number of arguments.");
2270 p = str_to_number(argv[0], &l, NULL);
2272 warnx("invalid tid \"%s\"", argv[0]);
2277 rc = read_reg(A_TP_CMM_TCB_BASE, 4, &val);
2281 addr = val + tid * TCB_SIZE;
2283 return (read_mem(addr, TCB_SIZE, show_tcb));
2287 read_i2c(int argc, const char *argv[])
2291 struct t4_i2c_data i2cd;
2294 if (argc < 3 || argc > 4) {
2295 warnx("incorrect number of arguments.");
2299 p = str_to_number(argv[0], &l, NULL);
2300 if (*p || l > UCHAR_MAX) {
2301 warnx("invalid port id \"%s\"", argv[0]);
2306 p = str_to_number(argv[1], &l, NULL);
2307 if (*p || l > UCHAR_MAX) {
2308 warnx("invalid i2c device address \"%s\"", argv[1]);
2313 p = str_to_number(argv[2], &l, NULL);
2314 if (*p || l > UCHAR_MAX) {
2315 warnx("invalid byte offset \"%s\"", argv[2]);
2321 p = str_to_number(argv[3], &l, NULL);
2322 if (*p || l > sizeof(i2cd.data)) {
2323 warnx("invalid number of bytes \"%s\"", argv[3]);
2330 rc = doit(CHELSIO_T4_GET_I2C, &i2cd);
2334 for (i = 0; i < i2cd.len; i++)
2335 printf("0x%x [%u]\n", i2cd.data[i], i2cd.data[i]);
2341 clearstats(int argc, const char *argv[])
2348 warnx("incorrect number of arguments.");
2352 p = str_to_number(argv[0], &l, NULL);
2354 warnx("invalid port id \"%s\"", argv[0]);
2359 return doit(CHELSIO_T4_CLEAR_STATS, &port);
2367 int rc, port_idx, i;
2370 /* Magic values: MPS_TRC_CFG = 0x9800. MPS_TRC_CFG[1:1] = TrcEn */
2371 rc = read_reg(0x9800, 4, &val);
2374 printf("tracing is %s\n", val & 2 ? "ENABLED" : "DISABLED");
2377 for (t.idx = 0; ; t.idx++) {
2378 rc = doit(CHELSIO_T4_GET_TRACER, &t);
2379 if (rc != 0 || t.idx == 0xff)
2382 if (t.tp.port < 4) {
2384 port_idx = t.tp.port;
2385 } else if (t.tp.port < 8) {
2387 port_idx = t.tp.port - 4;
2388 } else if (t.tp.port < 12) {
2390 port_idx = t.tp.port - 8;
2391 } else if (t.tp.port < 16) {
2393 port_idx = t.tp.port - 12;
2394 } else if (t.tp.port < 20) {
2396 port_idx = t.tp.port - 16;
2399 port_idx = t.tp.port;
2402 printf("\ntracer %u (currently %s) captures ", t.idx,
2403 t.enabled ? "ENABLED" : "DISABLED");
2405 printf("port %u %s, ", port_idx, s);
2407 printf("%s %u, ", s, port_idx);
2408 printf("snap length: %u, min length: %u\n", t.tp.snap_len,
2410 printf("packets captured %smatch filter\n",
2411 t.tp.invert ? "do not " : "");
2412 if (t.tp.skip_ofst) {
2413 printf("filter pattern: ");
2414 for (i = 0; i < t.tp.skip_ofst * 2; i += 2)
2415 printf("%08x%08x", t.tp.data[i],
2418 for (i = 0; i < t.tp.skip_ofst * 2; i += 2)
2419 printf("%08x%08x", t.tp.mask[i],
2423 printf("filter pattern: ");
2424 for (i = t.tp.skip_ofst * 2; i < T4_TRACE_LEN / 4; i += 2)
2425 printf("%08x%08x", t.tp.data[i], t.tp.data[i + 1]);
2427 for (i = t.tp.skip_ofst * 2; i < T4_TRACE_LEN / 4; i += 2)
2428 printf("%08x%08x", t.tp.mask[i], t.tp.mask[i + 1]);
2429 printf("@%u\n", (t.tp.skip_ofst + t.tp.skip_len) * 8);
2436 tracer_onoff(uint8_t idx, int enabled)
2441 t.enabled = enabled;
2444 return doit(CHELSIO_T4_SET_TRACER, &t);
2448 create_tracing_ifnet()
2451 "/sbin/ifconfig", __DECONST(char *, nexus), "create", NULL
2453 char *env[] = {NULL};
2456 close(STDERR_FILENO);
2457 execve(cmd[0], cmd, env);
2463 * XXX: Allow user to specify snaplen, minlen, and pattern (including inverted
2464 * matching). Right now this is a quick-n-dirty implementation that traces the
2465 * first 128B of all tx or rx on a port
2468 set_tracer(uint8_t idx, int argc, const char *argv[])
2473 bzero(&t, sizeof (t));
2479 warnx("must specify one of tx/rx/lo<n>");
2483 len = strlen(argv[0]);
2485 warnx("argument must be 3 characters (tx/rx/lo<n>). eg. tx0");
2489 if (strncmp(argv[0], "lo", 2) == 0) {
2490 port = argv[0][2] - '0';
2491 if (port < 0 || port > 3) {
2492 warnx("'%c' in %s is invalid", argv[0][2], argv[0]);
2496 } else if (strncmp(argv[0], "tx", 2) == 0) {
2497 port = argv[0][2] - '0';
2498 if (port < 0 || port > 3) {
2499 warnx("'%c' in %s is invalid", argv[0][2], argv[0]);
2503 } else if (strncmp(argv[0], "rx", 2) == 0) {
2504 port = argv[0][2] - '0';
2505 if (port < 0 || port > 3) {
2506 warnx("'%c' in %s is invalid", argv[0][2], argv[0]);
2510 warnx("argument '%s' isn't tx<n> or rx<n>", argv[0]);
2514 t.tp.snap_len = 128;
2521 create_tracing_ifnet();
2522 return doit(CHELSIO_T4_SET_TRACER, &t);
2526 tracer_cmd(int argc, const char *argv[])
2533 warnx("tracer: no arguments.");
2538 if (strcmp(argv[0], "list") == 0) {
2540 warnx("trailing arguments after \"list\" ignored.");
2542 return show_tracers();
2546 s = str_to_number(argv[0], NULL, &val);
2547 if (*s || val > 0xff) {
2548 warnx("\"%s\" is neither an index nor a tracer subcommand.",
2555 if (argc == 2 && strcmp(argv[1], "disable") == 0)
2556 return tracer_onoff(idx, 0);
2559 if (argc == 2 && strcmp(argv[1], "enable") == 0)
2560 return tracer_onoff(idx, 1);
2563 return set_tracer(idx, argc - 1, argv + 1);
2567 modinfo_raw(int port_id)
2570 struct t4_i2c_data i2cd;
2573 for (offset = 0; offset < 96; offset += sizeof(i2cd.data)) {
2574 bzero(&i2cd, sizeof(i2cd));
2575 i2cd.port_id = port_id;
2576 i2cd.dev_addr = 0xa0;
2577 i2cd.offset = offset;
2578 i2cd.len = sizeof(i2cd.data);
2579 rc = doit(CHELSIO_T4_GET_I2C, &i2cd);
2582 printf("%02x: %02x %02x %02x %02x %02x %02x %02x %02x",
2583 offset, i2cd.data[0], i2cd.data[1], i2cd.data[2],
2584 i2cd.data[3], i2cd.data[4], i2cd.data[5], i2cd.data[6],
2587 printf(" %c%c%c%c %c%c%c%c\n",
2588 isprint(i2cd.data[0]) ? i2cd.data[0] : '.',
2589 isprint(i2cd.data[1]) ? i2cd.data[1] : '.',
2590 isprint(i2cd.data[2]) ? i2cd.data[2] : '.',
2591 isprint(i2cd.data[3]) ? i2cd.data[3] : '.',
2592 isprint(i2cd.data[4]) ? i2cd.data[4] : '.',
2593 isprint(i2cd.data[5]) ? i2cd.data[5] : '.',
2594 isprint(i2cd.data[6]) ? i2cd.data[6] : '.',
2595 isprint(i2cd.data[7]) ? i2cd.data[7] : '.');
2602 modinfo(int argc, const char *argv[])
2605 char string[16], *p;
2606 struct t4_i2c_data i2cd;
2608 uint16_t temp, vcc, tx_bias, tx_power, rx_power;
2611 warnx("must supply a port");
2616 warnx("too many arguments");
2620 p = str_to_number(argv[0], &port, NULL);
2621 if (*p || port > UCHAR_MAX) {
2622 warnx("invalid port id \"%s\"", argv[0]);
2627 if (!strcmp(argv[1], "raw"))
2628 return (modinfo_raw(port));
2630 warnx("second argument can only be \"raw\"");
2635 bzero(&i2cd, sizeof(i2cd));
2637 i2cd.port_id = port;
2638 i2cd.dev_addr = SFF_8472_BASE;
2640 i2cd.offset = SFF_8472_ID;
2641 if ((rc = doit(CHELSIO_T4_GET_I2C, &i2cd)) != 0)
2644 if (i2cd.data[0] > SFF_8472_ID_LAST)
2645 printf("Unknown ID\n");
2647 printf("ID: %s\n", sff_8472_id[i2cd.data[0]]);
2649 bzero(&string, sizeof(string));
2650 for (i = SFF_8472_VENDOR_START; i < SFF_8472_VENDOR_END; i++) {
2652 if ((rc = doit(CHELSIO_T4_GET_I2C, &i2cd)) != 0)
2654 string[i - SFF_8472_VENDOR_START] = i2cd.data[0];
2656 printf("Vendor %s\n", string);
2658 bzero(&string, sizeof(string));
2659 for (i = SFF_8472_SN_START; i < SFF_8472_SN_END; i++) {
2661 if ((rc = doit(CHELSIO_T4_GET_I2C, &i2cd)) != 0)
2663 string[i - SFF_8472_SN_START] = i2cd.data[0];
2665 printf("SN %s\n", string);
2667 bzero(&string, sizeof(string));
2668 for (i = SFF_8472_PN_START; i < SFF_8472_PN_END; i++) {
2670 if ((rc = doit(CHELSIO_T4_GET_I2C, &i2cd)) != 0)
2672 string[i - SFF_8472_PN_START] = i2cd.data[0];
2674 printf("PN %s\n", string);
2676 bzero(&string, sizeof(string));
2677 for (i = SFF_8472_REV_START; i < SFF_8472_REV_END; i++) {
2679 if ((rc = doit(CHELSIO_T4_GET_I2C, &i2cd)) != 0)
2681 string[i - SFF_8472_REV_START] = i2cd.data[0];
2683 printf("Rev %s\n", string);
2685 i2cd.offset = SFF_8472_DIAG_TYPE;
2686 if ((rc = doit(CHELSIO_T4_GET_I2C, &i2cd)) != 0)
2689 if ((char )i2cd.data[0] & (SFF_8472_DIAG_IMPL |
2690 SFF_8472_DIAG_INTERNAL)) {
2692 /* Switch to reading from the Diagnostic address. */
2693 i2cd.dev_addr = SFF_8472_DIAG;
2696 i2cd.offset = SFF_8472_TEMP;
2697 if ((rc = doit(CHELSIO_T4_GET_I2C, &i2cd)) != 0)
2699 temp = i2cd.data[0] << 8;
2701 if ((temp & SFF_8472_TEMP_SIGN) == SFF_8472_TEMP_SIGN)
2705 printf("%dC\n", (temp & SFF_8472_TEMP_MSK) >>
2706 SFF_8472_TEMP_SHIFT);
2708 i2cd.offset = SFF_8472_VCC;
2709 if ((rc = doit(CHELSIO_T4_GET_I2C, &i2cd)) != 0)
2711 vcc = i2cd.data[0] << 8;
2712 printf("Vcc %fV\n", vcc / SFF_8472_VCC_FACTOR);
2714 i2cd.offset = SFF_8472_TX_BIAS;
2715 if ((rc = doit(CHELSIO_T4_GET_I2C, &i2cd)) != 0)
2717 tx_bias = i2cd.data[0] << 8;
2718 printf("TX Bias %fuA\n", tx_bias / SFF_8472_BIAS_FACTOR);
2720 i2cd.offset = SFF_8472_TX_POWER;
2721 if ((rc = doit(CHELSIO_T4_GET_I2C, &i2cd)) != 0)
2723 tx_power = i2cd.data[0] << 8;
2724 printf("TX Power %fmW\n", tx_power / SFF_8472_POWER_FACTOR);
2726 i2cd.offset = SFF_8472_RX_POWER;
2727 if ((rc = doit(CHELSIO_T4_GET_I2C, &i2cd)) != 0)
2729 rx_power = i2cd.data[0] << 8;
2730 printf("RX Power %fmW\n", rx_power / SFF_8472_POWER_FACTOR);
2733 printf("Diagnostics not supported.\n");
2739 warnx("No module/cable in port %ld", port);
2744 /* XXX: pass in a low/high and do range checks as well */
2746 get_sched_param(const char *param, const char *args[], long *val)
2750 if (strcmp(param, args[0]) != 0)
2753 p = str_to_number(args[1], val, NULL);
2755 warnx("parameter \"%s\" has bad value \"%s\"", args[0],
2764 sched_class(int argc, const char *argv[])
2766 struct t4_sched_params op;
2769 memset(&op, 0xff, sizeof(op));
2773 warnx("missing scheduling sub-command");
2776 if (!strcmp(argv[0], "config")) {
2777 op.subcmd = SCHED_CLASS_SUBCMD_CONFIG;
2778 op.u.config.minmax = -1;
2779 } else if (!strcmp(argv[0], "params")) {
2780 op.subcmd = SCHED_CLASS_SUBCMD_PARAMS;
2781 op.u.params.level = op.u.params.mode = op.u.params.rateunit =
2782 op.u.params.ratemode = op.u.params.channel =
2783 op.u.params.cl = op.u.params.minrate = op.u.params.maxrate =
2784 op.u.params.weight = op.u.params.pktsize = -1;
2786 warnx("invalid scheduling sub-command \"%s\"", argv[0]);
2790 /* Decode remaining arguments ... */
2792 for (i = 1; i < argc; i += 2) {
2793 const char **args = &argv[i];
2796 if (i + 1 == argc) {
2797 warnx("missing argument for \"%s\"", args[0]);
2802 if (!strcmp(args[0], "type")) {
2803 if (!strcmp(args[1], "packet"))
2804 op.type = SCHED_CLASS_TYPE_PACKET;
2806 warnx("invalid type parameter \"%s\"", args[1]);
2813 if (op.subcmd == SCHED_CLASS_SUBCMD_CONFIG) {
2814 if(!get_sched_param("minmax", args, &l))
2815 op.u.config.minmax = (int8_t)l;
2817 warnx("unknown scheduler config parameter "
2825 /* Rest applies only to SUBCMD_PARAMS */
2826 if (op.subcmd != SCHED_CLASS_SUBCMD_PARAMS)
2829 if (!strcmp(args[0], "level")) {
2830 if (!strcmp(args[1], "cl-rl"))
2831 op.u.params.level = SCHED_CLASS_LEVEL_CL_RL;
2832 else if (!strcmp(args[1], "cl-wrr"))
2833 op.u.params.level = SCHED_CLASS_LEVEL_CL_WRR;
2834 else if (!strcmp(args[1], "ch-rl"))
2835 op.u.params.level = SCHED_CLASS_LEVEL_CH_RL;
2837 warnx("invalid level parameter \"%s\"",
2841 } else if (!strcmp(args[0], "mode")) {
2842 if (!strcmp(args[1], "class"))
2843 op.u.params.mode = SCHED_CLASS_MODE_CLASS;
2844 else if (!strcmp(args[1], "flow"))
2845 op.u.params.mode = SCHED_CLASS_MODE_FLOW;
2847 warnx("invalid mode parameter \"%s\"", args[1]);
2850 } else if (!strcmp(args[0], "rate-unit")) {
2851 if (!strcmp(args[1], "bits"))
2852 op.u.params.rateunit = SCHED_CLASS_RATEUNIT_BITS;
2853 else if (!strcmp(args[1], "pkts"))
2854 op.u.params.rateunit = SCHED_CLASS_RATEUNIT_PKTS;
2856 warnx("invalid rate-unit parameter \"%s\"",
2860 } else if (!strcmp(args[0], "rate-mode")) {
2861 if (!strcmp(args[1], "relative"))
2862 op.u.params.ratemode = SCHED_CLASS_RATEMODE_REL;
2863 else if (!strcmp(args[1], "absolute"))
2864 op.u.params.ratemode = SCHED_CLASS_RATEMODE_ABS;
2866 warnx("invalid rate-mode parameter \"%s\"",
2870 } else if (!get_sched_param("channel", args, &l))
2871 op.u.params.channel = (int8_t)l;
2872 else if (!get_sched_param("class", args, &l))
2873 op.u.params.cl = (int8_t)l;
2874 else if (!get_sched_param("min-rate", args, &l))
2875 op.u.params.minrate = (int32_t)l;
2876 else if (!get_sched_param("max-rate", args, &l))
2877 op.u.params.maxrate = (int32_t)l;
2878 else if (!get_sched_param("weight", args, &l))
2879 op.u.params.weight = (int16_t)l;
2880 else if (!get_sched_param("pkt-size", args, &l))
2881 op.u.params.pktsize = (int16_t)l;
2883 warnx("unknown scheduler parameter \"%s\"", args[0]);
2889 * Catch some logical fallacies in terms of argument combinations here
2890 * so we can offer more than just the EINVAL return from the driver.
2891 * The driver will be able to catch a lot more issues since it knows
2892 * the specifics of the device hardware capabilities like how many
2893 * channels, classes, etc. the device supports.
2896 warnx("sched \"type\" parameter missing");
2899 if (op.subcmd == SCHED_CLASS_SUBCMD_CONFIG) {
2900 if (op.u.config.minmax < 0) {
2901 warnx("sched config \"minmax\" parameter missing");
2905 if (op.subcmd == SCHED_CLASS_SUBCMD_PARAMS) {
2906 if (op.u.params.level < 0) {
2907 warnx("sched params \"level\" parameter missing");
2910 if (op.u.params.mode < 0 &&
2911 op.u.params.level == SCHED_CLASS_LEVEL_CL_RL) {
2912 warnx("sched params \"mode\" parameter missing");
2915 if (op.u.params.rateunit < 0 &&
2916 (op.u.params.level == SCHED_CLASS_LEVEL_CL_RL ||
2917 op.u.params.level == SCHED_CLASS_LEVEL_CH_RL)) {
2918 warnx("sched params \"rate-unit\" parameter missing");
2921 if (op.u.params.ratemode < 0 &&
2922 (op.u.params.level == SCHED_CLASS_LEVEL_CL_RL ||
2923 op.u.params.level == SCHED_CLASS_LEVEL_CH_RL)) {
2924 warnx("sched params \"rate-mode\" parameter missing");
2927 if (op.u.params.channel < 0) {
2928 warnx("sched params \"channel\" missing");
2931 if (op.u.params.cl < 0 &&
2932 (op.u.params.level == SCHED_CLASS_LEVEL_CL_RL ||
2933 op.u.params.level == SCHED_CLASS_LEVEL_CL_WRR)) {
2934 warnx("sched params \"class\" missing");
2937 if (op.u.params.maxrate < 0 &&
2938 (op.u.params.level == SCHED_CLASS_LEVEL_CL_RL ||
2939 op.u.params.level == SCHED_CLASS_LEVEL_CH_RL)) {
2940 warnx("sched params \"max-rate\" missing for "
2941 "rate-limit level");
2944 if (op.u.params.level == SCHED_CLASS_LEVEL_CL_WRR &&
2945 (op.u.params.weight < 1 || op.u.params.weight > 99)) {
2946 warnx("sched params \"weight\" missing or invalid "
2947 "(not 1-99) for weighted-round-robin level");
2950 if (op.u.params.pktsize < 0 &&
2951 op.u.params.level == SCHED_CLASS_LEVEL_CL_RL) {
2952 warnx("sched params \"pkt-size\" missing for "
2953 "rate-limit level");
2956 if (op.u.params.mode == SCHED_CLASS_MODE_FLOW &&
2957 op.u.params.ratemode != SCHED_CLASS_RATEMODE_ABS) {
2958 warnx("sched params mode flow needs rate-mode absolute");
2961 if (op.u.params.ratemode == SCHED_CLASS_RATEMODE_REL &&
2962 !in_range(op.u.params.maxrate, 1, 100)) {
2963 warnx("sched params \"max-rate\" takes "
2964 "percentage value(1-100) for rate-mode relative");
2967 if (op.u.params.ratemode == SCHED_CLASS_RATEMODE_ABS &&
2968 !in_range(op.u.params.maxrate, 1, 100000000)) {
2969 warnx("sched params \"max-rate\" takes "
2970 "value(1-100000000) for rate-mode absolute");
2973 if (op.u.params.maxrate > 0 &&
2974 op.u.params.maxrate < op.u.params.minrate) {
2975 warnx("sched params \"max-rate\" is less than "
2982 warnx("%d error%s in sched-class command", errs,
2983 errs == 1 ? "" : "s");
2987 return doit(CHELSIO_T4_SCHED_CLASS, &op);
2991 sched_queue(int argc, const char *argv[])
2993 struct t4_sched_queue op = {0};
2998 /* need "<port> <queue> <class> */
2999 warnx("incorrect number of arguments.");
3003 p = str_to_number(argv[0], &val, NULL);
3004 if (*p || val > UCHAR_MAX) {
3005 warnx("invalid port id \"%s\"", argv[0]);
3008 op.port = (uint8_t)val;
3010 if (!strcmp(argv[1], "all") || !strcmp(argv[1], "*"))
3013 p = str_to_number(argv[1], &val, NULL);
3014 if (*p || val < -1) {
3015 warnx("invalid queue \"%s\"", argv[1]);
3018 op.queue = (int8_t)val;
3021 if (!strcmp(argv[2], "unbind") || !strcmp(argv[2], "clear"))
3024 p = str_to_number(argv[2], &val, NULL);
3025 if (*p || val < -1) {
3026 warnx("invalid class \"%s\"", argv[2]);
3029 op.cl = (int8_t)val;
3032 return doit(CHELSIO_T4_SCHED_QUEUE, &op);
3036 parse_offload_settings_word(const char *s, char **pnext, const char *ws,
3037 int *pneg, struct offload_settings *os)
3045 if (!strcmp(s, "not")) {
3050 if (!strcmp(s, "offload")) {
3051 os->offload = (*pneg + 1) & 1;
3053 } else if (!strcmp(s , "coalesce")) {
3054 os->rx_coalesce = (*pneg + 1) & 1;
3056 } else if (!strcmp(s, "timestamp") || !strcmp(s, "tstamp")) {
3057 os->tstamp = (*pneg + 1) & 1;
3059 } else if (!strcmp(s, "sack")) {
3060 os->sack = (*pneg + 1) & 1;
3062 } else if (!strcmp(s, "nagle")) {
3063 os->nagle = (*pneg + 1) & 1;
3065 } else if (!strcmp(s, "ecn")) {
3066 os->ecn = (*pneg + 1) & 1;
3068 } else if (!strcmp(s, "ddp")) {
3069 os->ddp = (*pneg + 1) & 1;
3071 } else if (!strcmp(s, "tls")) {
3072 os->tls = (*pneg + 1) & 1;
3078 /* Settings with additional parameter handled here. */
3081 warnx("\"%s\" is not a valid keyword, or it does not "
3082 "support negation.", s);
3086 while ((param = strsep(pnext, ws)) != NULL) {
3090 if (param == NULL) {
3091 warnx("\"%s\" is not a valid keyword, or it requires a "
3092 "parameter that has not been provided.", s);
3096 if (!strcmp(s, "cong")) {
3097 if (!strcmp(param, "reno"))
3099 else if (!strcmp(param, "tahoe"))
3101 else if (!strcmp(param, "newreno"))
3103 else if (!strcmp(param, "highspeed"))
3106 warnx("unknown congestion algorithm \"%s\".", s);
3109 } else if (!strcmp(s, "class")) {
3111 p = str_to_number(param, &val, NULL);
3112 /* (nsched_cls - 1) is spelled 15 here. */
3113 if (*p || val < 0 || val > 15) {
3114 warnx("invalid scheduling class \"%s\". "
3115 "\"class\" needs an integer value where "
3116 "0 <= value <= 15", param);
3119 os->sched_class = val;
3120 } else if (!strcmp(s, "bind") || !strcmp(s, "txq") ||
3121 !strcmp(s, "rxq")) {
3122 if (!strcmp(param, "random")) {
3124 } else if (!strcmp(param, "roundrobin")) {
3125 val = QUEUE_ROUNDROBIN;
3127 p = str_to_number(param, &val, NULL);
3128 if (*p || val < 0 || val > 0xffff) {
3129 warnx("invalid queue specification "
3130 "\"%s\". \"%s\" needs an integer"
3131 " value, \"random\", or "
3132 "\"roundrobin\".", param, s);
3136 if (!strcmp(s, "bind")) {
3139 } else if (!strcmp(s, "txq")) {
3141 } else if (!strcmp(s, "rxq")) {
3146 } else if (!strcmp(s, "mss")) {
3148 p = str_to_number(param, &val, NULL);
3149 if (*p || val <= 0) {
3150 warnx("invalid MSS specification \"%s\". "
3151 "\"mss\" needs a positive integer value",
3157 warnx("unknown settings keyword: \"%s\"", s);
3166 parse_offload_settings(const char *settings_ro, struct offload_settings *os)
3168 const char *ws = " \f\n\r\v\t";
3169 char *settings, *s, *next;
3170 int rc, nsettings, neg;
3171 static const struct offload_settings default_settings = {
3172 .offload = 0, /* No settings imply !offload */
3182 .txq = QUEUE_RANDOM,
3183 .rxq = QUEUE_RANDOM,
3187 *os = default_settings;
3189 next = settings = strdup(settings_ro);
3190 if (settings == NULL) {
3198 while ((s = strsep(&next, ws)) != NULL) {
3202 rc = parse_offload_settings_word(s, &next, ws, &neg, os);
3206 if (nsettings == 0) {
3207 warnx("no settings provided");
3212 warnx("%d stray negation(s) at end of offload settings", neg);
3222 isempty_line(char *line, size_t llen)
3225 /* skip leading whitespace */
3226 while (isspace(*line)) {
3230 if (llen == 0 || *line == '#' || *line == '\n')
3237 special_offload_rule(char *str)
3240 /* skip leading whitespaces */
3241 while (isspace(*str))
3244 /* check for special strings: "-", "all", "any" */
3247 } else if (!strncmp(str, "all", 3) || !strncmp(str, "any", 3)) {
3253 /* skip trailing whitespaces */
3254 while (isspace(*str))
3257 return (*str == '\0');
3261 * A rule has 3 parts: an open-type, a match expression, and offload settings.
3263 * [<open-type>] <expr> => <settings>
3266 parse_offload_policy_line(size_t lno, char *line, size_t llen, pcap_t *pd,
3267 struct offload_rule *r)
3269 char *expr, *settings, *s;
3271 bzero(r, sizeof(*r));
3273 /* Skip leading whitespace. */
3274 while (isspace(*line))
3276 /* Trim trailing whitespace */
3277 s = &line[llen - 1];
3278 while (isspace(*s)) {
3284 * First part of the rule: '[X]' where X = A/D/L/P
3286 if (*line++ != '[') {
3287 warnx("missing \"[\" on line %zd", lno);
3295 r->open_type = *line;
3298 warnx("invalid socket-type \"%c\" on line %zd.", *line, lno);
3302 if (*line++ != ']') {
3303 warnx("missing \"]\" after \"[%c\" on line %zd",
3308 /* Skip whitespace. */
3309 while (isspace(*line))
3313 * Rest of the rule: <expr> => <settings>
3316 s = strstr(line, "=>");
3320 while (isspace(*settings))
3325 * <expr> is either a special name (all, any) or a pcap-filter(7).
3326 * In case of a special name the bpf_prog stays all-zero.
3328 if (!special_offload_rule(expr)) {
3329 if (pcap_compile(pd, &r->bpf_prog, expr, 1,
3330 PCAP_NETMASK_UNKNOWN) < 0) {
3331 warnx("failed to compile \"%s\" on line %zd: %s", expr,
3332 lno, pcap_geterr(pd));
3337 /* settings to apply on a match. */
3338 if (parse_offload_settings(settings, &r->settings) != 0) {
3339 warnx("failed to parse offload settings \"%s\" on line %zd",
3341 pcap_freecode(&r->bpf_prog);
3350 * Note that op itself is not dynamically allocated.
3353 free_offload_policy(struct t4_offload_policy *op)
3357 for (i = 0; i < op->nrules; i++) {
3359 * pcap_freecode can cope with empty bpf_prog, which is the case
3360 * for an rule that matches on 'any/all/-'.
3362 pcap_freecode(&op->rule[i].bpf_prog);
3369 #define REALLOC_STRIDE 32
3372 * Fills up op->nrules and op->rule.
3375 parse_offload_policy(const char *fname, struct t4_offload_policy *op)
3379 int lno, maxrules, rc;
3381 struct offload_rule *r;
3384 fp = fopen(fname, "r");
3386 warn("Unable to open file \"%s\"", fname);
3389 pd = pcap_open_dead(DLT_EN10MB, 128);
3391 warnx("Failed to open pcap device");
3404 while ((llen = getline(&line, &lcap, fp)) != -1) {
3407 /* Skip empty lines. */
3408 if (isempty_line(line, llen))
3411 if (op->nrules == maxrules) {
3412 maxrules += REALLOC_STRIDE;
3413 r = realloc(op->rule,
3414 maxrules * sizeof(struct offload_rule));
3416 warnx("failed to allocate memory for %d rules",
3424 r = &op->rule[op->nrules];
3425 rc = parse_offload_policy_line(lno, line, llen, pd, r);
3427 warnx("Error parsing line %d of \"%s\"", lno, fname);
3436 warn("Error while reading from file \"%s\" at line %d",
3442 if (op->nrules == 0) {
3443 warnx("No valid rules found in \"%s\"", fname);
3450 free_offload_policy(op);
3457 load_offload_policy(int argc, const char *argv[])
3460 const char *fname = argv[0];
3461 struct t4_offload_policy op = {0};
3464 warnx("incorrect number of arguments.");
3468 if (!strcmp(fname, "clear") || !strcmp(fname, "none")) {
3469 /* op.nrules is 0 and that means clear policy */
3470 return (doit(CHELSIO_T4_SET_OFLD_POLICY, &op));
3473 rc = parse_offload_policy(fname, &op);
3475 /* Error message displayed already */
3479 rc = doit(CHELSIO_T4_SET_OFLD_POLICY, &op);
3480 free_offload_policy(&op);
3488 size_t clip_buf_size = 4096;
3489 char *buf, name[32];
3492 buf = malloc(clip_buf_size);
3494 warn("%s", __func__);
3498 snprintf(name, sizeof(name), "dev.t%unex.%u.misc.clip", chip_id, inst);
3499 rc = sysctlbyname(name, buf, &clip_buf_size, NULL, 0);
3501 warn("sysctl %s", name);
3506 printf("%s\n", buf);
3512 clip_cmd(int argc, const char *argv[])
3514 int rc, af = AF_INET6, add;
3515 struct t4_clip_addr ca = {0};
3517 if (argc == 1 && !strcmp(argv[0], "list")) {
3518 rc = display_clip();
3523 warnx("incorrect number of arguments.");
3527 if (!strcmp(argv[0], "hold")) {
3529 } else if (!strcmp(argv[0], "rel") || !strcmp(argv[0], "release")) {
3532 warnx("first argument must be \"hold\" or \"release\"");
3536 rc = parse_ipaddr(argv[0], argv, &af, &ca.addr[0], &ca.mask[0], 1);
3541 rc = doit(CHELSIO_T4_HOLD_CLIP_ADDR, &ca);
3543 rc = doit(CHELSIO_T4_RELEASE_CLIP_ADDR, &ca);
3549 run_cmd(int argc, const char *argv[])
3552 const char *cmd = argv[0];
3558 if (!strcmp(cmd, "reg") || !strcmp(cmd, "reg32"))
3559 rc = register_io(argc, argv, 4);
3560 else if (!strcmp(cmd, "reg64"))
3561 rc = register_io(argc, argv, 8);
3562 else if (!strcmp(cmd, "regdump"))
3563 rc = dump_regs(argc, argv);
3564 else if (!strcmp(cmd, "filter"))
3565 rc = filter_cmd(argc, argv, 0);
3566 else if (!strcmp(cmd, "context"))
3567 rc = get_sge_context(argc, argv);
3568 else if (!strcmp(cmd, "loadfw"))
3569 rc = loadfw(argc, argv);
3570 else if (!strcmp(cmd, "memdump"))
3571 rc = memdump(argc, argv);
3572 else if (!strcmp(cmd, "tcb"))
3573 rc = read_tcb(argc, argv);
3574 else if (!strcmp(cmd, "i2c"))
3575 rc = read_i2c(argc, argv);
3576 else if (!strcmp(cmd, "clearstats"))
3577 rc = clearstats(argc, argv);
3578 else if (!strcmp(cmd, "tracer"))
3579 rc = tracer_cmd(argc, argv);
3580 else if (!strcmp(cmd, "modinfo"))
3581 rc = modinfo(argc, argv);
3582 else if (!strcmp(cmd, "sched-class"))
3583 rc = sched_class(argc, argv);
3584 else if (!strcmp(cmd, "sched-queue"))
3585 rc = sched_queue(argc, argv);
3586 else if (!strcmp(cmd, "loadcfg"))
3587 rc = loadcfg(argc, argv);
3588 else if (!strcmp(cmd, "loadboot"))
3589 rc = loadboot(argc, argv);
3590 else if (!strcmp(cmd, "loadboot-cfg"))
3591 rc = loadbootcfg(argc, argv);
3592 else if (!strcmp(cmd, "dumpstate"))
3593 rc = dumpstate(argc, argv);
3594 else if (!strcmp(cmd, "policy"))
3595 rc = load_offload_policy(argc, argv);
3596 else if (!strcmp(cmd, "hashfilter"))
3597 rc = filter_cmd(argc, argv, 1);
3598 else if (!strcmp(cmd, "clip"))
3599 rc = clip_cmd(argc, argv);
3602 warnx("invalid command \"%s\"", cmd);
3613 char buffer[128], *buf;
3614 const char *args[MAX_ARGS + 1];
3617 * Simple loop: displays a "> " prompt and processes any input as a
3618 * cxgbetool command. You're supposed to enter only the part after
3619 * "cxgbetool t4nexX". Use "quit" or "exit" to exit.
3622 fprintf(stdout, "> ");
3624 buf = fgets(buffer, sizeof(buffer), stdin);
3626 if (ferror(stdin)) {
3627 warn("stdin error");
3628 rc = errno; /* errno from fgets */
3634 while ((args[i] = strsep(&buf, " \t\n")) != NULL) {
3635 if (args[i][0] != 0 && ++i == MAX_ARGS)
3641 continue; /* skip empty line */
3643 if (!strcmp(args[0], "quit") || !strcmp(args[0], "exit"))
3646 rc = run_cmd(i, args);
3649 /* rc normally comes from the last command (not including quit/exit) */
3654 parse_nexus_name(const char *s)
3658 if (sscanf(s, "t%unex%u%c", &chip_id, &inst, &junk) != 2)
3659 errx(EINVAL, "invalid nexus \"%s\"", s);
3664 main(int argc, const char *argv[])
3671 if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
3682 parse_nexus_name(argv[1]);
3684 /* progname and nexus */
3688 if (argc == 1 && !strcmp(argv[0], "stdio"))
3689 rc = run_cmd_loop();
3691 rc = run_cmd(argc, argv);